Answers.Body: <p>Assuming your sequences are always on a single line</p>
  <pre><code>grep -B 1 &quot;^TA&quot; seqences.fasta | grep -v &quot;\-\-&quot; &gt; filtered_seqences.fasta
  </code></pre>
  <p>should do the job. Argument <code>-B</code> specifies how many lines before the pattern match should be printed. But there grep separates individual entries with <code>--</code> that's why I used a second grep to get rid of those.</p>
  <p>Ha, apparently there is an undocumented <code>--no-group-separator</code> flag, so this should do as well</p>
  <pre><code>grep -B 1 &quot;^TA&quot; seqences.fasta --no-group-separator &gt; filtered_seqences.fasta
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-16T16:08:48.130Z
Answers.Text: GNU grep actually has an undocumented argument `--no-group-separator` that can do the trick too.
Answers.UserDisplayName: Jesse
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-16T08:23:57.833Z
Answers.LastActivityDate: 2020-09-16T17:02:27.253Z
Answers.LastEditDate: 2020-09-16T17:02:27.253Z
Answers.UserDisplayName: Kamil S Jaron
Answers.Body: <p><a href="https://github.com/fhcrc/seqmagick" rel="nofollow noreferrer">seqmagick</a> has a handy <code>--seq-pattern-include</code> feature that works similarly to what Kamil did with a regular grep.</p>
  <pre><code>$ cat sequences.fasta 
  &gt;chr8:106028475-106028517()
  GTaccaggcctagggttgcactcctgtagtctcagcattggg
  &gt;chr8:106040430-106040472()
  TAACCGGCTCTCCGCTGCCCTCATCTGTCTAGAATTCAGGTA
  &gt;chr9:100245605-100245648()
  TACCACCTCCCTCACTCTTTCCCAAATTTATGAGTTAGGCTAT
  
  $ seqmagick convert --seq-pattern-include &quot;^TA&quot; sequences.fasta -
  &gt;chr8:106040430-106040472()
  TAACCGGCTCTCCGCTGCCCTCATCTGTCTAGAATTCAGGTA
  &gt;chr9:100245605-100245648()
  TACCACCTCCCTCACTCTTTCCCAAATTTATGAGTTAGGCTAT
  </code></pre>
  <p>It's a great little tool for this sort of thing built around Biopython, though it's been falling behind in compatibility with the latest versions as you can see from some of the open GitHub issues.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-16T16:13:42.460Z
Answers.LastActivityDate: 2020-09-16T16:13:42.460Z
Answers.UserDisplayName: Jesse
Body: <p>I have a fasta file and the sequences in them are arranged like this:</p>
  <pre><code>&gt;chr8:106028475-106028517()
  GTaccaggcctagggttgcactcctgtagtctcagcattggg
  &gt;chr8:106040430-106040472()
  TAACCGGCTCTCCGCTGCCCTCATCTGTCTAGAATTCAGGTA
  &gt;chr9:100245605-100245648()
  TACCACCTCCCTCACTCTTTCCCAAATTTATGAGTTAGGCTAT
  </code></pre>
  <p>I want to extract only those which begin with TA. so my final output should look like</p>
  <pre><code>&gt;chr8:106040430-106040472()
  TAACCGGCTCTCCGCTGCCCTCATCTGTCTAGAATTCAGGTA
  &gt;chr9:100245605-100245648()
  TACCACCTCCCTCACTCTTTCCCAAATTTATGAGTTAGGCTAT
  </code></pre>
  <p>Kindly help.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-09-15T14:23:09.520Z
Comments.Text: Hi. People won't write your code for your (especially as a bit of googling leads to some very simple one-liners which do what you need), but they will help you if you show what code you have already tried to write. Thanks.
Comments.UserDisplayName: user438383
Tags: <fasta><sequence>
Title: get sequences begining with TA
ThreadText: # get sequences begining with TA
  
  (Asked by: username_0 on 2020-09-15)
  
  I have a fasta file and the sequences in them are arranged like this:
  
  ```
  >chr8:106028475-106028517()
  GTaccaggcctagggttgcactcctgtagtctcagcattggg
  >chr8:106040430-106040472()
  TAACCGGCTCTCCGCTGCCCTCATCTGTCTAGAATTCAGGTA
  >chr9:100245605-100245648()
  TACCACCTCCCTCACTCTTTCCCAAATTTATGAGTTAGGCTAT
  
  ```
  
  I want to extract only those which begin with TA. so my final output should look like
  
  ```
  >chr8:106040430-106040472()
  TAACCGGCTCTCCGCTGCCCTCATCTGTCTAGAATTCAGGTA
  >chr9:100245605-100245648()
  TACCACCTCCCTCACTCTTTCCCAAATTTATGAGTTAGGCTAT
  
  ```
  
  Kindly help.
  
  **Tags:** fasta, sequence
  
  > **Comments:**
  > **username_1**: Hi. People won't write your code for your (especially as a bit of googling leads to some very simple one-liners which do what you need), but they will help you if you show what code you have already tried to write. Thanks.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2020-09-16. Score: 1
  
  [seqmagick](https://github.com/fhcrc/seqmagick) has a handy `--seq-pattern-include` feature that works similarly to what username_2 did with a regular grep.
  
  ```
  $ cat sequences.fasta 
  >chr8:106028475-106028517()
  GTaccaggcctagggttgcactcctgtagtctcagcattggg
  >chr8:106040430-106040472()
  TAACCGGCTCTCCGCTGCCCTCATCTGTCTAGAATTCAGGTA
  >chr9:100245605-100245648()
  TACCACCTCCCTCACTCTTTCCCAAATTTATGAGTTAGGCTAT
  
  $ seqmagick convert --seq-pattern-include "^TA" sequences.fasta -
  >chr8:106040430-106040472()
  TAACCGGCTCTCCGCTGCCCTCATCTGTCTAGAATTCAGGTA
  >chr9:100245605-100245648()
  TACCACCTCCCTCACTCTTTCCCAAATTTATGAGTTAGGCTAT
  
  ```
  
  It's a great little tool for this sort of thing built around Biopython, though it's been falling behind in compatibility with the latest versions as you can see from some of the open GitHub issues.
  
  
  ---
  
  ### Answer by username_2 on 2020-09-16. Score: 0
  
  Assuming your sequences are always on a single line
  
  ```
  grep -B 1 "^TA" seqences.fasta | grep -v "\-\-" > filtered_seqences.fasta
  
  ```
  
  should do the job. Argument `-B` specifies how many lines before the pattern match should be printed. But there grep separates individual entries with `--` that's why I used a second grep to get rid of those.
  
  Ha, apparently there is an undocumented `--no-group-separator` flag, so this should do as well
  
  ```
  grep -B 1 "^TA" seqences.fasta --no-group-separator > filtered_seqences.fasta
  
  ```
  
  > **Comments:**
  > **username_3**: GNU grep actually has an undocumented argument `--no-group-separator` that can do the trick too.  
  
  ---
  
  