-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLROH.pl
92 lines (74 loc) · 2.08 KB
/
LROH.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/perl
use FileHandle;
use strict;
use Getopt::Long;
my $line;
my @array;
my $start_pos;
my $prev_gt;
my $counter;
my $start;
my $prev_chrom;
my $prev_pos;
my $args = scalar @ARGV;
my %options = (
size => undef,
infile => undef,
outfile => undef
);
GetOptions(
's=s' => \$options{size},
'i=s' => \$options{infile},
'o=s' => \$options{outfile}
);
my $in_file=$options{infile};
my $in_file_handle = new FileHandle;
if(defined($in_file)) {
# check defined input file exists
die("ERROR: Could not find input file ", $in_file, "\n") unless -e $in_file;
$in_file_handle->open($in_file) or die("ERROR: Could not read from input file ", $in_file, "\n");
}
# no file specified - try to read data off command line
else {
$in_file_handle = 'STDIN';
}
my $out_file=$options{infile}.".".$options{size}.".txt";
#my $out_file="out.txt";
open(FILE, "s_4_1.recal.snps.all_conf_sites.gt.pass.txt");
my $out_file_handle = new FileHandle;
$out_file_handle->open(">$out_file") or die("ERROR: Could not write to output file ", $out_file, "\n");
while(<FILE>) {
$line=$_;
@array=split("\t",$line);
my $gt=$array[2];
my $geno = chomp($gt);
#foreach $line ($lines){
if ($prev_gt) {
#if ($array[0] eq $prev_chrom && ($gt eq "0/0" || "1/1") && ($prev_gt eq "0/0" || "1/1")) {
unless ($gt eq "0/1" || $array[0] != $prev_chrom) {
if ($counter eq 0 || !defined($counter)) {
$start= $array[0].":".$array[1];
$start_pos=$array[1];
}
$counter++;
#f you want to print to STOUT, remove $out_file_handle from 2 following lines
#print $out_file_handle $array[0]."\t".$array[1]."\t".$gt."\t".$counter."\n";
}
else {
my $difference=$prev_pos-$start_pos;
#unless ($counter <= $options{size}) {
unless ($difference <= $options{size}) {
print $out_file_handle "\n--END OF LROH--".$prev_gt."\tSTRETCH:\t".$counter."\tREGION:\t".$start."-".$prev_pos."\tLENGTH(bp):\t".$difference;
}
$counter=0;
}
}
#else {
# $counter=0;
#}
#$prev_gt = $array[2];
$prev_gt = $gt;
$prev_chrom = $array[0];
$prev_pos = $array[1];
}
close FILE;