1

have been mocking around with this too long and tried grep, join, awk but I cant get the parameters right. I need to get the command right.

I have got two text files.

cat file1

@ABC:11:ABC:1:1111:1111:1111
@ABC:22:ABC:1:1111:4444:4444


cat file2

@ABC:11:ABC:1:1111:1111:1111 1:N:0:TCCCGCGC+AGGCGGGG
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
#FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
@ABC:11:ABC:1:1111:2222:2222 1:N:0:TCCCGCGC+AGGCGGGG
AGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGG
+
#FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
@ABC:22:ABC:1:1111:3333:3333 1:N:0:TCCCGCGC+AGGCGGGG
AGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGG
+
#FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
@ABC:22:ABC:1:1111:4444:4444 1:N:0:TCCCGCGC+AGGCGGGG
TTTTTTTTTTTTTGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTGGGGGGGGGGGGGGGGGGGG
+
#FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


I would like to do the two things:

output 1) Based on file1, extract all rows that contain the strings plus two additional string.
output 2) Based on file1, extract all rows that do not contain the strings plus two additional rows - but it should only try to match lines that start with @..



Example output 1):

cat output1

@ABC:11:ABC:1:1111:1111:1111 1:N:0:TCCCGCGC+AGGCGGGG
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
#FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
@ABC:22:ABC:1:1111:4444:4444 1:N:0:TCCCGCGC+AGGCGGGG
TTTTTTTTTTTTTGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTGGGGGGGGGGGGGGGGGGGG
+
#FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


Example output 2)

cat output2

@ABC:11:ABC:1:1111:2222:2222 1:N:0:TCCCGCGC+AGGCGGGG
AGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGG
+
#FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
@ABC:22:ABC:1:1111:3333:3333 1:N:0:TCCCGCGC+AGGCGGGG
AGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGGAGGCGGGG
+
#FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF



(no perl please )

0

What you are showing and asking for is to grep a given set of reads in a fastq file. I strongly recommend not to reinvent the wheel and use existing tools like seqkit grep for it.

Nevertheless here the "bash-only" variant:

4 consecutive lines belong to one read. So we can put them all in one line, delimited by tabs, grep for the ids and transform back the tabs to new lines.

$ cat file2.fq|paste - - - -|grep -f file1.txt|tr "\t" "\n"

Or for your second output we just use the invert parameter for grep

$ cat file2.fq|paste - - - -|grep -v -f file1.txt|tr "\t" "\n
  • Thanks, thats great. The paste - - - - did the trick. Very nice. Did not know seqkit, but it looks very useful. – Pat Feb 5 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.