Skip to content

Commit

Permalink
Added new sample metadata.
Browse files Browse the repository at this point in the history
Added new sample metadata, sample_uuid and sample_lims.
Provided mapping of the values of these metadata to
mlwh sample table columns. Updated test data.
  • Loading branch information
mgcam committed Dec 14, 2024
1 parent df38af5 commit e01509f
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/npg_irods/db/mlwh.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Sample(Base):
donor_id = mapped_column(String(255))
date_of_consent_withdrawn = mapped_column(DateTime)
marked_as_consent_withdrawn_by = mapped_column(String(255))
uuid_sample_lims = mapped_column(String(36), nullable=False)

iseq_flowcell: Mapped["IseqFlowcell"] = relationship(
"IseqFlowcell", back_populates="sample"
Expand Down
6 changes: 6 additions & 0 deletions src/npg_irods/metadata/lims.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ class TrackedSample(AsValueEnum):
CONTROL = "sample_control"
DONOR_ID = "sample_donor_id"
ID = "sample_id"
LIMS = "sample_lims"
NAME = "sample"
PUBLIC_NAME = "sample_public_name"
SUPPLIER_NAME = "sample_supplier_name"
UUID = "sample_uuid"


@unique
Expand All @@ -88,6 +90,8 @@ def make_sample_metadata(sample: Sample) -> list[AVU]:
- sample name
- sample public name
- sample supplier name
- sample uuid
- ID of the LIM system where this sample was registered
Args:
sample: An ML warehouse schema Sample.
Expand All @@ -104,9 +108,11 @@ def make_sample_metadata(sample: Sample) -> list[AVU]:
],
[TrackedSample.DONOR_ID, sample.donor_id],
[TrackedSample.ID, sample.id_sample_lims],
[TrackedSample.LIMS, sample.id_lims],
[TrackedSample.NAME, sample.name],
[TrackedSample.PUBLIC_NAME, sample.public_name],
[TrackedSample.SUPPLIER_NAME, sample.supplier_name],
[TrackedSample.UUID, sample.uuid_sample_lims],
]

return [avu for avu in starmap(avu_if_value, av) if avu is not None]
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def initialize_mlwh_study_and_sample(session: Session):
name="name1",
public_name="public_name1",
supplier_name="supplier_name1",
uuid_sample_lims="82429892-0ab6-11ee-b5ba-fa163eac3af7",
**default_timestamps,
)
session.add(sample_y)
Expand Down
7 changes: 6 additions & 1 deletion tests/illumina/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@ def make_sample(n):
name=f"name{n}",
public_name=f"public_name{n}",
supplier_name=f"supplier_name{n}",
uuid_sample_lims=f"52429892-0ab6-11ee-b5ba-fa163eac3af{n}",
**default_timestamps,
)

samples = [make_sample(n) for n in range(1, 4)]
control_sample = Sample(
id_lims="LIMS_888", id_sample_lims="phix", name="Phi X", **default_timestamps
id_lims="LIMS_888",
id_sample_lims="phix",
name="Phi X",
uuid_sample_lims="42429892-0ab6-11ee-b5ba-fa163eac3af3",
**default_timestamps,
)
session.add_all([*samples, control_sample])

Expand Down
4 changes: 4 additions & 0 deletions tests/illumina/test_metadata_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,11 @@ def test_updates_present_metadata(
AVU(TrackedSample.COMMON_NAME, "common_name1"),
AVU(TrackedSample.DONOR_ID, "donor_id1"),
AVU(TrackedSample.ID, "id_sample_lims1"),
AVU(TrackedSample.LIMS, "LIMS_01"),
AVU(TrackedSample.NAME, "name1"),
AVU(TrackedSample.PUBLIC_NAME, "public_name1"),
AVU(TrackedSample.SUPPLIER_NAME, "supplier_name1"),
AVU(TrackedSample.UUID, "52429892-0ab6-11ee-b5ba-fa163eac3af1"),
AVU(TrackedStudy.ID, "4000"),
AVU(TrackedStudy.NAME, "Study A"),
]
Expand Down Expand Up @@ -469,9 +471,11 @@ def test_updates_present_study_permissions(
AVU(TrackedSample.COMMON_NAME, "common_name1"),
AVU(TrackedSample.DONOR_ID, "donor_id1"),
AVU(TrackedSample.ID, "id_sample_lims1"),
AVU(TrackedSample.LIMS, "LIMS_01"),
AVU(TrackedSample.NAME, "name1"),
AVU(TrackedSample.PUBLIC_NAME, "public_name1"),
AVU(TrackedSample.SUPPLIER_NAME, "supplier_name1"),
AVU(TrackedSample.UUID, "52429892-0ab6-11ee-b5ba-fa163eac3af1"),
AVU(TrackedStudy.ID, "4000"),
AVU(TrackedStudy.NAME, "Study A"),
]
Expand Down
1 change: 1 addition & 0 deletions tests/ont/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def make_sample(n):
name=f"name{n}",
public_name=f"public_name{n}",
supplier_name=f"supplier_name{n}",
uuid_sample_lims=f"62429892-0ab6-11ee-b5ba-fa163eac3af{n}",
**default_timestamps,
)

