diff --git a/tools/gatk/analyze_covariates.xml b/tools/gatk/analyze_covariates.xml index 93732666d0f..01855e7a4a5 100644 --- a/tools/gatk/analyze_covariates.xml +++ b/tools/gatk/analyze_covariates.xml @@ -74,7 +74,7 @@ GenomeAnalysisTK: AnalyzeCovariates accepts an recal CSV file. **Outputs** -The output is in and HTML file with links to PDF graphs and a data files. +The output is in CSV and HTML files with links to PDF graphs and a data files. Go `here <http://www.broadinstitute.org/gsa/wiki/index.php/Input_files_for_the_GATK>`_ for details on GATK file formats. diff --git a/tools/gatk/count_covariates.xml b/tools/gatk/count_covariates.xml index 1e044acc240..c8df346894f 100644 --- a/tools/gatk/count_covariates.xml +++ b/tools/gatk/count_covariates.xml @@ -2,12 +2,15 @@ on BAM files gatk + samtools gatk_wrapper.py --max_jvm_heap_fraction "1" --stdout "${output_log}" -d "-I" "${reference_source.input_bam}" "${reference_source.input_bam.ext}" "gatk_input" - -d "" "${reference_source.input_bam.metadata.bam_index}" "bam_index" "gatk_input" ##hardcode galaxy ext type as bam_index + #if str( $reference_source.input_bam.metadata.bam_index ) != "None": + -d "" "${reference_source.input_bam.metadata.bam_index}" "bam_index" "gatk_input" ##hardcode galaxy ext type as bam_index + #end if -p 'java -jar "${GALAXY_DATA_INDEX_DIR}/shared/jars/gatk/GenomeAnalysisTK.jar" -T "CountCovariates" @@ -143,7 +146,6 @@ - @@ -155,7 +157,6 @@ - diff --git a/tools/gatk/depth_of_coverage.xml b/tools/gatk/depth_of_coverage.xml index c4fa518aa86..85fb0a46e76 100644 --- a/tools/gatk/depth_of_coverage.xml +++ b/tools/gatk/depth_of_coverage.xml @@ -2,13 +2,16 @@ on BAM files gatk + samtools gatk_wrapper.py --max_jvm_heap_fraction "1" --stdout "${output_log}" #for $i, $input_bam in enumerate( $reference_source.input_bams ): -d "-I" "${input_bam.input_bam}" "${input_bam.input_bam.ext}" "gatk_input_${i}" - -d "" "${input_bam.input_bam.metadata.bam_index}" "bam_index" "gatk_input_${i}" ##hardcode galaxy ext type as bam_index + #if str( $input_bam.input_bam.metadata.bam_index ) != "None": + -d "" "${input_bam.input_bam.metadata.bam_index}" "bam_index" "gatk_input_${i}" ##hardcode galaxy ext type as bam_index + #end if #end for -p 'java -jar "${GALAXY_DATA_INDEX_DIR}/shared/jars/gatk/GenomeAnalysisTK.jar" @@ -190,7 +193,6 @@ - @@ -204,7 +206,6 @@ - diff --git a/tools/gatk/gatk_wrapper.py b/tools/gatk/gatk_wrapper.py index b6d2f3f508f..17e8379811d 100644 --- a/tools/gatk/gatk_wrapper.py +++ b/tools/gatk/gatk_wrapper.py @@ -43,6 +43,23 @@ def html_report_from_directory( html_out, dir ): html_out.write( '
  • %s
  • \n' % ( fname, fname ) ) html_out.write( '\n\n\n' ) +def index_bam_files( bam_filenames, tmp_dir ): + for bam_filename in bam_filenames: + bam_index_filename = "%s.bai" % bam_filename + if not os.path.exists( bam_index_filename ): + #need to index this bam file + stderr_name = tempfile.NamedTemporaryFile( prefix = "bam_index_stderr" ).name + command = 'samtools index %s %s' % ( bam_filename, bam_index_filename ) + proc = subprocess.Popen( args=command, shell=True, stderr=open( stderr_name, 'wb' ) ) + return_code = proc.wait() + if return_code: + for line in open( stderr_name ): + print >> sys.stderr, line + os.unlink( stderr_name ) #clean up + cleanup_before_exit( tmp_dir ) + raise Exception( "Error indexing BAM file" ) + os.unlink( stderr_name ) #clean up + def __main__(): #Parse Command Line parser = optparse.OptionParser() @@ -67,11 +84,15 @@ def __main__(): cmd = cmd.replace( 'java ', 'java -Xmx%s ' % ( options.max_jvm_heap ), 1 ) elif options.max_jvm_heap_fraction is not None: cmd = cmd.replace( 'java ', 'java -XX:DefaultMaxRAMFraction=%s -XX:+UseParallelGC ' % ( options.max_jvm_heap_fraction ), 1 ) + bam_filenames = [] if options.datasets: for ( dataset_arg, filename, galaxy_ext, prefix ) in options.datasets: gatk_filename = gatk_filename_from_galaxy( filename, galaxy_ext, target_dir = tmp_dir, prefix = prefix ) if dataset_arg: cmd = '%s %s "%s"' % ( cmd, gatk_filetype_argument_substitution( dataset_arg, galaxy_ext ), gatk_filename ) + if galaxy_ext == "bam": + bam_filenames.append( gatk_filename ) + index_bam_files( bam_filenames, tmp_dir ) #set up stdout and stderr output options stdout = open_file_from_option( options.stdout, mode = 'wb' ) stderr = open_file_from_option( options.stderr, mode = 'wb' ) diff --git a/tools/gatk/indel_realigner.xml b/tools/gatk/indel_realigner.xml index a6c40a958bd..80fa4af1ee8 100644 --- a/tools/gatk/indel_realigner.xml +++ b/tools/gatk/indel_realigner.xml @@ -2,12 +2,15 @@ - perform local realignment gatk + samtools gatk_wrapper.py --max_jvm_heap_fraction "1" --stdout "${output_log}" -d "-I" "${reference_source.input_bam}" "${reference_source.input_bam.ext}" "gatk_input" - -d "" "${reference_source.input_bam.metadata.bam_index}" "bam_index" "gatk_input" ##hardcode galaxy ext type as bam_index + #if str( $reference_source.input_bam.metadata.bam_index ) != "None": + -d "" "${reference_source.input_bam.metadata.bam_index}" "bam_index" "gatk_input" ##hardcode galaxy ext type as bam_index + #end if -p 'java -jar "${GALAXY_DATA_INDEX_DIR}/shared/jars/gatk/GenomeAnalysisTK.jar" -T "IndelRealigner" @@ -121,7 +124,6 @@ - @@ -133,7 +135,6 @@ - diff --git a/tools/gatk/print_reads.xml b/tools/gatk/print_reads.xml index 7b10e74a115..5e0295430c1 100644 --- a/tools/gatk/print_reads.xml +++ b/tools/gatk/print_reads.xml @@ -2,13 +2,16 @@ from BAM files gatk + samtools gatk_wrapper.py --max_jvm_heap_fraction "1" --stdout "${output_log}" #for $i, $input_bam in enumerate( $reference_source.input_bams ): -d "-I" "${input_bam.input_bam}" "${input_bam.input_bam.ext}" "gatk_input_${i}" - -d "" "${input_bam.input_bam.metadata.bam_index}" "bam_index" "gatk_input_${i}" ##hardcode galaxy ext type as bam_index + #if str( $input_bam.input_bam.metadata.bam_index ) != "None": + -d "" "${input_bam.input_bam.metadata.bam_index}" "bam_index" "gatk_input_${i}" ##hardcode galaxy ext type as bam_index + #end if #end for -p 'java -jar "${GALAXY_DATA_INDEX_DIR}/shared/jars/gatk/GenomeAnalysisTK.jar" @@ -106,7 +109,6 @@ - @@ -120,7 +122,6 @@ - diff --git a/tools/gatk/realigner_target_creator.xml b/tools/gatk/realigner_target_creator.xml index 2f49f4359c0..3171ef42b38 100644 --- a/tools/gatk/realigner_target_creator.xml +++ b/tools/gatk/realigner_target_creator.xml @@ -2,12 +2,15 @@ for use in local realignment gatk + samtools gatk_wrapper.py --max_jvm_heap_fraction "1" --stdout "${output_log}" -d "-I" "${reference_source.input_bam}" "${reference_source.input_bam.ext}" "gatk_input" - -d "" "${reference_source.input_bam.metadata.bam_index}" "bam_index" "gatk_input" ##hardcode galaxy ext type as bam_index + #if str( $reference_source.input_bam.metadata.bam_index ) != "None": + -d "" "${reference_source.input_bam.metadata.bam_index}" "bam_index" "gatk_input" ##hardcode galaxy ext type as bam_index + #end if -p 'java -jar "${GALAXY_DATA_INDEX_DIR}/shared/jars/gatk/GenomeAnalysisTK.jar" -T "RealignerTargetCreator" @@ -109,7 +112,6 @@ - @@ -121,7 +123,6 @@ - diff --git a/tools/gatk/table_recalibration.xml b/tools/gatk/table_recalibration.xml index b30ab9d6186..9ad3c451edc 100644 --- a/tools/gatk/table_recalibration.xml +++ b/tools/gatk/table_recalibration.xml @@ -2,12 +2,15 @@ on BAM files gatk + samtools gatk_wrapper.py --max_jvm_heap_fraction "1" --stdout "${output_log}" -d "-I" "${reference_source.input_bam}" "${reference_source.input_bam.ext}" "gatk_input" - -d "" "${reference_source.input_bam.metadata.bam_index}" "bam_index" "gatk_input" ##hardcode galaxy ext type as bam_index + #if str( $reference_source.input_bam.metadata.bam_index ) != "None": + -d "" "${reference_source.input_bam.metadata.bam_index}" "bam_index" "gatk_input" ##hardcode galaxy ext type as bam_index + #end if -p 'java -jar "${GALAXY_DATA_INDEX_DIR}/shared/jars/gatk/GenomeAnalysisTK.jar" -T "TableRecalibration" @@ -126,7 +129,6 @@ - @@ -138,7 +140,6 @@ - diff --git a/tools/gatk/unified_genotyper.xml b/tools/gatk/unified_genotyper.xml index 7b9d16925a1..41ea01555dc 100644 --- a/tools/gatk/unified_genotyper.xml +++ b/tools/gatk/unified_genotyper.xml @@ -2,13 +2,16 @@ SNP and indel caller gatk + samtools gatk_wrapper.py --max_jvm_heap_fraction "1" --stdout "${output_log}" #for $i, $input_bam in enumerate( $reference_source.input_bams ): -d "-I" "${input_bam.input_bam}" "${input_bam.input_bam.ext}" "gatk_input_${i}" - -d "" "${input_bam.input_bam.metadata.bam_index}" "bam_index" "gatk_input_${i}" ##hardcode galaxy ext type as bam_index + #if str( $input_bam.input_bam.metadata.bam_index ) != "None": + -d "" "${input_bam.input_bam.metadata.bam_index}" "bam_index" "gatk_input_${i}" ##hardcode galaxy ext type as bam_index + #end if #end for -p 'java -jar "${GALAXY_DATA_INDEX_DIR}/shared/jars/gatk/GenomeAnalysisTK.jar" @@ -155,7 +158,6 @@ - @@ -169,7 +171,6 @@ - diff --git a/tools/gatk/variant_annotator.xml b/tools/gatk/variant_annotator.xml index c959ebadadf..6bc29d0a23d 100644 --- a/tools/gatk/variant_annotator.xml +++ b/tools/gatk/variant_annotator.xml @@ -2,13 +2,16 @@ gatk + samtools gatk_wrapper.py --max_jvm_heap_fraction "1" --stdout "${output_log}" #if str( $reference_source.input_bam ) != "None": -d "-I" "${reference_source.input_bam}" "${reference_source.input_bam.ext}" "gatk_input" - -d "" "${reference_source.input_bam.metadata.bam_index}" "bam_index" "gatk_input" ##hardcode galaxy ext type as bam_index + #if str( $reference_source.input_bam.metadata.bam_index ) != "None": + -d "" "${reference_source.input_bam.metadata.bam_index}" "bam_index" "gatk_input" ##hardcode galaxy ext type as bam_index + #end if #end if -d "--variant" "${reference_source.input_variant}" "${reference_source.input_variant.ext}" "input_variant" -p 'java @@ -151,7 +154,6 @@ - @@ -165,7 +167,6 @@ -