libgunshotmatch 0.9.0__py3-none-any.whl → 0.10.0__py3-none-any.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.
Potentially problematic release.
This version of libgunshotmatch might be problematic. Click here for more details.
- libgunshotmatch/__init__.py +1 -1
- libgunshotmatch/consolidate/__init__.py +40 -4
- libgunshotmatch/gzip_util.py +7 -1
- libgunshotmatch/project.py +47 -26
- libgunshotmatch/utils.py +3 -2
- {libgunshotmatch-0.9.0.dist-info → libgunshotmatch-0.10.0.dist-info}/METADATA +2 -2
- {libgunshotmatch-0.9.0.dist-info → libgunshotmatch-0.10.0.dist-info}/RECORD +10 -10
- {libgunshotmatch-0.9.0.dist-info → libgunshotmatch-0.10.0.dist-info}/LICENSE +0 -0
- {libgunshotmatch-0.9.0.dist-info → libgunshotmatch-0.10.0.dist-info}/WHEEL +0 -0
- {libgunshotmatch-0.9.0.dist-info → libgunshotmatch-0.10.0.dist-info}/entry_points.txt +0 -0
libgunshotmatch/__init__.py
CHANGED
|
@@ -29,5 +29,5 @@ Base library for GunShotMatch.
|
|
|
29
29
|
__author__: str = "Dominic Davis-Foster"
|
|
30
30
|
__copyright__: str = "2020-2023 Dominic Davis-Foster"
|
|
31
31
|
__license__: str = "MIT License"
|
|
32
|
-
__version__: str = "0.
|
|
32
|
+
__version__: str = "0.10.0"
|
|
33
33
|
__email__: str = "dominic@davis-foster.co.uk"
|
|
@@ -59,7 +59,8 @@ __all__ = (
|
|
|
59
59
|
"ConsolidatedSearchResult",
|
|
60
60
|
"match_counter",
|
|
61
61
|
"pairwise_ms_comparisons",
|
|
62
|
-
"ConsolidatedPeakFilter"
|
|
62
|
+
"ConsolidatedPeakFilter",
|
|
63
|
+
"InvertedFilter",
|
|
63
64
|
)
|
|
64
65
|
|
|
65
66
|
|
|
@@ -205,12 +206,16 @@ class ConsolidatedSearchResult:
|
|
|
205
206
|
:param d:
|
|
206
207
|
"""
|
|
207
208
|
|
|
209
|
+
hit_numbers = [float("nan") if hn == -65535 else hn for hn in d["hit_numbers"]]
|
|
210
|
+
mf_list = [float("nan") if mf == -65535 else mf for mf in d["mf_list"]]
|
|
211
|
+
rmf_list = [float("nan") if mf == -65535 else mf for mf in d["rmf_list"]]
|
|
212
|
+
|
|
208
213
|
return cls(
|
|
209
214
|
name=d["name"],
|
|
210
215
|
cas=d["cas"],
|
|
211
|
-
mf_list=
|
|
212
|
-
rmf_list=
|
|
213
|
-
hit_numbers=
|
|
216
|
+
mf_list=mf_list,
|
|
217
|
+
rmf_list=rmf_list,
|
|
218
|
+
hit_numbers=hit_numbers,
|
|
214
219
|
reference_data=d["reference_data"],
|
|
215
220
|
)
|
|
216
221
|
|
|
@@ -768,3 +773,34 @@ class ConsolidatedPeakFilter:
|
|
|
768
773
|
"""
|
|
769
774
|
|
|
770
775
|
return [cp for cp in consolidated_peaks if not self.should_filter_peak(cp)]
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
@_fix_init_annotations
|
|
779
|
+
@attr.define
|
|
780
|
+
class InvertedFilter(ConsolidatedPeakFilter):
|
|
781
|
+
"""
|
|
782
|
+
Inverted version of :class:`~.ConsolidatedPeakFilter`.
|
|
783
|
+
|
|
784
|
+
Returns peaks which would be excluded by a :class:`~.ConsolidatedPeakFilter`.
|
|
785
|
+
|
|
786
|
+
.. versionadded:: 0.10.0
|
|
787
|
+
"""
|
|
788
|
+
|
|
789
|
+
def print_skip_reason(self, peak: ConsolidatedPeak, reason: str) -> None: # noqa: D102
|
|
790
|
+
if self.verbose:
|
|
791
|
+
print(f"Would reject peak at {peak.rt / 60:0.3f} mins:", reason)
|
|
792
|
+
|
|
793
|
+
def filter(self, consolidated_peaks: List[ConsolidatedPeak]) -> List[ConsolidatedPeak]: # noqa: A003 # pylint: disable=redefined-builtin
|
|
794
|
+
"""
|
|
795
|
+
Filter a list of consolidated peaks.
|
|
796
|
+
|
|
797
|
+
:param consolidated_peaks:
|
|
798
|
+
"""
|
|
799
|
+
|
|
800
|
+
filtered_consolidated_peaks = []
|
|
801
|
+
|
|
802
|
+
for cp in consolidated_peaks:
|
|
803
|
+
if self.should_filter_peak(cp):
|
|
804
|
+
filtered_consolidated_peaks.append(cp)
|
|
805
|
+
|
|
806
|
+
return filtered_consolidated_peaks
|
libgunshotmatch/gzip_util.py
CHANGED
|
@@ -51,7 +51,13 @@ def read_gzip_json(path: PathLike) -> JSONOutput:
|
|
|
51
51
|
"""
|
|
52
52
|
|
|
53
53
|
with gzip.open(PathPlus(path), 'r') as f:
|
|
54
|
-
|
|
54
|
+
try:
|
|
55
|
+
# 3rd party
|
|
56
|
+
import orjson
|
|
57
|
+
data = f.read().decode().replace("NaN", "-65535")
|
|
58
|
+
return orjson.loads(data)
|
|
59
|
+
except ImportError:
|
|
60
|
+
return sdjson.load(f)
|
|
55
61
|
|
|
56
62
|
|
|
57
63
|
def write_gzip_json(path: PathLike, data: JSONInput, indent: Optional[int] = 2) -> None:
|
libgunshotmatch/project.py
CHANGED
|
@@ -50,7 +50,7 @@ from libgunshotmatch.datafile import Repeat
|
|
|
50
50
|
from libgunshotmatch.peak import PeakList, QualifiedPeak, peak_from_dict
|
|
51
51
|
from libgunshotmatch.utils import create_alignment
|
|
52
52
|
|
|
53
|
-
__all__ =
|
|
53
|
+
__all__ = ("Project", "consolidate")
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
@attr.define
|
|
@@ -176,31 +176,7 @@ class Project:
|
|
|
176
176
|
between the repeats for each aligned peak.
|
|
177
177
|
"""
|
|
178
178
|
|
|
179
|
-
ms_comparison_df =
|
|
180
|
-
|
|
181
|
-
peak_numbers: List[int] = []
|
|
182
|
-
peak: Optional[QualifiedPeak]
|
|
183
|
-
|
|
184
|
-
qualified_peak_array = []
|
|
185
|
-
|
|
186
|
-
# for experiment in project.alignment.expr_code:
|
|
187
|
-
for experiment in self.datafile_data:
|
|
188
|
-
qualified_peaks = self.datafile_data[experiment].qualified_peaks
|
|
189
|
-
assert qualified_peaks is not None
|
|
190
|
-
for peak in qualified_peaks:
|
|
191
|
-
assert peak.peak_number is not None
|
|
192
|
-
peak_numbers.append(peak.peak_number)
|
|
193
|
-
qualified_peak_array.append(qualified_peaks)
|
|
194
|
-
|
|
195
|
-
# Convert peak_numbers to a set and sort smallest to largest
|
|
196
|
-
peak_numbers = sorted(set(peak_numbers))
|
|
197
|
-
|
|
198
|
-
consolidated_peaks = match_counter(
|
|
199
|
-
engine=engine,
|
|
200
|
-
peak_numbers=peak_numbers,
|
|
201
|
-
qualified_peaks=qualified_peak_array,
|
|
202
|
-
ms_comp_data=ms_comparison_df,
|
|
203
|
-
)
|
|
179
|
+
consolidated_peaks, ms_comparison_df = consolidate(self, engine)
|
|
204
180
|
|
|
205
181
|
if peak_filter is None:
|
|
206
182
|
self.consolidated_peaks = consolidated_peaks
|
|
@@ -210,3 +186,48 @@ class Project:
|
|
|
210
186
|
return ms_comparison_df
|
|
211
187
|
|
|
212
188
|
# chart_data = make_chart_data(self)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def consolidate(
|
|
192
|
+
project: Project,
|
|
193
|
+
engine: pyms_nist_search.Engine,
|
|
194
|
+
) -> pandas.DataFrame:
|
|
195
|
+
"""
|
|
196
|
+
Consolidate the compound identification from the experiments into a single dataset.
|
|
197
|
+
|
|
198
|
+
:param project:
|
|
199
|
+
:param engine:
|
|
200
|
+
|
|
201
|
+
:returns: List of consolidated peaks and :class:`pandas.DataFrame`
|
|
202
|
+
giving the results of pairwise mass spectral comparisons between the repeats for each aligned peak.
|
|
203
|
+
|
|
204
|
+
.. versionadded:: 0.10.0
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
ms_comparison_df = pairwise_ms_comparisons(project.alignment)
|
|
208
|
+
|
|
209
|
+
peak_numbers: List[int] = []
|
|
210
|
+
peak: Optional[QualifiedPeak]
|
|
211
|
+
|
|
212
|
+
qualified_peak_array = []
|
|
213
|
+
|
|
214
|
+
# for experiment in project.alignment.expr_code:
|
|
215
|
+
for experiment in project.datafile_data:
|
|
216
|
+
qualified_peaks = project.datafile_data[experiment].qualified_peaks
|
|
217
|
+
assert qualified_peaks is not None
|
|
218
|
+
for peak in qualified_peaks:
|
|
219
|
+
assert peak.peak_number is not None
|
|
220
|
+
peak_numbers.append(peak.peak_number)
|
|
221
|
+
qualified_peak_array.append(qualified_peaks)
|
|
222
|
+
|
|
223
|
+
# Convert peak_numbers to a set and sort smallest to largest
|
|
224
|
+
peak_numbers = sorted(set(peak_numbers))
|
|
225
|
+
|
|
226
|
+
consolidated_peaks = match_counter(
|
|
227
|
+
engine=engine,
|
|
228
|
+
peak_numbers=peak_numbers,
|
|
229
|
+
qualified_peaks=qualified_peak_array,
|
|
230
|
+
ms_comp_data=ms_comparison_df,
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
return consolidated_peaks, ms_comparison_df
|
libgunshotmatch/utils.py
CHANGED
|
@@ -32,6 +32,7 @@ from typing import TYPE_CHECKING, Any, Iterable, List, Optional, Sequence, Tuple
|
|
|
32
32
|
|
|
33
33
|
# 3rd party
|
|
34
34
|
import numpy
|
|
35
|
+
from attr import AttrsInstance
|
|
35
36
|
from chemistry_tools.spectrum_similarity import SpectrumSimilarity
|
|
36
37
|
from mathematical.utils import rounders
|
|
37
38
|
from pyms.DPA.Alignment import Alignment
|
|
@@ -114,10 +115,10 @@ def ms_comparison(top_ms: MassSpectrum, bottom_ms: MassSpectrum) -> Optional[flo
|
|
|
114
115
|
return match * 1000
|
|
115
116
|
|
|
116
117
|
|
|
117
|
-
|
|
118
|
+
_AI = TypeVar("_AI", bound=AttrsInstance)
|
|
118
119
|
|
|
119
120
|
|
|
120
|
-
def _fix_init_annotations(method: Type[
|
|
121
|
+
def _fix_init_annotations(method: Type[_AI]) -> Type[_AI]:
|
|
121
122
|
init_annotations = method.__init__.__annotations__
|
|
122
123
|
cls_annotations = method.__annotations__
|
|
123
124
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: libgunshotmatch
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0
|
|
4
4
|
Summary: Base library for GunShotMatch.
|
|
5
5
|
Author-email: Dominic Davis-Foster <dominic@davis-foster.co.uk>
|
|
6
6
|
License: MIT
|
|
@@ -135,7 +135,7 @@ libgunshotmatch
|
|
|
135
135
|
.. |language| image:: https://img.shields.io/github/languages/top/GunShotMatch/libgunshotmatch
|
|
136
136
|
:alt: GitHub top language
|
|
137
137
|
|
|
138
|
-
.. |commits-since| image:: https://img.shields.io/github/commits-since/GunShotMatch/libgunshotmatch/v0.
|
|
138
|
+
.. |commits-since| image:: https://img.shields.io/github/commits-since/GunShotMatch/libgunshotmatch/v0.10.0
|
|
139
139
|
:target: https://github.com/GunShotMatch/libgunshotmatch/pulse
|
|
140
140
|
:alt: GitHub commits since tagged version
|
|
141
141
|
|
|
@@ -2,21 +2,21 @@ libgunshotmatch/comparison/__init__.py,sha256=g-KDfzG-oyRf2aeXlMaJJ3aWfQtQkr5-bG
|
|
|
2
2
|
libgunshotmatch/comparison/_utils.py,sha256=aZ6fnFM4M_vTsKq5t79V4tfven1eVdG4EUCuYFuXMVs,1895
|
|
3
3
|
libgunshotmatch/comparison/projects.py,sha256=Dq294cDndmQI2FnIcVXwleCQF0mF2m8U5wWnO5_aD9A,3356
|
|
4
4
|
libgunshotmatch/comparison/unknowns.py,sha256=kvJJDtfpMp-c3hjCOz7YtvuuDR0YksWmyUuaSBC_5Jg,2710
|
|
5
|
-
libgunshotmatch/consolidate/__init__.py,sha256=
|
|
5
|
+
libgunshotmatch/consolidate/__init__.py,sha256=zdnqx7YzV3MiW5IVFEiPSJZT43BdcOmlRqkIKOEBqPg,23816
|
|
6
6
|
libgunshotmatch/consolidate/_fields.py,sha256=0kfPXJ0EG7GhdFiNzvcmd6W4i1x6Y0s2Y58z3RltPiA,2759
|
|
7
7
|
libgunshotmatch/consolidate/_spectra.py,sha256=24aDoPwGWEyIFCH-fwRa4nifNMPqUyd-qTogk3BMeLY,2319
|
|
8
8
|
libgunshotmatch/method/__init__.py,sha256=TP_3rvv3WEbV6Y5E_QWd2lcORPFnbXV4YRKGwXDa4ds,9423
|
|
9
9
|
libgunshotmatch/method/_fields.py,sha256=HBFl0XmHBaAOHYdABs2NRbjtngGEw7kY0xP6D2Fl7h4,4941
|
|
10
|
-
libgunshotmatch/__init__.py,sha256=
|
|
10
|
+
libgunshotmatch/__init__.py,sha256=_8fk8Y_s16QckNbYhOXc8zxn6HIK0f_3TRYEIkYEYr4,1434
|
|
11
11
|
libgunshotmatch/datafile.py,sha256=4C4BiR95PBfIUbiUKQzVfh57tgZu_l6rLS8bIgrgPUs,16246
|
|
12
|
-
libgunshotmatch/gzip_util.py,sha256=
|
|
12
|
+
libgunshotmatch/gzip_util.py,sha256=PcfT4QC4TM0KI3uCGetRpjChbTXTGmNEJBr7BghO3i8,2414
|
|
13
13
|
libgunshotmatch/peak.py,sha256=huZ1hObIFcQpMPXyU6lYe7B-FFT-djSeG4jII7CgWAE,16923
|
|
14
|
-
libgunshotmatch/project.py,sha256=
|
|
14
|
+
libgunshotmatch/project.py,sha256=ch8v8egvcULjYk7_40KywgM-_j3mf2tvRTzAsIC6Kp0,6904
|
|
15
15
|
libgunshotmatch/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
libgunshotmatch/search.py,sha256=GMP7_DMnXFq3TG8AT1WARIn4ObCfOGfTDakpGeKzJYw,3123
|
|
17
|
-
libgunshotmatch/utils.py,sha256=
|
|
18
|
-
libgunshotmatch-0.
|
|
19
|
-
libgunshotmatch-0.
|
|
20
|
-
libgunshotmatch-0.
|
|
21
|
-
libgunshotmatch-0.
|
|
22
|
-
libgunshotmatch-0.
|
|
17
|
+
libgunshotmatch/utils.py,sha256=8wrdSk1ZWIgIu6eN9QEDF23goxN7z2VszxcDYZZ8ov0,5729
|
|
18
|
+
libgunshotmatch-0.10.0.dist-info/LICENSE,sha256=bFtJt-lyVJHV-88FeFa_r3BEOsmpna5qG2KOl9JUNfU,1064
|
|
19
|
+
libgunshotmatch-0.10.0.dist-info/METADATA,sha256=B26beZpWIdl-1YRu3Bl51SqsjWIOd0Y4vy2C1Osy7oA,6394
|
|
20
|
+
libgunshotmatch-0.10.0.dist-info/WHEEL,sha256=3vSnEhs48RUlSXcCXKCl4DOHs_qqaP2dU3IGkMqN2oI,84
|
|
21
|
+
libgunshotmatch-0.10.0.dist-info/entry_points.txt,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
|
+
libgunshotmatch-0.10.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|