annotate libexec/consolidateResults.pl @ 8:2cee4ed50058

nothing relevant
author mini
date Fri, 26 Sep 2014 14:33:07 +0200
parents 87568e5a7d4f
children 0e8e6011082b
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 #my $optDir;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
39 #my $vcftDir;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
40 BEGIN {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
41 my $thisDir=(File::Spec->splitpath($0))[1];
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
42 $baseDir=File::Spec->catdir($thisDir,File::Spec->updir());
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
43 $libDir=File::Spec->catdir($baseDir,'lib');
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
44 #$optDir=File::Spec->catdir($baseDir,'opt');
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
45 #$vcftDir=File::Spec->catdir($optDir,'vcftools','lib','perl5','site_perl');
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
46 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
47 use lib $libDir;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
48 use Utils;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
49 #use lib $vcftDir;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
50 use Vcf;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
51
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
52 if(getAbsPath($baseDir)) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
53 errorX("Can't resolve path for strelka_workflow install directory: '$baseDir'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
54 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
55 #$optDir=File::Spec->catdir($baseDir,'opt');
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
56
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
57
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
58 my $scriptName=(File::Spec->splitpath($0))[2];
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
59 my $argCount=scalar(@ARGV);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
60 my $cmdline=join(' ',$0,@ARGV);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
61
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
62
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
63 my $configFile;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
64 my $help;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
65
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
66 GetOptions( "config=s" => \$configFile,
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
67 "help|h" => \$help) or pod2usage(2);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
68
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
69 pod2usage(2) if($help);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
70 pod2usage(2) unless(defined($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 # check fixed paths
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
74 #
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
75 #my $samtoolsBin = File::Spec->catfile($optDir,'samtools','samtools');
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
76 #checkFile($samtoolsBin,"samtools binary");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
77
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 # read config and validate values
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
81 #
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
82 checkFile($configFile,"configuration ini");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
83 my $config = parseConfigIni($configFile);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
84
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
85
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
86 for (qw(outDir chromOrder)) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
87 errorX("Undefined configuration option: '$_'") unless(defined($config->{derived}{$_}));
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
88 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
89 for (qw(isWriteRealignedBam binSize)) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
90 errorX("Undefined configuration option: '$_'") unless(defined($config->{user}{$_}));
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
91 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
92
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
93 my $userconfig = $config->{user};
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
94
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
95 my @chromOrder = split(/\t/,$config->{derived}{chromOrder});
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
96 for my $chrom (@chromOrder) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
97 my $chromSizeKey = "chrom_" . $chrom . "_size";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
98 errorX("Undefined configuration option: '$_'") unless(defined($chromSizeKey));
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
99 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
100
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
101 my $outDir = $config->{derived}{outDir};
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
102 checkDir($outDir,"output");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
103
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
104
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
105 my $isWriteRealignedBam = $userconfig->{isWriteRealignedBam};
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
106
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
107 for my $chrom (@chromOrder) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
108 my $chromDir = File::Spec->catdir($outDir,'chromosomes',$chrom);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
109 checkDir($chromDir,"input chromosome");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
110
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
111 next unless($isWriteRealignedBam);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
112 my $chromSizeKey = "chrom_" . $chrom . "_size";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
113 my $binList = getBinList($config->{derived}{$chromSizeKey},$userconfig->{binSize});
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
114 for my $binId (@$binList) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
115 my $dir = File::Spec->catdir($chromDir,'bins',$binId);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
116 checkDir($dir,"input bin");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
117 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
118 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
119
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
120
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
121
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
122 # suffix used for large result file intermediates:
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
123 my $itag = ".incomplete";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
124
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
125
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
126 #
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
127 # concatenate vcfs:
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
128 #
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
129 sub concatenateVcfs($) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
130 my $fileName = shift;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
131
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
132 my $is_first = 1;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
133
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
134 my $allFileName = "all." . $fileName;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
135 my $allFile = File::Spec->catfile($outDir,'results',$allFileName . $itag);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
136 open(my $aFH,'>',"$allFile")
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
137 || errorX("Failed to open file: '$allFile'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
138
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
139 # 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
140 my $headervcf;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
141 for my $chrom (@chromOrder) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
142 my $chromDir = File::Spec->catdir($outDir,'chromosomes',$chrom);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
143 my $iFile = File::Spec->catfile($chromDir,$fileName);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
144 checkFile($iFile);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
145
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
146 my $depthKey="maxDepth_${chrom}";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
147
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
148 if($is_first) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
149 open(my $iFH,'<',"$iFile")
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
150 || errorX("Failed to open file: '$iFile'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
151 $headervcf = Vcf->new(fh=>$iFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
152 $headervcf->parse_header();
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
153 $headervcf->remove_header_line(key=>"cmdline");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
154 $headervcf->add_header_line({key=>"cmdline",value=>$cmdline});
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
155 $headervcf->remove_header_line(key=>"$depthKey");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
156 close($iFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
157 $is_first=0;
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 {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
161 open(my $iFH,'<',"$iFile")
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
162 || errorX("Failed to open file: '$iFile'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
163 my $vcf = Vcf->new(fh=>$iFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
164 $vcf->parse_header();
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
165 for my $line (@{$vcf->get_header_line(key=>"$depthKey")}) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
166 # $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
167 $headervcf->add_header_line($line->[0]);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
168 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
169 $vcf->close();
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
170 close($iFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
171 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
172 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
173 print $aFH $headervcf->format_header();
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
174 $headervcf->close();
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
175
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
176 for my $chrom (@chromOrder) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
177 my $chromDir = File::Spec->catdir($outDir,'chromosomes',$chrom);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
178 my $iFile = File::Spec->catfile($chromDir,$fileName);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
179
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
180 open(my $iFH,'<',"$iFile")
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
181 || errorX("Failed to open file: '$iFile'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
182
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
183 my $vcf = Vcf->new(fh=>$iFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
184 $vcf->parse_header();
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
185 print $aFH $_ while(<$iFH>);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
186 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
187
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
188 close($aFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
189
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
190 # make a second set of files with only the passed variants:
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
191 my $passedFileName = "passed." . $fileName;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
192 my $passedFile = File::Spec->catfile($outDir,'results',$passedFileName . $itag);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
193 open(my $pFH,'>',"$passedFile")
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
194 || errorX("Failed to open file: '$passedFile'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
195
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
196 open(my $arFH,'<',"$allFile")
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
197 || errorX("Failed to open file: '$allFile'");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
198
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
199 while(<$arFH>) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
200 chomp;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
201 unless(/^#/) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
202 my @F = split(/\t/);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
203 next if((scalar(@F)>=7) && ($F[6] ne "PASS"));
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
204 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
205 print $pFH "$_\n";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
206 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
207
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
208 close($arFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
209 close($pFH);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
210
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
211 my $allFileFinished = File::Spec->catfile($outDir,'results',$allFileName);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
212 checkMove($allFile,$allFileFinished);
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 $passedFileFinished = File::Spec->catfile($outDir,'results',$passedFileName);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
215 checkMove($passedFile,$passedFileFinished);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
216 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
217
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
218 concatenateVcfs("somatic.snvs.vcf");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
219 concatenateVcfs("somatic.indels.vcf");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
220
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
221
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
222 my $bamSuffix = ".realigned.bam";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
223
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
224 sub consolidateBam($) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
225 my $label = shift;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
226
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
227 my $fileName = $label . $bamSuffix;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
228
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
229 my $reDir = File::Spec->catdir($outDir,'realigned');
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
230 checkMakeDir($reDir);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
231
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
232 my @bamList;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
233 for my $chrom (@chromOrder) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
234 my $chromDir = File::Spec->catdir($outDir,'chromosomes',$chrom);
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 $chromSizeKey = "chrom_" . $chrom . "_size";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
237 my $binList = getBinList($config->{derived}{$chromSizeKey},$userconfig->{binSize});
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
238 for my $binId (@$binList) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
239 my $binDir = File::Spec->catdir($chromDir,'bins',$binId);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
240 my $rbamFile = File::Spec->catfile($binDir,$fileName);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
241 checkFile($rbamFile,"bin realigned bam file");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
242
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
243 push @bamList,$rbamFile;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
244 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
245 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
246
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
247 return unless(scalar(@bamList));
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
248
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
249 my $headerFH = File::Temp->new();
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
250 my $getHeaderCmd = "bash -c '$samtoolsBin view -H ".$bamList[0]." > $headerFH'";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
251 executeCmd($getHeaderCmd);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
252
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
253 my $allFile = File::Spec->catfile($reDir,$fileName . $itag);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
254 my $cmd="$samtoolsBin merge -h $headerFH $allFile ". join(" ",@bamList);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
255 executeCmd($cmd);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
256
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
257 my $allFileFinished = File::Spec->catfile($reDir,$fileName);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
258 checkMove($allFile,$allFileFinished);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
259
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
260 my $indexCmd="$samtoolsBin index $allFileFinished";
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
261 executeCmd($indexCmd);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
262
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
263 # for now don't remove all the bin realignments...
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
264 # unlink(@bamList);
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
265 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
266
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
267 if($isWriteRealignedBam) {
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
268 consolidateBam("normal");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
269 consolidateBam("tumor");
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
270 }
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
271
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
272
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
273 1;
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
274
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
275 __END__
87568e5a7d4f Testing strelka version 0.0.1
mini
parents:
diff changeset
276