annotate varscan_somatic.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
51969e284317 Uploaded
fcaramia
parents:
diff changeset
4 use strict;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
5 use Cwd;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
6
51969e284317 Uploaded
fcaramia
parents:
diff changeset
7 die qq(
51969e284317 Uploaded
fcaramia
parents:
diff changeset
8 Bad numbr of inputs
51969e284317 Uploaded
fcaramia
parents:
diff changeset
9
51969e284317 Uploaded
fcaramia
parents:
diff changeset
10 ) if(!@ARGV);
51969e284317 Uploaded
fcaramia
parents:
diff changeset
11
51969e284317 Uploaded
fcaramia
parents:
diff changeset
12 my $options ="";
51969e284317 Uploaded
fcaramia
parents:
diff changeset
13 my $normal="";
51969e284317 Uploaded
fcaramia
parents:
diff changeset
14 my $command="";
51969e284317 Uploaded
fcaramia
parents:
diff changeset
15 my $tumor="";
51969e284317 Uploaded
fcaramia
parents:
diff changeset
16 my $output="";
51969e284317 Uploaded
fcaramia
parents:
diff changeset
17 my $working_dir = cwd();
51969e284317 Uploaded
fcaramia
parents:
diff changeset
18 my $snp = "$working_dir/output.snp.vcf";
51969e284317 Uploaded
fcaramia
parents:
diff changeset
19 my $indels = "$working_dir/output.indel.vcf";
51969e284317 Uploaded
fcaramia
parents:
diff changeset
20
51969e284317 Uploaded
fcaramia
parents:
diff changeset
21 foreach my $input (@ARGV)
51969e284317 Uploaded
fcaramia
parents:
diff changeset
22 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
23 my @tmp = split "::", $input;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
24 if($tmp[0] eq "COMMAND")
51969e284317 Uploaded
fcaramia
parents:
diff changeset
25 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
26 $command = $tmp[1];
51969e284317 Uploaded
fcaramia
parents:
diff changeset
27 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
28 if($tmp[0] eq "NORMAL")
51969e284317 Uploaded
fcaramia
parents:
diff changeset
29 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
30 $normal = $tmp[1];
51969e284317 Uploaded
fcaramia
parents:
diff changeset
31 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
32 elsif($tmp[0] eq "TUMOR")
51969e284317 Uploaded
fcaramia
parents:
diff changeset
33 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
34 $tumor = $tmp[1];
51969e284317 Uploaded
fcaramia
parents:
diff changeset
35 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
36 elsif($tmp[0] eq "OPTION")
51969e284317 Uploaded
fcaramia
parents:
diff changeset
37 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
38 $options = "$options ${tmp[1]}";
51969e284317 Uploaded
fcaramia
parents:
diff changeset
39 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
40 elsif($tmp[0] eq "OUTPUT")
51969e284317 Uploaded
fcaramia
parents:
diff changeset
41 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
42 $output = $tmp[1];
51969e284317 Uploaded
fcaramia
parents:
diff changeset
43 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
44
51969e284317 Uploaded
fcaramia
parents:
diff changeset
45 else
51969e284317 Uploaded
fcaramia
parents:
diff changeset
46 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
47 die("Unknown Input: $input\n");
51969e284317 Uploaded
fcaramia
parents:
diff changeset
48 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
49 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
50
51969e284317 Uploaded
fcaramia
parents:
diff changeset
51 system ("$command $normal $tumor $options ");
51969e284317 Uploaded
fcaramia
parents:
diff changeset
52 system("grep -v '^\#' $indels | grep -v '^chrom position' >> $snp");
51969e284317 Uploaded
fcaramia
parents:
diff changeset
53
51969e284317 Uploaded
fcaramia
parents:
diff changeset
54 my @chr_ord = chromosome_order($tumor);
51969e284317 Uploaded
fcaramia
parents:
diff changeset
55
51969e284317 Uploaded
fcaramia
parents:
diff changeset
56 vs2vcf($snp, $output,\@chr_ord);
51969e284317 Uploaded
fcaramia
parents:
diff changeset
57
51969e284317 Uploaded
fcaramia
parents:
diff changeset
58
51969e284317 Uploaded
fcaramia
parents:
diff changeset
59 sub vs2vcf
51969e284317 Uploaded
fcaramia
parents:
diff changeset
60 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
61
51969e284317 Uploaded
fcaramia
parents:
diff changeset
62 #
51969e284317 Uploaded
fcaramia
parents:
diff changeset
63 # G l o b a l v a r i a b l e s
51969e284317 Uploaded
fcaramia
parents:
diff changeset
64 #
51969e284317 Uploaded
fcaramia
parents:
diff changeset
65 my $version = '0.1';
51969e284317 Uploaded
fcaramia
parents:
diff changeset
66
51969e284317 Uploaded
fcaramia
parents:
diff changeset
67 #
51969e284317 Uploaded
fcaramia
parents:
diff changeset
68 # Read in file
51969e284317 Uploaded
fcaramia
parents:
diff changeset
69 #
51969e284317 Uploaded
fcaramia
parents:
diff changeset
70 my $input = shift;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
71 my $output = shift;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
72 my $chr_ord = shift;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
73 open(IN, $input) or die "Can't open $input': $!\n";
51969e284317 Uploaded
fcaramia
parents:
diff changeset
74 open(OUT, ">$output") or die "Can't create $output': $!\n";
51969e284317 Uploaded
fcaramia
parents:
diff changeset
75 my %output;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
76
51969e284317 Uploaded
fcaramia
parents:
diff changeset
77 while ( <IN> )
51969e284317 Uploaded
fcaramia
parents:
diff changeset
78 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
79 if ( /^#/ )
51969e284317 Uploaded
fcaramia
parents:
diff changeset
80 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
81 print OUT;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
82 next;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
83 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
84 chomp;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
85 my $line = $_;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
86
51969e284317 Uploaded
fcaramia
parents:
diff changeset
87 my @flds = split ( "\t", $line );
51969e284317 Uploaded
fcaramia
parents:
diff changeset
88 my $ref = $flds[3];
51969e284317 Uploaded
fcaramia
parents:
diff changeset
89 my $alt = $flds[4];
51969e284317 Uploaded
fcaramia
parents:
diff changeset
90 #
51969e284317 Uploaded
fcaramia
parents:
diff changeset
91 # Deletion of bases
51969e284317 Uploaded
fcaramia
parents:
diff changeset
92 #
51969e284317 Uploaded
fcaramia
parents:
diff changeset
93 if ( $alt =~ /^\-/ )
51969e284317 Uploaded
fcaramia
parents:
diff changeset
94 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
95 ($flds[3], $flds[4]) = ($ref.substr($alt,1), $ref);
51969e284317 Uploaded
fcaramia
parents:
diff changeset
96 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
97
51969e284317 Uploaded
fcaramia
parents:
diff changeset
98 #
51969e284317 Uploaded
fcaramia
parents:
diff changeset
99 # Insertion of bases
51969e284317 Uploaded
fcaramia
parents:
diff changeset
100 #
51969e284317 Uploaded
fcaramia
parents:
diff changeset
101 if ( $alt =~ /^\+/ )
51969e284317 Uploaded
fcaramia
parents:
diff changeset
102 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
103 $flds[4] = $ref.substr($alt,1);
51969e284317 Uploaded
fcaramia
parents:
diff changeset
104 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
105 print OUT join( "\t", @flds),"\n" unless defined $chr_ord;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
106 $output{$flds[0]}{$flds[1]} = join( "\t", @flds)."\n" if defined $chr_ord;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
107 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
108 close(IN);
51969e284317 Uploaded
fcaramia
parents:
diff changeset
109 # if chromosome order given return in sorted order
51969e284317 Uploaded
fcaramia
parents:
diff changeset
110 if(defined $chr_ord)
51969e284317 Uploaded
fcaramia
parents:
diff changeset
111 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
112 for my $chrom (@{ $chr_ord })
51969e284317 Uploaded
fcaramia
parents:
diff changeset
113 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
114 for my $pos (sort {$a<=>$b} keys %{ $output{$chrom} })
51969e284317 Uploaded
fcaramia
parents:
diff changeset
115 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
116 print OUT $output{$chrom}{$pos};
51969e284317 Uploaded
fcaramia
parents:
diff changeset
117 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
118 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
119 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
120 close(OUT);
51969e284317 Uploaded
fcaramia
parents:
diff changeset
121 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
122
51969e284317 Uploaded
fcaramia
parents:
diff changeset
123
51969e284317 Uploaded
fcaramia
parents:
diff changeset
124 sub chromosome_order
51969e284317 Uploaded
fcaramia
parents:
diff changeset
125 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
126 my $input = shift;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
127 # calculate flagstats
51969e284317 Uploaded
fcaramia
parents:
diff changeset
128 my $COMM = "samtools view -H $input | grep '^\@SQ'";
51969e284317 Uploaded
fcaramia
parents:
diff changeset
129 my @SQ = `$COMM`;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
130 chomp @SQ;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
131 for(my $i = 0; $i <= $#SQ; $i++)
51969e284317 Uploaded
fcaramia
parents:
diff changeset
132 {
51969e284317 Uploaded
fcaramia
parents:
diff changeset
133 $SQ[$i] =~ s/^\@SQ\tSN:(.*?)\tLN:\d+$/$1/;
51969e284317 Uploaded
fcaramia
parents:
diff changeset
134 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
135 return(@SQ);
51969e284317 Uploaded
fcaramia
parents:
diff changeset
136 }
51969e284317 Uploaded
fcaramia
parents:
diff changeset
137
51969e284317 Uploaded
fcaramia
parents:
diff changeset
138