libgunshotmatch 0.10.1__py3-none-any.whl → 0.11.1__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.

@@ -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.10.1"
32
+ __version__: str = "0.11.1"
33
33
  __email__: str = "dominic@davis-foster.co.uk"
@@ -27,7 +27,7 @@ Functions for combining peak identifications across aligned peaks into a single
27
27
  #
28
28
 
29
29
  # stdlib
30
- from collections import Counter
30
+ from collections import Counter, defaultdict
31
31
  from fnmatch import fnmatch
32
32
  from itertools import permutations
33
33
  from multiprocessing import Pool
@@ -61,6 +61,7 @@ __all__ = (
61
61
  "pairwise_ms_comparisons",
62
62
  "ConsolidatedPeakFilter",
63
63
  "InvertedFilter",
64
+ "combine_spectra",
64
65
  )
65
66
 
66
67
 
@@ -476,10 +477,17 @@ class ConsolidatedPeak:
476
477
  for hit in d["hits"]:
477
478
  hits.append(ConsolidatedSearchResult.from_dict(hit))
478
479
 
480
+ ms_list: MutableSequence[Optional[MassSpectrum]] = []
481
+ for msd in d["ms_list"]:
482
+ if msd is None:
483
+ ms_list.append(None)
484
+ else:
485
+ ms_list.append(MassSpectrum.from_dict(msd))
486
+
479
487
  return cls(
480
488
  rt_list=d["rt_list"],
481
489
  area_list=d["area_list"],
482
- ms_list=[MassSpectrum.from_dict(msd) for msd in d["ms_list"]],
490
+ ms_list=ms_list,
483
491
  meta=d["meta"],
484
492
  ms_comparison=d["ms_comparison"],
485
493
  hits=hits,
@@ -804,3 +812,31 @@ class InvertedFilter(ConsolidatedPeakFilter):
804
812
  filtered_consolidated_peaks.append(cp)
805
813
 
806
814
  return filtered_consolidated_peaks
815
+
816
+
817
+ def combine_spectra(peak: ConsolidatedPeak) -> Tuple[List[int], List[float]]:
818
+ """
819
+ Sum the intensities across all mass spectra in the given peak.
820
+
821
+ :param peak:
822
+
823
+ :returns: List of masses and list of corresponding intensities.
824
+
825
+ .. versionadded:: v0.11.0
826
+ """
827
+
828
+ combined_ms_data: Dict[int, float] = defaultdict(float)
829
+
830
+ for ms in peak.ms_list:
831
+ if ms is not None:
832
+ for mass, intensity in zip(ms.mass_list, ms.intensity_list):
833
+ combined_ms_data[mass] += intensity
834
+
835
+ mass_list, intensity_list = [], []
836
+ for mass, intensity in combined_ms_data.items():
837
+ mass_list.append(mass)
838
+ intensity_list.append(intensity)
839
+
840
+ # mass_list, intensity_list = zip(*combined_ms_data.items())
841
+
842
+ return mass_list, intensity_list
libgunshotmatch/peak.py CHANGED
@@ -55,6 +55,7 @@ __all__ = (
55
55
  "filter_peaks",
56
56
  "peak_from_dict",
57
57
  "write_alignment",
58
+ "base_peak_mass",
58
59
  )
59
60
 
60
61
 
@@ -240,6 +241,10 @@ class PeakList(List[Peak]):
240
241
 
241
242
  peaks_as_pure_list: List[Dict[str, Any]] = []
242
243
  for peak in self:
244
+ if peak is None:
245
+ peaks_as_pure_list.append(None)
246
+ continue
247
+
243
248
  try:
244
249
  ion_areas = peak.ion_areas
245
250
  except ValueError:
@@ -531,3 +536,25 @@ def _to_peak_list(a_list: List[Peak]) -> PeakList:
531
536
  return a_list
532
537
  else:
533
538
  return PeakList(a_list)
539
+
540
+
541
+ def base_peak_mass(peak: Peak) -> float:
542
+ """
543
+ Returns the mass of the largest fragment in the peak's mass spectrum.
544
+
545
+ :param peak:
546
+
547
+ .. versionadded:: v0.11.0
548
+ """
549
+
550
+ apex_mass_list = peak.mass_spectrum.mass_list
551
+ apex_mass_spec = peak.mass_spectrum.mass_spec
552
+
553
+ # Determine the intensity of the base peak in the mass spectrum
554
+ base_peak_intensity = max(apex_mass_spec)
555
+
556
+ # Determine the index of the base peak in the mass spectrum
557
+ base_peak_index = apex_mass_spec.index(base_peak_intensity)
558
+
559
+ # Finally, determine the mass of the base peak
560
+ return apex_mass_list[base_peak_index]
@@ -28,7 +28,7 @@ Represents a collection of repeat analyses.
28
28
 
29
29
  # stdlib
30
30
  import os
31
- from typing import Any, Dict, List, Mapping, Optional, Type
31
+ from typing import Any, Dict, List, Mapping, MutableSequence, Optional, Type
32
32
 
33
33
  # 3rd party
34
34
  import attr
@@ -131,14 +131,15 @@ class Project:
131
131
  """
132
132
 
133
133
  alignment_as_dict = d["alignment"]
134
- alignment_peaks: List[List[Peak]] = []
134
+ alignment_peaks: List[MutableSequence[Optional[Peak]]] = []
135
135
  for row in alignment_as_dict["peaks"]:
136
136
  alignment_peaks.append([])
137
137
  for peak in row:
138
138
  # print(peak)
139
- peak_obj = peak_from_dict(peak)
140
-
141
- alignment_peaks[-1].append(peak_obj)
139
+ if peak is None:
140
+ alignment_peaks[-1].append(None)
141
+ else:
142
+ alignment_peaks[-1].append(peak_from_dict(peak))
142
143
 
143
144
  alignment = create_alignment(
144
145
  alignment_peaks,
libgunshotmatch/utils.py CHANGED
@@ -171,7 +171,11 @@ def get_rt_range(project: "Project") -> Tuple[float, float]:
171
171
  return min_rt, max_rt
172
172
 
173
173
 
174
- def create_alignment(peakpos: Sequence[Sequence[Peak]], expr_code: List[str], similarity: float = 0) -> Alignment:
174
+ def create_alignment(
175
+ peakpos: Sequence[Sequence[Optional[Peak]]],
176
+ expr_code: List[str],
177
+ similarity: float = 0,
178
+ ) -> Alignment:
175
179
  """
176
180
  Create a new :class:`pyms.DPA.Alignment.Alignment` object.
177
181
 
@@ -185,7 +189,7 @@ def create_alignment(peakpos: Sequence[Sequence[Peak]], expr_code: List[str], si
185
189
  """
186
190
 
187
191
  alignment = Alignment(None)
188
- alignment.peakpos = [list(p) for p in peakpos]
192
+ alignment.peakpos = [list(p) for p in peakpos] # type: ignore[arg-type]
189
193
  alignment.peakalgt = numpy.transpose(alignment.peakpos).tolist() # type: ignore[arg-type]
190
194
  alignment.expr_code = expr_code
191
195
  alignment.similarity = similarity
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: libgunshotmatch
3
- Version: 0.10.1
3
+ Version: 0.11.1
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.10.1
138
+ .. |commits-since| image:: https://img.shields.io/github/commits-since/GunShotMatch/libgunshotmatch/v0.11.1
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=zdnqx7YzV3MiW5IVFEiPSJZT43BdcOmlRqkIKOEBqPg,23816
5
+ libgunshotmatch/consolidate/__init__.py,sha256=qjY5meI2TMCpMGwzLSo4NZ4HbhH8VJoR1t9ev4ObBmA,24706
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=i3HVJY9SEvFk18-i0gI49ED5BEIsvg8VBCVS1XqinV8,1434
10
+ libgunshotmatch/__init__.py,sha256=RYV-3nDk5ruAuFXDnZuk5LbiFM_503YfSuKwtGTdddk,1434
11
11
  libgunshotmatch/datafile.py,sha256=4C4BiR95PBfIUbiUKQzVfh57tgZu_l6rLS8bIgrgPUs,16246
12
12
  libgunshotmatch/gzip_util.py,sha256=PcfT4QC4TM0KI3uCGetRpjChbTXTGmNEJBr7BghO3i8,2414
13
- libgunshotmatch/peak.py,sha256=srEDCOOYF2ZCmfyjoiWXWbjquNosIzK4D-2hZG1xgfc,16943
14
- libgunshotmatch/project.py,sha256=ch8v8egvcULjYk7_40KywgM-_j3mf2tvRTzAsIC6Kp0,6904
13
+ libgunshotmatch/peak.py,sha256=jIbuOTj_FWTeb46pZtzSwnGsMK_c71Dd9_T9Gj2DxNk,17616
14
+ libgunshotmatch/project.py,sha256=498xoKkDSFDsFodwoRwwEfRL-FOX_hnzyDLLgPNxWr0,6987
15
15
  libgunshotmatch/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  libgunshotmatch/search.py,sha256=GMP7_DMnXFq3TG8AT1WARIn4ObCfOGfTDakpGeKzJYw,3123
17
- libgunshotmatch/utils.py,sha256=8wrdSk1ZWIgIu6eN9QEDF23goxN7z2VszxcDYZZ8ov0,5729
18
- libgunshotmatch-0.10.1.dist-info/LICENSE,sha256=bFtJt-lyVJHV-88FeFa_r3BEOsmpna5qG2KOl9JUNfU,1064
19
- libgunshotmatch-0.10.1.dist-info/METADATA,sha256=7m2IcSNK4v86wxEbQsmve7vlvwznveFFheK_htAx1Xw,6394
20
- libgunshotmatch-0.10.1.dist-info/WHEEL,sha256=3vSnEhs48RUlSXcCXKCl4DOHs_qqaP2dU3IGkMqN2oI,84
21
- libgunshotmatch-0.10.1.dist-info/entry_points.txt,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- libgunshotmatch-0.10.1.dist-info/RECORD,,
17
+ libgunshotmatch/utils.py,sha256=7WVJPd9wNBFFoAFqh2J6Lsu7BGrGksW32ZqpH7ZIL_I,5776
18
+ libgunshotmatch-0.11.1.dist-info/LICENSE,sha256=bFtJt-lyVJHV-88FeFa_r3BEOsmpna5qG2KOl9JUNfU,1064
19
+ libgunshotmatch-0.11.1.dist-info/METADATA,sha256=X6IRaQ7QLl3ugK51lSmpa205f0Ds1QmbVICEaFucBtw,6394
20
+ libgunshotmatch-0.11.1.dist-info/WHEEL,sha256=pUf8gZsdmDXXTtqZfolZFpfoEwFoEdADIuUvQVl5qAY,83
21
+ libgunshotmatch-0.11.1.dist-info/entry_points.txt,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ libgunshotmatch-0.11.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: whey (0.0.24)
2
+ Generator: whey (0.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any