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

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This example is invalid because the count field is and it is required.
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
metagenome_annotation_id: nmdc:wfmtan-99-123456.1
was_generated_by: nmdc:wfmtan-99-123456.1
gene_function_id: KEGG.ORTHOLOGY:K00627
count: 120
type: nmdc:FunctionalAnnotationAggMember
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
23 changes: 16 additions & 7 deletions src/schema/nmdc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,23 @@ classes:

FunctionalAnnotationAggMember:
class_uri: nmdc:FunctionalAnnotationAggMember
unique_keys:
Copy link
Author

Choose a reason for hiding this comment

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

leaving a note here to make sure @turbomam or @sierra-moxon review this use of unique_keys (in response to microbiomedata#2155)

Copy link
Member

Choose a reason for hiding this comment

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

Have we discussed this at all? @kheal do you still want to discuss the use of unique_keys even though the PR is closed?

Copy link
Author

Choose a reason for hiding this comment

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

I have moved this PR to the nmdc-schema repo: microbiomedata#2203. I'd appreciate input on the unique_keys use there.

main:
description: A FunctionalAnntoationAggMember record is uniquely identified by the combination of the was_generated_by and gene_function_id slots.
unique_key_slots:
- was_generated_by
- gene_function_id
slots:
- metagenome_annotation_id
- was_generated_by
- gene_function_id
- count
- type
slot_usage:
metagenome_annotation_id:
structured_pattern: # doesn't include act
syntax: "{id_nmdc_prefix}:(wfmgan|wfmtan)-{id_shoulder}-{id_blade}{id_version}$"
was_generated_by:
structured_pattern:
syntax: "{id_nmdc_prefix}:(wfmgan|wfmp|wfmtan)-{id_shoulder}-{id_blade}{id_version}$"
interpolated: true
required: true

Database:
class_uri: nmdc:Database
Expand Down Expand Up @@ -958,19 +965,21 @@ 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
any_of:
- range: MetagenomeAnnotation
- range: MetatranscriptomeAnnotation
deprecated: "not used. 2024-10 https://github.com/microbiomedata/nmdc-schema/issues/1253"


gene_function_id:
range: uriorcurie
description: The identifier for the gene function.
examples:
- value: KEGG.ORTHOLOGY:K00627
required: true

count:
range: integer
description: The number of sequences (for a metagenome or metatranscriptome) or spectra (for metaproteomics) associated with the specified function.
required: true

functional_annotation_agg:
range: FunctionalAnnotationAggMember
multivalued: true
Expand Down
Loading