Grep search question
Hi,
I was wondering if I have 2 sequences of interest: A and B.
Is it possible to do a grep search for reads (in a fastq):
- that contain just sequence "A" and exclude "B" (and vice versa)
- that contain both sequence "A" and "B" together
if so, would someone be able to provide/refer me to the commands to do so?
Thank you so much!
• 1,152 views
•
link
1 answer
You can do it with:
# Grep sequences with A
grep $A file.fastq -B 1 -A 2 > hasA.fastq
# Grep B where A is found
grep $B hasA.fastq -B 1 -A 2 > hasAandB.fastq
# Remove lines in file 1 that are found in file 2
comm -23 hasA.fastq hasAandB.fastq > hasAnotB.fastq
Replace $A and $B with the sequences or set the value of the variables to the sequences you are searching.
• 0 views
•
link
Log in to answer this question.
Keep in mind that
grepwill only do perfect matches. You may want to use a NGS data specific tool likeseqkit greporbbduk.shin filter mode, if you want to allow for other cases than perfect matches.