I need to find the following pattern from a genomic sequence

B represents C, G, or T
N15 represents A, T, G or C and these four base combination should have the length of 15 bases.

To do the same, I tried grep command, but I could not specify B and N15 in the grep command line. Therefore, please help me to find the same.

For example, I have a nucleotide sequences as follows


Expected outcome,


Thanks in advance.

  • 1
    $\begingroup$ Could you please update your question to clarify that N15 represents A, T, G or C for exactly 15 bases? $\endgroup$
    – gringer
    Nov 5, 2019 at 23:00

1 Answer 1

  • [CGT] looks for one occurrence of one of the three.
  • [ATGC]{1,15} looks for "up to 15 letter long" combinations of the four bases.

Moreover, -P makes your regex call Perl-like and is required to make this regex work. Different regex flavors behave (slightly) differently.

  • $\begingroup$ Dear @haci, I have followed your command line for the test data (I had given in the example section of my question), which gives proper result. But when I tried the same with my genome file with the following command, echo $(<org15.fasta) | grep -oP 'TTCG[CGT][ATGC]{1,15}TTCG[CGT]' and I am getting output as follows, TTCGCCGCGGCGACGTTTTCGC TTCGCATTCGG TTCGCCACCTTGTTCGG TTCGGCTTTCGC TTCGTGGCCTTCGG TTCGGCTTCTTCGT TTCGTCAAGGACCCGATTTCGG TTCGCATCTTCGC $\endgroup$
    – Kumar
    Nov 5, 2019 at 11:48
  • $\begingroup$ The thing is that, the script mining TTCGB.....TTCGB, but fails to fulfil the length N15 criteria. kindly help me to fix this. Thank you. $\endgroup$
    – Kumar
    Nov 5, 2019 at 11:50
  • $\begingroup$ What is your "N15 criteria" though? [ATGC]{1,15} looks for up to 15 repetitions of the four bases as you specified in your question. And as far as I can see in the output you get, this is what you are getting, 2 TTCGB stretches are connected by up to 15 bases. $\endgroup$
    – haci
    Nov 5, 2019 at 11:55
  • 2
    $\begingroup$ N15 usually means exactly 15 of any nucleotides. So use [ACGTN]{15} . Also, -i flag for grep may need to be added if some of the sequence is lower case, for example repeat masked. $\endgroup$ Nov 5, 2019 at 13:01
  • 2
    $\begingroup$ OK, then just change [ATGC]{1,15} to [ATGC]{15} as Timur Shtatland suggested. The reason for [ATGC]{1,15} was your phrase in the question: "N represents A, T, G or C up to 15 bases". $\endgroup$
    – haci
    Nov 5, 2019 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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