# get sequences begining with TA [closed]

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.

• 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. Sep 15 '20 at 14:23

seqmagick has a handy --seq-pattern-include feature that works similarly to what Kamil 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.

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

• GNU grep actually has an undocumented argument --no-group-separator that can do the trick too. Sep 16 '20 at 16:08