rainbow-api 1.0.13__cp38-cp38-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
rainbow/__init__.py ADDED
@@ -0,0 +1,79 @@
1
+ import os
2
+ from rainbow.datafile import DataFile
3
+ from rainbow.datadirectory import DataDirectory
4
+ from rainbow import agilent, waters
5
+
6
+
7
+ def read(path, prec=0, hrms=False, requested_files=None):
8
+ """
9
+ Reads a chromatogram data directory. Main method of the package.
10
+
11
+ Increasing the precision may drastically increase memory usage for \
12
+ larger files. Specifying a higher precision mainly affects the \
13
+ parsing of MS data, because intensities are summed within the given \
14
+ precision for each ylabel.
15
+
16
+ Max precision available for Agilent MS data is 1.
17
+
18
+ Max precision recommended for Waters MS data is 3.
19
+
20
+ Agilent HRMS parsing may be slow. Set the flag to enable it.
21
+
22
+ Args:
23
+ path (str): Path of the directory.
24
+ prec (int, optional): Number of decimals to round ylabels.
25
+ hrms (bool, optional): Flag for Agilent HRMS parsing.
26
+ requested_files (list, optional): List of filenames to parse.
27
+
28
+ Returns:
29
+ DataDirectory representing the directory.
30
+
31
+ """
32
+ if not isinstance(path, str) or not os.path.isdir(path):
33
+ raise Exception(f"{path} is not a directory.")
34
+
35
+ if not isinstance(prec, int) or prec < 0:
36
+ raise Exception(f"Invalid precision: {prec}.")
37
+
38
+ if not isinstance(hrms, bool):
39
+ raise Exception(f"The hrms flag must be a boolean.")
40
+
41
+ if requested_files is not None and not isinstance(requested_files, list):
42
+ raise Exception(f"The requested_files argument must be a list.")
43
+
44
+ if requested_files:
45
+ requested_files = list(map(str.lower, requested_files))
46
+
47
+ datadir = None
48
+ ext = os.path.splitext(path)[1]
49
+ if ext.upper() == '.D':
50
+ datadir = agilent.read(path, prec, hrms, requested_files)
51
+ elif ext.lower() == '.raw':
52
+ datadir = waters.read(path, prec, requested_files)
53
+
54
+ if datadir is None:
55
+ raise Exception(f"Rainbow cannot read {path}.")
56
+ return datadir
57
+
58
+
59
+ def read_metadata(path):
60
+ """
61
+ Reads the metadata for a chromatogram data directory. Main method of the package.
62
+
63
+ Args:
64
+ path (str): Path of the directory.
65
+
66
+ Returns:
67
+ Dictionary containing a list of datafiles and the metadata.
68
+
69
+ """
70
+ datadir = None
71
+ ext = os.path.splitext(path)[1]
72
+ if ext.upper() == '.D':
73
+ metadata = agilent.read_metadata(path)
74
+ elif ext.lower() == '.raw':
75
+ metadata = waters.read_metadata(path)
76
+
77
+ if metadata is None:
78
+ raise Exception(f"Rainbow cannot read {path}.")
79
+ return metadata
@@ -0,0 +1,55 @@
1
+ import os
2
+
3
+ from rainbow.agilent import chemstation
4
+ from rainbow.datadirectory import DataDirectory
5
+
6
+
7
+ def read(path, prec=0, hrms=False, requested_files=None):
8
+ """
9
+ Reads an Agilent .D directory.
10
+
11
+ Args:
12
+ path (str): Path of the directory.
13
+ prec (int, optional): Number of decimals to round masses.
14
+ hrms (bool, optional): Flag for HRMS parsing.
15
+ requested_files (list, optional): List of filenames to parse.
16
+
17
+ Returns:
18
+ DataDirectory representing the Agilent .D directory.
19
+
20
+ """
21
+ datafiles = []
22
+ datafiles.extend(chemstation.parse_allfiles(path, prec, requested_files))
23
+ if hrms:
24
+ try:
25
+ from rainbow.agilent import masshunter
26
+ datafiles.extend(masshunter.parse_allfiles(path))
27
+ except ModuleNotFoundError:
28
+ raise ModuleNotFoundError("You must install python-lzf to parse masshunter files.")
29
+
30
+ metadata = chemstation.parse_metadata(path, datafiles)
31
+
32
+ return DataDirectory(path, datafiles, metadata)
33
+
34
+
35
+ def read_metadata(path):
36
+ """
37
+ Reads metadata from an Agilent .D directory.
38
+
39
+ Args:
40
+ path (str): Path of the directory.
41
+
42
+ Returns:
43
+ Dictionary containing a list of datafiles and the metadata.
44
+
45
+ """
46
+ datafiles = []
47
+ metadata = chemstation.parse_metadata(path, datafiles)
48
+ if len(metadata) == 1:
49
+ datadir = read(path)
50
+ if datadir:
51
+ return {'datafiles': datadir.datafiles + datadir.analog, 'metadata': datadir.metadata}
52
+ return None
53
+ # Masshunter datafiles are not located.
54
+ datafiles = [fn for fn in os.listdir(path) if fn[-3:].lower() in ('.uv', '.ch', '.ms')]
55
+ return {'datafiles': datafiles, 'metadata': metadata}