I have written the following script to search for a motif(substring) in a protein sequences(strings). I am beginner and writing this has been tough for me. I have two questions regarding the same: 1. Errors: The following script has few errors. I have been at it for quite sometime now but have not figured out what and why? 2. The following script has been written to search for one motif(substring) in protein sequences(strings). My next task involves searching for multiple motifs in a specific order (ex: motif1 motif2 motif 3 motif4 this order cannot be changed) in the same protein sequences(strings)
use strict;
use warnings;
my @file_data=();
my $motif ='';
my $protein_seq='';
my $h= '[VLIM]';
my $s= '[AG]';
my $x= '[ARNDCEQGHILKMFPSTWYV]';
my $regexp = "($h){4}D($x){4}D"; #motif to be searched is hhhhDxxxxD
my @locations=();
@file_data= get_file_data("seq.txt");
$protein_seq= extract_sequence(@file_data);
#searching for a motif hhhhDxxxxD in each protein sequence in the give file
foreach my $line(@file_data){
if ($motif=~ /$regexp/){
print "found motif \n\n";
}
else {
print "not found \n\n";
}
}
#recording the location/position of motif to be outputed
@locations= match_position($regexp,$seq);
if (@locations){
print "Searching for motifs $regexp \n";
print "Catalytic site is at location:\n";
}
else{
print "motif not found \n\n";
}
exit;
sub get_file_data{
my ($filename)=@_;
use strict;
use warnings;
my $sequence='';
foreach my $line(@file_data){
if ($line=~ /^\s*$/){
next;
}
elsif ($line=~ /^\s*#/){
next;
}
elsif ($line=~ /^>/){
next;
}
else {
$sequence.=$line;
}
}
$sequence=~ s/\s//g;
return $sequence;
}
sub(match_positions) {
my ($regexp, $sequence)=@_;
use strict;
my @position=();
while ($sequence=~ /$regexp/ig){
push (@position, $-[0]);
}
return @position;
}