On 2011-05-13 17:46, Nathalie Conte wrote:

ATGGATAGATA\n
I want to calculate the AT ratio of each base based on their position
(3/4) for the 1st position, 3/4 on the second, (0/4) on the 3rd...

perl -MData::Dumper -wle '
  my %pos;
  my $s = $ARGV[0];
  push @{ $pos{ substr $s, $_, 2  } }, $_ for 0 .. length($s) - 2;
  print Dumper \%pos;
' ATGGATAGATA

$VAR1 = {
          'AG' => [
                    '6'
                  ],
          'GA' => [
                    '3',
                    '7'
                  ],
          'TG' => [
                    '1'
                  ],
          'GG' => [
                    '2'
                  ],
          'AT' => [
                    '0',
                    '4',
                    '8'
                  ],
          'TA' => [
                    '5',
                    '9'
                  ]
        };

--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to