输入文件
Xm_ABL1 Geneious extracted region 1 168 . + . Name=Extracted region from gi|371443098|gb|JH556762.1|;Extracted interval="3512970000000 -> 3514640000000"
Xm_ABL1 Geneious extracted region 169 334 . + . Name=Extracted region from gi|371443098|gb|JH556762.1|;Extracted interval="3717850000000 -> 3719500000000"
Perl 代码的一部分
if ($array[1] =~ /extracted region/){
die "No CDS record for $key!\n" unless $metadata->{$key};
(my $label = $array[7]) =~ s/.*region from (.*)\|;.*/$1/;
$label =~ s/\|/_/g;
$group->{$label} ||= {
pos1 => 1e10,
pos2 => 0,
metadata => $metadata->{$key},
sequences => [],
};
(my $pos1, my $arr, my $pos2) = ($array[7]=~/.*interval=\"(\d+) (<?->?) (\d+)\"$/gm);
# capture hi/lo values for group
$group->{$label}->{pos1} = $pos1 if $pos1 < $group->{$label}->{pos1};
$group->{$label}->{pos2} = $pos2 if $pos2 > $group->{$label}->{pos2};
# push this sequence onto the group's array
push(@{ $group->{$label}->{sequences} }, [ $pos1, $pos2, $arrow->{$arr} ]);
}
在代码中 $pos1=3512970000000,3717850000000 & $pos2=3514640000000,3719500000000。我的代码打印新行查找最小值和最大值(如果 $pos1 小于 10,000),但如果该值大于 10,0000,则会在打印 pos1 的最小值时出错。在调试中查找 $pos1 的最小值和 $pos2 的最大值时,我们将不胜感激。
答案1
$group->{$label}->{pos1}
总是被定义的,你用第 6 行初始化它:
pos1 => 1e10,
这样,它就可以正常工作,直到$pos1 <= 1e10
。如果您想要打印最小值$group->{$label}->{pos1} = 3512970000000
(如示例输入),则必须初始化$group->{$label}->{pos1} = -1
(第 6 行):
pos1 => -1,
并将第 13 行修改为:
$group->{$label}->{pos1} = $pos1 if (($group->{$label}->{pos1} < 0) || ($pos1 < $group->{$label}->{pos1}));
答案2
通过更改第 13 行的代码:使用 defiend
$group->{$label}->{pos1} = $pos1 if ((!defined $group->{$label}->{pos1})
|| ($pos1 < $group->{$label}->{pos1}));