This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Find motif and cut adjacent bases

Dear All,

how can I find a motif in a sequence and cut X number of adjacent bases ahead and X number after the motif.

As example (motif AAATTT; 10 adjacent bases ahead and after):

> cgtcgtcgtcgtagctgtaaatttacgatcgtagctagctagtcgat

to get the fasta:

tcgtagctgtaaatttacgatcgtag

Much appreciated, thank you.

motif adjacent regions

1 answer

 echo "cgtcgtcgtcgtagctgtaaatttacgatcgtagctagctagtcgat" | grep -iEo '[atgc]{1,10}AAATTT[atgc]{1,10}' 
tcgtagctgtaaatttacgatcgtag

thanks! and if I have a fasta file with multiple sequences as input?

loop over? how can I run the command on a file input with 10000 fasta sequences?

Log in to answer this question.