【发布时间】:2019-02-05 10:38:16
【问题描述】:
我有两个制表符分隔的文件: 一个是包含数千个条目的参考 另一个是数百万个标准的列表 用于搜索参考。
我使用以下代码对参考文件进行哈希处理
use strict;
use warnings;
#use Data::Dumper;
#use Timer::Runtime;
use feature qw( say );
my $in_qfn = $ARGV[0];
my $out_qfn = $ARGV[1];
my $transcripts_qfn = "file";
my %transcripts;
{
open(my $transcripts_fh, "<", $transcripts_qfn)
or die("Can't open \"$transcripts_qfn\": $!\n");
while ( <$transcripts_fh> ) {
chomp;
my @refs = split(/\t/, $_);
my ($ref_chr, $ref_strand) = @refs[0, 6];
my $values = {
start => $refs[3],
end => $refs[4],
info => $refs[8]
};
#print Data::Dumper->Dump([$values]), $/; #confirm structure is fine
push @{ $transcripts{$ref_chr}{$ref_strand} }, $values;
}
}
然后我打开另一个输入文件,定义元素,并解析哈希以找到匹配条件
while ( <$in_fh> ) {
chomp;
my ($x, $strand, $chr, $y, $z) = split(/\t/, $_);
#match the reference hash for things equal to $chr and $strand
my $transcripts_array = $transcripts{$chr}{$strand};
for my $transcript ( @$transcripts_array ) {
my $start = $transcript->{start};
my $end = $transcript->{end};
my $info = $transcript->{info};
#print $info and other criteria from if statements to outfile, this code works
}
}
这可行,但我想知道我是否可以在哈希中找到匹配 $chr 但不匹配 $strand(具有任一符号的二进制值)的元素。
我在前一个 for 之后将以下内容放入同一个 while 块中,但它似乎不起作用
my $transcripts_opposite_strand = $transcripts{$chr}{!$strand};
for my $transcript (@$transcripts_opposite_strand) {
my $start = $transcript->{start};
my $end = $transcript->{end};
my $info = $transcript->{info};
#print $info and other criteria from if statements
}
我为代码 sn-ps 道歉;我试图保留相关信息。由于文件的大小,我不能真正通过逐行进行暴力破解。
【问题讨论】: