forked from betharowan/TIGER_Scripts-for-distribution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreaks_smoother.pl
100 lines (86 loc) · 1.8 KB
/
breaks_smoother.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
93
94
95
96
97
98
99
100
#! /usr/bin/perl
use strict;
use FindBin;
use lib $FindBin::Bin;
use Getopt::Std;
use IO::File;
use Time::HiRes;
#use Constant_Math_lib;
my % options=();
use IO::Handle;
my $break_file="";
my $output_file="output.txt";
my %POS=();
my$opt_string='hb:o:';
getopts("$opt_string",\%options) or usage();
usage()if $options{h};
init();
main();
sub usage
{
my $usage = " usage:perl prepare_data_for_overview_plot.pl -b breakfile -o output \n";
print $usage;
exit();
}
sub init
{
if($options{b})
{
$break_file= $options{b};
}
else
{
die usage();
}
if($options{o})
{
$output_file=$options{o};
}
}
sub main
{
my $input_file = new IO::File($break_file, "r") or die "could not open $break_file: $!\n";
my $sample="";
my $chr=0;
my $begin="";
my $end="";
my $genotype="";
my $file_writer=IO::File->new();
$file_writer->open(">".$output_file) or die "Could not open ".$output_file." $!\n" ;
while (my $line = $input_file->getline)
{
chomp($line);
#print " read line ".$line ."\n";
my @a = split " ", $line;
if($chr != $a[1])
{
#print
if($chr !=0)
{
$file_writer->print($sample."\t".$chr."\t".$begin."\t".$end."\t".$genotype."\n");
}
$sample=$a[0];
$chr=$a[1];
$begin=$a[2];
$end=$a[3];
$genotype=$a[4];
}
else
{
if($genotype eq $a[4])
{
$end=$a[3];
}
else
{
#print $sample."\t".$a[1]."\t".$a[2]."\t".$a[3]."\t".$a[4]." current line".$line ."\n";
$file_writer->print($sample."\t".$chr."\t".$begin."\t".$end."\t".$genotype."\n");
$chr=$a[1];
$begin=$a[2];
$end=$a[3];
$genotype=$a[4];
}
}
}
$file_writer->print($sample."\t".$chr."\t".$begin."\t".$end."\t".$genotype."\n");
}