Skip to content

Commit

Permalink
Add support for updating Sequenom metadata in iRODS
Browse files Browse the repository at this point in the history
  • Loading branch information
kjsanger committed Apr 30, 2024
1 parent 6a888a3 commit d82a906
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 13 deletions.
64 changes: 51 additions & 13 deletions src/npg_irods/cli/locate_data_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from partisan.irods import AVU, DataObject, query_metadata
from sqlalchemy.orm import Session

from npg_irods import illumina, ont, pacbio
from npg_irods import illumina, ont, pacbio, sequenom
from npg_irods.cli.util import (
add_date_range_arguments,
add_db_config_arguments,
Expand Down Expand Up @@ -73,14 +73,14 @@
Examples:
locate-data-objects --verbose --colour --database-config db.ini --zone seq \\
locate-data-objects --verbose --colour --db-config db.ini --zone seq \\
consent-withdrawn
locate-data-objects --verbose --json --database-config db.ini --zone seq \\
locate-data-objects --verbose --json --db-config db.ini --zone seq \\
illumina-updates --begin-date `date --iso --date=-7day` \\
--skip-absent-runs 5
locate-data-objects --verbose --colour --database-config db.ini --zone seq \\
locate-data-objects --verbose --colour --db-config db.ini --zone seq \\
ont-updates --begin-date `date --iso --date=-7day`
The --skip-absent-runs option is used to skip runs that cannot be found in iRODS after
Expand Down Expand Up @@ -109,7 +109,7 @@


def consent_withdrawn(cli_args: argparse.ArgumentParser):
dbconfig = DBConfig.from_file(cli_args.database_config.name, "mlwh_ro")
dbconfig = DBConfig.from_file(cli_args.db_config.name, "mlwh_ro")
engine = sqlalchemy.create_engine(dbconfig.url)
with Session(engine) as session:
num_processed = num_errors = 0
Expand Down Expand Up @@ -150,7 +150,7 @@ def consent_withdrawn(cli_args: argparse.ArgumentParser):
def illumina_updates_cli(cli_args: argparse.ArgumentParser):
"""Process the command line arguments for finding Illumina data objects and execute
the command."""
dbconf = DBConfig.from_file(cli_args.database_config.name, "mlwh_ro")
dbconf = DBConfig.from_file(cli_args.db_config.name, "mlwh_ro")
eng = sqlalchemy.create_engine(dbconf.url)
since = cli_args.begin_date
until = cli_args.end_date
Expand Down Expand Up @@ -262,7 +262,7 @@ def illumina_updates(
def ont_updates_cli(cli_args: argparse.ArgumentParser):
"""Process the command line arguments for finding ONT data objects and execute the
command."""
dbconf = DBConfig.from_file(cli_args.database_config.name, "mlwh_ro")
dbconf = DBConfig.from_file(cli_args.db_config.name, "mlwh_ro")
eng = sqlalchemy.create_engine(dbconf.url)
since = cli_args.begin_date
until = cli_args.end_date
Expand Down Expand Up @@ -328,7 +328,7 @@ def ont_updates(
def pacbio_updates_cli(cli_args: argparse.ArgumentParser):
"""Process the command line arguments for finding PacBio data objects and execute
the command."""
dbconf = DBConfig.from_file(cli_args.database_config.name, "mlwh_ro")
dbconf = DBConfig.from_file(cli_args.db_config.name, "mlwh_ro")
eng = sqlalchemy.create_engine(dbconf.url)
since = cli_args.begin_date
until = cli_args.end_date
Expand Down Expand Up @@ -415,7 +415,7 @@ def pacbio_updates(
def infinium_updates_cli(cli_args: argparse.ArgumentParser):
"""Process the command line arguments for finding Infinium microarray data objects
and execute the command."""
dbconf = DBConfig.from_file(cli_args.database_config.name, "mlwh_ro")
dbconf = DBConfig.from_file(cli_args.db_config.name, "mlwh_ro")
eng = sqlalchemy.create_engine(dbconf.url)
since = cli_args.begin_date
until = cli_args.end_date
Expand All @@ -433,9 +433,49 @@ def infinium_updates_cli(cli_args: argparse.ArgumentParser):
def infinium_microarray_updates(
sess: Session, since: datetime, until: datetime, zone: str = None
) -> (int, int):
num_processed = num_errors = 0

query = [AVU(infinium.Instrument.BEADCHIP, "%", operator="like")]
num_processed, num_errors = _print_data_objects_updated_in_mlwh(
sess, query, since=since, until=until, zone=zone
)

log.info(f"Processed {num_processed} with {num_errors} errors")

return num_processed, num_errors


def sequenom_updates_cli(cli_args: argparse.ArgumentParser):
"""Process the command line arguments for finding Sequenom genotype data objects
and execute the command."""
dbconf = DBConfig.from_file(cli_args.db_config.name, "mlwh_ro")
eng = sqlalchemy.create_engine(dbconf.url)
since = cli_args.begin_date
until = cli_args.end_date
zone = cli_args.zone

with Session(eng) as sess:
num_proc, num_errors = sequenom_genotype_updates(sess, since, until, zone=zone)

if num_errors:
sys.exit(1)


def sequenom_genotype_updates(
sess: Session, since: datetime, until: datetime, zone: str = None
) -> (int, int):
query = [AVU(sequenom.Instrument.SEQUENOM_PLATE, "%", operator="like")]
num_processed, num_errors = _print_data_objects_updated_in_mlwh(
sess, query, since=since, until=until, zone=zone
)

log.info(f"Processed {num_processed} with {num_errors} errors")

return num_processed, num_errors


def _print_data_objects_updated_in_mlwh(
sess: Session, query: list[AVU], since: datetime, until: datetime, zone: str = None
) -> (int, int):
num_processed = num_errors = 0

studies = find_updated_studies(sess, since=since, until=until)
np, ne = _find_and_print_data_objects(
Expand All @@ -451,8 +491,6 @@ def infinium_microarray_updates(
num_processed += np
num_errors += ne

log.info(f"Processed {num_processed} with {num_errors} errors")

return num_processed, num_errors


Expand Down
28 changes: 28 additions & 0 deletions src/npg_irods/sequenom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
#
# Copyright © 2024 Genome Research Ltd. All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# @author Keith James <kdj@sanger.ac.uk>

from partisan.metadata import AsValueEnum


class Instrument(AsValueEnum):
"""Sequenom genotyping platform metadata"""

SEQUENOM_PLATE = "sequenom_plate"
SEQUENOM_WELL = "sequenom_well"
SEQUENOM_PLEX = "sequenom_plex"

0 comments on commit d82a906

Please sign in to comment.