annotate libexec/consolidateResults.pl @ 9:0e8e6011082b

Strelka Workflow 0.0.2
author mini
date Fri, 26 Sep 2014 15:51:35 +0200
parents 87568e5a7d4f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
1 #!/usr/bin/env perl
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
2
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
3 =head1 LICENSE
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
4
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
5 Strelka Workflow Software
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
6 Copyright (c) 2009-2013 Illumina, Inc.
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
7
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
8 This software is provided under the terms and conditions of the
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
9 Illumina Open Source Software License 1.
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
10
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
11 You should have received a copy of the Illumina Open Source
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
12 Software License 1 along with this program. If not, see
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
13 <https://github.com/downloads/sequencing/licenses/>.
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
14
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
15 =head1 SYNOPSIS
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
16
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
17 consolidateSomaticVariants.pl [options] | --help
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
18
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
19 =head2 SUMMARY
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
20
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
21 Aggregate final results from all chromosomes
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
22
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
23 =cut
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
24
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
25 use warnings FATAL => 'all';
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
26 use strict;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
27
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
28 use Carp;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
29 $SIG{__DIE__} = \&Carp::confess;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
30
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
31 use File::Spec;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
32 use File::Temp;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
33 use Getopt::Long;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
34 use Pod::Usage;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
35
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
36 my $baseDir;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
37 my $libDir;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
38 BEGIN {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
39 my $thisDir=(File::Spec->splitpath($0))[1];
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
40 $baseDir=File::Spec->catdir($thisDir,File::Spec->updir());
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
41 $libDir=File::Spec->catdir($baseDir,'lib');
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
42 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
43 use lib $libDir;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
44 use Utils;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
45 use Vcf;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
46
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
47 if(getAbsPath($baseDir)) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
48 errorX("Can't resolve path for strelka_workflow install directory: '$baseDir'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
49 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
50
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
51
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
52 my $scriptName=(File::Spec->splitpath($0))[2];
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
53 my $argCount=scalar(@ARGV);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
54 my $cmdline=join(' ',$0,@ARGV);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
55
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
56
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
57 my $configFile;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
58 my $help;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
59
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
60 GetOptions( "config=s" => \$configFile,
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
61 "help|h" => \$help) or pod2usage(2);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
62
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
63 pod2usage(2) if($help);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
64 pod2usage(2) unless(defined($configFile));
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
65
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
66 #
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
67 # read config and validate values
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
68 #
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
69 checkFile($configFile,"configuration ini");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
70 my $config = parseConfigIni($configFile);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
71
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
72
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
73 for (qw(outDir chromOrder)) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
74 errorX("Undefined configuration option: '$_'") unless(defined($config->{derived}{$_}));
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
75 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
76 for (qw(isWriteRealignedBam binSize)) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
77 errorX("Undefined configuration option: '$_'") unless(defined($config->{user}{$_}));
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
78 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
79
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
80 my $userconfig = $config->{user};
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
81
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
82 my @chromOrder = split(/\t/,$config->{derived}{chromOrder});
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
83 for my $chrom (@chromOrder) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
84 my $chromSizeKey = "chrom_" . $chrom . "_size";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
85 errorX("Undefined configuration option: '$_'") unless(defined($chromSizeKey));
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
86 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
87
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
88 my $outDir = $config->{derived}{outDir};
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
89 checkDir($outDir,"output");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
90
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
91
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
92 my $isWriteRealignedBam = $userconfig->{isWriteRealignedBam};
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
93
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
94 for my $chrom (@chromOrder) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
95 my $chromDir = File::Spec->catdir($outDir,'chromosomes',$chrom);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
96 checkDir($chromDir,"input chromosome");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
97
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
98 next unless($isWriteRealignedBam);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
99 my $chromSizeKey = "chrom_" . $chrom . "_size";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
100 my $binList = getBinList($config->{derived}{$chromSizeKey},$userconfig->{binSize});
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
101 for my $binId (@$binList) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
102 my $dir = File::Spec->catdir($chromDir,'bins',$binId);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
103 checkDir($dir,"input bin");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
104 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
105 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
106
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
107
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
108
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
109 # suffix used for large result file intermediates:
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
110 my $itag = ".incomplete";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
111
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
112
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
113 #
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
114 # concatenate vcfs:
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
115 #
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
116 sub concatenateVcfs($) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
117 my $fileName = shift;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
118
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
119 my $is_first = 1;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
120
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
121 my $allFileName = "all." . $fileName;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
122 my $allFile = File::Spec->catfile($outDir,'results',$allFileName . $itag);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
123 open(my $aFH,'>',"$allFile")
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
124 || errorX("Failed to open file: '$allFile'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
125
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
126 # loop over all chroms once to create the header, and one more time for all the data:
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
127 my $headervcf;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
128 for my $chrom (@chromOrder) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
129 my $chromDir = File::Spec->catdir($outDir,'chromosomes',$chrom);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
130 my $iFile = File::Spec->catfile($chromDir,$fileName);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
131 checkFile($iFile);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
132
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
133 my $depthKey="maxDepth_${chrom}";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
134
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
135 if($is_first) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
136 open(my $iFH,'<',"$iFile")
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
137 || errorX("Failed to open file: '$iFile'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
138 $headervcf = Vcf->new(fh=>$iFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
139 $headervcf->parse_header();
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
140 $headervcf->remove_header_line(key=>"cmdline");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
141 $headervcf->add_header_line({key=>"cmdline",value=>$cmdline});
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
142 $headervcf->remove_header_line(key=>"$depthKey");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
143 close($iFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
144 $is_first=0;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
145 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
146
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
147 {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
148 open(my $iFH,'<',"$iFile")
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
149 || errorX("Failed to open file: '$iFile'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
150 my $vcf = Vcf->new(fh=>$iFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
151 $vcf->parse_header();
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
152 for my $line (@{$vcf->get_header_line(key=>"$depthKey")}) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
153 # $line seems to be returned as a length 1 array ref to a hash -- ??!?!??!!
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
154 $headervcf->add_header_line($line->[0]);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
155 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
156 $vcf->close();
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
157 close($iFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
158 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
159 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
160 print $aFH $headervcf->format_header();
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
161 $headervcf->close();
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
162
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
163 for my $chrom (@chromOrder) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
164 my $chromDir = File::Spec->catdir($outDir,'chromosomes',$chrom);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
165 my $iFile = File::Spec->catfile($chromDir,$fileName);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
166
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
167 open(my $iFH,'<',"$iFile")
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
168 || errorX("Failed to open file: '$iFile'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
169
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
170 my $vcf = Vcf->new(fh=>$iFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
171 $vcf->parse_header();
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
172 print $aFH $_ while(<$iFH>);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
173 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
174
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
175 close($aFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
176
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
177 # make a second set of files with only the passed variants:
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
178 my $passedFileName = "passed." . $fileName;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
179 my $passedFile = File::Spec->catfile($outDir,'results',$passedFileName . $itag);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
180 open(my $pFH,'>',"$passedFile")
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
181 || errorX("Failed to open file: '$passedFile'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
182
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
183 open(my $arFH,'<',"$allFile")
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
184 || errorX("Failed to open file: '$allFile'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
185
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
186 while(<$arFH>) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
187 chomp;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
188 unless(/^#/) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
189 my @F = split(/\t/);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
190 next if((scalar(@F)>=7) && ($F[6] ne "PASS"));
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
191 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
192 print $pFH "$_\n";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
193 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
194
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
195 close($arFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
196 close($pFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
197
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
198 my $allFileFinished = File::Spec->catfile($outDir,'results',$allFileName);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
199 checkMove($allFile,$allFileFinished);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
200
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
201 my $passedFileFinished = File::Spec->catfile($outDir,'results',$passedFileName);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
202 checkMove($passedFile,$passedFileFinished);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
203 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
204
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
205 concatenateVcfs("somatic.snvs.vcf");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
206 concatenateVcfs("somatic.indels.vcf");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
207
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
208
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
209 my $bamSuffix = ".realigned.bam";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
210
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
211 sub consolidateBam($) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
212 my $label = shift;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
213
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
214 my $fileName = $label . $bamSuffix;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
215
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
216 my $reDir = File::Spec->catdir($outDir,'realigned');
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
217 checkMakeDir($reDir);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
218
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
219 my @bamList;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
220 for my $chrom (@chromOrder) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
221 my $chromDir = File::Spec->catdir($outDir,'chromosomes',$chrom);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
222
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
223 my $chromSizeKey = "chrom_" . $chrom . "_size";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
224 my $binList = getBinList($config->{derived}{$chromSizeKey},$userconfig->{binSize});
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
225 for my $binId (@$binList) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
226 my $binDir = File::Spec->catdir($chromDir,'bins',$binId);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
227 my $rbamFile = File::Spec->catfile($binDir,$fileName);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
228 checkFile($rbamFile,"bin realigned bam file");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
229
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
230 push @bamList,$rbamFile;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
231 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
232 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
233
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
234 return unless(scalar(@bamList));
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
235
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
236 my $headerFH = File::Temp->new();
9
0e8e6011082b Strelka Workflow 0.0.2
mini
parents: 6
diff changeset
237 my $getHeaderCmd = "bash -c 'samtools view -H ".$bamList[0]." > $headerFH'";
6
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
238 executeCmd($getHeaderCmd);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
239
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
240 my $allFile = File::Spec->catfile($reDir,$fileName . $itag);
9
0e8e6011082b Strelka Workflow 0.0.2
mini
parents: 6
diff changeset
241 my $cmd="samtools merge -h $headerFH $allFile ". join(" ",@bamList);
6
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
242 executeCmd($cmd);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
243
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
244 my $allFileFinished = File::Spec->catfile($reDir,$fileName);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
245 checkMove($allFile,$allFileFinished);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
246
9
0e8e6011082b Strelka Workflow 0.0.2
mini
parents: 6
diff changeset
247 my $indexCmd="samtools index $allFileFinished";
6
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
248 executeCmd($indexCmd);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
249
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
250 # for now don't remove all the bin realignments...
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
251 # unlink(@bamList);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
252 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
253
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
254 if($isWriteRealignedBam) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
255 consolidateBam("normal");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
256 consolidateBam("tumor");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
257 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
258
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
259
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
260 1;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
261
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
262 __END__
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
263