我正在使用Perl生成一个独特的外显子列表(它是基因的单位).
我已经生成了这种格式的文件(包含数十万行):
chr1 1000 2000 gene1
chr1 3000 4000 gene2
chr1 5000 6000 gene3
chr1 1000 2000 gene4
位置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 …Run Code Online (Sandbox Code Playgroud) 好的 - 我确定之前已经回答了这个问题,但我找不到它......
我的问题:我有一个列表与这个组成
0.2 A
0.1 A
0.3 A
0.3 B
0.2 C
0.5℃
我的目标是输出以下内容:
0.6 A
0.3 B
0.7℃
换句话说,我需要将来自多行的数据合并在一起.
这是我正在使用的代码:
unique_percents = []
for line in percents:
new_percent = float(line[0])
for inner_line in percents:
if line[1] == inner_line[1]:
new_percent += float(inner_line[0])
else:
temp = []
temp.append(new_percent)
temp.append(line[1])
unique_percents.append(temp)
break
Run Code Online (Sandbox Code Playgroud)
我认为它应该可以工作,但它并没有增加百分比,仍然有重复.也许我不明白"休息"是如何运作的?
我还会提出更好的循环结构或算法的建议.谢谢,大卫.