-
Notifications
You must be signed in to change notification settings - Fork 5
/
SNPtable2windowgenome.pl
48 lines (45 loc) · 1.17 KB
/
SNPtable2windowgenome.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
#!/bin/perl
use strict;
use warnings;
my $window_size = $ARGV[0];
my $current_chr = "NA";
my $current_start = 0;
my $current_end = $current_start+$window_size;
my $header;
my $outfh = "NA";
while(<STDIN>){
chomp;
if ($. == 1){
$header = $_;
}else{
my @a = split(/\t/,$_);
my $chr = $a[0];
if ($chr =~ m/scaffold/){next;}
my $pos = $a[1];
if ($current_chr ne $chr){
close FH;
$current_chr = $chr;
$current_start = 0;
$current_end = $current_start+$window_size;
until ($pos <= $current_end){
$current_start += $window_size;
$current_end += $window_size;
}
my $filename = "$current_chr.$current_start.$current_end.tab";
open (FH, '>', $filename);
print FH "$header";
}
if ($pos > $current_end){
#print STDERR "End of window $current_end with pos $pos with window size $window_size\n";
close FH;
until ($pos <= $current_end){
$current_start += $window_size;
$current_end += $window_size;
}
my $filename = "$current_chr.$current_start.$current_end.tab";
open (FH, '>', $filename);
print FH "$header"
}
print FH "\n$_";
}
}