Skip to content

Commit

Permalink
Re-org some constant strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mobiusklein committed Sep 24, 2024
1 parent e92573c commit 513dba9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
23 changes: 13 additions & 10 deletions mzspeclib/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,21 @@
from mzspeclib.cluster import SpectrumCluster

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.spectrum import Spectrum
from mzspeclib.analyte import Analyte, Interpretation, InterpretationMember
from mzspeclib.attributes import Attributed, AttributedEntity, AttributeSet, AttributeManagedProperty
from mzspeclib.ontology import _VocabularyResolverMixin
from mzspeclib.const import (
FORMAT_VERSION_TERM,
LIBRARY_NAME_TERM,
LIBRARY_IDENTIFIER_TERM,
LIBRARY_VERSION_TERM,
LIBRARY_URI_TERM,
LIBRARY_DESCRIPTION_TERM,
ANALYTE_MIXTURE_TERM,
LIBRARY_SPECTRUM_INDEX,
LIBRARY_SPECTRUM_KEY
)

from .utils import open_stream, _LineBuffer

Expand All @@ -31,14 +42,6 @@

ANALYTE_MIXTURE_CURIE = ANALYTE_MIXTURE_TERM.split("|")[0]

FORMAT_VERSION_TERM = 'MS:1003186|library format version'
LIBRARY_NAME_TERM = "MS:1003188|library name"
LIBRARY_VERSION_TERM = "MS:1003190|library version"
LIBRARY_IDENTIFIER_TERM = "MS:1003187|library identifier"
LIBRARY_DESCRIPTION_TERM = "MS:1003189|library description"
LIBRARY_URI_TERM = "MS:1003191|library URI"


DEFAULT_VERSION = '1.0'


Expand Down
7 changes: 6 additions & 1 deletion mzspeclib/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@
SPECTRUM_NAME = "MS:1003061|library spectrum name"
LIBRARY_SPECTRUM_KEY = "MS:1003237|library spectrum key"
LIBRARY_SPECTRUM_INDEX = "MS:1003062|library spectrum index"
PRECURSOR_MZ = "MS:1003208|experimental precursor monoisotopic m/z"
PRECURSOR_MZ = "MS:1003208|experimental precursor monoisotopic m/z"
THEORETICAL_MZ = "MS:1003053|theoretical monoisotopic m/z"

SPECTRUM_AGGREGATION_TYPE = "MS:1003065|spectrum aggregation type"
NUMBER_OF_REPLICATE_SPECTRA_USED = "MS:1003070|number of replicate spectra used"
NUMBER_OF_REPLICATE_SPECTRA_AVAILABLE = "MS:1003069|number of replicate spectra available"
14 changes: 8 additions & 6 deletions mzspeclib/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
AttributeProxy as _AttributeProxy, AttributeFacet
)
from mzspeclib.analyte import Analyte, InterpretationCollection, Interpretation
from .const import (SPECTRUM_NAME, LIBRARY_SPECTRUM_INDEX, LIBRARY_SPECTRUM_KEY, PRECURSOR_MZ, CHARGE_STATE)
from .const import (SPECTRUM_NAME, LIBRARY_SPECTRUM_INDEX, LIBRARY_SPECTRUM_KEY, PRECURSOR_MZ, CHARGE_STATE,
SPECTRUM_AGGREGATION_TYPE, NUMBER_OF_REPLICATE_SPECTRA_USED, NUMBER_OF_REPLICATE_SPECTRA_AVAILABLE,
THEORETICAL_MZ, PEAK_ATTRIBUTE)

if TYPE_CHECKING:
from mzspeclib.spectrum_library import SpectrumLibrary
Expand All @@ -18,9 +20,9 @@


class SpectrumAggregation(_AttributeProxy):
aggregation_type = AttributeManagedProperty("MS:1003065|spectrum aggregation type")
replicates_used = AttributeManagedProperty[int]("MS:1003070|number of replicate spectra used")
replicates_available = AttributeManagedProperty[int]("MS:1003069|number of replicate spectra available")
aggregation_type = AttributeManagedProperty(SPECTRUM_AGGREGATION_TYPE)
replicates_used = AttributeManagedProperty[int](NUMBER_OF_REPLICATE_SPECTRA_USED)
replicates_available = AttributeManagedProperty[int](NUMBER_OF_REPLICATE_SPECTRA_AVAILABLE)


class Spectrum(AttributeManager):
Expand Down Expand Up @@ -82,12 +84,12 @@ def __init__(self, attributes=None, peak_list=None, analytes=None,

precursor_mz = AttributeListManagedProperty[float](
[PRECURSOR_MZ,
"MS:1003053|theoretical monoisotopic m/z"])
THEORETICAL_MZ])

_precursor_charge = AttributeManagedProperty[int](CHARGE_STATE)

spectrum_aggregation = AttributeFacet[SpectrumAggregation](SpectrumAggregation)
peak_aggregations = AttributeManagedProperty("MS:1003254|peak attribute", multiple=True)
peak_aggregations = AttributeManagedProperty(PEAK_ATTRIBUTE, multiple=True)

@property
def precursor_charge(self) -> int:
Expand Down

0 comments on commit 513dba9

Please sign in to comment.