libgunshotmatch 0.7.3__py3-none-any.whl → 0.8.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.

@@ -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.7.3"
32
+ __version__: str = "0.8.0"
33
33
  __email__: str = "dominic@davis-foster.co.uk"
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env python3
2
+ #
3
+ # __init__.py
4
+ """
5
+ Comparison between projects and unknowns.
6
+
7
+ The two submodules, :mod:`~.comparison.projects` and :mod:`~.comparison.unknowns`,
8
+ provide identical APIs with different internals to handle reference projects (containing two or more repeats)
9
+ and unknown samples (from a single datafile).
10
+
11
+ .. versionadded:: 0.8.0
12
+ """
13
+ #
14
+ # Copyright © 2024 Dominic Davis-Foster <dominic@davis-foster.co.uk>
15
+ #
16
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ # of this software and associated documentation files (the "Software"), to deal
18
+ # in the Software without restriction, including without limitation the rights
19
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ # copies of the Software, and to permit persons to whom the Software is
21
+ # furnished to do so, subject to the following conditions:
22
+ #
23
+ # The above copyright notice and this permission notice shall be included in all
24
+ # copies or substantial portions of the Software.
25
+ #
26
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
29
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
30
+ # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
31
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
32
+ # OR OTHER DEALINGS IN THE SOFTWARE.
33
+ #
34
+
35
+ # stdlib
36
+ from typing import List, Sequence, Tuple
37
+
38
+ # 3rd party
39
+ from pyms.DPA.Alignment import Alignment # type: ignore[import]
40
+ from pyms.DPA.PairwiseAlignment import PairwiseAlignment, align_with_tree # type: ignore[import]
41
+
42
+ # this package
43
+ from libgunshotmatch.project import Project
44
+
45
+ # this package
46
+ from . import projects, unknowns
47
+ from ._utils import _PaddedPeakList
48
+
49
+ __all__ = ("align_projects", "get_padded_peak_lists")
50
+
51
+ # Aliases to prevent clashes with argument names
52
+ _projects_mod = projects
53
+ _unknowns_mod = unknowns
54
+
55
+
56
+ def align_projects(projects: Sequence[Project] = (), unknowns: Sequence[Project] = ()) -> Alignment:
57
+ """
58
+ Align multiple projects and/or unknowns.
59
+
60
+ :param projects:
61
+ :param unknowns:
62
+ """
63
+
64
+ project_alignments = map(_projects_mod.filter_alignment_to_consolidate, projects)
65
+ unknown_alignments = map(_unknowns_mod.filter_alignment_to_consolidate, unknowns)
66
+
67
+ pwa = PairwiseAlignment([*project_alignments, *unknown_alignments], D=2.5, gap=0.3)
68
+ return align_with_tree(pwa)
69
+
70
+
71
+ def get_padded_peak_lists(
72
+ alignment: Alignment,
73
+ projects: Sequence[Project] = (),
74
+ unknowns: Sequence[Project] = (),
75
+ ) -> Tuple[List[_PaddedPeakList], List[_PaddedPeakList]]:
76
+ """
77
+ Pad the consolidated peak lists in each project/unknown, from the given between-project alignment.
78
+
79
+ :param alignment:
80
+ :param projects:
81
+ :param unknowns:
82
+ """
83
+
84
+ data = alignment.get_peak_alignment(require_all_expr=False, minutes=False)
85
+
86
+ projects_padded_cp = [_projects_mod.get_padded_peak_list(p, data) for p in projects]
87
+ unknowns_padded_cp = [_unknowns_mod.get_padded_peak_list(p, data) for p in unknowns]
88
+ return projects_padded_cp, unknowns_padded_cp
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env python3
2
+ #
3
+ # _utils.py
4
+ """
5
+ Utility functions.
6
+ """
7
+ #
8
+ # Copyright © 2024 Dominic Davis-Foster <dominic@davis-foster.co.uk>
9
+ #
10
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ # of this software and associated documentation files (the "Software"), to deal
12
+ # in the Software without restriction, including without limitation the rights
13
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ # copies of the Software, and to permit persons to whom the Software is
15
+ # furnished to do so, subject to the following conditions:
16
+ #
17
+ # The above copyright notice and this permission notice shall be included in all
18
+ # copies or substantial portions of the Software.
19
+ #
20
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
24
+ # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
26
+ # OR OTHER DEALINGS IN THE SOFTWARE.
27
+ #
28
+
29
+ # stdlib
30
+ from typing import List, MutableSequence, Optional
31
+
32
+ # 3rd party
33
+ import numpy
34
+
35
+ # this package
36
+ from libgunshotmatch import project
37
+ from libgunshotmatch.consolidate import ConsolidatedPeak
38
+
39
+ _PaddedPeakList = MutableSequence[Optional[ConsolidatedPeak]]
40
+
41
+
42
+ def _get_padded_peak_list(project: project.Project, rts: List[float]) -> _PaddedPeakList:
43
+
44
+ assert project.consolidated_peaks is not None
45
+
46
+ padded_cp_list: _PaddedPeakList = []
47
+
48
+ for cp in project.consolidated_peaks:
49
+ if rts:
50
+ top_rt = rts.pop(0)
51
+ while numpy.isnan(top_rt):
52
+ padded_cp_list.append(None)
53
+ if rts:
54
+ top_rt = rts.pop(0)
55
+ else:
56
+ break
57
+ padded_cp_list.append(cp)
58
+
59
+ return padded_cp_list
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env python3
2
+ #
3
+ # project.py
4
+ """
5
+ Comparison between projects.
6
+ """
7
+ #
8
+ # Copyright © 2024 Dominic Davis-Foster <dominic@davis-foster.co.uk>
9
+ #
10
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ # of this software and associated documentation files (the "Software"), to deal
12
+ # in the Software without restriction, including without limitation the rights
13
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ # copies of the Software, and to permit persons to whom the Software is
15
+ # furnished to do so, subject to the following conditions:
16
+ #
17
+ # The above copyright notice and this permission notice shall be included in all
18
+ # copies or substantial portions of the Software.
19
+ #
20
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
24
+ # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
26
+ # OR OTHER DEALINGS IN THE SOFTWARE.
27
+ #
28
+
29
+ # 3rd party
30
+ import numpy
31
+ import pandas # type: ignore[import]
32
+ from pyms.DPA.Alignment import Alignment # type: ignore[import]
33
+
34
+ # this package
35
+ from libgunshotmatch.project import Project
36
+ from libgunshotmatch.utils import create_alignment
37
+
38
+ # this package
39
+ from ._utils import _get_padded_peak_list, _PaddedPeakList
40
+
41
+ __all__ = ("filter_alignment_to_consolidate", "get_padded_peak_list")
42
+
43
+
44
+ def filter_alignment_to_consolidate(project: Project) -> Alignment:
45
+ """
46
+ Filter peaks from a project's ``alignment`` to only those which survived the ``consolidate`` process.
47
+
48
+ :param project:
49
+ """
50
+
51
+ assert project.consolidated_peaks is not None
52
+
53
+ # Sort expr_code and peakpos into order from datafile_data
54
+ desired_order = list(project.datafile_data)[::-1]
55
+ sort_map = [desired_order.index(code) for code in project.alignment.expr_code]
56
+ expr_code = [project.alignment.expr_code[idx] for idx in sort_map]
57
+ peakpos = [project.alignment.peakpos[idx] for idx in sort_map]
58
+
59
+ consolidated_peak_retention_times = [cp.rt_list for cp in project.consolidated_peaks]
60
+
61
+ aligned_peaks_surviving_consolidate = []
62
+ for aligned_peaks in zip(*peakpos):
63
+ aprt = [p.rt for p in reversed(aligned_peaks)]
64
+ if aprt in consolidated_peak_retention_times:
65
+ aligned_peaks_surviving_consolidate.append(aligned_peaks)
66
+
67
+ alignment_surviving_consolidate = list(zip(*aligned_peaks_surviving_consolidate))
68
+
69
+ # Sanity check
70
+ for c_expr_peaks, expr_peaks in zip(alignment_surviving_consolidate, peakpos):
71
+ for peak in c_expr_peaks:
72
+ assert peak in expr_peaks
73
+
74
+ # Create new Alignment object
75
+ return create_alignment(alignment_surviving_consolidate, expr_code)
76
+
77
+
78
+ def get_padded_peak_list(project: Project, alignment_rts: pandas.DataFrame) -> _PaddedPeakList:
79
+ """
80
+ Returns a list of consolidated peaks for the project, based on the between-project alignment.
81
+
82
+ :param project:
83
+ :param alignment_rts: Pandas DataFrame giving retention times for the peak alignment.
84
+ The output of :meth:`~pyms.DPA.Alignment.Alignment.get_peak_alignment`.
85
+
86
+ """
87
+
88
+ rts = [numpy.mean(row[1:]) for row in alignment_rts[list(project.datafile_data)].itertuples()]
89
+
90
+ return _get_padded_peak_list(project, rts)
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env python3
2
+ #
3
+ # unknown.py
4
+ """
5
+ Comparison between project(s) and unknowns.
6
+ """
7
+ #
8
+ # Copyright © 2024 Dominic Davis-Foster <dominic@davis-foster.co.uk>
9
+ #
10
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ # of this software and associated documentation files (the "Software"), to deal
12
+ # in the Software without restriction, including without limitation the rights
13
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ # copies of the Software, and to permit persons to whom the Software is
15
+ # furnished to do so, subject to the following conditions:
16
+ #
17
+ # The above copyright notice and this permission notice shall be included in all
18
+ # copies or substantial portions of the Software.
19
+ #
20
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
24
+ # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
26
+ # OR OTHER DEALINGS IN THE SOFTWARE.
27
+ #
28
+
29
+ # 3rd party
30
+ import pandas # type: ignore[import]
31
+ from pyms.DPA.Alignment import Alignment # type: ignore[import]
32
+
33
+ # this package
34
+ from libgunshotmatch.project import Project
35
+ from libgunshotmatch.utils import create_alignment
36
+
37
+ # this package
38
+ from ._utils import _get_padded_peak_list, _PaddedPeakList
39
+
40
+ __all__ = ("filter_alignment_to_consolidate", "get_padded_peak_list")
41
+
42
+
43
+ def filter_alignment_to_consolidate(unknown: Project) -> Alignment:
44
+ """
45
+ Filter peaks from an unknown's ``alignment`` to only those which survived the ``consolidate`` process.
46
+
47
+ :param project:
48
+ """
49
+
50
+ assert unknown.consolidated_peaks is not None
51
+
52
+ cp_rts = [cp.rt for cp in unknown.consolidated_peaks]
53
+
54
+ aligned_peaks = [peak for peak in unknown.alignment.peakpos[0] if peak.rt in cp_rts]
55
+
56
+ # Sanity check
57
+ for c_expr_peaks, expr_peaks in zip([aligned_peaks], unknown.alignment.peakpos):
58
+ for peak in c_expr_peaks:
59
+ assert peak in expr_peaks
60
+
61
+ # Create new Alignment object
62
+ return create_alignment([aligned_peaks], [unknown.name])
63
+
64
+
65
+ def get_padded_peak_list(unknown: Project, alignment_rts: pandas.DataFrame) -> _PaddedPeakList:
66
+ """
67
+ Returns a list of consolidated peaks for the unknown sample, based on the between-project alignment.
68
+
69
+ :param unknown:
70
+ :param alignment_rts: Pandas DataFrame giving retention times for the peak alignment.
71
+ The output of :meth:`~pyms.DPA.Alignment.Alignment.get_peak_alignment`.
72
+ """
73
+
74
+ rts = list(alignment_rts[unknown.name])
75
+
76
+ return _get_padded_peak_list(unknown, rts)
@@ -246,6 +246,9 @@ class ConsolidatedPeak:
246
246
  :param hits: Optional list of possible identities for this peak.
