0

我有一个 HoHoA 声明如下:

输入:

six1    XLOC_000118_0.779368:6.54933,_Change:3.07097,_p:0.0041,_q:0.384698  98.56   gi|65102|emb|X07318.1|_Xenopus_laevis_U3_snRNA
six1    XLOC_000119_0.513953:3.88566,_Change:2.91845,_p:0.00305,_q:0.352441 97.74   gi|65102|emb|X07318.1|_Xenopus_laevis_U3_snRNA
six1    XLOC_000120_0.20564:1.71294,_Change:3.05828,_p:0.0499,_q:0.998475   97.72   gi|65102|emb|X07318.1|_Xenopus_laevis_U3_snRNA
six1    XLOC_000156_24.4984:46.2343,_Change:0.916274,_p:0.036,_q:0.998475   99.66   gi|475392713|dbj|AB759708.1|_Xenopus_laevis_PhyHd_mRNA_for_phytanoyl-CoA_dioxygenase_like_protein,_complete_cds
six1    XLOC_000159_47.4513:129.702,_Change:1.45068,_p:5e-05,_q:0.025683    98.11   gi|12007283|gb|AF310008.1|_Xenopus_laevis_putative_transmembrane_protein_TA-2_mRNA,_complete_cds
six1    XLOC_000360_4871.65:887.169,_Change:-2.45713,_p:0.01895,_q:0.932076 90.83   gi|166006832|gb|BC158454.1|_Xenopus_tropicalis_cDNA_clone_IMAGE:6991249
six1    XLOC_000441_3.2887:14.6726,_Change:2.15754,_p:0.0176,_q:0.886907    86.96   gi|49115451|gb|BC073380.1|_Xenopus_laevis_Cysteine_and_histidine-rich_protein_1A,_mRNA_(cDNA_clone_IMAGE:5513813),_partial_cds
six1    XLOC_000456_0.781282:1.82923,_Change:1.22732,_p:0.0448,_q:0.998475  100.00  gi|291419709|gb|GU725438.1|_Xenopus_laevis_runt-related_transcription_factor_3_(Runx3)_mRNA,_complete_cds
eya1    XLOC_000577_4.51367:2.36674,_Change:-0.931399,_p:0.0266,_q:0.998475 89.68   gi|512838432|ref|XM_002935635.2|_PREDICTED:_Xenopus_(Silurana)_tropicalis_hyaluronoglucosaminidase_1_(hyal1),_mRNA
eya1    XLOC_000639_1.97849:5.08116,_Change:1.36076,_p:0.02,_q:0.963795 100.00  gi|147898581|ref|NM_001094479.1|_Xenopus_laevis_histone_cluster_1,_H2aj_(hist1h2aj),_mRNA
eya1    XLOC_000838_0.907085:2.91695,_Change:1.68515,_p:0.0012,_q:0.233803  89.61   gi|283799550|emb|FN550108.1|_Xenopus_(Silurana)_tropicalis_mRNA_for_alpha-2,3-sialyltransferase_ST3Gal_V_(st3gal5_gene)
eya1    XLOC_000906_0.831191:2.33687,_Change:1.49132,_p:0.03045,_q:0.998475 91.02   gi|148223430|ref|NM_001092286.1|_Xenopus_laevis_HECT_and_RLD_domain_containing_E3_ubiquitin_protein_ligase_family_member_6_(herc6),_mRNA
eya1    XLOC_000993_1.93915:3.92975,_Change:1.01901,_p:0.0271,_q:0.998475   99.85   gi|148234446|ref|NM_001095481.1|_Xenopus_laevis_GRAM_domain_containing_3_(gramd3),_mRNA
eya1    XLOC_001130_0.15212:1.70739,_Change:3.48852,_p:0.01285,_q:0.726057  92.37   gi|112807523|emb|CU075479.1|_Xenopus_tropicalis_finished_cDNA,_clone_THdA030p05
eya1    XLOC_001184_0.620541:3.46599,_Change:2.48167,_p:0.00655,_q:0.499758 97.95   gi|65102|emb|X07318.1|_Xenopus_laevis_U3_snRNA
eya1    XLOC_001364_0.945792:2.66698,_Change:1.49561,_p:0.0478,_q:0.998475  99.75   gi|2598062|emb|AJ001730.1|_Xenopus_laevis_mRNA_for_Xsox17-alpha_protein
eya1    XLOC_001624_18.5985:34.7338,_Change:0.901154,_p:0.0111,_q:0.66721   100.00  gi|147905253|ref|NM_001090340.1|_Xenopus_laevis_serum/

