forked from pxulab/MRLR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2nd_match_sum.pl
More file actions
executable file
·63 lines (57 loc) · 1.43 KB
/
2nd_match_sum.pl
File metadata and controls
executable file
·63 lines (57 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl -w
##
use strict;
my $file = shift or die "Usage: $0 <2nd_NA12878_P_C_match>\n";
my $before;
my ($sum,$high);
my $start;
my $end;
my @array;
open my $file_h,'<',$file;
while(<$file_h>){
my @line=split;
next if /\.\t\.\t\./;
next if $line[-4]=~/^0-/ or $line[-4]=~/wrong/;
my $id="$line[0]\t$line[-3]\t$line[-2]\t$line[-4]";
if(defined($before) &&($id eq $before)){
$end=$line[1];
$sum++;
}
else{
if(defined($before) && ($id ne $before)){
if($sum>=3){
my @tmp=split /\t/,$before;
push @array, "$tmp[0]\t$start\t$end\t$tmp[3]\t$tmp[1]\t$tmp[2]\t$sum";
}
}
$before=$id;
$sum=1;
$start=$line[1];
$end=$line[1];
}
}
if(eof($file_h)){
if($sum>=3){
my @tmp=split /\t/,$before;
push @array, "$tmp[0]\t$start\t$end\t$tmp[3]\t$tmp[1]\t$tmp[2]\t$sum";
}
}
my $pre_id;
foreach my $id (@array){
if(defined($pre_id)){
my @line=split /\t/,$id;
my @pre_line=split /\t/,$pre_id;
if("$pre_line[0]\t$pre_line[3]\t$pre_line[4]\t$pre_line[5]" eq "$line[0]\t$line[3]\t$line[4]\t$line[5]"){
$pre_line[2]=$line[2];
$pre_line[-1]+=$line[-1];
$pre_id=join "\t",@pre_line;
}
else{
print $pre_id,"\n";
$pre_id=$id;
}
}
else{
$pre_id=$id;
}
}