【发布时间】:2011-08-08 04:58:42
【问题描述】:
我正在使用 Perl 生成一个独特的外显子列表(它们是基因的单位)。
我已经生成了这种格式的文件(有几十万行):
chr1 1000 2000 基因1
chr1 3000 4000 基因2
chr1 5000 6000 基因3
chr1 1000 2000 基因4
位置1是染色体,位置2是外显子的起始坐标,位置3是外显子的结束坐标,位置4是基因名称。
由于基因通常由不同排列的外显子构成,因此您在多个基因中具有相同的外显子(参见第一组和第四组)。我想删除这些“重复” - 即删除gene1或gene4(删除哪个并不重要)。
我已经把头撞在墙上好几个小时了,试图做(我认为)是一项简单的任务。谁能指出我正确的方向?我知道人们经常使用哈希来删除重复的元素,但这些并不完全是重复的(因为基因名称不同)。重要的是我也不会丢失基因名称。否则这会更简单。
这是我尝试过的完全没有功能的循环。 “外显子”数组将每一行存储为标量,因此是子例程。不要笑。我知道它不起作用,但至少你可以看到(我希望)我正在尝试做的事情:
for (my $i = 0; $i < scalar @exons; $i++) {
my @temp_line = line_splitter($exons[$i]); # runs subroutine turning scalar into array
for (my $j = 0; $j < scalar @exons_dup; $j++) {
my @inner_temp_line = line_splitter($exons_dup[$j]); # runs subroutine turning scalar into array
unless (($temp_line[1] == $inner_temp_line[1]) && # this loop ensures that the the loop
($temp_line[3] eq $inner_temp_line[3])) { # below skips the identical lines
if (($temp_line[1] == $inner_temp_line[1]) && # if the coordinates are the same
($temp_line[2] == $inner_temp_line[2])) { # between the comparisons
splice(@exons, $i, 1); # delete the first one
}
}
}
}
【问题讨论】:
标签: perl duplicates bioinformatics