-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgetPileupResultsByPosns.pl
executable file
·91 lines (73 loc) · 1.92 KB
/
getPileupResultsByPosns.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
#!/usr/bin/perl -w
=head1 NAME
perl-template.pl
-head1 SYNOPSIS
=head1 OPTIONS
-pileupFile <STDIN> generated by samtools pileup command
-inFormat|f <string> {'SNVMix','VCF','SAMtools'}
-positions|p <string> filename of file containing single column (chr:posn)
-out|o <string>
=head1 DESCRIPTION
=head1 CONTACT
Gavin Ha <[email protected]>
=cut
use strict;
#use DBI;
use File::Basename;
use Getopt::Long;
sub usage () {
exec('perldoc', $0);
exit;
}
my ($snvMixFile, $inFormat, $positions, $out, $help);
GetOptions (
'positions|p=s' => \$positions,
'inFormat|f=s' => \$inFormat,
#'out|o=s' => \$out,
'help|?' => \$help
);
if($help) {
&usage();
}
#print "Parameters:\ninType=$inFormat\npositions=$positions\nout=$out\n";
open POS, $positions || die("Can't open $positions\n");
<POS>; #skip first line
my %pos = ();
while (<POS>) {
chomp;
if ($inFormat eq 'SNVMix'){
my ($chr,@rest) = split(/\t/,$_);
$chr =~ s/chr//g;
$chr =~ s/23/X/g; $chr =~ s/24/Y/g;
$pos{$chr} = 1;
}elsif ($inFormat eq 'VCF'){
my ($chr,$posn,@rest) = split(/\t/,$_);
$chr =~ s/chr//g;
$chr =~ s/23/X/g; $chr =~ s/24/Y/g;
my $chrStr = $chr . ":" . $posn;
$pos{$chrStr} = 1;
}elsif ($inFormat eq 'SAMtools'){
my ($ps_id,$chr,$posn,@rest) = split(/\t/,$_);
$chr =~ s/chr//g;
$chr =~ s/23/X/g; $chr =~ s/24/Y/g;
my $chrStr = $chr . ":" . $posn;
$pos{$chrStr} = 1;
}
}
close POS;
#open SNV, $snvMixFile || die("Can't open $snvMixFile\n");
#open OUT, ">$out" || die("Can't write to $out\n");
my $linesRead = 0;
while (<STDIN>){
chomp;
my ($chr, $posn,$base,$depth,@rest) = split(/\t/,$_);
$chr =~ s/chr//g;
my $chrPosn = $chr . ":" . $posn;
if (defined $pos{$chrPosn} && $depth>=5) {
#print OUT $_ . "\n";
print $_ . "\n";
}
$linesRead +=1;
#print "Extracting pileup by positions: $linesRead lines read\n" if($linesRead%1000000==0);
}
#close OUT;