• 【代码速记】四重复和两重复计算各位点的错误率


    use strict;
    
    open DATA , "<name1-50-a.txt" or die ("cannot open file : $!");
    
    open OUT , ">check_result_50.txt";
    open LOG , ">log.txt";
    my @all;
    my @all_array;
    @all = <DATA>;
    foreach (@all){
        push @all_array, [split(/    /, $_)]
    }
    
    
    #删除重复元素, 提取种群数和位点数
    sub uniq{
        my %count;
        my @uniq = grep { ++$count{ $_ } < 2; } @_;
        return @uniq;
    }
    my @array;
    foreach (@all_array){
        push @array, @$_[0];
    }
    my @uniq_type;
    @uniq_type = &uniq(@array);
    @uniq_type = grep(/[^sample]/,@uniq_type);
    
    my %hash_data;
    my %hash_data_binary;
    my @loci;
    for (my $i = 1; $i < scalar(@all_array); $i++){
        for (my $j = 1; $j < scalar(@{$all_array[$i]});$j++){
            $hash_data{$all_array[$i][0]}{$all_array[0][$j]} = $all_array[$i][$j];
            if($all_array[$i][$j]){
                $hash_data_binary{$all_array[$i][0]}{$all_array[0][$j]} = 1;
            }else{
                $hash_data_binary{$all_array[$i][0]}{$all_array[0][$j]} = 0;
            }
            push @loci, $all_array[0][$j];
        }
    }
    
    my @list_type;
    foreach my $tmp (keys %hash_data_binary){
        $tmp =~ /_[01]_[FP]/;
        push @list_type, $`;
    }
    @list_type = &uniq(@list_type);
    
    my %rate;
    my %peaks;
    foreach my $locus (@loci){
        my $score1 = 0;
        my $record1 = 0;
        foreach my $type (@list_type){
            my $score2 = 0;
            my $record2 = 0;
            my $state;
            my $score3;
            foreach my $sample (keys %hash_data_binary){
                if ($sample =~ /^$type/){
                    $score2 += $hash_data_binary{$sample}{$locus};
                    $record2 ++;
                }
            }
            $state = $score2/$record2;
            if($state == 0 or $state == 0.25){
                print LOG $type."-".$locus."
    ";
            }else{
                if ($state == 1){
                    $score3 = 1;
                }elsif($state == 0.5){
                    $score3 = 0;
                }elsif ($state == 0.75){
                    $score3 = 1;
                }else{
                    $score3 = 0;
                    print LOG print $state."
    ";
                }
                $score1 += $score3;
                $record1 ++;
            }
        }
        if ($record1 != 0){
            $rate{$locus} = $score1/$record1;
            $peaks{$locus} = $record1;
        }else{
            $rate{$locus} = "";
            $peaks{$locus} = "0";
        }
    }
    
    # while((my $key, my $value) = each (%rate)){
        # print OUT $key."    ".$value."
    "
    # }
    
    for my $tmp (keys %rate){
        print OUT $tmp."    ".$rate{$tmp}."    ".$peaks{$tmp}."
    ";
    }
    
    ##test for the usage of {} and scalar, important!!!
    #print scalar(@{$all_array[1]})."
    ";
    #print scalar(@{[1,2,3]});
    
    close (DATA); close(OUT);
  • 相关阅读:
    51nod1229 序列求和 V2
    51nod 1228、1258 序列求和
    题解P3711:【仓鼠的数学题】
    伯努利数学习笔记的说...
    题解 P4692 【[Ynoi2016]谁的梦】
    积性函数与卷积
    题解 P5065 【[Ynoi2014]不归之人与望眼欲穿的人们】
    [Ynoi2018]末日时在做什么?有没有空?可以来拯救吗?
    [51nod1965]奇怪的式子
    PGCD2
  • 原文地址:https://www.cnblogs.com/liulele/p/8045057.html
Copyright © 2020-2023  润新知