diff --git a/README.md b/README.md index c82a9f6..f02f3f7 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,6 @@ For development, run: pip install --editable . ``` -Or from the root of this repository: -```sh -pip install --editable implementations/python -``` - Test with ``` pytest diff --git a/bench/nist_msp_ftp_test.py b/bench/nist_msp_ftp_test.py index 521332a..abbd39a 100644 --- a/bench/nist_msp_ftp_test.py +++ b/bench/nist_msp_ftp_test.py @@ -5,8 +5,8 @@ from urllib.request import urlopen -from mzlib.backends import msp -from mzlib import annotation +from mzspeclib.backends import msp +from mzspeclib import annotation urls = [ diff --git a/examples/draw_entry.py b/examples/draw_entry.py index 8126d7e..5ffe989 100644 --- a/examples/draw_entry.py +++ b/examples/draw_entry.py @@ -4,8 +4,8 @@ from matplotlib import pyplot as plt -from mzlib.spectrum_library import SpectrumLibrary -from mzlib.draw import draw_spectrum +from mzspeclib.spectrum_library import SpectrumLibrary +from mzspeclib.draw import draw_spectrum def main(path, spectrum_key): diff --git a/examples/first_n_entries.py b/examples/first_n_entries.py index 0aa4c05..bc175d0 100644 --- a/examples/first_n_entries.py +++ b/examples/first_n_entries.py @@ -1,10 +1,10 @@ import click -from mzlib import SpectrumLibrary -from mzlib.backends import SpectralLibraryBackendBase, FormatInferenceFailure, TextSpectralLibraryWriter -from mzlib.cluster import SpectrumCluster -from mzlib.index import MemoryIndex, SQLIndex -from mzlib.spectrum import Spectrum +from mzspeclib import SpectrumLibrary +from mzspeclib.backends import SpectralLibraryBackendBase, FormatInferenceFailure, TextSpectralLibraryWriter +from mzspeclib.cluster import SpectrumCluster +from mzspeclib.index import MemoryIndex, SQLIndex +from mzspeclib.spectrum import Spectrum @click.command('first_n_entries') @click.argument('inpath', type=click.Path(exists=True)) diff --git a/makefile b/makefile index 1ccafcb..f73040d 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ test: - pytest -r a -v tests --cov mzlib --cov-report=html --cov-report term + pytest -r a -v tests --cov mzspeclib --cov-report=html --cov-report term retest: py.test -v tests --lf --pdb diff --git a/mzlib/__init__.py b/mzlib/__init__.py deleted file mode 100644 index 65badd8..0000000 --- a/mzlib/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -"""HUPO-PSI Spectral library format.""" - -from mzlib.spectrum import Spectrum -from mzlib.analyte import Analyte, Interpretation - -from mzlib.index import MemoryIndex, SQLIndex - -from mzlib.spectrum_library import SpectrumLibrary -from mzlib.spectrum_library_index import SpectrumLibraryIndex -from mzlib.spectrum_library_collection import SpectrumLibraryCollection -from mzlib.universal_spectrum_identifier import UniversalSpectrumIdentifier diff --git a/mzspeclib/__init__.py b/mzspeclib/__init__.py new file mode 100644 index 0000000..668fab7 --- /dev/null +++ b/mzspeclib/__init__.py @@ -0,0 +1,11 @@ +"""HUPO-PSI Spectral library format.""" + +from mzspeclib.spectrum import Spectrum +from mzspeclib.analyte import Analyte, Interpretation + +from mzspeclib.index import MemoryIndex, SQLIndex + +from mzspeclib.spectrum_library import SpectrumLibrary +from mzspeclib.spectrum_library_index import SpectrumLibraryIndex +from mzspeclib.spectrum_library_collection import SpectrumLibraryCollection +from mzspeclib.universal_spectrum_identifier import UniversalSpectrumIdentifier diff --git a/mzlib/analyte.py b/mzspeclib/analyte.py similarity index 98% rename from mzlib/analyte.py rename to mzspeclib/analyte.py index 12f8a25..82d3714 100644 --- a/mzlib/analyte.py +++ b/mzspeclib/analyte.py @@ -4,7 +4,7 @@ from pyteomics import proforma -from mzlib.attributes import AttributedEntity, IdentifiedAttributeManager, AttributeManagedProperty, AttributeProxy, AttributeGroupFacet +from mzspeclib.attributes import AttributedEntity, IdentifiedAttributeManager, AttributeManagedProperty, AttributeProxy, AttributeGroupFacet FIRST_ANALYTE_KEY = '1' diff --git a/mzlib/annotation.py b/mzspeclib/annotation.py similarity index 100% rename from mzlib/annotation.py rename to mzspeclib/annotation.py diff --git a/mzlib/attributes.py b/mzspeclib/attributes.py similarity index 100% rename from mzlib/attributes.py rename to mzspeclib/attributes.py diff --git a/mzlib/backends/__init__.py b/mzspeclib/backends/__init__.py similarity index 100% rename from mzlib/backends/__init__.py rename to mzspeclib/backends/__init__.py diff --git a/mzlib/backends/base.py b/mzspeclib/backends/base.py similarity index 98% rename from mzlib/backends/base.py rename to mzspeclib/backends/base.py index 8a876ec..4f4b371 100644 --- a/mzlib/backends/base.py +++ b/mzspeclib/backends/base.py @@ -12,13 +12,13 @@ from psims.controlled_vocabulary import Entity from psims.controlled_vocabulary.controlled_vocabulary import ( load_uo, load_unimod, load_psims) -from mzlib.cluster import SpectrumCluster +from mzspeclib.cluster import SpectrumCluster -from mzlib.index import MemoryIndex, SQLIndex, IndexBase -from mzlib.spectrum import LIBRARY_SPECTRUM_INDEX, LIBRARY_SPECTRUM_KEY, Spectrum -from mzlib.analyte import Analyte, Interpretation, InterpretationMember, ANALYTE_MIXTURE_TERM -from mzlib.attributes import Attributed, AttributedEntity, AttributeSet, AttributeManagedProperty -from mzlib.ontology import _VocabularyResolverMixin +from mzspeclib.index import MemoryIndex, SQLIndex, IndexBase +from mzspeclib.spectrum import LIBRARY_SPECTRUM_INDEX, LIBRARY_SPECTRUM_KEY, Spectrum +from mzspeclib.analyte import Analyte, Interpretation, InterpretationMember, ANALYTE_MIXTURE_TERM +from mzspeclib.attributes import Attributed, AttributedEntity, AttributeSet, AttributeManagedProperty +from mzspeclib.ontology import _VocabularyResolverMixin from .utils import open_stream, _LineBuffer diff --git a/mzlib/backends/bibliospec.py b/mzspeclib/backends/bibliospec.py similarity index 95% rename from mzlib/backends/bibliospec.py rename to mzspeclib/backends/bibliospec.py index 91e5095..229510b 100644 --- a/mzlib/backends/bibliospec.py +++ b/mzspeclib/backends/bibliospec.py @@ -13,14 +13,14 @@ from pyteomics import proforma -from mzlib import annotation -from mzlib.analyte import FIRST_ANALYTE_KEY, FIRST_INTERPRETATION_KEY, Analyte -from mzlib.spectrum import Spectrum, SPECTRUM_NAME, CHARGE_STATE -from mzlib.attributes import AttributeManager, Attributed +from mzspeclib import annotation +from mzspeclib.analyte import FIRST_ANALYTE_KEY, FIRST_INTERPRETATION_KEY, Analyte +from mzspeclib.spectrum import Spectrum, SPECTRUM_NAME, CHARGE_STATE +from mzspeclib.attributes import AttributeManager, Attributed -from mzlib.backends.base import SpectralLibraryBackendBase, FORMAT_VERSION_TERM, DEFAULT_VERSION +from mzspeclib.backends.base import SpectralLibraryBackendBase, FORMAT_VERSION_TERM, DEFAULT_VERSION -from mzlib.index.base import IndexBase +from mzspeclib.index.base import IndexBase class BibliospecBase: diff --git a/mzlib/backends/diann.py b/mzspeclib/backends/diann.py similarity index 96% rename from mzlib/backends/diann.py rename to mzspeclib/backends/diann.py index a137438..6713aa6 100644 --- a/mzlib/backends/diann.py +++ b/mzspeclib/backends/diann.py @@ -10,10 +10,10 @@ from pyteomics import proforma -from mzlib import annotation -from mzlib.backends.base import DEFAULT_VERSION, FORMAT_VERSION_TERM, LIBRARY_NAME_TERM, _CSVSpectralLibraryBackendBase -from mzlib.backends.utils import open_stream, urlify -from mzlib.spectrum import Spectrum, SPECTRUM_NAME +from mzspeclib import annotation +from mzspeclib.backends.base import DEFAULT_VERSION, FORMAT_VERSION_TERM, LIBRARY_NAME_TERM, _CSVSpectralLibraryBackendBase +from mzspeclib.backends.utils import open_stream, urlify +from mzspeclib.spectrum import Spectrum, SPECTRUM_NAME def _rewrite_unimod_peptide_as_proforma(sequence: str) -> str: diff --git a/mzlib/backends/encyclopedia.py b/mzspeclib/backends/encyclopedia.py similarity index 94% rename from mzlib/backends/encyclopedia.py rename to mzspeclib/backends/encyclopedia.py index 4a9118b..292bb4b 100644 --- a/mzlib/backends/encyclopedia.py +++ b/mzspeclib/backends/encyclopedia.py @@ -13,14 +13,14 @@ from pyteomics import proforma -from mzlib import annotation -from mzlib.analyte import FIRST_ANALYTE_KEY, FIRST_INTERPRETATION_KEY, Analyte, ProteinDescription -from mzlib.spectrum import Spectrum, SPECTRUM_NAME, CHARGE_STATE -from mzlib.attributes import AttributeManager, Attributed, Attribute +from mzspeclib import annotation +from mzspeclib.analyte import FIRST_ANALYTE_KEY, FIRST_INTERPRETATION_KEY, Analyte, ProteinDescription +from mzspeclib.spectrum import Spectrum, SPECTRUM_NAME, CHARGE_STATE +from mzspeclib.attributes import AttributeManager, Attributed, Attribute -from mzlib.backends.base import SpectralLibraryBackendBase, FORMAT_VERSION_TERM, DEFAULT_VERSION +from mzspeclib.backends.base import SpectralLibraryBackendBase, FORMAT_VERSION_TERM, DEFAULT_VERSION -from mzlib.index.base import IndexBase +from mzspeclib.index.base import IndexBase DECOY_SPECTRUM = "MS:1003192|decoy spectrum" diff --git a/mzlib/backends/json.py b/mzspeclib/backends/json.py similarity index 98% rename from mzlib/backends/json.py rename to mzspeclib/backends/json.py index 82aa594..eee6155 100644 --- a/mzlib/backends/json.py +++ b/mzspeclib/backends/json.py @@ -7,13 +7,13 @@ from typing import Any, Iterable, List, Dict, Mapping, Union from pathlib import Path -from mzlib.cluster import SpectrumCluster +from mzspeclib.cluster import SpectrumCluster -from mzlib.index import MemoryIndex -from mzlib.attributes import AttributeManager, Attributed, AttributeSet -from mzlib.annotation import parse_annotation, IonAnnotationBase -from mzlib.analyte import Analyte, Interpretation, FIRST_INTERPRETATION_KEY -from mzlib.spectrum import Spectrum +from mzspeclib.index import MemoryIndex +from mzspeclib.attributes import AttributeManager, Attributed, AttributeSet +from mzspeclib.annotation import parse_annotation, IonAnnotationBase +from mzspeclib.analyte import Analyte, Interpretation, FIRST_INTERPRETATION_KEY +from mzspeclib.spectrum import Spectrum from .base import SpectralLibraryBackendBase, SpectralLibraryWriterBase, FORMAT_VERSION_TERM, AttributeSetTypes from .utils import open_stream diff --git a/mzlib/backends/msp.py b/mzspeclib/backends/msp.py similarity index 92% rename from mzlib/backends/msp.py rename to mzspeclib/backends/msp.py index 8d68a11..cdeb4e0 100644 --- a/mzlib/backends/msp.py +++ b/mzspeclib/backends/msp.py @@ -5,6 +5,7 @@ cover a representative subset from the NIST and some found in the wild. If you encounter an MSP file that does not parse properly, please report it. """ +from dataclasses import dataclass, field import re import io import os @@ -12,18 +13,21 @@ import itertools import warnings +from fractions import Fraction + from typing import ( Any, Callable, Collection, Dict, List, Mapping, Optional, - Set, Tuple, Iterable, DefaultDict) + Set, Tuple, Iterable, DefaultDict, + NamedTuple) from pyteomics import proforma -from mzlib import annotation +from mzspeclib import annotation -from mzlib.analyte import FIRST_ANALYTE_KEY, FIRST_INTERPRETATION_KEY, Analyte, Interpretation, ProteinDescription -from mzlib.spectrum import Spectrum, SPECTRUM_NAME -from mzlib.attributes import AttributeManager, AttributeSet, Attributed +from mzspeclib.analyte import FIRST_ANALYTE_KEY, FIRST_INTERPRETATION_KEY, Analyte, Interpretation, ProteinDescription +from mzspeclib.spectrum import Spectrum, SPECTRUM_NAME +from mzspeclib.attributes import Attribute, AttributeManager, AttributeSet, Attributed from .base import ( DEFAULT_VERSION, FORMAT_VERSION_TERM, _PlainTextSpectralLibraryBackendBase, @@ -56,8 +60,10 @@ def _generate_numpeaks_keys(): NUM_PEAKS_KEYS = _generate_numpeaks_keys() -leader_terms_pattern = re.compile(r"(Name|NAME|Compound|COMPOUND)\s*:") -leader_terms_line_pattern = re.compile(r'(?:Name|NAME|Compound|COMPOUND)\s*:\s+(.+)') +LEADER_TERMS_PATTERN = re.compile(r"(Name|NAME|Compound|COMPOUND)\s*:") +LEADER_TERMS_LINE_PATTERN = re.compile(r'(?:Name|NAME|Compound|COMPOUND)\s*:\s+(.+)') + +SPACE_SPLITTER = re.compile(r"\s+") STRIPPED_PEPTIDE_TERM = "MS:1000888|stripped peptide sequence" PEPTIDE_MODIFICATION_TERM = "MS:1001471|peptide modification details" @@ -66,6 +72,12 @@ def _generate_numpeaks_keys(): PEAK_ATTRIB = "MS:1003254|peak attribute" +RawPeakLine = Tuple[float, float, str, str] +PeakLine = Tuple[float, float, List[annotation.IonAnnotationBase], List[Any]] + +PeakAggregateParseFn = Callable[[str], Any] + + class AttributeHandler: keys: Collection[str] @@ -296,8 +308,8 @@ def add(self, handler: AttributeHandler): "MC": "MS:1003044|number of missed cleavages", "Mods": PEPTIDE_MODIFICATION_TERM, "Naa": "MS:1003043|number of residues", + "Parent": "MS:1000744|selected ion m/z", "PrecursorMonoisoMZ": "MS:1003208|experimental precursor monoisotopic m/z", - "Parent": "MS:1003208|experimental precursor monoisotopic m/z", "ObservedPrecursorMZ": "MS:1003208|experimental precursor monoisotopic m/z", "PrecursorMZ": "MS:1003208|experimental precursor monoisotopic m/z", "PRECURSORMZ": "MS:1003208|experimental precursor monoisotopic m/z", @@ -355,6 +367,7 @@ def unassigned_peaks_handler(key: str, value: str, container: Attributed) -> boo is_top_20 = True value = value.split("/")[0] value = int(value) + assert isinstance(value, int) if is_top_20: container.add_attribute("MS:1003290|number of unassigned peaks among top 20 peaks", value) else: @@ -362,20 +375,19 @@ def unassigned_peaks_handler(key: str, value: str, container: Attributed) -> boo return True -interpretation_terms = CaseInsensitiveDict({ - "Unassigned_all_20ppm": "MS:1003079|total unassigned intensity fraction", - "Unassign_all": "MS:1003079|total unassigned intensity fraction", - - "top_20_num_unassigned_peaks_20ppm": "MS:1003290|number of unassigned peaks among top 20 peaks", - "num_unassigned_peaks_20ppm": unassigned_peaks_handler, - "num_unassigned_peaks": unassigned_peaks_handler, - - "max_unassigned_ab_20ppm": "MS:1003289|intensity of highest unassigned peak", - "max_unassigned_ab": "MS:1003289|intensity of highest unassigned peak", - - "Unassigned_20ppm": "MS:1003080|top 20 peak unassigned intensity fraction", - "Unassigned": "MS:1003080|top 20 peak unassigned intensity fraction", -}) +interpretation_terms = CaseInsensitiveDict( + { + "Unassigned_all_20ppm": "MS:1003079|total unassigned intensity fraction", + "Unassign_all": "MS:1003079|total unassigned intensity fraction", + "top_20_num_unassigned_peaks_20ppm": unassigned_peaks_handler, + "num_unassigned_peaks_20ppm": unassigned_peaks_handler, + "num_unassigned_peaks": unassigned_peaks_handler, + "max_unassigned_ab_20ppm": "MS:1003289|intensity of highest unassigned peak", + "max_unassigned_ab": "MS:1003289|intensity of highest unassigned peak", + "Unassigned_20ppm": "MS:1003080|top 20 peak unassigned intensity fraction", + "Unassigned": "MS:1003080|top 20 peak unassigned intensity fraction", + } +) interpretation_member_terms = CaseInsensitiveDict({ @@ -879,6 +891,111 @@ def add(self, key: str, value: Optional[str] = None): ] +def proportion_parser(aggregation: str) -> float: + """Parse for fractions or percentages""" + if '/' in aggregation: + aggregation: Fraction = Fraction(aggregation) + return float(aggregation) + else: + return float(aggregation) + + +@dataclass +class PeakAggregationParser: + """ + Parse peak aggregation information. + + Subtypes may produce different attributes. + + Attributes + ---------- + peak_attributes : list[:class:`~.Attribute`] + The attributes this parser expects + """ + + peak_attributes: List[Tuple[Attribute, PeakAggregateParseFn]] = field(default_factory=lambda: [Attribute(PEAK_ATTRIB, PEAK_OBSERVATION_FREQ)]) + + def __call__(self, aggregation: str, wrap_errors: bool=True, **kwargs) -> List[Tuple[Attribute, float]]: + parsed = [] + for i, (k, parser), token in enumerate(SPACE_SPLITTER.split(aggregation)): + try: + result = parser(token) + parsed.append((k, result)) + except Exception as err: + if not wrap_errors: + raise err from None + else: + logger.error(f"Failed to parse aggregation at {i}") + parsed.append((k, token)) + + +@dataclass +class PeakParsingStrategy: + """ + A combination of peak annotation parsing and peak aggregation parsing + strategies. + + Attributes + ---------- + annotation_parser : :class:`MSPAnnotationStringParser` + The peak annotation parser + """ + + annotation_parser: Optional[MSPAnnotationStringParser] = None + aggregation_parser: Optional[PeakAggregationParser] = None + + def has_aggregation(self) -> bool: + return self.aggregation_parser is not None + + def has_annotation(self) -> bool: + return self.annotation_parser is not None + + def parse_aggregation(self, aggregation: str, wrap_errors: bool=True, **kwargs): + return self.aggregation_parser(aggregation=aggregation, wrap_errors=wrap_errors, **kwargs) + + def parse_annotation(self, annotation: str, wrap_errors: bool=True, **kwargs): + return self.annotation_parser(annotation_string=annotation, wrap_errors=wrap_errors, **kwargs) + + def parse_peak_annotations(self, peal_list: List[RawPeakLine]): + pass + + def parse_peak_list(self, peak_lines: List[str]) -> List[RawPeakLine]: + peak_list = [] + for values in peak_lines: + interpretations = "" + aggregation = "" + if len(values) == 1: + mz = values + intensity = "1" + if len(values) == 2: + mz, intensity = values + elif len(values) == 3: + mz, intensity, interpretations = values + elif len(values) > 3: + mz, intensity, interpretations = values[0:2] + else: + mz = "1" + intensity = "1" + + interpretations = interpretations.strip('"') + aggregation = None + if interpretations.startswith("?"): + parts = SPACE_SPLITTER.split(interpretations) + if len(parts) > 1: + # Some msp files have a concept for ?i, but this requires a definition + interpretations = "?" + aggregation = parts[1:] + else: + if " " in interpretations: + parts = SPACE_SPLITTER.split(interpretations) + interpretations = parts[0] + aggregation = parts[1:] + + #### Add to the peak list + peak_list.append([float(mz), float(intensity), interpretations, aggregation]) + return peak_list + + class MSPSpectralLibrary(_PlainTextSpectralLibraryBackendBase): """ A reader for the plain text NIST MSP spectral library format. @@ -917,7 +1034,7 @@ def __init__(self, filename, index_type=None, read_metadata=True, create_index: def guess_from_header(cls, filename: str) -> bool: with open_stream(filename, 'r') as stream: first_line = stream.readline() - if leader_terms_pattern.match(first_line): + if LEADER_TERMS_PATTERN.match(first_line): return True return False @@ -947,7 +1064,7 @@ def _parse_header_from_stream(self, stream: io.IOBase) -> Tuple[bool, int]: attributes.add_attribute(LIBRARY_NAME_TERM, stream.name.rsplit('.msp', 1)[0].split(os.sep)[-1]) self.attributes.clear() self.attributes._from_iterable(attributes) - if leader_terms_pattern.match(first_line): + if LEADER_TERMS_PATTERN.match(first_line): return True, 0 return False, 0 @@ -1009,7 +1126,7 @@ def create_index(self) -> int: line = line.rstrip() # TODO: Name: could be Compound or SpectrumName if state == 'header': - if leader_terms_pattern.match(line): + if LEADER_TERMS_PATTERN.match(line): state = 'body' spectrum_file_offset = line_beginning_file_offset else: @@ -1017,7 +1134,7 @@ def create_index(self) -> int: if state == 'body': if len(line) == 0: continue - if leader_terms_pattern.match(line): + if LEADER_TERMS_PATTERN.match(line): if len(spectrum_buffer) > 0: self.index.add( number=n_spectra + start_index, @@ -1032,7 +1149,7 @@ def create_index(self) -> int: logger.info(f"... Indexed {file_offset} bytes, {n_spectra} spectra read") spectrum_file_offset = line_beginning_file_offset - spectrum_name = leader_terms_line_pattern.match(line).group(1) + spectrum_name = LEADER_TERMS_LINE_PATTERN.match(line).group(1) spectrum_buffer.append(line) logger.debug(f"Processed {file_offset} bytes, {n_spectra} spectra read") @@ -1068,7 +1185,7 @@ def _buffer_from_stream(self, infile: Iterable[str]) -> List[str]: if state == 'body': if len(line) == 0: continue - if leader_terms_pattern.match(line): + if LEADER_TERMS_PATTERN.match(line): if len(spectrum_buffer) > 0: return spectrum_buffer spectrum_buffer.append(line) diff --git a/mzlib/backends/spectronaut.py b/mzspeclib/backends/spectronaut.py similarity index 97% rename from mzlib/backends/spectronaut.py rename to mzspeclib/backends/spectronaut.py index 7750fb6..f95cbcd 100644 --- a/mzlib/backends/spectronaut.py +++ b/mzspeclib/backends/spectronaut.py @@ -7,11 +7,11 @@ from pyteomics import proforma -from mzlib import annotation -from mzlib.analyte import Analyte -from mzlib.backends.base import LIBRARY_NAME_TERM, _CSVSpectralLibraryBackendBase, FORMAT_VERSION_TERM, DEFAULT_VERSION -from mzlib.backends.utils import open_stream, urlify -from mzlib.spectrum import Spectrum, SPECTRUM_NAME +from mzspeclib import annotation +from mzspeclib.analyte import Analyte +from mzspeclib.backends.base import LIBRARY_NAME_TERM, _CSVSpectralLibraryBackendBase, FORMAT_VERSION_TERM, DEFAULT_VERSION +from mzspeclib.backends.utils import open_stream, urlify +from mzspeclib.spectrum import Spectrum, SPECTRUM_NAME CHARGE_STATE = "MS:1000041|charge state" diff --git a/mzlib/backends/sptxt.py b/mzspeclib/backends/sptxt.py similarity index 91% rename from mzlib/backends/sptxt.py rename to mzspeclib/backends/sptxt.py index 957f2a1..719f17c 100644 --- a/mzlib/backends/sptxt.py +++ b/mzspeclib/backends/sptxt.py @@ -3,12 +3,12 @@ from typing import Dict, Tuple -from mzlib.attributes import AttributeManager +from mzspeclib.attributes import AttributeManager -from mzlib.annotation import AnnotationStringParser +from mzspeclib.annotation import AnnotationStringParser -from mzlib.backends.base import DEFAULT_VERSION, FORMAT_VERSION_TERM, LIBRARY_NAME_TERM -from mzlib.backends.utils import open_stream +from mzspeclib.backends.base import DEFAULT_VERSION, FORMAT_VERSION_TERM, LIBRARY_NAME_TERM +from mzspeclib.backends.utils import open_stream from .msp import MSPSpectralLibrary as _MSPSpectralLibrary from .utils import CaseInsensitiveDict diff --git a/mzlib/backends/text.py b/mzspeclib/backends/text.py similarity index 99% rename from mzlib/backends/text.py rename to mzspeclib/backends/text.py index 1e92209..ae3125b 100644 --- a/mzlib/backends/text.py +++ b/mzspeclib/backends/text.py @@ -11,12 +11,12 @@ from collections import deque from typing import ClassVar, List, Optional, Tuple, Union, Iterable -from mzlib.annotation import parse_annotation -from mzlib.spectrum import Spectrum -from mzlib.cluster import SpectrumCluster -from mzlib.attributes import Attribute, AttributeManager, Attributed, AttributeSet -from mzlib.analyte import Analyte, Interpretation, InterpretationMember -from mzlib.validate.object_rule import ValidationWarning +from mzspeclib.annotation import parse_annotation +from mzspeclib.spectrum import Spectrum +from mzspeclib.cluster import SpectrumCluster +from mzspeclib.attributes import Attribute, AttributeManager, Attributed, AttributeSet +from mzspeclib.analyte import Analyte, Interpretation, InterpretationMember +from mzspeclib.validate.object_rule import ValidationWarning from .base import ( SpectralLibraryBackendBase, diff --git a/mzlib/backends/utils.py b/mzspeclib/backends/utils.py similarity index 100% rename from mzlib/backends/utils.py rename to mzspeclib/backends/utils.py diff --git a/mzlib/cluster.py b/mzspeclib/cluster.py similarity index 93% rename from mzlib/cluster.py rename to mzspeclib/cluster.py index 7bba278..b1cca78 100644 --- a/mzlib/cluster.py +++ b/mzspeclib/cluster.py @@ -4,7 +4,7 @@ from typing import Dict, List -from mzlib.attributes import AttributeManager, AttributeManagedProperty, AttributeGroupFacet +from mzspeclib.attributes import AttributeManager, AttributeManagedProperty, AttributeGroupFacet from .utils import ensure_iter, flatten SIMILAR_SPECTRUM_KEYS = "MS:1003263|similar spectrum keys" diff --git a/mzlib/defaults.py b/mzspeclib/defaults.py similarity index 100% rename from mzlib/defaults.py rename to mzspeclib/defaults.py diff --git a/mzlib/draw.py b/mzspeclib/draw.py similarity index 100% rename from mzlib/draw.py rename to mzspeclib/draw.py diff --git a/mzlib/index/__init__.py b/mzspeclib/index/__init__.py similarity index 100% rename from mzlib/index/__init__.py rename to mzspeclib/index/__init__.py diff --git a/mzlib/index/base.py b/mzspeclib/index/base.py similarity index 100% rename from mzlib/index/base.py rename to mzspeclib/index/base.py diff --git a/mzlib/index/memory.py b/mzspeclib/index/memory.py similarity index 99% rename from mzlib/index/memory.py rename to mzspeclib/index/memory.py index a9310f8..0802112 100644 --- a/mzlib/index/memory.py +++ b/mzspeclib/index/memory.py @@ -6,7 +6,7 @@ from numbers import Integral from collections import defaultdict -from mzlib.index.base import IndexRecordBase +from mzspeclib.index.base import IndexRecordBase from .base import IndexBase, IndexRecordBase, IndexInitializedRecord diff --git a/mzlib/index/sql.py b/mzspeclib/index/sql.py similarity index 99% rename from mzlib/index/sql.py rename to mzspeclib/index/sql.py index 9b9387d..b8c512d 100644 --- a/mzlib/index/sql.py +++ b/mzspeclib/index/sql.py @@ -7,7 +7,7 @@ from sqlalchemy import Column, ForeignKey, Integer, Float, String, DateTime, Text, LargeBinary -from mzlib.index.base import IndexRecordBase +from mzspeclib.index.base import IndexRecordBase try: # For SQLAlchemy 2.0 from sqlalchemy.orm import declarative_base except ImportError: diff --git a/mzlib/obo/psi-ms.obo b/mzspeclib/obo/psi-ms.obo similarity index 100% rename from mzlib/obo/psi-ms.obo rename to mzspeclib/obo/psi-ms.obo diff --git a/mzlib/ontology.py b/mzspeclib/ontology.py similarity index 100% rename from mzlib/ontology.py rename to mzspeclib/ontology.py diff --git a/mzlib/ontology_term.py b/mzspeclib/ontology_term.py similarity index 100% rename from mzlib/ontology_term.py rename to mzspeclib/ontology_term.py diff --git a/mzlib/peak_list.py b/mzspeclib/peak_list.py similarity index 100% rename from mzlib/peak_list.py rename to mzspeclib/peak_list.py diff --git a/mzlib/spectrum.py b/mzspeclib/spectrum.py similarity index 96% rename from mzlib/spectrum.py rename to mzspeclib/spectrum.py index c919a24..e3a2311 100644 --- a/mzlib/spectrum.py +++ b/mzspeclib/spectrum.py @@ -4,14 +4,14 @@ from typing import Any, Dict, List, Optional, TYPE_CHECKING -from mzlib.attributes import ( +from mzspeclib.attributes import ( AttributeManager, AttributeManagedProperty, AttributeListManagedProperty, AttributeProxy as _AttributeProxy, AttributeFacet ) -from mzlib.analyte import Analyte, InterpretationCollection, Interpretation +from mzspeclib.analyte import Analyte, InterpretationCollection, Interpretation if TYPE_CHECKING: - from mzlib.spectrum_library import SpectrumLibrary + from mzspeclib.spectrum_library import SpectrumLibrary #A class that holds data for each spectrum that is read from the SpectralLibrary class @@ -171,7 +171,7 @@ def write(self, format="text", **kwargs): # pragma: no cover #### If the format is text if format == "text": - from mzlib.backends.text import format_spectrum + from mzspeclib.backends.text import format_spectrum return format_spectrum(self, **kwargs) #### If the format is TSV @@ -239,7 +239,7 @@ def write(self, format="text", **kwargs): # pragma: no cover #### If the format is JSON elif format == "json": - from mzlib.backends.json import format_spectrum + from mzspeclib.backends.json import format_spectrum return format_spectrum(self, **kwargs) #### Otherwise we don't know this format diff --git a/mzlib/spectrum_library.py b/mzspeclib/spectrum_library.py similarity index 96% rename from mzlib/spectrum_library.py rename to mzspeclib/spectrum_library.py index 2bbbadb..0736dfe 100644 --- a/mzlib/spectrum_library.py +++ b/mzspeclib/spectrum_library.py @@ -3,14 +3,14 @@ import pathlib from typing import Optional, Type, List, Union -from mzlib.attributes import AttributeManagedProperty, AttributeManager -from mzlib.backends.base import LIBRARY_DESCRIPTION_TERM, LIBRARY_NAME_TERM, LIBRARY_URI_TERM, LIBRARY_VERSION_TERM -from mzlib.cluster import SpectrumCluster - -from mzlib.spectrum_library_index import SpectrumLibraryIndex -from mzlib.spectrum import Spectrum -from mzlib.index import IndexBase -from mzlib.backends import guess_implementation, SpectralLibraryBackendBase, SpectralLibraryWriterBase +from mzspeclib.attributes import AttributeManagedProperty, AttributeManager +from mzspeclib.backends.base import LIBRARY_DESCRIPTION_TERM, LIBRARY_NAME_TERM, LIBRARY_URI_TERM, LIBRARY_VERSION_TERM +from mzspeclib.cluster import SpectrumCluster + +from mzspeclib.spectrum_library_index import SpectrumLibraryIndex +from mzspeclib.spectrum import Spectrum +from mzspeclib.index import IndexBase +from mzspeclib.backends import guess_implementation, SpectralLibraryBackendBase, SpectralLibraryWriterBase debug = False diff --git a/mzlib/spectrum_library_collection.py b/mzspeclib/spectrum_library_collection.py similarity index 100% rename from mzlib/spectrum_library_collection.py rename to mzspeclib/spectrum_library_collection.py diff --git a/mzlib/spectrum_library_index.py b/mzspeclib/spectrum_library_index.py similarity index 100% rename from mzlib/spectrum_library_index.py rename to mzspeclib/spectrum_library_index.py diff --git a/mzlib/tools/__init__.py b/mzspeclib/tools/__init__.py similarity index 100% rename from mzlib/tools/__init__.py rename to mzspeclib/tools/__init__.py diff --git a/mzlib/tools/cli.py b/mzspeclib/tools/cli.py similarity index 95% rename from mzlib/tools/cli.py rename to mzspeclib/tools/cli.py index 7c3abcd..c726cd6 100644 --- a/mzlib/tools/cli.py +++ b/mzspeclib/tools/cli.py @@ -7,14 +7,14 @@ from typing import DefaultDict, List -from mzlib.spectrum_library import SpectrumLibrary -from mzlib.index import MemoryIndex, SQLIndex -from mzlib.backends.base import FormatInferenceFailure, SpectralLibraryBackendBase -from mzlib.validate import validator -from mzlib.validate.level import RequirementLevel -from mzlib.ontology import ControlledVocabularyResolver - -from mzlib.tools.utils import ColoringFormatter +from mzspeclib.spectrum_library import SpectrumLibrary +from mzspeclib.index import MemoryIndex, SQLIndex +from mzspeclib.backends.base import FormatInferenceFailure, SpectralLibraryBackendBase +from mzspeclib.validate import validator +from mzspeclib.validate.level import RequirementLevel +from mzspeclib.ontology import ControlledVocabularyResolver + +from mzspeclib.tools.utils import ColoringFormatter CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) diff --git a/mzlib/tools/utils.py b/mzspeclib/tools/utils.py similarity index 100% rename from mzlib/tools/utils.py rename to mzspeclib/tools/utils.py diff --git a/mzlib/universal_spectrum_identifier.py b/mzspeclib/universal_spectrum_identifier.py similarity index 100% rename from mzlib/universal_spectrum_identifier.py rename to mzspeclib/universal_spectrum_identifier.py diff --git a/mzlib/utils.py b/mzspeclib/utils.py similarity index 100% rename from mzlib/utils.py rename to mzspeclib/utils.py diff --git a/mzlib/validate/__init__.py b/mzspeclib/validate/__init__.py similarity index 100% rename from mzlib/validate/__init__.py rename to mzspeclib/validate/__init__.py diff --git a/mzlib/validate/level.py b/mzspeclib/validate/level.py similarity index 100% rename from mzlib/validate/level.py rename to mzspeclib/validate/level.py diff --git a/mzlib/validate/object_rule.py b/mzspeclib/validate/object_rule.py similarity index 93% rename from mzlib/validate/object_rule.py rename to mzspeclib/validate/object_rule.py index 680352c..b7a2712 100644 --- a/mzlib/validate/object_rule.py +++ b/mzspeclib/validate/object_rule.py @@ -3,12 +3,12 @@ from typing import TYPE_CHECKING, List, Tuple -from mzlib.attributes import Attributed +from mzspeclib.attributes import Attributed -from mzlib.spectrum import Spectrum -from mzlib.annotation import IonAnnotationBase, InvalidAnnotation +from mzspeclib.spectrum import Spectrum +from mzspeclib.annotation import IonAnnotationBase, InvalidAnnotation -from mzlib.validate.level import RequirementLevel +from mzspeclib.validate.level import RequirementLevel if TYPE_CHECKING: from .validator import ValidatorBase diff --git a/mzlib/validate/rules/__init__.py b/mzspeclib/validate/rules/__init__.py similarity index 100% rename from mzlib/validate/rules/__init__.py rename to mzspeclib/validate/rules/__init__.py diff --git a/mzlib/validate/rules/all.json b/mzspeclib/validate/rules/all.json similarity index 100% rename from mzlib/validate/rules/all.json rename to mzspeclib/validate/rules/all.json diff --git a/mzlib/validate/rules/base.json b/mzspeclib/validate/rules/base.json similarity index 100% rename from mzlib/validate/rules/base.json rename to mzspeclib/validate/rules/base.json diff --git a/mzlib/validate/rules/consensus.json b/mzspeclib/validate/rules/consensus.json similarity index 100% rename from mzlib/validate/rules/consensus.json rename to mzspeclib/validate/rules/consensus.json diff --git a/mzlib/validate/rules/convert_to_xlsx.py b/mzspeclib/validate/rules/convert_to_xlsx.py similarity index 100% rename from mzlib/validate/rules/convert_to_xlsx.py rename to mzspeclib/validate/rules/convert_to_xlsx.py diff --git a/mzlib/validate/rules/gold.json b/mzspeclib/validate/rules/gold.json similarity index 100% rename from mzlib/validate/rules/gold.json rename to mzspeclib/validate/rules/gold.json diff --git a/mzlib/validate/rules/peptide.json b/mzspeclib/validate/rules/peptide.json similarity index 100% rename from mzlib/validate/rules/peptide.json rename to mzspeclib/validate/rules/peptide.json diff --git a/mzlib/validate/rules/silver.json b/mzspeclib/validate/rules/silver.json similarity index 100% rename from mzlib/validate/rules/silver.json rename to mzspeclib/validate/rules/silver.json diff --git a/mzlib/validate/rules/single.json b/mzspeclib/validate/rules/single.json similarity index 100% rename from mzlib/validate/rules/single.json rename to mzspeclib/validate/rules/single.json diff --git a/mzspeclib/validate/rules/test.xlsx b/mzspeclib/validate/rules/test.xlsx new file mode 100644 index 0000000..718a9b3 Binary files /dev/null and b/mzspeclib/validate/rules/test.xlsx differ diff --git a/mzlib/validate/rules/tmp/README.md b/mzspeclib/validate/rules/tmp/README.md similarity index 100% rename from mzlib/validate/rules/tmp/README.md rename to mzspeclib/validate/rules/tmp/README.md diff --git a/mzlib/validate/rules/tmp/excel_terms_to_json_rules.py b/mzspeclib/validate/rules/tmp/excel_terms_to_json_rules.py similarity index 100% rename from mzlib/validate/rules/tmp/excel_terms_to_json_rules.py rename to mzspeclib/validate/rules/tmp/excel_terms_to_json_rules.py diff --git a/mzlib/validate/rules/tmp/terms.xlsx b/mzspeclib/validate/rules/tmp/terms.xlsx similarity index 100% rename from mzlib/validate/rules/tmp/terms.xlsx rename to mzspeclib/validate/rules/tmp/terms.xlsx diff --git a/mzlib/validate/rules/validator-rules-schema.json b/mzspeclib/validate/rules/validator-rules-schema.json similarity index 100% rename from mzlib/validate/rules/validator-rules-schema.json rename to mzspeclib/validate/rules/validator-rules-schema.json diff --git a/mzlib/validate/semantic_rule.py b/mzspeclib/validate/semantic_rule.py similarity index 99% rename from mzlib/validate/semantic_rule.py rename to mzspeclib/validate/semantic_rule.py index 4d6f030..630d331 100644 --- a/mzlib/validate/semantic_rule.py +++ b/mzspeclib/validate/semantic_rule.py @@ -11,9 +11,9 @@ from typing import Any, ClassVar, Dict, List, TYPE_CHECKING, Mapping, Optional, Sequence, Set, Tuple, Union -from mzlib.attributes import Attributed -from mzlib.utils import flatten, ensure_iter -from mzlib.ontology import _VocabularyResolverMixin +from mzspeclib.attributes import Attributed +from mzspeclib.utils import flatten, ensure_iter +from mzspeclib.ontology import _VocabularyResolverMixin from .level import RequirementLevel, CombinationLogic diff --git a/mzlib/validate/validator.py b/mzspeclib/validate/validator.py similarity index 96% rename from mzlib/validate/validator.py rename to mzspeclib/validate/validator.py index 2db65b9..5c8d933 100644 --- a/mzlib/validate/validator.py +++ b/mzspeclib/validate/validator.py @@ -9,19 +9,19 @@ from psims.controlled_vocabulary.entity import Entity, ListOfType -from mzlib.attributes import Attribute, Attributed +from mzspeclib.attributes import Attribute, Attributed -from mzlib.spectrum import Spectrum -from mzlib.analyte import Analyte, Interpretation -from mzlib.spectrum_library import SpectrumLibrary +from mzspeclib.spectrum import Spectrum +from mzspeclib.analyte import Analyte, Interpretation +from mzspeclib.spectrum_library import SpectrumLibrary -from mzlib.ontology import _VocabularyResolverMixin +from mzspeclib.ontology import _VocabularyResolverMixin -from mzlib.validate.level import RequirementLevel -from mzlib.validate.semantic_rule import ScopedSemanticRule, load_rule_set -from mzlib.validate.object_rule import ScopedObjectRuleBase, SpectrumPeakAnnotationRule, ValidationWarning -from mzlib.defaults import DEFAULT_UNITS +from mzspeclib.validate.level import RequirementLevel +from mzspeclib.validate.semantic_rule import ScopedSemanticRule, load_rule_set +from mzspeclib.validate.object_rule import ScopedObjectRuleBase, SpectrumPeakAnnotationRule, ValidationWarning +from mzspeclib.defaults import DEFAULT_UNITS logger = logging.getLogger(__name__) logger.addHandler(logging.NullHandler()) diff --git a/pyproject.toml b/pyproject.toml index 2c30b3e..c1d114e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [project] -name='mzlib' +name='mzspeclib' version='0.1.0-alpha' description='HUPO-PSI Spectral library format' classifiers=[ @@ -30,7 +30,7 @@ docs = [ ] [project.scripts] -mzspeclib = "mzlib.tools.cli:main" +mzspeclib = "mzspeclib.tools.cli:main" [build-system] requires = ["setuptools"] diff --git a/tests/test_cluster.py b/tests/test_cluster.py index a4a3047..6c7c1d4 100644 --- a/tests/test_cluster.py +++ b/tests/test_cluster.py @@ -1,8 +1,8 @@ import os import unittest -from mzlib.backends import TextSpectralLibrary -from mzlib.cluster import SpectrumCluster +from mzspeclib.backends import TextSpectralLibrary +from mzspeclib.cluster import SpectrumCluster from .common import datafile diff --git a/tests/test_data/generate_annotations.py b/tests/test_data/generate_annotations.py index 14ee290..44fa686 100644 --- a/tests/test_data/generate_annotations.py +++ b/tests/test_data/generate_annotations.py @@ -1,7 +1,7 @@ import os -from mzlib import SpectrumLibrary -from mzlib import annotation +from mzspeclib import SpectrumLibrary +from mzspeclib import annotation workspace = os.path.dirname(__file__) diff --git a/tests/test_index.py b/tests/test_index.py index a10459b..0235a3e 100644 --- a/tests/test_index.py +++ b/tests/test_index.py @@ -2,8 +2,8 @@ import unittest import tempfile -from mzlib.backends import TextSpectralLibrary -from mzlib.index import MemoryIndex, SQLIndex +from mzspeclib.backends import TextSpectralLibrary +from mzspeclib.index import MemoryIndex, SQLIndex from .common import datafile diff --git a/tests/test_library.py b/tests/test_library.py index 26614bb..3c20277 100644 --- a/tests/test_library.py +++ b/tests/test_library.py @@ -2,7 +2,7 @@ import unittest import tempfile -from mzlib.spectrum_library import SpectrumLibrary +from mzspeclib.spectrum_library import SpectrumLibrary from .common import datafile from .test_library_backend import LibraryBehaviorBase diff --git a/tests/test_library_backend.py b/tests/test_library_backend.py index 1983002..f5703b4 100644 --- a/tests/test_library_backend.py +++ b/tests/test_library_backend.py @@ -2,9 +2,9 @@ import os import unittest -from mzlib.spectrum import Spectrum -from mzlib.backends import (MSPSpectralLibrary, TextSpectralLibrary, JSONSpectralLibrary, SpectronautTSVSpectralLibrary, DIANNTSVSpectralLibrary) -from mzlib.analyte import ANALYTE_MIXTURE_TERM +from mzspeclib.spectrum import Spectrum +from mzspeclib.backends import (MSPSpectralLibrary, TextSpectralLibrary, JSONSpectralLibrary, SpectronautTSVSpectralLibrary, DIANNTSVSpectralLibrary) +from mzspeclib.analyte import ANALYTE_MIXTURE_TERM from .common import datafile diff --git a/tests/test_msp_attributes.py b/tests/test_msp_attributes.py index 6b47b2a..a0df70e 100644 --- a/tests/test_msp_attributes.py +++ b/tests/test_msp_attributes.py @@ -1,7 +1,7 @@ import unittest -from mzlib.backends import (MSPSpectralLibrary) -from mzlib.backends import msp +from mzspeclib.backends import (MSPSpectralLibrary) +from mzspeclib.backends import msp from .common import datafile diff --git a/tests/test_spectrum.py b/tests/test_spectrum.py index 534486a..45df0c0 100644 --- a/tests/test_spectrum.py +++ b/tests/test_spectrum.py @@ -2,7 +2,7 @@ import unittest import tempfile -from mzlib.backends import MSPSpectralLibrary, TextSpectralLibrary +from mzspeclib.backends import MSPSpectralLibrary, TextSpectralLibrary from .common import datafile diff --git a/tests/test_validate.py b/tests/test_validate.py index 1a71fc9..cec7270 100644 --- a/tests/test_validate.py +++ b/tests/test_validate.py @@ -1,7 +1,7 @@ import unittest -from mzlib.spectrum_library import SpectrumLibrary -from mzlib.validate import validator +from mzspeclib.spectrum_library import SpectrumLibrary +from mzspeclib.validate import validator from .common import datafile