comparison sra.py @ 0:9f74a22d2060 draft default tip

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sra-tools commit 70fadb7e8972b1db550d0e067584930ce1ec8673-dirty
author mvdbeek
date Wed, 04 Nov 2015 06:57:32 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:9f74a22d2060
1 """
2 NCBI sra class
3 """
4 import logging
5 import binascii
6 from galaxy.datatypes.data import nice_size
7 from galaxy.datatypes.binary import Binary
8
9 log = logging.getLogger(__name__)
10
11 class Sra(Binary):
12 """ Sequence Read Archive (SRA) """
13 file_ext = 'sra'
14
15 def __init__( self, **kwd ):
16 Binary.__init__( self, **kwd )
17
18 def sniff( self, filename ):
19 """ The first 8 bytes of any NCBI sra file is 'NCBI.sra', and the file is binary.
20 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
21 """
22 try:
23 header = open(filename).read(8)
24 if binascii.b2a_hex(header) == binascii.hexlify('NCBI.sra'):
25 return True
26 else:
27 return False
28 except:
29 return False
30
31 def set_peek(self, dataset, is_multi_byte=False):
32 if not dataset.dataset.purged:
33 dataset.peek = 'Binary sra file'
34 dataset.blurb = nice_size(dataset.get_size())
35 else:
36 dataset.peek = 'file does not exist'
37 dataset.blurb = 'file purged from disk'
38
39 def display_peek(self, dataset):
40 try:
41 return dataset.peek
42 except:
43 return 'Binary sra file (%s)' % (nice_size(dataset.get_size()))
44
45 Binary.register_sniffable_binary_format('sra', 'sra', Sra)