我有一些以下格式的输入数据(制表符划定):
(基因条件值)
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
我可以按如下方式循环,但不确定如何在一个 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.
}
}
让我知道如果我能进一步澄清这一点