Debian Codegraph @

docs/source/code_inc/compress_all_files_in_folder_2_igzip.inc

raw
1 .. code-block:: python
2
3 #!/usr/bin/env python3
4
5 import sys
6 import os
7 from pymzml.utils.utils import index_gzip
8 # from pymzml.run import Reader
9 import pymzml
10 import glob
11
12
13 def main(folder):
14 """
15 Create an indexed gzip mzML file from a plain mzML of all files in folder
16
17 Usage: python3 gzip_mzml.py <folder>
18 """
19
20 for mzml_path in glob.glob(os.path.join(folder, '*.mzML')):
21 if os.path.exists('{0}.gz'.format(mzml_path)):
22 print('Skipping: {0}'.format(mzml_path))
23 continue
24 print('Processing file: {0}'.format(mzml_path))
25 with open(mzml_path) as fin:
26 fin.seek(0,2)
27 max_offset_len = fin.tell()
28 max_spec_no = pymzml.run.Reader(mzml_path).get_spectrum_count() + 10
29 out_path = '{0}.gz'.format(mzml_path)
30 index_gzip(
31 mzml_path,
32 out_path,
33 max_idx = max_spec_no,
34 idx_len = len(str(max_offset_len))
35 )
36 print('Wrote file {0}'.format(out_path))
37
38 if __name__ == '__main__':
39 main(sys.argv[1])