Mercurial > repos > matt-shirley > sra_tools
annotate sra.py @ 18:384f93a14b47 draft
try static build to resolve missing libraries
author | Matt Shirley <mdshw5@gmail.com> |
---|---|
date | Mon, 17 Jun 2013 21:22:17 -0400 |
parents | 93a60318b9ca |
children | a1255154fa3f |
rev | line source |
---|---|
0
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
1 """ |
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
2 Sra class |
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
3 """ |
16 | 4 import logging |
12 | 5 import binascii |
16 | 6 from galaxy.datatypes.data import * |
0
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
7 from galaxy.datatypes.sniff import * |
16 | 8 from galaxy.datatypes.binary import * |
9 from galaxy.datatypes.metadata import * | |
0
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
10 |
16 | 11 log = logging.getLogger(__name__) |
12 | |
13 class SRA( Binary ): | |
0
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
14 """ Sequence Read Archive (SRA) """ |
1 | 15 file_ext = 'sra' |
0
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
16 |
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
17 def __init__( self, **kwd ): |
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
18 Binary.__init__( self, **kwd ) |
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
19 def sniff( self, filename ): |
1 | 20 """ The first 8 bytes of any NCBI sra file is 'NCIB.sra', and the file is binary. Not sure if EBI and DDBJ files may differ. |
21 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 | |
22 """ | |
0
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
23 try: |
1 | 24 header = open(filename).read(8) |
25 if binascii.b2a_hex(header) == binascii.hexlify('NCBI.sra'): | |
0
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
26 return True |
12 | 27 else: |
28 return False | |
0
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
29 except: |
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
30 return False |
1 | 31 def set_peek(self, dataset, is_multi_byte=False): |
0
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
32 if not dataset.dataset.purged: |
12 | 33 dataset.peek = 'Binary SRA file' |
1 | 34 dataset.blurb = data.nice_size(dataset.get_size()) |
0
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
35 else: |
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
36 dataset.peek = 'file does not exist' |
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
37 dataset.blurb = 'file purged from disk' |
1 | 38 def display_peek(self, dataset): |
0
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
39 try: |
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
40 return dataset.peek |
ffdd41766195
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
matt-shirley <mdshw5@gmail.com>
parents:
diff
changeset
|
41 except: |
16 | 42 return 'Binary SRA file (%s)' % ( data.nice_size(dataset.get_size())) |
43 | |
44 if hasattr(Binary, 'register_sniffable_binary_format'): | |
45 Binary.register_sniffable_binary_format('SRA', 'SRA', SRA) |