Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def write(self, data):
if len(data) + len(self._buffer) > 65536 and len(self._buffer) != 0:
self.flush()
super(BamWriter, self).write(data)
assert 'b' in mode.lower(), 'BAM files must be used in binary mode'
write_modes = ['w', 'a', 'x', 'r+']
# Check if user wants to write a BAM file
if any([wm in mode.lower() for wm in write_modes]):
write_args = ('filepath_or_object', 'mode', 'compresslevel',
'ignore_overwrite', 'copy_header', 'header',
'reference_names', 'reference_lengths')
wargs = {}
for key in write_args:
try:
wargs.update({key: kwargs.pop(key)})
except KeyError:
pass
bam.BamWriter.__init__(self, **wargs)
else:
read_args = ('filepath_or_object', 'mode', 'max_cache', 'index_filename',
'filename', 'check_header', 'check_sq', 'reference_filename',
'filepath_index', 'require_index', 'duplicate_filehandle',
'ignore_truncation')
rargs = {}
for key in read_args:
try:
rargs.update({key: kwargs.pop(key)})
except KeyError:
pass
bam.BamReader.__init__(self, **rargs)