1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #!/usr/bin/perl
use strict;
use warnings;
use List::MoreUtils qw(pairwise);
my @nucleotides_array = qw(T C T C A C T C T C G A C T G A C T G A C G A C T G);
my @values_array = qw(1.83 1.98 1.60 0.51 1.93 3.65 1.74 0.36 0.30 0.38 1.81 0.45 0.54 1.70 1.77 0.28 1.83 1.51 1.73 1.83 0.37 1.57 0.31 1.74 0.52 0.39);
my @unic_array = qw(1.51 1.57 1.6 1.7 1.73 1.74 1.74 1.77 1.81 1.83 1.83 1.83 1.93 1.98);
# Get unique values (and the number of occurence for each one)
my %unic_array;
$unic_array{$_}++ foreach @unic_array;
# Sort all nucleotides with their corresponding values
my @nucleotides = sort { $a->[0] <=> $b->[0] } pairwise { [ $a => $b ] } @values_array, @nucleotides_array;
# Count the number of nucleotide in the unic array
my %count;
$count{$_}++ foreach map {
my $unic = $_;
my @nucl = grep $_->[0] == $unic, @nucleotides;
warn "Number of nucleotide in nucleotide array is greater than in the unic array for value $_\n"
if @nucl != $unic_array{$unic};
map $_->[1], @nucl[0..$unic_array{$unic}-1]
} keys %unic_array;
print "$_: $count{$_}\n" foreach keys %count;
my %repart;
foreach my $unic (keys %unic_array) {
my @nucl = grep $_->[0] == $unic, @nucleotides;
warn "Number of nucleotide in nucleotide array is greater than in the unic array for value $_\n"
if @nucl != $unic_array{$unic};
push @{$repart{$_->[1]}}, $_->[0] foreach @nucl[0..$unic_array{$unic}-1]
};
print "$_: ", (join ", ", @{$repart{$_}}), "\n" foreach keys %repart; |