liutingloveliu 2021-07-22 17:15 采纳率: 75%
浏览 93
已结题

合并坐标,考虑二元素

如下表所示,将重复序列进行合并,如果两种重复序列在坐标上是有重合,则将两个重复序列合并成一个,输出。
请写清楚完整代码
我参考网上的写了一个但是发现无法统计染色体结果

img

use strict;
use warnings;
my @name_array ;
my $hash;
open (FILE, "trf.gff");
while(<FILE>){
        my ($scaff, $a, $b, $min, $max, $c, $d, $e, $f, $g, $class, $h, $i, $j) = split(/\t|;/);   #是对的
        unless (grep $_->[8] eq $class ,@name_array){
                push  @name_array, [$scaff, $a, $b, $c, $d, $e, $f, $g, $class, $h, $i, $j];
        } ;

        ($min,$max) = ($max,$min) if $min > $max ;

        if($hash->{$class}){
                sort_matrix($min,$max,$hash->{$class});
        }
        else{
                push @{$hash->{$class}},[$min,$max];
        }

}
###print sort result
for my $item( @name_array ){
        my $class = $item->[8];
        for (0..$#{$hash->{$class}}){
                print $item->[0]," ",$item->[1]," ",$item->[2]," ",$hash->{$class}->[$_][0]," ",$hash->{$class}->[$_][1]," ",$item->[3]," ",$item->[4]," ",$item->[5]," ",$item->[6]," ",$item->[7]," ",$class,"_E",($_+1)," ",$item->[9]," ",$item->[10]," ",$item->[11],"\n";
        }
}

sub sort_matrix{
        my ($cur_min,$cur_max,$matrix) = @_;
        # record index
        my @splice_index;
        for (0..$#$matrix){
                my $item_min = $matrix->[$_]->[0];
                my $item_max = $matrix->[$_]->[1];
                next if $cur_max < $item_min or $cur_min > $item_max;
                return if $cur_min >= $item_min and $cur_max <= $item_max;
                $cur_min  = $cur_min < $item_min ? $cur_min : $item_min;
                $cur_max = $cur_max < $item_max ? $item_max : $cur_max;
                push @splice_index, $_;
        }
        push @$matrix,[$cur_min,$cur_max];
        #print "@splice_index\n";

        for (0..$#splice_index){
                splice(@$matrix,$splice_index[$_]-$_,1);##This is trick
        }
        #print $cur_min,":",$cur_max,"\n";
}

  • 写回答

1条回答 默认 最新

  • sanzhong104204 2021-07-23 07:57
    关注

    坐标是啥,染色体又是啥?两种重复序列是什么意思?另外,只考虑perl吗?其他语言实现ok不?

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 7月23日
  • 创建了问题 7月22日

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料