Answers.Body: <pre><code>echo "&gt;ATGCTTATTGCCCATTTCGTGCATGCATATGCGCATTCGCGATCGATTAGGGATAT" | grep -oP  'TTCG[CGT][ATGC]{1,15}TTCG[CGT]'
  </code></pre>
  
  <ul>
  <li><code>[CGT]</code> looks for one occurrence of one of the three.</li>
  <li><code>[ATGC]{1,15}</code> looks for "up to 15 letter long" combinations of the four bases.</li>
  </ul>
  
  <p>Moreover, <code>-P</code> makes your regex call <code>Perl-like</code> and is required to make this regex work. Different regex flavors behave (slightly) differently.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-05T11:48:35.327Z
Answers.Text: 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
  `
Answers.UserDisplayName: Kumar
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-05T11:50:09.993Z
Answers.Text: 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.
Answers.UserDisplayName: Kumar
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-05T11:55:38.287Z
Answers.Text: 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.
Answers.UserDisplayName: haci
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-05T13:01:59.803Z
Answers.Text: 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.
Answers.UserDisplayName: Timur Shtatland
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-05T13:45:12.150Z
Answers.Text: @haci N15 means any of the 4 bases, but N15 length should be 15. exactly, The output should be like this, `TTCGB-ATGCTAGCATGATAG-TTCGB`. The output sequence should have `TTCGB` at both ends, at the same time in between `TTCGB` 15 bases also should be there. That 15 bases can be the combination of any of the four bases, but it should have 15 bases. Sorry, if my question is not clear.
Answers.UserDisplayName: Kumar
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-05T13:50:09.543Z
Answers.Text: 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".
Answers.UserDisplayName: haci
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-05T13:57:41.377Z
Answers.Text: @haci I did it `echo $(<org15.fasta) | grep -oP 'TTCG[CGT][ATGCN]{15}TTCG[CGT]'`. It works, thank you so much @haci and @Timur Shtatland.
Answers.UserDisplayName: Kumar
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-05T11:09:23.707Z
Answers.LastActivityDate: 2019-11-05T11:15:26.517Z
Answers.LastEditDate: 2019-11-05T11:15:26.517Z
Answers.UserDisplayName: haci
Body: <p>I need to find the following pattern from a genomic sequence</p>
  
  <pre><code>TTCGB-N15-TTCGB
  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.
  </code></pre>
  
  <p>To do the same, I tried <code>grep</code> command, but I could not specify <code>B</code> and <code>N15</code> in the <code>grep</code> command line. Therefore, please help me to find the same.</p>
  
  <p>For example, I have a nucleotide sequences as follows</p>
  
  <pre><code>&gt;ATGCTTATTGCCCATTTCGTGCATGCATATGCGCATTCGCGATCGATTAGGGATAT
  </code></pre>
  
  <p>Expected outcome,</p>
  
  <blockquote>
    <p>TTCGTGCATGCATATGCGCATTCGC</p>
  </blockquote>
  
  <p>Thanks in advance.  </p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-05T23:00:59.633Z
Comments.Text: Could you please update your question to clarify that N15 represents A, T, G or C for *exactly* 15 bases?
Comments.UserDisplayName: gringer
Tags: <r><python><bash><perl><shell>
Title: Pattern mining from a genomic sequence
ThreadText: # Pattern mining from a genomic sequence
  
  (Asked by: username_0 on 2019-11-05)
  
  I need to find the following pattern from a genomic sequence
  
  ```
  TTCGB-N15-TTCGB
  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
  
  ```
  >ATGCTTATTGCCCATTTCGTGCATGCATATGCGCATTCGCGATCGATTAGGGATAT
  
  ```
  
  Expected outcome,
  
  > TTCGTGCATGCATATGCGCATTCGC
  
  Thanks in advance.
  
  **Tags:** r, python, bash, perl, shell
  
  > **Comments:**
  > **username_1**: Could you please update your question to clarify that N15 represents A, T, G or C for *exactly* 15 bases?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-11-05. Score: 4 | Accepted answer
  
  ```
  echo ">ATGCTTATTGCCCATTTCGTGCATGCATATGCGCATTCGCGATCGATTAGGGATAT" | grep -oP  'TTCG[CGT][ATGC]{1,15}TTCG[CGT]'
  
  ```
  
  * `[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.
  
  > **Comments:**
  > **username_0**: Dear @username_2,                                                                                                                       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 `  
  > **username_0**: 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.  
  > **username_2**: 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.  
  > **username_3**: 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.  
  > **username_0**: @username_2 N15 means any of the 4 bases, but N15 length should be 15. exactly, The output should be like this, `TTCGB-ATGCTAGCATGATAG-TTCGB`. The output sequence should have `TTCGB` at both ends, at the same time in between `TTCGB` 15 bases also should be there. That 15 bases can be the combination of any of the four bases, but it should have 15 bases. Sorry, if my question is not clear.  
  > **username_2**: OK, then just change `[ATGC]{1,15}` to `[ATGC]{15}` as username_3 suggested. The reason for `[ATGC]{1,15}` was your phrase in the question: "N represents A, T, G or C up to 15 bases".  
  > **username_0**: @username_2 I did it `echo $(<org15.fasta) | grep -oP 'TTCG[CGT][ATGCN]{15}TTCG[CGT]'`. It works, thank you so much @username_2 and @username_3.  
  
  ---
  
  