Mercurial > repos > matt-shirley > sra_tools
comparison sra.py @ 1:28fda7631857 draft
minor fixes
| author | Matt Shirley <mdshw5@gmail.com> |
|---|---|
| date | Wed, 29 May 2013 22:08:19 -0400 |
| parents | ffdd41766195 |
| children | b77840618b8f |
comparison
equal
deleted
inserted
replaced
| 0:ffdd41766195 | 1:28fda7631857 |
|---|---|
| 8 from galaxy.datatypes.metadata import MetadataElement | 8 from galaxy.datatypes.metadata import MetadataElement |
| 9 from galaxy.datatypes import metadata | 9 from galaxy.datatypes import metadata |
| 10 from galaxy.datatypes.sniff import * | 10 from galaxy.datatypes.sniff import * |
| 11 from galaxy import eggs | 11 from galaxy import eggs |
| 12 import pkg_resources | 12 import pkg_resources |
| 13 pkg_resources.require( "bx-python" ) | 13 pkg_resources.require( 'bx-python' ) |
| 14 import os, subprocess, tempfile | 14 import os, subprocess, tempfile |
| 15 import struct | 15 import struct |
| 16 | 16 |
| 17 class Sra( Binary ): | 17 class Sra( Binary ): |
| 18 """ Sequence Read Archive (SRA) """ | 18 """ Sequence Read Archive (SRA) """ |
| 19 file_ext = "sra" | 19 file_ext = 'sra' |
| 20 | 20 |
| 21 def __init__( self, **kwd ): | 21 def __init__( self, **kwd ): |
| 22 Binary.__init__( self, **kwd ) | 22 Binary.__init__( self, **kwd ) |
| 23 def sniff( self, filename ): | 23 def sniff( self, filename ): |
| 24 # The first 8 bytes of any NCBI sra file is 'NCIB.sra', and the file is binary. EBI and DDBJ files may differ. For details | 24 """ 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. |
| 25 # about the format, see http://www.ncbi.nlm.nih.gov/books/n/helpsra/SRA_Overview_BK/#SRA_Overview_BK.4_SRA_Data_Structure | 25 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 |
| 26 """ | |
| 26 try: | 27 try: |
| 27 header = open( filename ).read(8) | 28 header = open(filename).read(8) |
| 28 if binascii.b2a_hex( header ) == binascii.hexlify( 'NCBI.sra' ): | 29 if binascii.b2a_hex(header) == binascii.hexlify('NCBI.sra'): |
| 29 return True | 30 return True |
| 30 return False | 31 return False |
| 31 except: | 32 except: |
| 32 return False | 33 return False |
| 33 def set_peek( self, dataset, is_multi_byte=False ): | 34 def set_peek(self, dataset, is_multi_byte=False): |
| 34 if not dataset.dataset.purged: | 35 if not dataset.dataset.purged: |
| 35 dataset.peek = "Binary sra file" | 36 dataset.peek = 'Binary sra file' |
| 36 dataset.blurb = data.nice_size( dataset.get_size() ) | 37 dataset.blurb = data.nice_size(dataset.get_size()) |
| 37 else: | 38 else: |
| 38 dataset.peek = 'file does not exist' | 39 dataset.peek = 'file does not exist' |
| 39 dataset.blurb = 'file purged from disk' | 40 dataset.blurb = 'file purged from disk' |
| 40 def display_peek( self, dataset ): | 41 def display_peek(self, dataset): |
| 41 try: | 42 try: |
| 42 return dataset.peek | 43 return dataset.peek |
| 43 except: | 44 except: |
| 44 return "Binary sra file (%s)" % ( data.nice_size( dataset.get_size() ) ) | 45 return 'Binary sra file (%s)' % ( data.nice_size(dataset.get_size())) |
| 45 | 46 |
| 46 Binary.register_sniffable_binary_format("sra", "sra", Sra) | 47 Binary.register_sniffable_binary_format('sra', 'sra', Sra) |
