-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprepforfixeddif2junctiondistance.pl
53 lines (53 loc) · 1.33 KB
/
prepforfixeddif2junctiondistance.pl
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
#!/bin/perl
use strict;
use warnings;
my $max_dist = 1;
my %sample;
my $current_chr = 0;
my %previous;
my %previous_data;
print "sample\tdist\tjunction";
while(<STDIN>){
chomp;
my @a = split(/\t/);
if ($. == 1){
foreach my $i (4..$#a){
$sample{$i} = $a[$i];
}
}else{
my $chr = $a[0];
my $pos = $a[1];
my $cm = $a[2];
if ($cm eq "NA"){next};
if ($chr ne $current_chr){
undef(%previous_data);
print STDERR "Now processing $chr...\n";
$current_chr = $chr;
}
foreach my $i (4..$#a){
my $sample = $sample{$i};
my $current_state = $a[$i];
if ($current_state eq "N"){next;}
if ($current_state eq "1"){next;}
my $current_cm = $cm;
if ($previous_data{$sample}){
foreach my $cm (keys %{$previous_data{$sample}}){
my $current_dist = $current_cm - $cm;
if ($current_dist > $max_dist){
delete($previous_data{$sample}{$cm});
next;
}
my $previous_state = $previous_data{$sample}{$cm};
if ($previous_state eq $current_state){
print "\n$sample\t$current_dist\t0";
}else{
print "\n$sample\t$current_dist\t1";
}
$previous_data{$sample}{$current_cm} = $current_state;
}
}else{
$previous_data{$sample}{$current_cm} = $current_state;
}
}
}
}