libgunshotmatch 0.9.0__tar.gz → 0.10.0__tar.gz

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.

Files changed (22) hide show
  1. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/PKG-INFO +2 -2
  2. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/README.rst +1 -1
  3. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/__init__.py +1 -1
  4. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/consolidate/__init__.py +40 -4
  5. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/gzip_util.py +7 -1
  6. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/project.py +47 -26
  7. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/utils.py +3 -2
  8. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/pyproject.toml +1 -1
  9. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/LICENSE +0 -0
  10. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/comparison/__init__.py +0 -0
  11. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/comparison/_utils.py +0 -0
  12. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/comparison/projects.py +0 -0
  13. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/comparison/unknowns.py +0 -0
  14. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/consolidate/_fields.py +0 -0
  15. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/consolidate/_spectra.py +0 -0
  16. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/datafile.py +0 -0
  17. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/method/__init__.py +0 -0
  18. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/method/_fields.py +0 -0
  19. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/peak.py +0 -0
  20. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/py.typed +0 -0
  21. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/libgunshotmatch/search.py +0 -0
  22. {libgunshotmatch-0.9.0 → libgunshotmatch-0.10.0}/requirements.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libgunshotmatch
3
- Version: 0.9.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.9.0
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
 
@@ -91,7 +91,7 @@ libgunshotmatch
91
91
  .. |language| image:: https://img.shields.io/github/languages/top/GunShotMatch/libgunshotmatch
92
92
  :alt: GitHub top language
93
93
 
94
- .. |commits-since| image:: https://img.shields.io/github/commits-since/GunShotMatch/libgunshotmatch/v0.9.0
94
+ .. |commits-since| image:: https://img.shields.io/github/commits-since/GunShotMatch/libgunshotmatch/v0.10.0
95
95
  :target: https://github.com/GunShotMatch/libgunshotmatch/pulse
96
96
  :alt: GitHub commits since tagged version
97
97
 
@@ -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.9.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=d["mf_list"],
212
- rmf_list=d["rmf_list"],
213
- hit_numbers=d["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
@@ -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
- return sdjson.load(f)
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:
@@ -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__ = ["Project"]
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 = pairwise_ms_comparisons(self.alignment)
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
@@ -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
- _O = TypeVar("_O", bound=object)
118
+ _AI = TypeVar("_AI", bound=AttrsInstance)
118
119
 
119
120
 
120
- def _fix_init_annotations(method: Type[_O]) -> Type[_O]:
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
 
@@ -4,7 +4,7 @@ build-backend = "whey"
4
4
 
5
5
  [project]
6
6
  name = "libgunshotmatch"
7
- version = "0.9.0"
7
+ version = "0.10.0"
8
8
  description = "Base library for GunShotMatch."
9
9
  readme = "README.rst"
10
10
  keywords = []