generated from linkml/linkml-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Make some slots on MassSpectrometryConfiguration and ChromatographyConfiguration required and create a migrator #2465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hesspnnl
merged 11 commits into
main
from
2456-massspectrometryconfigurations-chromatographyconfigurationslots-required
May 29, 2025
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c125371
creasting new migrators
hesspnnl 88329c7
schema change
hesspnnl 894ee75
adding invalid tests for ChromatographyConfiguration
hesspnnl ea5db93
MassSpectrometryConfiguration invalid examples, syntax error
hesspnnl dc01e80
Update nmdc_schema/migrators/partials/migrator_from_11_7_0_to_11_8_0/…
hesspnnl ca75c85
Update nmdc_schema/migrators/partials/migrator_from_11_7_0_to_11_8_0/…
hesspnnl 5cc92b8
Update nmdc_schema/migrators/partials/migrator_from_11_7_0_to_11_8_0/…
hesspnnl da665c0
altering to use a var for id
hesspnnl db28448
Update nmdc_schema/migrators/partials/migrator_from_11_7_0_to_11_8_0/…
hesspnnl eb4e704
Update nmdc_schema/migrators/partials/migrator_from_11_7_0_to_11_8_0/…
hesspnnl 3979c52
Merge branch 'main' of https://github.com/microbiomedata/nmdc-schema …
hesspnnl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...igrators/partials/migrator_from_11_7_0_to_11_8_0/migrator_from_11_7_0_to_11_8_0_part_4.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from nmdc_schema.migrators.migrator_base import MigratorBase | ||
|
||
class Migrator(MigratorBase): | ||
r"""Migrates a database between two schemas.""" | ||
|
||
_from_version = "11.8.0.part_3" | ||
_to_version = "11.8.0.part_4" | ||
|
||
def upgrade(self) -> None: | ||
r"""Migrates the database from conforming to the original schema, to conforming to the new schema.""" | ||
self.adapter.do_for_each_document("configuration_set", self.validate_mass_spec_config_slots) | ||
self.adapter.do_for_each_document("configuration_set", self.validate_chrom_config_slots) | ||
|
||
def validate_mass_spec_config_slots(self, configuration_record: dict) -> None: | ||
r""" | ||
If the configuration record is of type MassSpectrometryConfiguration, does not have mass_spectrometry_acquisition_strategy, resolution_categories, mass_analyzers, ionization_source, mass_spectrum_collection_modes, and polarity_mode AND those keys do not have a value, raise a ValueError. | ||
|
||
>>> m = Migrator() | ||
>>> m.validate_mass_spec_config_slots({"id": 123, "type": "nmdc:MassSpectrometryConfiguration", "mass_spectrometry_acquisition_strategy": "data_independent_acquisition", "resolution_categories": "high", "mass_analyzers": "ion_trap", "ionization_source": "electron_ionization", "mass_spectrum_collection_modes": "centroid", "polarity_mode": "positive"}) | ||
>>> m.validate_mass_spec_config_slots({"id": 123, "type": "nmdc:MassSpectrometryConfiguration", "mass_spectrometry_acquisition_strategy": "data_independent_acquisition", "resolution_categories": "high", "mass_analyzers": "ion_trap", "ionization_source": "electron_ionization", "mass_spectrum_collection_modes": "centroid"}) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: `polarity_mode` is required and is not present in the configuration record 123 | ||
>>> m.validate_mass_spec_config_slots({"id": 123, "type": "nmdc:MassSpectrometryConfiguration", "mass_spectrometry_acquisition_strategy": "data_independent_acquisition", "resolution_categories": "high", "mass_analyzers": "ion_trap", "ionization_source": "electron_ionization", "polarity_mode": "positive"}) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: `mass_spectrum_collection_modes` is required and is not present in the configuration record 123 | ||
>>> m.validate_mass_spec_config_slots({"id": 123, "type": "nmdc:MassSpectrometryConfiguration", "mass_spectrometry_acquisition_strategy": "data_independent_acquisition", "resolution_categories": "high", "mass_analyzers": "ion_trap", "mass_spectrum_collection_modes": "centroid", "polarity_mode": "positive"}) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: `ionization_source` is required and is not present in the configuration record 123 | ||
>>> m.validate_mass_spec_config_slots({"id": 123, "type": "nmdc:MassSpectrometryConfiguration", "mass_spectrometry_acquisition_strategy": "data_independent_acquisition", "resolution_categories": "high", "mass_spectrum_collection_modes": "centroid", "polarity_mode": "positive"}) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: `mass_analyzers` is required and is not present in the configuration record 123 | ||
>>> m.validate_mass_spec_config_slots({"id": 123, "type": "nmdc:MassSpectrometryConfiguration", "mass_spectrometry_acquisition_strategy": "data_independent_acquisition", "mass_analyzers": "ion_trap", "ionization_source": "electron_ionization", "mass_spectrum_collection_modes": "centroid", "polarity_mode": "positive"}) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: `resolution_categories` is required and is not present in the configuration record 123 | ||
>>> m.validate_mass_spec_config_slots({"id": 123, "type": "nmdc:MassSpectrometryConfiguration", "resolution_categories": "high", "mass_analyzers": "ion_trap", "ionization_source": "electron_ionization", "mass_spectrum_collection_modes": "centroid", "polarity_mode": "positive"}) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: `mass_spectrometry_acquisition_strategy` is required and is not present in the configuration record 123 | ||
""" | ||
# get the slots that are required for mass spectrometry configuration | ||
if configuration_record.get("type") == "nmdc:MassSpectrometryConfiguration": | ||
mass_spectrometry_acquisition_strategy = configuration_record.get("mass_spectrometry_acquisition_strategy") | ||
|
||
if mass_spectrometry_acquisition_strategy is None: | ||
raise ValueError(f"`mass_spectrometry_acquisition_strategy` is required and is not present in the configuration record {configuration_record.get('id')}") | ||
hesspnnl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
resolution_categories = configuration_record.get("resolution_categories") | ||
if resolution_categories is None: | ||
raise ValueError(f"`resolution_categories` is required and is not present in the configuration record {configuration_record.get('id')}") | ||
|
||
mass_analyzers = configuration_record.get("mass_analyzers") | ||
if mass_analyzers is None: | ||
raise ValueError(f"`mass_analyzers` is required and is not present in the configuration record {configuration_record.get('id')}") | ||
ionization_source = configuration_record.get("ionization_source") | ||
if ionization_source is None: | ||
raise ValueError(f"`ionization_source` is required and is not present in the configuration record {configuration_record.get('id')}") | ||
mass_spectrum_collection_modes = configuration_record.get("mass_spectrum_collection_modes") | ||
if mass_spectrum_collection_modes is None: | ||
raise ValueError(f"`mass_spectrum_collection_modes` is required and is not present in the configuration record {configuration_record.get('id')}") | ||
polarity_mode = configuration_record.get("polarity_mode") | ||
if polarity_mode is None: | ||
raise ValueError(f"`polarity_mode` is required and is not present in the configuration record {configuration_record.get('id')}") | ||
hesspnnl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def validate_chrom_config_slots(self, configuration_record:dict) -> None: | ||
r""" | ||
If the configuration record is of type ChromatographyConfiguration, does not chromatographic_category and stationary_phase, AND those keys do not have a value, raise a ValueError. | ||
hesspnnl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
>>> m = Migrator() | ||
>>> m.validate_chrom_config_slots({"id": 123, "type": "nmdc:ChromatographyConfiguration", "chromatographic_category": "gas_chromatography", "stationary_phase": "C18"}) | ||
>>> m.validate_chrom_config_slots({"id": 123, "type": "nmdc:ChromatographyConfiguration", "chromatographic_category": "gas_chromatography"}) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: `stationary_phase` is required and is not present in the configuration record 123 | ||
>>> m.validate_chrom_config_slots({"id": 123, "type": "nmdc:ChromatographyConfiguration", "stationary_phase": "C18"}) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: `chromatographic_category` is required and is not present in the configuration record 123 | ||
""" | ||
if configuration_record.get("type") == "nmdc:ChromatographyConfiguration": | ||
chromatographic_category = configuration_record.get("chromatographic_category") | ||
if chromatographic_category is None: | ||
raise ValueError(f"`chromatographic_category` is required and is not present in the configuration record {configuration_record.get('id')}") | ||
|
||
stationary_phase = configuration_record.get("stationary_phase") | ||
if stationary_phase is None: | ||
raise ValueError(f"`stationary_phase` is required and is not present in the configuration record {configuration_record.get('id')}") | ||
|
6 changes: 6 additions & 0 deletions
6
src/data/invalid/ChromatograohyConfiguration-invalid-no_sp.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# this is invalid because it is missing the required field `stationary_phase` | ||
id: nmdc:chrcon-99-oW43DzG0 | ||
type: nmdc:ChromatographyConfiguration | ||
name: "EMSL GC method for small molecules" | ||
description: "EMSL's GC method for small molecule analysis" | ||
chromatographic_category: gas_chromatography |
6 changes: 6 additions & 0 deletions
6
src/data/invalid/ChromatographyConfiguration-invalid-no_CC.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#this is invalid because it is missing the chromatographic_category field | ||
id: nmdc:chrcon-99-oW43DzG0 | ||
type: nmdc:ChromatographyConfiguration | ||
name: "EMSL LC method for non-polar metabolites" | ||
description: "EMSL's LC method for non-polar metabolites" | ||
stationary_phase: C18 |
13 changes: 13 additions & 0 deletions
13
src/data/invalid/MassSpectrometryConfiguration-invalid-no_is.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# this is invalid because it is missing the required field `ionization_source` | ||
id: nmdc:mscon-99-oW43DzG0 | ||
name: EMSL_NOM_method1 | ||
description: Mass Spectrometry method used by EMSL for NOM analysis | ||
type: nmdc:MassSpectrometryConfiguration | ||
mass_spectrometry_acquisition_strategy: full_scan_only | ||
resolution_categories: | ||
- high | ||
mass_analyzers: | ||
- ion_cyclotron_resonance | ||
mass_spectrum_collection_modes: | ||
- full_profile | ||
polarity_mode: negative |
12 changes: 12 additions & 0 deletions
12
src/data/invalid/MassSpectrometryConfiguration-invalid-no_ma.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# this is invalid because it is missing the required field `mass_analyzers` | ||
id: nmdc:mscon-99-oW43DzG0 | ||
name: EMSL_NOM_method1 | ||
description: Mass Spectrometry method used by EMSL for NOM analysis | ||
type: nmdc:MassSpectrometryConfiguration | ||
mass_spectrometry_acquisition_strategy: full_scan_only | ||
resolution_categories: | ||
- high | ||
ionization_source: electrospray_ionization | ||
mass_spectrum_collection_modes: | ||
- full_profile | ||
polarity_mode: negative |
13 changes: 13 additions & 0 deletions
13
src/data/invalid/MassSpectrometryConfiguration-invalid-no_msas.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# this file is invalid because it does not have a `mass_spectrometry_acquisition_strategy` field | ||
id: nmdc:mscon-99-oW43DzG0 | ||
name: EMSL_NOM_method1 | ||
description: Mass Spectrometry method used by EMSL for NOM analysis | ||
type: nmdc:MassSpectrometryConfiguration | ||
resolution_categories: | ||
- high | ||
mass_analyzers: | ||
- ion_cyclotron_resonance | ||
ionization_source: electrospray_ionization | ||
mass_spectrum_collection_modes: | ||
- full_profile | ||
polarity_mode: negative |
12 changes: 12 additions & 0 deletions
12
src/data/invalid/MassSpectrometryConfiguration-invalid-no_mscm.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# this is invalid because it is missing the required field `mass_spectrum_collection_modes` | ||
id: nmdc:mscon-99-oW43DzG0 | ||
name: EMSL_NOM_method1 | ||
description: Mass Spectrometry method used by EMSL for NOM analysis | ||
type: nmdc:MassSpectrometryConfiguration | ||
mass_spectrometry_acquisition_strategy: full_scan_only | ||
resolution_categories: | ||
- high | ||
mass_analyzers: | ||
- ion_cyclotron_resonance | ||
ionization_source: electrospray_ionization | ||
polarity_mode: negative |
13 changes: 13 additions & 0 deletions
13
src/data/invalid/MassSpectrometryConfiguration-invalid-no_pm.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# this is invalid because it is missing the required field `polarity_mode` | ||
id: nmdc:mscon-99-oW43DzG0 | ||
name: EMSL_NOM_method1 | ||
description: Mass Spectrometry method used by EMSL for NOM analysis | ||
type: nmdc:MassSpectrometryConfiguration | ||
mass_spectrometry_acquisition_strategy: full_scan_only | ||
resolution_categories: | ||
- high | ||
mass_analyzers: | ||
- ion_cyclotron_resonance | ||
ionization_source: electrospray_ionization | ||
mass_spectrum_collection_modes: | ||
- full_profile |
12 changes: 12 additions & 0 deletions
12
src/data/invalid/MassSpectrometryConfiguration-invalid-no_rc.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# this is invalid because it is missing the required field `resolution_categories` | ||
id: nmdc:mscon-99-oW43DzG0 | ||
name: EMSL_NOM_method1 | ||
description: Mass Spectrometry method used by EMSL for NOM analysis | ||
type: nmdc:MassSpectrometryConfiguration | ||
mass_spectrometry_acquisition_strategy: full_scan_only | ||
mass_analyzers: | ||
- ion_cyclotron_resonance | ||
ionization_source: electrospray_ionization | ||
mass_spectrum_collection_modes: | ||
- full_profile | ||
polarity_mode: negative |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.