This is a test version of Biostars. For the public version, visit https://www.biostars.org.
cutadapt and vsearch script to process a set of files

Hi all,I have already looked up for similar questions but I did not find what I am looking for. I have two questions:

1.I want to trim the primers for 12 fastq files and I am using this loop

for i in $(ls):; do cutadapt -a TCCTCCGCTTATTGATAGC -o ${i}trimmed.fastq ${i}; done

but the outfile name that I get is e.g C1P1.fastqtrimmed.fastq, how do I write the script in the way that I get C1P1_trimmed.fastq as the output file name?

  1. I would like to do the same thing with vsearch, so process a number of files in one time. I use

    for i in *$(ls):; do vsearch --rereplicate ${i} --relabel ${i}seq --output ${i}.fasta; done

but I would like to use these comands just for some fasta files in the directory not all the files of the directory. thanks a lot in advance.

next-gen

1 answer

just for some fasta files

Are you able to selectively list the files with ls? If so that command could be substituted in place of ls in the loop above.

Change -o ${i}trimmed.fastq to -o ${i}\_trimmed.fastq to get C1P1_trimmed.fastq type names.

thanks a lot for your answer! no, I am not able, I tried few things but I did not get it right.. Could you tell me how is it done? thank you so much for your help!

Without knowing your file names/what exactly you want to select it would be difficult. Look at this page to see if you are able to identify a pattern that works for you with ls.

Thanks, i will look at it!

I changed the -o ${i}_trimmed.fastq but I still get C1P1.fastq_trimmed.fastq instead of C1P1_trimmed.fastq...

Ah I see. Replace ls with ls | sed 's/.fastq//'. Your command would become

for i in $(ls | sed 's/.fastq//'); do cutadapt -a TCCTCCGCTTATTGATAGC -o ${i}\_trimmed.fastq ${i}.fastq; done

it worked! great, thanks a lot!

Log in to answer this question.