Skip to content

Commit

Permalink
Merge pull request #4410 from jmchilton/excel97
Browse files Browse the repository at this point in the history
Add Excel97 Datatype
  • Loading branch information
bgruening committed Aug 11, 2017
2 parents cca00ea + fbde34f commit c6e45e7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/datatypes_conf.xml.sample
Expand Up @@ -384,6 +384,7 @@
<datatype extension="rdf" type="galaxy.datatypes.triples:Rdf" display_in_upload="true"/>
<datatype extension="jsonld" type="galaxy.datatypes.triples:Jsonld" display_in_upload="true"/>
<!-- Excel datatypes -->
<datatype extension="excel.xls" type="galaxy.datatypes.binary:ExcelXls" display_in_upload="true"/>
<datatype extension="xlsx" type="galaxy.datatypes.binary:Xlsx" display_in_upload="true" />
<datatype extension="btwisted" type="galaxy.datatypes.data:Text" subclass="true"/>
<datatype extension="cai" type="galaxy.datatypes.data:Text" subclass="true"/>
Expand Down
34 changes: 34 additions & 0 deletions lib/galaxy/datatypes/binary.py
Expand Up @@ -1174,6 +1174,40 @@ def sniff( self, filename ):
Binary.register_sniffable_binary_format("xlsx", "xlsx", Xlsx)


class ExcelXls( Binary ):
"""Class describing an Excel (xls) file"""
file_ext = "excel.xls"
edam_format = "format_3468"

def sniff( self, filename ):
mime_type = subprocess.check_output("file --mime-type '{}'".format(filename), shell=True).rstrip()
if mime_type.find("application/vnd.ms-excel") != -1:
return True
else:
return False

def get_mime( self ):
"""Returns the mime type of the datatype"""
return 'application/vnd.ms-excel'

def set_peek( self, dataset, is_multi_byte=False ):
if not dataset.dataset.purged:
dataset.peek = "Microsoft Excel XLS file"
dataset.blurb = data.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:
return "Microsoft Excel XLS file (%s)" % ( data.nice_size( dataset.get_size() ) )


Binary.register_sniffable_binary_format("excel.xls", "excel.xls", ExcelXls)


class Sra( Binary ):
""" Sequence Read Archive (SRA) datatype originally from mdshw5/sra-tools-galaxy"""
file_ext = 'sra'
Expand Down
3 changes: 3 additions & 0 deletions lib/galaxy/datatypes/sniff.py
Expand Up @@ -383,6 +383,9 @@ def guess_ext( fname, sniff_order, is_multi_byte=False ):
>>> fname = get_test_fname('diamond_db.dmnd')
>>> guess_ext(fname, sniff_order)
'dmnd'
>>> fname = get_test_fname('1.xls')
>>> guess_ext(fname, sniff_order)
'excel.xls'
"""
file_ext = None
for datatype in sniff_order:
Expand Down
Binary file added lib/galaxy/datatypes/test/1.xls
Binary file not shown.

0 comments on commit c6e45e7

Please sign in to comment.