Some (many?) versions of grep, such as the "standard" version included in Linux distributions, take the option "-P" meaning "interpret regex as a Perl regex". So if Perl can do it, so can grep.
Extracting Sequences After "Motif" & Between Motifs In Multifasta File
Hi I want to extract sequences after a motif say "TTTTTAAAAA" from a multifasta file. I do not want the nucleotides before this keyword. Is it possible to extract nucleotides between 2 motifs with grep? eg. nucleotides between TTTTTAAAA & AAAATTTT. I tried with grep but I need the fasta headers also. Can anybody suggest a solution in grep (if possible) or perl or python.
thanx raghul
• 5,037 views
•
link
2 answers
I don't think it would be possible with grep but this can be done w/a regex in perl. Something along the lines of:
$line = "";
foreach(<FILE>) { #for every line of the file
chomp;
if($_[0] == ">") { #if line starts with >, it is a header so process the previous sequence
if($line =~ /[TTTTTAAAAA([ACTGN]+)AAAATTTT/g) { #regex to match motif
print "$1\n" #print sequence in between motif
}
$line = ""
print "$_"; #print header
}
else {
$line = $line.$_ #append sequence
}
}
if($line =~ /[ACTGN]*TTTTTAAAAA([ACTGN]+)AAAATTTT/g) {
print "$1\n"
}
or something like that, (warning above code is untested and should be treated as pseudocode)
• 39 views
•
link
• 0 views
•
link
grep way
echo NNNTTTTTAAAACCCAAAATTTTNNN > sequence
grep -o TTTTTAAAA[A-Z]*AAAATTTT sequence
TTTTTAAAACCCAAAATTTT
• 99 views
•
link
Log in to answer this question.
You can get a case with the motif found several times within a same sequence. How do you want to deal with that?
Hello!, I would like to do something similar...did you find a way to complete your task?