Skip to content

Commit

Permalink
Merge pull request #6597 from bgruening/trr
Browse files Browse the repository at this point in the history
add trr datatype
  • Loading branch information
jmchilton committed Aug 15, 2018
2 parents ef0a515 + e42829f commit 318fc09
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/datatypes_conf.xml.sample
Expand Up @@ -573,6 +573,7 @@
<datatype extension="phar" type="galaxy.datatypes.molecules:PHAR" display_in_upload="false"/>
<datatype extension="pdb" type="galaxy.datatypes.molecules:PDB" display_in_upload="true"/>
<datatype extension="pdbqt" type="galaxy.datatypes.molecules:PDBQT" display_in_upload="true"/>
<datatype extension="trr" type="galaxy.datatypes.binary:Trr" display_in_upload="true"/>
<datatype extension="grd" type="galaxy.datatypes.molecules:grd" display_in_upload="true"/>
<datatype extension="grd.tgz" type="galaxy.datatypes.molecules:grdtgz" display_in_upload="true"/>
<!-- mothur formats -->
Expand Down Expand Up @@ -723,6 +724,7 @@
<sniffer type="galaxy.datatypes.binary:PostgresqlArchive"/>
<sniffer type="galaxy.datatypes.binary:ICM"/>
<sniffer type="galaxy.datatypes.binary:Idat"/>
<sniffer type="galaxy.datatypes.binary:Trr"/>
<sniffer type="galaxy.datatypes.annotation:Augustus"/>
<sniffer type="galaxy.datatypes.triples:Rdf"/>
<sniffer type="galaxy.datatypes.blast:BlastXml"/>
Expand Down
43 changes: 43 additions & 0 deletions lib/galaxy/datatypes/binary.py
Expand Up @@ -736,6 +736,49 @@ def display_peek(self, dataset):
return "Binary HDF5 file (%s)" % (nice_size(dataset.get_size()))


class Trr(Binary):
"""
Class describing an trr file from the GROMACS suite
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('em.trr')
>>> Trr().sniff(fname)
True
>>> fname = get_test_fname('interval.interval')
>>> Trr().sniff(fname)
False
"""
file_ext = "trr"

def __init__(self, **kwd):
Binary.__init__(self, **kwd)
self._magic_number = 1993

def sniff(self, filename):
# The first 4 bytes of any trr file containing 1993
try:
header = open(filename, 'rb').read(struct.calcsize('>1i'))
if struct.unpack('>1i', header)[0] == self._magic_number:
return True
return False
except Exception:
return False

def set_peek(self, dataset, is_multi_byte=False):
if not dataset.dataset.purged:
dataset.peek = "Binary GROMACS trr file"
dataset.blurb = nice_size(dataset.get_size())
else:
dataset.peek = 'file does not exist'
dataset.blurb = 'file purged from disk'

def display_peek(self, dataset):
try:
return dataset.peek
except Exception:
return "Binary GROMACS trr file (%s)" % (nice_size(dataset.get_size()))


class Biom2(H5):
"""
Class describing a biom2 file (http://biom-format.org/documentation/biom_format.html)
Expand Down
Binary file added lib/galaxy/datatypes/test/em.trr
Binary file not shown.

0 comments on commit 318fc09

Please sign in to comment.