annotate varscan/varscan_mpileup.pl @ 0:848f3dc54593 draft

Uploaded
author geert-vandeweyer
date Fri, 07 Mar 2014 06:17:32 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
1 #!/usr/bin/perl
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
2
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
3 use strict;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
4 use Cwd;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
5
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
6 die qq(
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
7 Bad numbr of inputs
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
8
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
9 ) if(!@ARGV);
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
10
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
11 my $options ="";
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
12 my $file="";
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
13 my $command="";
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
14 my $output="";
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
15 my $working_dir = cwd();
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
16 my $temp_vcf = "$working_dir/temp";
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
17 my $log="";
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
18
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
19 foreach my $input (@ARGV)
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
20 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
21 my @tmp = split "::", $input;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
22 if($tmp[0] eq "COMMAND")
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
23 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
24 $command = $tmp[1];
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
25 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
26 elsif($tmp[0] eq "INPUT")
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
27 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
28 $file = $tmp[1];
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
29 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
30 elsif($tmp[0] eq "OPTION")
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
31 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
32 my @p = split(/\s+/,$tmp[1]);
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
33 if ($p[0] =~ m/variants|strand-filter|output-vcf/ && $p[1] == 0) {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
34 next;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
35 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
36
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
37 $options = "$options ${tmp[1]}";
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
38 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
39 elsif($tmp[0] eq "OUTPUT")
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
40 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
41 $output = $tmp[1];
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
42 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
43 elsif($tmp[0] eq "LOG")
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
44 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
45 $log = $tmp[1];
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
46 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
47 else
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
48 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
49 die("Unknown Input: $input\n");
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
50 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
51 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
52
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
53 system ("$command $file $options 1>$temp_vcf 2>$log");
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
54
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
55 vs2vcf($temp_vcf, $output);
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
56
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
57
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
58 sub vs2vcf
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
59 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
60
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
61 #
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
62 # G l o b a l v a r i a b l e s
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
63 #
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
64 my $version = '0.1';
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
65
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
66 #
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
67 # Read in file
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
68 #
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
69 my $input = shift;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
70 my $output = shift;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
71 my $chr_ord = shift;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
72 open(IN, $input) or die "Can't open $input': $!\n";
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
73 open(OUT, ">$output") or die "Can't create $output': $!\n";
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
74 my %output;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
75
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
76 while ( <IN> )
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
77 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
78 if ( /^#/ )
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
79 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
80 print OUT;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
81 next;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
82 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
83 chomp;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
84 my $line = $_;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
85
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
86 my @flds = split ( "\t", $line );
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
87 my $ref = $flds[3];
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
88 my $alt = $flds[4];
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
89 #
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
90 # Deletion of bases
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
91 #
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
92 if ( $alt =~ /^\-/ )
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
93 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
94 ($flds[3], $flds[4]) = ($ref.substr($alt,1), $ref);
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
95 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
96
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
97 #
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
98 # Insertion of bases
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
99 #
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
100 if ( $alt =~ /^\+/ )
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
101 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
102 $flds[4] = $ref.substr($alt,1);
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
103 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
104 print OUT join( "\t", @flds),"\n" unless defined $chr_ord;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
105 $output{$flds[0]}{$flds[1]} = join( "\t", @flds)."\n" if defined $chr_ord;
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
106 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
107 close(IN);
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
108 # if chromosome order given return in sorted order
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
109 if(defined $chr_ord)
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
110 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
111 for my $chrom (@{ $chr_ord })
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
112 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
113 for my $pos (sort {$a<=>$b} keys %{ $output{$chrom} })
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
114 {
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
115 print OUT $output{$chrom}{$pos};
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
116 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
117 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
118 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
119 close(OUT);
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
120 }
848f3dc54593 Uploaded
geert-vandeweyer
parents:
diff changeset
121