Debian Codegraph @

pymzml/file_classes/bytesMzml.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 """
4 Interface for binary streams of uncompressed mzML.
5
6 @author: Sylvain Le Bon
7 """
8 from io import TextIOWrapper
9
10 from .. import regex_patterns
11 from .standardMzml import StandardMzml
12
13
14 class BytesMzml(StandardMzml):
15 def __init__(self, binary, encoding, build_index_from_scratch=False):
16 """
17 Initalize Wrapper object for standard mzML files.
18
19 Arguments:
20 path (str) : path to the file
21 encoding (str) : encoding of the file
22 """
23 self.binary = binary
24 self.file_handler = self.get_file_handler(encoding)
25 self.offset_dict = dict()
26 self.spec_open = regex_patterns.SPECTRUM_OPEN_PATTERN
27 self.spec_close = regex_patterns.SPECTRUM_CLOSE_PATTERN
28 if build_index_from_scratch is True:
29 seeker = self.get_binary_file_handler()
30 self._build_index_from_scratch(seeker)
31 seeker.close()
32
33 def get_binary_file_handler(self):
34 self.binary.seek(0)
35 return self.binary
36
37 def get_file_handler(self, encoding):
38 return TextIOWrapper(self.binary, encoding=encoding)