comparison ngsutils/support/bgzip.py @ 2:7a68005de299 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ngsutils commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
author iuc
date Sun, 27 Nov 2016 15:01:21 -0500
parents 4e4e4093d65d
children
comparison
equal deleted inserted replaced
1:8187a729d9f4 2:7a68005de299
4 4
5 BAM files are stored as blocks in a bgzip archive. This class 5 BAM files are stored as blocks in a bgzip archive. This class
6 will load the bgzip archive and output the block information. 6 will load the bgzip archive and output the block information.
7 ''' 7 '''
8 8
9 import sys
10 import os 9 import os
11 import struct 10 import struct
11 import sys
12 12
13 13
14 class BGZip(object): 14 class BGZip(object):
15 def __init__(self, fname): 15 def __init__(self, fname):
16 self.fname = fname 16 self.fname = fname
39 return 39 return
40 40
41 if whence == 0: 41 if whence == 0:
42 self.seek(0, 0) 42 self.seek(0, 0)
43 43
44 ### read into chunk, if not enough data in chunk, read next chunk 44 # read into chunk, if not enough data in chunk, read next chunk
45 ret = '' 45 ret = ''
46 while amount and self.pos < self.fsize: 46 while amount and self.pos < self.fsize:
47 if len(self.cdata) - self.cpos < amount: 47 if len(self.cdata) - self.cpos < amount:
48 ret += self.cdata[self.cpos:self.cpos + amount] 48 ret += self.cdata[self.cpos:self.cpos + amount]
49 self.cpos += amount 49 self.cpos += amount
131 def _read_fields(self, field_types): 131 def _read_fields(self, field_types):
132 size = struct.calcsize(field_types) 132 size = struct.calcsize(field_types)
133 self.pos += size 133 self.pos += size
134 return struct.unpack(field_types, self.fileobj.read(size)) 134 return struct.unpack(field_types, self.fileobj.read(size))
135 135
136
136 if __name__ == '__main__': 137 if __name__ == '__main__':
137 print BGZip(sys.argv[1]).dump() 138 print BGZip(sys.argv[1]).dump()