annotate varscan_mpileup.pl @ 2:51969e284317 draft default tip

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