in reply to Problem computing GC content

AppleFritter seems to have given you a good solution to the specific question you asked. However, I would suggest you become familiar with the string manipulation facilities of Perl.

Specifically for this problem, the tr operator would seem very useful. Please see its discussion via the tr link and in the Quote-Like Operators section of perlop.

c:\@Work\Perl>perl -wMstrict -le "my $sequence = 'xxxGCxxCxxxxCGxGxxxGxxxxxCxx'; ;; my $sequencelength = length $sequence; print qq{sequence length: $sequencelength}; ;; my $GCcount = $sequence =~ tr/GC//; print qq{total Gs and Cs: $GCcount}; ;; my $GCcontent = ($GCcount / $sequencelength) * 100; print qq{GCcontent: $GCcontent percent} " sequence length: 28 total Gs and Cs: 8 GCcontent: 28.5714285714286 percent

Replies are listed 'Best First'.
Re^2: Problem computing GC content
by zuepinhel (Initiate) on Jul 13, 2014 at 21:18 UTC

    But it doesn't solve the problem because it continues on computing just one sequence.

      It wasn't intended to solve "the problem". AppleFritter has already offered what seems an adequate solution to the problem — although I must admit that my understanding of the problem may be very defective.

      What I wanted to offer was an approach to solving a portion of the problem: quickly counting the number of 'G' and 'C' characters in a string. One very Perlish way to do something like this is by using the tr operator.


      Data! SHOW US THE DATA!


      Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
      1. code
      2. verbatim error and/or warning messages
      3. a coherent explanation of what "doesn't work actually means.

      check Ln42!