【发布时间】:2013-04-30 09:08:55
【问题描述】:
我制作了一个散列散列,其中文件的所有行都根据它们的第 5 个字段的值排序到“主”散列的一个键中。
%Tiles 有 n 个键,其中每个键是不同的 $Tile_Number。
%Tiles 的每个元素的值是对哈希哈希的引用,该哈希哈希包含所有以$Tile_Number 为当前哈希键编号的行。这些新键(行)中的每一个的值都只有 1。
$Tiles{$Tile_Number}{$Line}=1 ,其中$Tiles{$Tile_Number} 有许多$Line=1 条目。
我想在单独的文件中打印每个 $Tiles{$Tile_Number} 哈希,最好在创建 $Tile_Number 键时创建文件,并在添加每个新的 $Tiles{$Tile_Number}{$Line}=1 时打印,以节省内存。
最好不要打印最终值 (1),但我想我可以取消它。
如何告诉 Perl 为“主”散列中的每个键打开一个新文件并打印其所有键?
代码:
use strict;
use warnings;
my ($Line) = "";
my (@Alignment_Line) = ();
my (%Tiles) = ();
my $Huge_BAM_File= $ARGV[0] or die $USAGE;
open(HUGE_BAM_FILE,"< $Huge_BAM_File") || die "Sorry I couldn't open the INPUT file: $Huge_BAM_File !\n";
while(<HUGE_BAM_FILE>){
### Remove new line characters "\n"
### Split each line by "\t" and by ":" (for fields within READ ID FIELD)
chomp;
$Line = $_;
@Alignment_Line = split(/\t+|\:/, $Line);
my $Tile_Number = $Alignment_Line[4]
##########################################################
### Fill in hash of hashes %Tiles ###
### Key = $Tile_Number ###
### Second key is $Line ###
### and is filled with a 1 ###
### Each key contains all the alignments with that tile###
### number ###
##########################################################
$Tiles{$Tile_Number}{$Line} = 1;
##Here, I would like to write this new entry into the corresponding file,
and maybe remove it from the hash so the program doesn't run out of memory.
}
关闭(HUGE_BAM_FILE); 关闭(ALL_OUTPUTS_GENERATED);
【问题讨论】:
-
您期望$Tile_Number 有多少个值,对于每个值,$Line 有多少个值?我认为您寻求的答案取决于这些数字。另外,考虑到许多现代计算机中的可用 RAM,您为什么要节省内存?
-
我期待 96 个 $Tile_Number,每个包含 10-1500 万个条目,并为 8 个项目并行执行此操作。
标签: perl hash printing file-handling