为 HoHoA 分配各种值:

while (<$fh>) { 
        chomp;
        my $condition = $1 if ($_ =~  /(^\w+\d+)/);
        my $xloc = $1 if ($_ =~ /(XLOC_\d+)/);
        my $change = $1 if ($_ =~ /Change:(-?\d+\.\d+|-?inf)/);
        my $q_value = $1 if ($_ =~ /q:(\d+\.\d+)/);
        my @split = split('\t');
        my $percent_id = $split[2];
        my $gene = $split[3];
        $experiment{$gene}{$condition} = [ $xloc, $change, $q_value, $percent_id ];
    }

我现在想循环浏览键/值并将它们打印出来。但是在这样做之前,我需要对值进行一些比较(因此需要访问每个哈希键组合的每个值)。注释掉指示的行后,下面的代码可以工作,但因此我无法访问各个值。如何正确取消引用此数据结构?

    for my $gene (sort keys %experiment) { 
    for my $condition ( sort keys %{$experiment{$gene}} ) {
        print "$gene\t$condition\t";
            for my $values (@{$experiment{$gene}{$condition}} ) {
#               my ($xloc, $change, $q_val, $percentage) = @$values; # How can I dereference properly here...
#               print "[$xloc\t$change\t$q_val\t$percentage]"; #...to print out like this?
                print "[$values]\t";
            }
        print "\n";
     }
}

这将打印(仅第一行):

gi|110289870|emb|CU025180.1|_Xenopus_tropicalis_finished_cDNA,_clone_THdA035f23 six1    [XLOC_000990]   [inf]   [0.100767]  [88.02] 
gi|112807523|emb|CU075479.1|_Xenopus_tropicalis_finished_cDNA,_clone_THdA030p05 eya1    [XLOC_001130]   [3.48852]   [0.726057]  [92.37] 
gi|112807523|emb|CU075479.1|_Xenopus_tropicalis_finished_cDNA,_clone_THdA030p05 six1    [XLOC_001146]   [4.52249]   [0.999592]  [92.37] 
gi|12007283|gb|AF310008.1|_Xenopus_laevis_putative_transmembrane_protein_TA-2_mRNA,_complete_cds    six1    [XLOC_000159]   [1.45068]   [0.025683]  [98.11] 
gi|147898581|ref|NM_001094479.1|_Xenopus_laevis_histone_cluster_1,_H2aj_(hist1h2aj),_mRNA   eya1    [XLOC_000639]   [1.36076]   [0.963795]  [100.00]    
gi|147903202|ref|NM_001097651.1|_Xenopus_laevis_forkhead_box_I4,_gene_1_(foxi4.1),_mRNA six1    [XLOC_000837]   [1.16613]   [0.532793]  [99.89] 
4

3 回答 3

2

第三个for循环不是必需的。

for my $gene (sort keys %experiment) { 
    for my $condition ( sort keys %{$experiment{$gene}} ) {

        print "$gene\t$condition\t";
        my ($xloc, $change, $q_val, $percentage) = @{$experiment{$gene}{$condition}};
        ...
        print "\n";
     }
}
于 2013-09-11T17:16:59.740 回答
1

$experiment{$gene}{$condition}是对数组的引用。所以你可以简单地使用以下来取消引用它。如果您不想遍历此数组的元素,则不需要第三个嵌套循环。

my ($xloc, $change, $q_val, $percentage) = @{$experiment{$gene}{$condition}};
于 2013-09-11T17:19:06.000 回答
1

您已经在该行中取消引用您的 arrayref

for my $values ( @{$experiment{$gene}{$condition}} )

而不是最里面的循环,我怀疑你真正想要的是

my ($xloc, $change, $q_val, $percentage) = @{$experiment{$gene}{$condition}};
于 2013-09-11T17:17:04.007 回答