This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Trimming Fastq File Based On First Nucleotide

Hi all,

I have several fastq files and they are biased at the first sequenced base, which is a in too many reads a G. So what I would like is a simple script that removes the first base when it is a G in all reads from the fastq file. Is this possible?

Thanks

fastq trimming

1 answer

See the "HEADCROP" option for trimmomatic as one (of likely very very many) methods.

Edit: Since you only wanted 1-base cropping if the first base is a G, then something like the following should work:

zcat something.fastq.gz | awk '{if(NR%4==2) { if(substr($1, 1, 1) == "G") { print substr($1,2); getline; print $1; getline; print substr($1,2)} else {print $1; getline; print $1; getline; print $1}} else { print $1}}' | gzip > something.trimmed.fastq.gz

Thanks for your reply. But as far as I understand this removes all the first bases and I want that only the first G will be removed but when there is an A, C or T it can stay.

Ah, that was unclear to me. I've updated by answer with an example of how to do that with awk.

Yes perfect! thanks a lot!

Log in to answer this question.