Skip to content
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

[POST-berkeley-MERGER] Update FunctionalAnnotationAggMember class for compatibility with MetaP Aggregation tables #242

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions nmdc_schema/migrators/migrator_from_XX_to_PR242.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from nmdc_schema.migrators.migrator_base import MigratorBase


class Migrator(MigratorBase):
r"""Migrates a database between two schemas."""

_from_version = "XX"
_to_version = "XX" # PR242

def upgrade(self):
r"""Migrates the database from conforming to the original schema, to conforming to the new schema."""

self.adapter.process_each_document(
"functional_annotation_agg", [self.move_metagenome_id_to_was_generated_by]
)

def move_metagenome_id_to_was_generated_by(self, fun_agg: dict) -> dict:
r"""
Updates the `FunctionalAnnotationAggMember` records so the value originally in its `metagenome_annotation_id` field
is stored in a new field named `was_generated_by`; and removes the `metagenome_annotation_id` field.

`metagenome_annotation_id` is required on these records and has the same value as `was_generated_by` in the new schema,
so no data is lost in this migration nor do we need to check for the existence of the field.

>>> m = Migrator()
>>> m.move_metagenome_id_to_was_generated_by({'id': 123, 'metagenome_annotation_id': 'mgm123', 'count': 1})
{'id': 123, 'count': 1, 'was_generated_by': 'mgm123'}

"""
self.logger.info(f"Migrating Extraction: {fun_agg['id']}")
fun_agg["was_generated_by"] = fun_agg.pop("metagenome_annotation_id")
return fun_agg
2 changes: 1 addition & 1 deletion src/data/invalid/Database-functional_annotation_agg.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#invalid b/c a required slot is missing
functional_annotation_agg:
- metagenome_annotation_id: nmdc:8253bcdcd0387177ff895c38a047c719
- was_generated_by: nmdc:8253bcdcd0387177ff895c38a047c719
kheal marked this conversation as resolved.
Show resolved Hide resolved
count: 120
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This example is invalid because the count field is missing and the was_generated_by field refers to a MetagenomeAnnotation
type: nmdc:FunctionalAnnotationAggMember
was_generated_by: nmdc:wfmgan-99-123456.1
gene_function_id: KEGG.ORTHOLOGY:K00627
2 changes: 1 addition & 1 deletion src/data/valid/Database-functional_annotation_agg.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
functional_annotation_agg:
- metagenome_annotation_id: nmdc:wfmgan-99-123456.1
- was_generated_by: nmdc:wfmgan-99-123456.1
gene_function_id: KEGG.ORTHOLOGY:K00627
count: 120
type: nmdc:FunctionalAnnotationAggMember
2 changes: 1 addition & 1 deletion src/data/valid/Database-interleaved.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ functional_annotation_agg:
- gene_function_id: KEGG.ORTHOLOGY:K00627
count: 120
type: nmdc:FunctionalAnnotationAggMember
metagenome_annotation_id: nmdc:wfmgan-99-123456.1
was_generated_by: nmdc:wfmgan-99-123456.1
biosample_set:
- id: nmdc:bsm-99-isqhuW
type: nmdc:Biosample
Expand Down
2 changes: 1 addition & 1 deletion src/data/valid/FunctionalAnnotationAggMember-minimal.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
metagenome_annotation_id: nmdc:wfmgan-99-123456.1
was_generated_by: nmdc:wfmgan-99-123456.1
gene_function_id: KEGG.ORTHOLOGY:K00627
count: 120
type: nmdc:FunctionalAnnotationAggMember
21 changes: 17 additions & 4 deletions src/schema/nmdc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,28 @@ classes:
FunctionalAnnotationAggMember:
class_uri: nmdc:FunctionalAnnotationAggMember
slots:
- metagenome_annotation_id
- was_generated_by
- gene_function_id
- count
- type
slot_usage:
metagenome_annotation_id:
was_generated_by:
structured_pattern:
syntax: "{id_nmdc_prefix}:wfmgan-{id_shoulder}-{id_blade}{id_version}{id_locus}$"
syntax: "{id_nmdc_prefix}:(wfmgan|wfmp)-{id_shoulder}-{id_blade}{id_version}$"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backmerge such that mfmtan is also a valid typecode.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aclum - you mean "wfmtan", correct? MetatranscriptomeAnnotation class?

interpolated: true
required: true
rules:
kheal marked this conversation as resolved.
Show resolved Hide resolved
- title: count_required_if_MetagenomeAnnotation
description: >-
If was_generated_by is a MetagenomeAnnotation, then count is required.
preconditions:
slot_conditions:
was_generated_by:
pattern: ^.+:wfmgan-.+$
postconditions:
slot_conditions:
count:
required: true

Database:
class_uri: nmdc:Database
Expand Down Expand Up @@ -925,6 +938,7 @@ slots:
range: WorkflowExecution
description: The identifier for the analysis activity that generated the functional annotation results, where the analysis activity is an instance of the/an appropriate subclass of WorkflowExecution
required: true
deprecated: "not used. 2024-10 https://github.com/microbiomedata/nmdc-schema/issues/1253"

gene_function_id:
range: uriorcurie
Expand All @@ -934,7 +948,6 @@ slots:
required: true
count:
range: integer
required: true
functional_annotation_agg:
range: FunctionalAnnotationAggMember
multivalued: true
Expand Down
Loading