annotate strelka2/libexec/consolidateResults.pl @ 0:7a9f20ca4ad5

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