annotate sra.py @ 16:dd337a830b5c

Use patched versions of tools.
author Matt Shirley <mdshw5@gmail.com>
date Mon, 30 Mar 2015 16:22:27 -0400
parents 558a88cd49e4
children ce2bb7841f17
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
1 """
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
2 NCBI sra class
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
3 """
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
4 import logging
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
5 import binascii
6
e4c21444a3ba Add sniffer, clean up imports, register sniffable datatype.
Matt Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
6 from galaxy.datatypes.data import nice_size
e4c21444a3ba Add sniffer, clean up imports, register sniffable datatype.
Matt Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
7 from galaxy.datatypes.binary import Binary
3
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
8
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
9 log = logging.getLogger(__name__)
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
10
6
e4c21444a3ba Add sniffer, clean up imports, register sniffable datatype.
Matt Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
11 class Sra(Binary):
3
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
12 """ Sequence Read Archive (SRA) """
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
13 file_ext = 'sra'
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
14
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
15 def __init__( self, **kwd ):
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
16 Binary.__init__( self, **kwd )
6
e4c21444a3ba Add sniffer, clean up imports, register sniffable datatype.
Matt Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
17
3
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
18 def sniff( self, filename ):
6
e4c21444a3ba Add sniffer, clean up imports, register sniffable datatype.
Matt Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
19 """ The first 8 bytes of any NCBI sra file is 'NCBI.sra', and the file is binary.
e4c21444a3ba Add sniffer, clean up imports, register sniffable datatype.
Matt Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
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
3
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
21 """
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
22 try:
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
23 header = open(filename).read(8)
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
24 if binascii.b2a_hex(header) == binascii.hexlify('NCBI.sra'):
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
25 return True
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
26 else:
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
27 return False
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
28 except:
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
29 return False
6
e4c21444a3ba Add sniffer, clean up imports, register sniffable datatype.
Matt Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
30
3
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
31 def set_peek(self, dataset, is_multi_byte=False):
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
32 if not dataset.dataset.purged:
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
33 dataset.peek = 'Binary sra file'
6
e4c21444a3ba Add sniffer, clean up imports, register sniffable datatype.
Matt Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
34 dataset.blurb = nice_size(dataset.get_size())
3
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
35 else:
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
36 dataset.peek = 'file does not exist'
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
37 dataset.blurb = 'file purged from disk'
6
e4c21444a3ba Add sniffer, clean up imports, register sniffable datatype.
Matt Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
38
3
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
39 def display_peek(self, dataset):
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
40 try:
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
41 return dataset.peek
956e892b299d Add missing SRA datatype
matt-shirley
parents:
diff changeset
42 except:
6
e4c21444a3ba Add sniffer, clean up imports, register sniffable datatype.
Matt Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
43 return 'Binary sra file (%s)' % (nice_size(dataset.get_size()))