예제 #1
0
파일: bgzf.py 프로젝트: wojdyr/biopython
 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
예제 #2
0
 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())
예제 #3
0
파일: bgzip.py 프로젝트: jhrf/Playground
 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()) 
예제 #4
0
파일: bgzf.py 프로젝트: sogada/biopython
 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
예제 #5
0
 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