我制作了一个散列散列,其中文件的所有行都根据它们的第 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.
}
关闭(巨大的 BAM_FILE);关闭(ALL_OUTPUTS_GENERATED);