Mercurial > repos > mvdbeek > test_sra
diff sra.py @ 0:ec8b334b5ebb draft
planemo upload commit 96ecd86165525684766848f98a1c3be4353ec3b1-dirty
author | mvdbeek |
---|---|
date | Fri, 14 Aug 2015 12:23:28 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sra.py Fri Aug 14 12:23:28 2015 -0400 @@ -0,0 +1,45 @@ +""" +NCBI sra class +""" +import logging +import binascii +from galaxy.datatypes.data import nice_size +from galaxy.datatypes.binary import Binary + +log = logging.getLogger(__name__) + +class Sra(Binary): + """ Sequence Read Archive (SRA) """ + file_ext = 'sra' + + def __init__( self, **kwd ): + Binary.__init__( self, **kwd ) + + def sniff( self, filename ): + """ The first 8 bytes of any NCBI sra file is 'NCBI.sra', and the file is binary. + For details about the format, see http://www.ncbi.nlm.nih.gov/books/n/helpsra/SRA_Overview_BK/#SRA_Overview_BK.4_SRA_Data_Structure + """ + try: + header = open(filename).read(8) + if binascii.b2a_hex(header) == binascii.hexlify('NCBI.sra'): + return True + else: + return False + except: + return False + + def set_peek(self, dataset, is_multi_byte=False): + if not dataset.dataset.purged: + dataset.peek = 'Binary sra 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: + return 'Binary sra file (%s)' % (nice_size(dataset.get_size())) + +Binary.register_sniffable_binary_format('sra', 'sra', Sra)