Expand Down
1 change: 1 addition & 0 deletions tests/pacbio/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def make_sample(n):
name=f"name{n}",
public_name=f"public_name{n}",
supplier_name=f"supplier_name{n}",
uuid_sample_lims=f"72429892-0ab6-11ee-b5ba-fa163eac3af{n}",
**default_timestamps,
)

Expand Down
4 changes: 4 additions & 0 deletions tests/pacbio/test_metadata_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ def test_updates_present_metadata(
AVU(TrackedSample.COMMON_NAME, "common_name1"),
AVU(TrackedSample.DONOR_ID, "donor_id1"),
AVU(TrackedSample.ID, "id_sample_lims1"),
AVU(TrackedSample.LIMS, "LIMS_01"),
AVU(TrackedSample.NAME, "name1"),
AVU(TrackedSample.PUBLIC_NAME, "public_name1"),
AVU(TrackedSample.SUPPLIER_NAME, "supplier_name1"),
AVU(TrackedSample.UUID, "72429892-0ab6-11ee-b5ba-fa163eac3af1"),
AVU(TrackedStudy.ID, "1000"),
AVU(TrackedStudy.NAME, "Study X"),
]
Expand Down Expand Up @@ -245,9 +247,11 @@ def test_updates_present_study_permissions(
AVU(TrackedSample.COMMON_NAME, "common_name1"),
AVU(TrackedSample.DONOR_ID, "donor_id1"),
AVU(TrackedSample.ID, "id_sample_lims1"),
AVU(TrackedSample.LIMS, "LIMS_01"),
AVU(TrackedSample.NAME, "name1"),
AVU(TrackedSample.PUBLIC_NAME, "public_name1"),
AVU(TrackedSample.SUPPLIER_NAME, "supplier_name1"),
AVU(TrackedSample.UUID, "72429892-0ab6-11ee-b5ba-fa163eac3af1"),
AVU(TrackedStudy.ID, "1000"),
AVU(TrackedStudy.NAME, "Study X"),
]
Expand Down
3 changes: 2 additions & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@ def test_ensure_secondary_metadata_updated(
AVU(TrackedStudy.TITLE, "Test Study Title"),
AVU(TrackedStudy.ACCESSION_NUMBER, "Test Accession"),
AVU(TrackedSample.ID, sample_id),
AVU(TrackedSample.LIMS, "LIMS_01"),
AVU(TrackedSample.ACCESSION_NUMBER, "Test Accession"),
AVU(TrackedSample.COMMON_NAME, "common_name1"),
AVU(TrackedSample.DONOR_ID, "donor_id1"),
AVU(TrackedSample.NAME, "name1"),
AVU(TrackedSample.PUBLIC_NAME, "public_name1"),
AVU(TrackedSample.SUPPLIER_NAME, "supplier_name1"),
AVU(TrackedSample.UUID, "82429892-0ab6-11ee-b5ba-fa163eac3af7"),
]

obj = DataObject(simple_study_and_sample_data_object)
assert ensure_secondary_metadata_updated(obj, simple_study_and_sample_mlwh)

for avu in expected_avus:
assert avu in obj.metadata()

Expand Down
2 changes: 2 additions & 0 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,14 @@ def test_update_secondary_metadata(
AVU(TrackedStudy.TITLE, "Test Study Title"),
AVU(TrackedStudy.ACCESSION_NUMBER, "Test Accession"),
AVU(TrackedSample.ID, "id_sample_lims1"),
AVU(TrackedSample.LIMS, "LIMS_01"),
AVU(TrackedSample.ACCESSION_NUMBER, "Test Accession"),
AVU(TrackedSample.COMMON_NAME, "common_name1"),
AVU(TrackedSample.DONOR_ID, "donor_id1"),
AVU(TrackedSample.NAME, "name1"),
AVU(TrackedSample.PUBLIC_NAME, "public_name1"),
AVU(TrackedSample.SUPPLIER_NAME, "supplier_name1"),
AVU(TrackedSample.UUID, "82429892-0ab6-11ee-b5ba-fa163eac3af7"),
]

obj = DataObject(simple_study_and_sample_data_object)
Expand Down

0 comments on commit e01509f

Please sign in to comment.