This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Getting sequences from fastq file using Grep command

I have been trying to get a sequence (e.g. GCGAGCCCCACATCGCCCCCCCGATTGTAATAAATAA) from a fastq file (file.fastq) I have and output a fq file. I have tried the command:

grep -A 2 -B 1 'GCGAGCCCCACATCGCCCCCCCGATTGTAATAAATAA' file.fastq | sed '/--/d' > output.fq

I got an output as 6- lines of reads that are different, while my target sequence is basically more in number. A part from that they might be just not there, Are the - A and - B is getting only the upstream and trailing sequences surroundng my target or do they get these along with the target sequences. I red the -- help page, but could not understand it. Thanks for any help.

linux

Are you confident this sequence will only appear once?

Actually it is much longer I only gives example...

let's try another way. Show us the output of:

cat file.fastq | paste - - - - | grep -F GCGAGCCCCACATCGCCCCCCCGATTGTAATAAATAA 

Could you let me know what paste is doing ?

Thanks

Converting to a single line

3 answers

Use bbduk.sh from BBMap suite in filter mode. grep has its place but a proper tool is foolproof.

bbduk.sh -Xmx2g in=your.fq outm=filtered.fq literal=GCGAGCCCCACATCGCCCCCCCGATTGTAATAAATAA

Add rcomp=f if you don't want to find reverse complemented sequence.

Try seqkit grep, which searches on both strands, you might need to add --only-positive-strand.

seqkit grep -s -p GCGAGCCCCACATCGCCCCCCCGATTGTAATAAATAA file.fastq -o out.fq.gz

If things aren't working the way you think they should, go simpler to troubleshoot. Do

grep 'GCGAGCCCCACATCGCCCCCCCGATTGTAATAAATAA' file.fastq  | wc -l

Do you get more than 6 lines?

(Is your fastq really unzipped?)

It is actually unzipped and it gave me 6-lines when running your line

Then that exact sequence is only in there 6 times.

Log in to answer this question.