How to find a specific sequence pattern in a fasta file?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to find a specific sequence pattern in a fasta file?
# 1  
Old 11-29-2019
How to find a specific sequence pattern in a fasta file?

I have to mine the following sequence pattern from a large fasta file namely gene.fasta (contains multiple fasta sequences) along with the flanking sequences of 5 bases at starting position and ending position,
Code:
AAGCZ-N16-AAGCZ
Z represents A, C or G (Except T)
N16 represents any of the four bases including A, T, G or C and these four base combination should have the length of 16 bases.

I have a fasta file as follows,
gene.fasta
Code:
>dox
ATGCTATGATAGTAGTAGATAGAGAGAGAGATAGATAGAGAGATAGATAG
>cyclin
ATGAGATAGAAAGCCATAGATAGTAGTAGATAAGCATATAGATAGATAGTAGTGATA
>fyl
TAGTAGTAGATAGATAGATGCGTACTGCTGATGATAGATGATAGATAGATAGATTAGAT
>tubulin
TAGATAGAAAGCAATAGATAGAACAAGATAAGCCTAGTCGTAGATGATAGATAG

The expected output should be like this,
Code:
>org1_1
ATAGAAAGCCATAGATAGTAGTAGATAAGCATATAG
>org1_2
ATAGAAAGCAATAGATAGAACAAGATAAGCCTAGTC

In order to mine the above mentioned pattern, I have used grep command but, I do not know how to specify only 3 bases for Z and also I could not specify N16 criteria in the grep command line. In addition to this, I do not know how to mine the 5 of the flanking bases along with the pattern. So kindly help me in this regard.
Thank you in advance.

Last edited by dineshkumarsrk; 11-29-2019 at 07:15 AM..
# 2  
Old 11-29-2019
How about (given there are only A, C, G, T in the fasta sequences, so no test for other chars needed)
Code:
grep -oE ".{5}AAGC[^T].{16}AAGC[^T].{5}" file
ATAGAAAGCCATAGATAGTAGTAGATAAGCATATAG
ATAGAAAGCAATAGATAGAACAAGATAAGCCTAGTC

This User Gave Thanks to RudiC For This Post:
# 3  
Old 11-29-2019
If you also want to print the >id then you can do it with perl:
Code:
perl -ne '/^>.*/ and $id=$&; /.{5}AAGC[^T].{16}AAGC[^T].{5}/ and printf "%s\n%s\n",$id,$&' gene.fasta

This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 11-29-2019
Can it occur only once per sequence? If not what should happen with multiple matches per sequence?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

2. Shell Programming and Scripting

Count and search by sequence in multiple fasta file

Hello, I have 10 fasta files with sequenced reads information with read sizes from 15 - 35 . I have combined the reads and collapsed in to unique reads and filtered for sizes 18 - 26 bp long unique reads. Now i wanted to count each unique read appearance in all the fasta files and make a table... (5 Replies)
Discussion started by: empyrean
5 Replies

3. Shell Programming and Scripting

Extract sequence from fasta file

Hi, I want to match the sequence id (sub-string of line starting with '>' and extract the information upto next '>' line ). Please help . input > fefrwefrwef X900 AGAGGGAATTGG AGGGGCCTGGAG GGTTCTCTTC > fefrwefrwef X932 AGAGGGAATTGG AGGAGGTGGAG GGTTCTCTTC > fefrwefrwef X937... (2 Replies)
Discussion started by: ritakadm
2 Replies

4. Shell Programming and Scripting

How to find a file with a specific pattern for current sysdate & upon find email the details?

I need assistance with following requirement, I am new to Unix. I want to do the following task but stuck with file creation date(sysdate) Following is the requirement I need to create a script that will read the abc/xyz/klm folder and look for *.err files for that day’s date and then send an... (4 Replies)
Discussion started by: PreetArul
4 Replies

5. UNIX for Dummies Questions & Answers

Change sequence names in fasta file

I have fasta files with multiple sequences in each. I need to change the sequence name headers from: >accD:_59176-60699 ATGGAAAAGTGGAGGATTTATTCGTTTCAGAAGGAGTTCGAACGCA >atpA_(reverse_strand):_showing_revcomp_of_10525-12048 ATGGTAACCATTCAAGCCGACGAAATTAGTAATCTTATCCGGGAAC... (2 Replies)
Discussion started by: tyrianthinae
2 Replies

6. UNIX for Dummies Questions & Answers

How to change sequence name in along fasta file?

Hi I have an alignment file (.fasta) with ~80 sequences. They look like this- >JV101.contig00066(+):25302-42404|sequence_index=0|block_index=4|species=JV101|JV101_4_0 GAGGTTAATTATCGATAACGTTTAATTAAAGTGTTTAGGTGTCATAATTT TAAATGACGATTTCTCATTACCATACACCTAAATTATCATCAATCTGAAT... (2 Replies)
Discussion started by: baika
2 Replies

7. UNIX for Dummies Questions & Answers

Find & Replace command - Fasta file

Hi all ! I have a fasta file that looks like that: >Sequence1 RTYIPLCASQHKLCPITFLAVK (it's just an example, obviously in reality I have several pairs of lines like that) Using UNIX command(s), would it be possible to replace all the characters except the "C" of the second line only by... (7 Replies)
Discussion started by: Cevin21
7 Replies

8. Shell Programming and Scripting

Parsing a fasta sequence with start and end coordinates

Hi.. I have a seperate chromosome sequences and i wanted to parse some regions of chromosome based on start site and end site.. how can i achieve this? For Example Chr 1 is in following format I need regions from 2 - 10 should give me AATTCCAAA and in a similar way 15- 25 should give... (8 Replies)
Discussion started by: empyrean
8 Replies

9. UNIX for Dummies Questions & Answers

cmd sequence to find & cut out a specific string

A developer of mine has this requirement - I couldn't tell her quickly how to do it with UNIX commands or a quick script so she's writing a quick program to do it - but that got my curiousity up and thought I'd ask here for advice. In a text file, there are some records (about half of them)... (4 Replies)
Discussion started by: LisaS
4 Replies
Login or Register to Ask a Question