Today I learnt about -A. Thanks.
I have a file with a set of read ids called tmp. I want to extract reads with these read ids from another fastq file called reads.fastq. When I use grep -f tmp reads.fastq I get only the first line (header) of the read. How can I get the output in full fastq format.
3 answers
For bash, I would use a nice one-liner:
for x in $(cat tmp); do reads.fastq | grep $x -A 3; done
Of course you can redirect to wherever you want:
for x in $(cat tmp); do reads.fastq | grep $x -A 3; done > tmp2
I hope that this helps!
Brent Wilson, PhD | Project Scientist | Cofactor Genomics
4044 Clayton Ave. | St. Louis, MO 63110 | tel. 314.531.4647
Catch the latest from Cofactor on our blog.
For m desired reads out of a fastq file with n total reads, this takes O(mn) time, as opposed to the -f flag given to grep (or just using BBMap), which is likely O(n).
Log in to answer this question.