Merge pull request #163 from nekrut/bcf_metadata

[WIP] Added default indexing for bcf files
This commit is contained in:
Daniel Blankenberg
2015-04-28 16:43:25 -04:00
6 changed files with 52 additions and 1 deletions
+33 -1
View File
@@ -423,11 +423,12 @@ class Bam( Binary ):
Binary.register_sniffable_binary_format("bam", "bam", Bam)
class Bcf( Binary):
"""Class describing a BCF file"""
file_ext = "bcf"
MetadataElement( name="bcf_index", desc="BCF Index File", param=metadata.FileParameter, file_ext="csi", readonly=True, no_value=None, visible=False, optional=True )
def sniff( self, filename ):
# BCF is compressed in the BGZF format, and must not be uncompressed in Galaxy.
# The first 3 bytes of any bcf file is 'BCF', and the file is binary.
@@ -439,6 +440,37 @@ class Bcf( Binary):
except:
return False
def set_meta( self, dataset, overwrite = True, **kwd ):
""" Creates the index for the BCF file. """
# These metadata values are not accessible by users, always overwrite
index_file = dataset.metadata.bcf_index
if not index_file:
index_file = dataset.metadata.spec['bcf_index'].param.new_file( dataset = dataset )
# Create the bcf index
##$ bcftools index
##Usage: bcftools index <in.bcf>
dataset_symlink = os.path.join( os.path.dirname( index_file.file_name ),
'__dataset_%d_%s' % ( dataset.id, os.path.basename( index_file.file_name ) ) )
os.symlink( dataset.file_name, dataset_symlink )
stderr_name = tempfile.NamedTemporaryFile( prefix = "bcf_index_stderr" ).name
command = [ 'bcftools', 'index', dataset_symlink ]
proc = subprocess.Popen( args=command, stderr=open( stderr_name, 'wb' ) )
exit_code = proc.wait()
shutil.move( dataset_symlink + '.csi', index_file.file_name )
stderr = open( stderr_name ).read().strip()
if stderr:
if exit_code != 0:
os.unlink( stderr_name ) #clean up
raise Exception, "Error Setting BCF Metadata: %s" % stderr
else:
print stderr
dataset.metadata.bcf_index = index_file
# Remove temp file
os.unlink( stderr_name )
Binary.register_sniffable_binary_format("bcf", "bcf", Bcf)
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
gzip compressed data, extra field
+16
View File
@@ -0,0 +1,16 @@
<tool id="metadata_bcf" name="metadata_BCF" version="1.0.0">
<command>file "${input_bcf.metadata.bcf_index}" &gt; "${output_of_input_metadata}"</command>
<inputs>
<param name="input_bcf" type="data" format="bcf" label="BCF File"/>
</inputs>
<outputs>
<data format="txt" name="output_of_input_metadata" />
</outputs>
<tests>
<test>
<param name="input_bcf" value="bcf_index_metadata_test.bcf" ftype="bcf" />
<!-- Tests whether the .bcf.csi file is of "gzip compressed data, extra field" type -->
<output name="output_of_input_metadata" ftype="txt" file="bcf_index_metadata_test.txt" compare="contains"/>
</test>
</tests>
</tool>
@@ -12,5 +12,6 @@
<datatype extension="fastqillumina" type="galaxy.datatypes.sequence:FastqIllumina" display_in_upload="true" />
<datatype extension="sam" type="galaxy.datatypes.tabular:Sam" display_in_upload="true" />
<datatype extension="bam" type="galaxy.datatypes.binary:Bam" mimetype="application/octet-stream" display_in_upload="true" description="A binary file compressed in the BGZF format with a '.bam' file extension." description_url="https://wiki.galaxyproject.org/Learn/Datatypes#BAM" />
<datatype extension="bcf" type="galaxy.datatypes.binary:Bcf" mimetype="application/octet-stream" display_in_upload="true" description="A binary file compressed in the BGZF format with a '.bcf' file extension." description_url="https://wiki.galaxyproject.org/Learn/Datatypes#BCF" />
</registration>
</datatypes>
@@ -16,6 +16,7 @@
<tool file="composite_output.xml" />
<tool file="metadata.xml" />
<tool file="metadata_bam.xml" />
<tool file="metadata_bcf.xml" />
<tool file="detect_errors_aggressive.xml" />
<tool file="md5sum.xml" />
<tool file="job_properties.xml" />