Friday, November 9, 2012

Perl programming #4

Hi,
We started learning perl programs in our last post. For viewing previous posts, use the links ( perl #1 #2
 #3 )


Today I'm gonna give you a program for searching a specific amino acid in a protein sequence.You can easily understand the logic by yourself. Here we go,

Program for searching an amino acid in a protein sequence:


print "enter a protein file\n";
$proteinfile=<>;
chomp($proteinfile);
unless(open(PROTEINFILE,$proteinfile))
{
print "file not found\n";
exit;
}
$protein=<PROTEINFILE>;
$protein=join("",$protein);
$protein=~s/\s//g;
$protein=uc($protein);
print "The sequence is",$protein,"\n";
$a=A;
$position=0;
for($i=0;$i<length($protein);$i=$position+1)
{
$position=index($protein,$a,$i);
if($position=~-1)
{
last;
}
print $position+1,"\t";
}
print "- the position(s) in which alanine is found\n";
exit;

The output for the above program will be like this. Try executing! 


Happy programming! :) :) 

No comments:

Post a Comment