次の形式の入力データがあります(タブで区切られています):
(遺伝子条件値)
wnt condition1 1
wnt condition2 10
wnt condition3 15
wnt condition4 -1
bmp condition1 10
bmp condition2 inf
bmp condition3 12
bmp condition4 -1
frz condition1 -12
frz condition2 -6
frz condition3 -0.3
そして、次のようにHoHを構築しています:
#!/usr/bin/perl
use warnings;
use strict;
use File::Slurp;
use Data::Dumper;
my @data = read_file('stack.txt');
my %hash;
foreach (@data){
chomp;
my ($gene, $condition, $value) = (/^(\w+)\t(\w+\d)\t(-?\d+|-?inf)/);
$hash{$gene}{$condition} = $value;
}
HoH をループして、各遺伝子について、その遺伝子のすべての値が正 (たとえば 10) または負 (-3) のいずれかである場合に値を出力します。上記のデータでは、次のように印刷するだけです。
frz condition1 -12
frz condition2 -6
frz condition3 -0.3
他の両方の遺伝子には、正と負の両方の値を持つ条件が含まれているため:
wnt condition1 1
wnt condition2 10
wnt condition3 15
wnt condition4 -1 # discrepancy
bmp condition1 10
bmp condition2 inf
bmp condition3 12
bmp condition4 -1 # discrepancy
次のようにループできますが、1 つの HoH 値とその遺伝子条件キー コンボの「次の」値を比較する方法がわかりません。
for my $gene (sort keys %hash) {
for my $condition (sort keys %{$hash{$gene}}) {
my $value = $hash{$gene}{$condition};
print "$gene\t$condition\t$value\n" if $value =~ m/-/; # This obviously will only print out negative values. I want to compare all values here, and if they are all positive, or all negative, print them.
}
}
これをさらに明確にすることができれば教えてください