-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new EPP for calculating available material for seq reload
- Loading branch information
1 parent
9b388f3
commit c9d56b1
Showing
4 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import logging | ||
import sys | ||
from typing import List | ||
|
||
import click | ||
from cg_lims.exceptions import LimsError | ||
from cg_lims.get.artifacts import get_artifacts | ||
from cg_lims.get.samples import get_one_sample_from_artifact | ||
from cg_lims.get.udfs import get_analyte_udf | ||
from genologics.entities import Artifact, Process | ||
from genologics.lims import Lims | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def get_total_amount_after_prep(lims: Lims, sample_id: str) -> float: | ||
"""""" | ||
return get_analyte_udf( | ||
lims=lims, sample_id=sample_id, process_types=["ONT Start Sequencing"], udf="Amount (fmol)" | ||
) | ||
|
||
|
||
def get_loading_amount(lims: Lims, sample_id: str) -> float: | ||
"""""" | ||
return get_analyte_udf( | ||
lims=lims, | ||
sample_id=sample_id, | ||
process_types=["ONT Start Sequencing"], | ||
udf="Loading Amount (fmol)", | ||
) | ||
|
||
|
||
def get_reload_amounts(lims: Lims, sample_id: str) -> List[float]: | ||
"""""" | ||
result_files = lims.get_artifacts( | ||
process_type="ONT Sequencing and Reloading v2", samplelimsid=sample_id, type="ResultFile" | ||
) | ||
amounts = [] | ||
for result_file in result_files: | ||
if result_file.name == "EPP Log": | ||
continue | ||
else: | ||
amounts.append(result_file.udf.get("Reload Amount (fmol)")) | ||
return amounts | ||
|
||
|
||
def get_available_amount(lims: Lims, artifact: Artifact) -> float: | ||
"""""" | ||
sample_id = get_one_sample_from_artifact(artifact=artifact).id | ||
original_amount = get_total_amount_after_prep(lims=lims, sample_id=sample_id) | ||
loading_amount = get_loading_amount(lims=lims, sample_id=sample_id) | ||
total_reload_amount = sum(get_reload_amounts(lims=lims, sample_id=sample_id)) | ||
return original_amount - loading_amount - total_reload_amount | ||
|
||
|
||
def set_available_amount(lims: Lims, artifact: Artifact) -> None: | ||
"""""" | ||
available_amount = get_available_amount(lims=lims, artifact=artifact) | ||
artifact.udf["Available Amount (fmol)"] = available_amount | ||
artifact.put() | ||
|
||
|
||
@click.command() | ||
@click.pass_context | ||
def ont_available_sequencing_reload(ctx): | ||
"""Calculates and sets the amount of material available for reload of ONT runs.""" | ||
|
||
LOG.info(f"Running {ctx.command_path} with params: {ctx.params}") | ||
|
||
lims: Lims = ctx.obj["lims"] | ||
process: Process = ctx.obj["process"] | ||
|
||
try: | ||
artifacts = get_artifacts(process=process, measurement=True) | ||
for artifact in artifacts: | ||
set_available_amount(lims=lims, artifact=artifact) | ||
message: str = "Available amounts have been successfully calculated and set." | ||
LOG.info(message) | ||
click.echo(message) | ||
except LimsError as e: | ||
LOG.error(e.message) | ||
sys.exit(e.message) |
This file contains 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
This file contains 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