Created
October 27, 2025 16:06
-
-
Save nerdstrike/991c9d215b1a4124eac54de2b828f6a6 to your computer and use it in GitHub Desktop.
How one might create compliant metadata without directly writing to iRODS
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
| #!/usr/bin/env python | |
| # Find sample in warehouse, also find a study row | |
| # Feed to npg_irods.metadata.lims.make_sample_metadata() | |
| # Extract AVU objects and convert to JSON. They'll be turned back into AVUs later... but that's batching for you. | |
| import json | |
| import sqlalchemy | |
| from npg.conf import IniData | |
| from npg_irods.db import Config | |
| from npg_irods.metadata.lims import make_sample_metadata, make_study_metadata | |
| from npg_irods.db.mlwh import ( | |
| find_study_by_study_id, | |
| find_sample_by_sample_id, | |
| session_context, | |
| ) | |
| dbconfig = IniData(Config).from_file( | |
| ini_file="/Users/kt19/.npg/mlwh_ro.ini", section="mlwh_ro" | |
| ) | |
| engine = sqlalchemy.create_engine(dbconfig.url, pool_pre_ping=True, pool_recycle=3600) | |
| with session_context(engine) as session: | |
| sample = find_sample_by_sample_id(session, "10132480") | |
| study = find_study_by_study_id(session, "6496") | |
| study_avus = make_study_metadata(study) | |
| sample_avus = make_sample_metadata(sample) | |
| # implement a to_json on partisan.irods.AVU instead? | |
| # print(study_avus, sample_avus) | |
| # Probably need to check `default namespace` when converting to json things | |
| meta = [{study_thing.attribute: study_thing.value, study_thing.units} for study_thing in study_avus] | |
| meta.extend( | |
| [{sample_thing.attribute: sample_thing.value, sample_thing.units} for sample_thing in sample_avus] | |
| ) | |
| print(json.dumps(meta)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment