Hey guys! I'm new to Perl, and on my first assignment i've been developing a program to calculate the GC content of DNA sequences on a txt file. The file has +10 sequences and i'm only getting the result of the last one. Is there some problem with the loops ? The code is as follows. Thanks!
#!/usr/local/bin/perl open (FASTAFILE, 'human_fold_25.txt'); $sequence = ' '; $Ccount = 0; $Gcount = 0; $identifier = ' '; while ($line = <FASTAFILE>) { chomp $line; if ( $line =~ /^>/ ) { $identifier = $line; } elsif ( $line =~ /^\./ ) { next; } elsif ( $line =~ /^\(/ ) { }else { $sequence = $line; } } $sequencelength = length ($sequence); @nucleotides = split ( '' , $sequence ); foreach $nuc (@nucleotides) { if ( $nuc eq 'G') { $Gcount = $Gcount + 1; } elsif ( $nuc eq 'C') { $Ccount = $Ccount + 1; } } $GCcontent = ((( $Gcount + $Ccount )/ $sequencelength ) * 100); close (FASTAFILE); print "$identifier", ", ", "$GCcontent\n"
In reply to Problem computing GC content by zuepinhel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |