zuepinhel has asked for the wisdom of the Perl Monks concerning the following question:
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"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Problem computing GC content
by AppleFritter (Vicar) on Jul 13, 2014 at 17:37 UTC | |
by zuepinhel (Initiate) on Jul 13, 2014 at 17:46 UTC | |
by AppleFritter (Vicar) on Jul 13, 2014 at 18:02 UTC | |
by zuepinhel (Initiate) on Jul 13, 2014 at 18:13 UTC | |
by AppleFritter (Vicar) on Jul 13, 2014 at 18:16 UTC | |
| |
by Bethany (Scribe) on Jul 13, 2014 at 18:10 UTC | |
by zuepinhel (Initiate) on Jul 13, 2014 at 18:19 UTC | |
by AnomalousMonk (Archbishop) on Jul 13, 2014 at 20:30 UTC | |
by Bethany (Scribe) on Jul 13, 2014 at 18:51 UTC | |
Re: Problem computing GC content
by AnomalousMonk (Archbishop) on Jul 13, 2014 at 20:57 UTC | |
by zuepinhel (Initiate) on Jul 13, 2014 at 21:18 UTC | |
by AnomalousMonk (Archbishop) on Jul 13, 2014 at 23:30 UTC | |
by ww (Archbishop) on Jul 13, 2014 at 22:51 UTC | |
Re: Problem computing GC content
by Kenosis (Priest) on Jul 14, 2014 at 17:03 UTC |