def __init__(self, filename=None, mode="w", fileobj=None, compresslevel=6): if fileobj: assert filename is None handle = fileobj else: if "w" not in mode.lower() and "a" not in mode.lower(): raise ValueError("Must use write or append mode, not %r" % mode) if "a" in mode.lower(): handle = _open(filename, "ab") else: handle = _open(filename, "wb") self._text = "b" not in mode.lower() self._handle = handle self._buffer = b"" self.compresslevel = compresslevel
def __init__(self, filename=None, mode="r", fileobj=None, max_cache=100): # TODO - Assuming we can seek, check for 28 bytes EOF empty block # and if missing warn about possible truncation (as in samtools)? if max_cache < 1: raise ValueError("Use max_cache with a minimum of 1") # Must open the BGZF file in binary mode, but we may want to # treat the contents as either text or binary (unicode or # bytes under Python 3) if fileobj: assert filename is None handle = fileobj assert "b" in handle.mode.lower() else: if "w" in mode.lower() \ or "a" in mode.lower(): raise ValueError( "Must use read mode (default), not write or append mode") handle = _open(filename, "rb") self._text = "b" not in mode.lower() if self._text: self._newline = "\n" else: self._newline = b"\n" self._handle = handle self.max_cache = max_cache self._buffers = {} self._block_start_offset = None self._block_raw_length = None self._load_block(handle.tell())
def __init__(self, filename=None, mode="r", fileobj=None, max_cache=100): #TODO - Assuming we can seek, check for 28 bytes EOF empty block #and if missing warn about possible truncation (as in samtools)? if max_cache < 1: raise ValueError("Use max_cache with a minimum of 1") #Must open the BGZF file in binary mode, but we may want to #treat the contents as either text or binary (unicode or #bytes under Python 3) if fileobj: assert filename is None handle = fileobj assert "b" in handle.mode.lower() else: if "w" in mode.lower() \ or "a" in mode.lower(): raise ValueError("Must use read mode (default), not write or append mode") handle = _open(filename, "rb") self._text = "b" not in mode.lower() if self._text: self._newline = "\n" else: self._newline = b"\n" self._handle = handle self.max_cache = max_cache self._buffers = {} self._block_start_offset = None self._block_raw_length = None self._load_block(handle.tell())
def __init__(self, filename=None, mode="w", fileobj=None, compresslevel=6): if fileobj: assert filename is None handle = fileobj else: if "w" not in mode.lower() \ and "a" not in mode.lower(): raise ValueError("Must use write or append mode, not %r" % mode) if "a" in mode.lower(): handle = _open(filename, "ab") else: handle = _open(filename, "wb") self._text = "b" not in mode.lower() self._handle = handle self._buffer = b"" self.compresslevel = compresslevel
def __init__(self, filename=None, mode="w", fileobj=None, compresslevel=6): """Initilize the class.""" if fileobj: assert filename is None handle = fileobj else: if "w" not in mode.lower() and "a" not in mode.lower(): raise ValueError("Must use write or append mode, not %r" % mode) if "a" in mode.lower(): raise NotImplementedError("Append mode is not implemented yet") # handle = _open(filename, "ab") else: handle = _open(filename, "wb") self._text = "b" not in mode.lower() self._handle = handle self._buffer = b"" self.compresslevel = compresslevel