247
247
  :param ms_comparison: Mapping or Pandas :class:`~pandas.Series` giving pairwise mass spectral comparison scores.
248
248
  :param meta: Optional dictionary for storing e.g. peak number or whether the peak should be hidden.
249
+
250
+ .. latex:clearpage::
251
+ .. autosummary-widths:: 3/10
249
252
  """
250
253
 
251
254
  #: List of retention times of the aligned peaks.
@@ -456,7 +459,7 @@ class ConsolidatedPeak:
456
459
 
457
460
  def __len__(self) -> int:
458
461
  """
459
- How many instances of the peak make up this :~.ConsolidatedPeak`.
462
+ How many instances of the peak make up this :class:`~.ConsolidatedPeak`.
460
463
  """
461
464
 
462
465
  return numpy.count_nonzero(~numpy.isnan(self.rt_list))
@@ -692,7 +695,7 @@ class ConsolidatedPeakFilter:
692
695
 
693
696
  min_appearances: int = Integer.field(default=-1)
694
697
  """
695
- Number of times the hit must appear across individual the aligned peaks.
698
+ Number of times the hit must appear across the individual aligned peaks.
696
699
 
697
700
  Consolidated peaks where the most common hit appears fewer times than this will be excluded.
698
701
 
@@ -708,6 +711,10 @@ class ConsolidatedPeakFilter:
708
711
  Construct a :class:`~.ConsolidatedPeakFilter` from a :class:`~.ConsolidateMethod`.
709
712
 
710
713
  :param method:
714
+
715
+ :rtype:
716
+
717
+ .. latex:clearpage::
711
718
  """
712
719
 
713
720
  return cls(
@@ -49,7 +49,7 @@ from libgunshotmatch import gzip_util
49
49
  from libgunshotmatch.method import SavitzkyGolayMethod
50
50
  from libgunshotmatch.peak import PeakList, QualifiedPeak, _to_peak_list, peak_from_dict
51
51
 
52
- __all__ = ["Datafile", "FileType", "Repeat", "get_info_from_gcms_data", "GCMSDataInfo"]
52
+ __all__ = ("Datafile", "FileType", "Repeat", "get_info_from_gcms_data", "GCMSDataInfo")
53
53
 
54
54
 
55
55
  class FileType(IntEnum):
@@ -189,6 +189,7 @@ class Datafile:
189
189
  :param crop_mass_range: The range of masses to which the GC-MS data should be limited to.
190
190
 
191
191
  """
192
+
192
193
  intensity_matrix = build_intensity_matrix_i(gcms_data)
193
194
 
194
195
  # Show the m/z of the maximum and minimum bins
@@ -321,9 +322,7 @@ class Datafile:
321
322
 
322
323
  def export(self, output_dir: PathLike) -> str:
323
324
  """
324
- Export as a ``.gsmd`` file.
325
-
326
- :returns: The output filename.
325
+ Export as a ``.gsmd`` file and return the output filename.
327
326
  """
328
327
 
329
328
  export_filename = os.path.join(output_dir, f"{self.name}.gsmd")
@@ -344,7 +343,7 @@ class Datafile:
344
343
 
345
344
  class GCMSDataInfo(NamedTuple):
346
345
  """
347
- Represents information about a :class:`pyms.GCMS.Class.GCMS_data` object returned by :func:`get_info_from_gcms_data`.
346
+ Represents information about a :class:`~pyms.GCMS.Class.GCMS_data` object returned by :func:`get_info_from_gcms_data`.
348
347
  """
349
348
 
350
349
  #: The minimum and maximum retention times.
@@ -501,9 +500,7 @@ class Repeat:
501
500
 
502
501
  def export(self, output_dir: PathLike) -> str:
503
502
  """
504
- Export as a ``.gsmr`` file.
505
-
506
- :returns: The output filename.
503
+ Export as a ``.gsmr`` file and return the output filename.
507
504
 
508
505
  .. versionadded:: 0.4.0
509
506
  """
@@ -35,7 +35,7 @@ import sdjson
35
35
  from domdf_python_tools.paths import PathPlus
36
36
  from domdf_python_tools.typing import PathLike
37
37
 
38
- __all__ = ["read_gzip_json", "write_gzip_json"]
38
+ __all__ = ("read_gzip_json", "write_gzip_json")
39
39
 
40
40
  JSONOutput = Union[str, int, float, bool, None, Dict[str, Any], List[Any]]
41
41
  JSONInput = Union[JSONOutput, Tuple[Any, ...], OrderedDict]
@@ -53,7 +53,7 @@ from libgunshotmatch.method._fields import (
53
53
  )
54
54
  from libgunshotmatch.utils import _fix_init_annotations, _to_list
55
55
 
56
- __all__ = [
56
+ __all__ = (
57
57
  "MethodBase",
58
58
  "Method",
59
59
  "IntensityMatrixMethod",
@@ -62,7 +62,7 @@ __all__ = [
62
62
  "AlignmentMethod",
63
63
  "ConsolidateMethod",
64
64
  "SavitzkyGolayMethod",
65
- ]
65
+ )
66
66
 
67
67
  _MB = TypeVar("_MB", bound="MethodBase")
68
68
 
@@ -272,7 +272,7 @@ class ConsolidateMethod(MethodBase):
272
272
 
273
273
  def _submethod_field(submethod_type: Type[_MB]) -> _MB:
274
274
  # Actually returns attr.Attribute, but mypy doesn't like it
275
- return attr.field(default=attr.Factory(submethod_type), converter=submethod_type._coerce)
275
+ return attr.field(factory=submethod_type, converter=submethod_type._coerce)
276
276
 
277
277
 
278
278
  @_fix_init_annotations
@@ -280,6 +280,8 @@ def _submethod_field(submethod_type: Type[_MB]) -> _MB:
280
280
  class Method(MethodBase):
281
281
  """
282
282
  Overall GunShotMatch method.
283
+
284
+ .. latex:vspace:: 4mm
283
285
  """
284
286
 
285
287
  #: Method used for constructing an intensity matrix from a datafile.
@@ -33,7 +33,7 @@ from typing import Any, Generic, Iterable, Optional, Set, Tuple, Type, TypeVar,
33
33
  import attr
34
34
  from pyms.Utils.Time import time_str_secs # type: ignore[import]
35
35
 
36
- __all__ = [
36
+ __all__ = (
37
37
  "Boolean",
38
38
  "FieldType",
39
39
  "Integer",
@@ -42,7 +42,7 @@ __all__ = [
42
42
  "convert_crop_mass_range",
43
43
  "convert_rt_range",
44
44
  "default_base_peak_filter"
45
- ]
45
+ )
46
46
 
47
47
  _FT = TypeVar("_FT")
48
48
 
libgunshotmatch/peak.py CHANGED
@@ -46,7 +46,7 @@ from pyms.Peak.List.Function import sele_peaks_by_rt # type: ignore[import]
46
46
  from pyms.Spectrum import MassSpectrum # type: ignore[import]
47
47
  from pyms_nist_search import SearchResult
48
48
 
49
- __all__ = [
49
+ __all__ = (
50
50
  "PeakList",
51
51
  "QualifiedPeak",
52
52
  "QualifiedPeakList",
@@ -54,8 +54,8 @@ __all__ = [
54
54
  "filter_aligned_peaks",
55
55
  "filter_peaks",
56
56
  "peak_from_dict",
57
- "write_alignment"
58
- ]
57
+ "write_alignment",
58
+ )
59
59
 
60
60
 
61
61
  class QualifiedPeak(Peak):
@@ -217,6 +217,8 @@ class QualifiedPeak(Peak):
217
217
  class PeakList(List[Peak]):
218
218
  """
219
219
  Represents a list of peaks.
220
+
221
+ .. autosummary-widths:: 35/100
220
222
  """
221
223
 
222
224
  #: String identifier for the datafile the peaks were detected in.
@@ -362,6 +364,10 @@ def align_peaks(
362
364
  :param gap_penalty: Gap parameter for pairwise alignments.
363
365
  :param min_peaks: Minimum number of peaks required for the alignment position to survive filtering.
364
366
  If set to ``-1`` the number of repeats in the project are used.
367
+
368
+ :rtype:
369
+
370
+ .. latex:clearpage::
365
371
  """
366
372
 
367
373
  print("\nAligning\n")
@@ -434,7 +440,7 @@ def write_alignment(
434
440
  alignment_ms_filename = (output_dir_p / f"{project_name}_alignment_ms.json")
435
441
  alignment_ms_filename.dump_json(
436
442
  ms_alignment.to_dict(),
437
- json_library=sdjson, # type: ignore
443
+ json_library=sdjson, # type: ignore[arg-type]
438
444
  )
439
445
 
440
446
 
@@ -500,6 +506,10 @@ def peak_from_dict(d: Dict[str, Any]) -> Peak:
500
506
  Construct a :class:`~pyms.Peak.Class.Peak` from a dictionary.
501
507
 
502
508
  :param d:
509
+
510
+ :rtype:
511
+
512
+ .. latex:clearpage::
503
513
  """
504
514
 
505
515
  peak_obj = Peak(d["rt"], MassSpectrum(**d["mass_spectrum"]), outlier=d["is_outlier"])
libgunshotmatch/search.py CHANGED
@@ -38,7 +38,7 @@ from pyms.Peak.Class import Peak # type: ignore[import]
38
38
  from libgunshotmatch.peak import QualifiedPeak
39
39
  from libgunshotmatch.utils import round_rt
40
40
 
41
- __all__ = ["identify_peaks"]
41
+ __all__ = ("identify_peaks", )
42
42
 
43
43
 
44
44
  def identify_peaks(
libgunshotmatch/utils.py CHANGED
@@ -34,6 +34,8 @@ from typing import TYPE_CHECKING, Any, Iterable, List, Optional, Sequence, Tuple
34
34
  import numpy
35
35
  from chemistry_tools.spectrum_similarity import SpectrumSimilarity
36
36
  from mathematical.utils import rounders
37
+ from pyms.DPA.Alignment import Alignment # type: ignore[import]
38
+ from pyms.Peak.Class import Peak # type: ignore[import]
37
39
  from pyms.Spectrum import MassSpectrum # type: ignore[import]
38
40
  from scipy.stats import truncnorm # type: ignore[import]
39
41
 
@@ -41,7 +43,7 @@ if TYPE_CHECKING:
41
43
  # this package
42
44
  from libgunshotmatch.project import Project
43
45
 
44
- __all__ = ("round_rt", "get_truncated_normal", "ms_comparison", "get_rt_range")
46
+ __all__ = ("round_rt", "get_truncated_normal", "ms_comparison", "get_rt_range", "create_alignment")
45
47
 
46
48
 
47
49
  def round_rt(rt: Union[str, float, Decimal]) -> Decimal:
@@ -150,7 +152,7 @@ def get_rt_range(project: "Project") -> Tuple[float, float]:
150
152
 
151
153
  :rtype:
152
154
 
153
- ,, versionadded:: 0.7.0
155
+ .. versionadded:: 0.7.0
154
156
  """
155
157
 
156
158
  # Get RT extremes from intensity matrix
@@ -166,3 +168,25 @@ def get_rt_range(project: "Project") -> Tuple[float, float]:
166
168
  max_rt = max(max_rts) / 60
167
169
 
168
170
  return min_rt, max_rt
171
+
172
+
173
+ def create_alignment(peakpos: Sequence[Sequence[Peak]], expr_code: List[str], similarity: float = 0) -> Alignment:
174
+ """
175
+ Create a new :class:`pyms.DPA.Alignment.Alignment` object.
176
+
177
+ :param peakpos: Nested list of aligned peaks. Top level list contains lists of peaks for each experiment in ``expr_code``.
178
+ :param expr_code: Experiment names. Order must match ``peakpos``.
179
+ :param similarity:
180
+
181
+ :rtype:
182
+
183
+ .. versionadded:: 0.8.0
184
+ """
185
+
186
+ alignment = Alignment(None)
187
+ alignment.peakpos = peakpos
188
+ alignment.peakalgt = numpy.transpose(alignment.peakpos).tolist()
189
+ alignment.expr_code = expr_code
190
+ alignment.similarity = similarity
191
+
192
+ return alignment
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libgunshotmatch
3
- Version: 0.7.3
3
+ Version: 0.8.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.7.3
138
+ .. |commits-since| image:: https://img.shields.io/github/commits-since/GunShotMatch/libgunshotmatch/v0.8.0
139
139
  :target: https://github.com/GunShotMatch/libgunshotmatch/pulse
140
140
  :alt: GitHub commits since tagged version
141
141
 
@@ -0,0 +1,22 @@
1
+ libgunshotmatch/comparison/__init__.py,sha256=t1ZPlK3TV8Ye0FTYAVQK0PcH0x0F_ivJUlkOezirSKI,3151
2
+ libgunshotmatch/comparison/_utils.py,sha256=aZ6fnFM4M_vTsKq5t79V4tfven1eVdG4EUCuYFuXMVs,1895
3
+ libgunshotmatch/comparison/projects.py,sha256=AZ1z2WoDr-ZA7do7qDP5T_a7a5ps00MXaSrEwE70EiY,3372
4
+ libgunshotmatch/comparison/unknowns.py,sha256=xfj57Y0JUG-sYggcpvRBAAJ7ksCgas_dP2Ab5-T9FLg,2726
5
+ libgunshotmatch/consolidate/__init__.py,sha256=vIrmxXNbm3s7_5dkyfSvcT1u2T-xbTl2uRG67uw5xcU,22929
6
+ libgunshotmatch/consolidate/_fields.py,sha256=7gPIQaFaFySLZFrIuSMjwS84WEBHxZhCNhpXATlYjVw,2691
7
+ libgunshotmatch/consolidate/_spectra.py,sha256=7q_xVPN_oASayLdyMDjwaBLG4maIybHCqkGhiMIO940,2343
8
+ libgunshotmatch/method/__init__.py,sha256=wx3xwlH-0WrBzL4NnSmsg8-ymH-u6Utlq2LGIvJyf8g,9439
9
+ libgunshotmatch/method/_fields.py,sha256=lrf5kvd7w0uvyYeBE7g88_BNmMIOMIk-P4hdii-q064,5025
10
+ libgunshotmatch/__init__.py,sha256=e4kuRRHCi5revHSwvpZ8XaHgE3fRnMmpM7As5BqjbeY,1433
11
+ libgunshotmatch/datafile.py,sha256=aW1DjiNX5Or_7fig5y57bSqf-EHQEa2_-n6Lbdqk1vA,16278
12
+ libgunshotmatch/gzip_util.py,sha256=pvD78_qnzRNCm4PK3KTb1cbOxzFfqTYcHB3VRi25oL0,2270
13
+ libgunshotmatch/peak.py,sha256=sMuEukQkAIPp8Pz66CvddgQGHoj_4yoVveeRgwgRBrM,17070
14
+ libgunshotmatch/project.py,sha256=2dvbWA4OHIxJQPjIgEglBbLB6NEQMxvgZA21Qgcb70c,6477
15
+ libgunshotmatch/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ libgunshotmatch/search.py,sha256=cV45Ad9wz0proi4OAkJYoyXYpy0QQgQ-4btDRL3OynE,3139
17
+ libgunshotmatch/utils.py,sha256=9sSzfIs-mfOr--eJe4tx3y3UhmMOimPEcv4-6Lh3wlQ,5706
18
+ libgunshotmatch-0.8.0.dist-info/LICENSE,sha256=bFtJt-lyVJHV-88FeFa_r3BEOsmpna5qG2KOl9JUNfU,1064
19
+ libgunshotmatch-0.8.0.dist-info/METADATA,sha256=tLqXC9xq2ADjUDZEwDkDOXNKbxqtnDDgX5UCYBFAKq0,6392
20
+ libgunshotmatch-0.8.0.dist-info/WHEEL,sha256=3vSnEhs48RUlSXcCXKCl4DOHs_qqaP2dU3IGkMqN2oI,84
21
+ libgunshotmatch-0.8.0.dist-info/entry_points.txt,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ libgunshotmatch-0.8.0.dist-info/RECORD,,
@@ -1,18 +0,0 @@
1
- libgunshotmatch/consolidate/__init__.py,sha256=gOqPqFcoSkVob8hKOpcNobK84yADyCwB3UNBPJM3vAc,22834
2
- libgunshotmatch/consolidate/_fields.py,sha256=7gPIQaFaFySLZFrIuSMjwS84WEBHxZhCNhpXATlYjVw,2691
3
- libgunshotmatch/consolidate/_spectra.py,sha256=7q_xVPN_oASayLdyMDjwaBLG4maIybHCqkGhiMIO940,2343
4
- libgunshotmatch/method/__init__.py,sha256=138s5xt_E-WbCf1_H366crhT0PNptB7hD1uOJt2CV8o,9429
5
- libgunshotmatch/method/_fields.py,sha256=GQNw9GdGhy9c_-0U_31eJDTXr1sG5_t5Lh0Z_nzE0RE,5025
6
- libgunshotmatch/__init__.py,sha256=pv1kJbZIqxC9x7Ugvh0m05M9LhvAFJGM5kI-2Z1oTzc,1433
7
- libgunshotmatch/datafile.py,sha256=r20e9fJ5oMx5hTpvPvau4m_ut_CQf0bu6IMU06Ml1mE,16282
8
- libgunshotmatch/gzip_util.py,sha256=mQuiQI2pCb1Ba5J_HA5TfeMEEQ_lSF_dNDDSRQWoaqo,2270
9
- libgunshotmatch/peak.py,sha256=X8aDKJctRbYyvnOqXa9saUQLAv04F6mc-oxntsDbyaY,16960
10
- libgunshotmatch/project.py,sha256=2dvbWA4OHIxJQPjIgEglBbLB6NEQMxvgZA21Qgcb70c,6477
11
- libgunshotmatch/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- libgunshotmatch/search.py,sha256=qjIXuTo3OqvC_zSLdwZkEDHfza064iYCTZzGeAZoW5s,3137
13
- libgunshotmatch/utils.py,sha256=H-Ikm6oEGCgRoPvuCo3H5p1iKz3B9PuUqcpcH-rhgYA,4917
14
- libgunshotmatch-0.7.3.dist-info/LICENSE,sha256=bFtJt-lyVJHV-88FeFa_r3BEOsmpna5qG2KOl9JUNfU,1064
15
- libgunshotmatch-0.7.3.dist-info/METADATA,sha256=gOSO8CvLDpl5xnJRnIskkdSRtCb5GjX-XUmlfQ-9Kko,6392
16
- libgunshotmatch-0.7.3.dist-info/WHEEL,sha256=3vSnEhs48RUlSXcCXKCl4DOHs_qqaP2dU3IGkMqN2oI,84
17
- libgunshotmatch-0.7.3.dist-info/entry_points.txt,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- libgunshotmatch-0.7.3.dist-info/RECORD,,