Dear Perl Guru:

I want to write a script which takes input a text file with sequence of alphabets (amino acids) like GAGAGAGAGAAAAGA etc. and converts them to a three letter corresponding code [G= GLY, A= ALA]. The output should be then written to another file. I wrote the following script, but it seems it goes in an infinite loop and only prints GLY GLY GLY....infinitely for an input of GAAAGAGAAGA etc. Any suggestions? Thanks in advance
-Vineet

****************************************
#!/usr/bin/perl
use warnings;

my $fasta_file = "fasta.txt"; #this contains single letter code#
chomp $fasta_file;
my $charmm_file = "charmm.txt"; #this is expected to have three letter converted#
unless (open (IN, $fasta_file) )
{
print "Cannot open file \"fasta_file\"\n\n";
exit;
}

open OUT, ">$charmm_file" or die;
@protein = <IN>;
close IN;
$protein = join( '', @protein);
$protein =~ s/\s//g;

for ( $position=0; $position < length $protein; ++$protein )

{
$aa = substr($protein, $position, 1);


                   if ($aa eq 'G') {
                           $praa = "GLY ";
                           print OUT $praa;
                                   }
                elsif ($aa eq 'A') {
                           $prab = "ALA ";
                           print OUT $prab;
                                   }
                else {
                        exit;
                     }
                      }

                      close OUT;

**********************************************

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to