0
|
1 #!/usr/bin/perl
|
|
2
|
|
3 use strict;
|
|
4
|
|
5 use Getopt::Std;
|
|
6 my $opt_string = 'hi:c:t:';
|
|
7 my %opt;
|
|
8 getopts( "$opt_string", \%opt ) or usage();
|
|
9 usage() if $opt{h};
|
|
10 my $SNVMIX_FILE = "-";
|
|
11 $SNVMIX_FILE = $opt{i} if $opt{i};
|
|
12 my $TYPE = 2;
|
|
13 $TYPE = $opt{c} if $opt{c};
|
|
14 my $THRESHOLD = 0;
|
|
15 $THRESHOLD = $opt{t} if $opt{t};
|
|
16 if($TYPE != 2 && $TYPE != 3) { die("ERROR: Unknown class TYPE\n"); }
|
|
17
|
|
18 print STDERR "Reading from ".($SNVMIX_FILE eq "-" ? "STDIN" : $SNVMIX_FILE)."\n";
|
|
19 print STDERR "Calculating for max between AA".($TYPE == 2 ? " and {AB u BB}" : ", AB and BB")."\n";
|
|
20 if($THRESHOLD) {
|
|
21 print STDERR "Applying threshold of $THRESHOLD, reporting only if ".($TYPE == 2 ? "P{AB u BB}" : "(P{AB} || P{BB})")." >= $THRESHOLD\n";
|
|
22 }
|
|
23
|
|
24 open(INPUT, "<$SNVMIX_FILE") || die("ERROR: Could not open '$SNVMIX_FILE' for reading\n");
|
|
25 while(<INPUT>) {
|
|
26 chomp;
|
|
27 s/
//;
|
|
28 my $line = $_;
|
|
29 my ($chr_pos, $ref, $nref, $call_str, @extra) = split(/\t/, $line);
|
|
30 my ($ref_num, $nref_num, $pAA, $pAB, $pBB, $call) = split(/,/, $call_str);
|
|
31 my $snv = 0;
|
|
32 if($TYPE == 2) {
|
|
33 if($pAA < ($pAB + $pBB)) {
|
|
34 if( ($pAB + $pBB) >= $THRESHOLD) {
|
|
35 $snv = 1;
|
|
36 }
|
|
37 }
|
|
38 } elsif($TYPE == 3) {
|
|
39 if($call == 2 || $call == 3) {
|
|
40 if( $pAB >= $THRESHOLD || $pBB >= $THRESHOLD) {
|
|
41 $snv = 1;
|
|
42 }
|
|
43 }
|
|
44 } else {
|
|
45 die("ERROR, and a weird one, script shouldn't even BE in here...\n");
|
|
46 }
|
|
47 if($snv) {
|
|
48 #print "$chr_pos\t$ref\t".( $snv ? $nref : "-")."\t$snv\n";
|
|
49 print "$line\n";
|
|
50 }
|
|
51 }
|
|
52 close(INPUT);
|
|
53
|
|
54 sub usage() {
|
|
55 print "Syntax:\n";
|
|
56 print "$0 [-i <file>] -c <TYPE> [-t <THRESHOLD>]\n";
|
|
57 print "\tIf file not given, STDIN is read\n";
|
|
58 print "\tTYPE is the number of classes to consider\n";
|
|
59 print "\t\t'2'\tconsiders only AA and {AB U BB} (default)\n";
|
|
60 print "\t\t'3'\tconsiders AA, AB and BB\n";
|
|
61 print "\tIf -t THRESHOLD is given, then SNVs will be reported\n";
|
|
62 print "\twhen the selected probability exceeds this\n";
|
|
63 exit;
|
|
64 }
|