Skip to content

Commit

Permalink
Merge pull request #5 from mgcam/render_product_metrics
Browse files Browse the repository at this point in the history
Added a check for unlinked data.
  • Loading branch information
nerdstrike authored Jun 13, 2024
2 parents 6e5472a + 372fc56 commit 579138b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lang_qc/db/helper/wells.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ def get_metrics_by_well_product_id(
) -> QCPoolMetrics | None:
well = self.get_mlwh_well_by_product_id(id_product)
if well and well.demultiplex_mode and "Instrument" in well.demultiplex_mode:

product_metrics = well.pac_bio_product_metrics
lib_lims_data = [
product.pac_bio_run
for product in product_metrics
if product.pac_bio_run is not None
]
if len(lib_lims_data) != len(product_metrics):
raise Exception("Partially linked LIMS data or no linked LIMS data")

cov: float | None
if any(p.hifi_num_reads is None for p in product_metrics):
Expand All @@ -94,27 +102,28 @@ def get_metrics_by_well_product_id(
hifi_reads = [prod.hifi_num_reads for prod in product_metrics]
cov = stdev(hifi_reads) / mean(hifi_reads) * 100

return QCPoolMetrics(
pool_coeff_of_variance=cov,
products=[
sample_stats = []
for (i, prod) in enumerate(product_metrics):
sample_stats.append(
SampleDeplexingStats(
id_product=prod.id_pac_bio_product,
tag1_name=prod.pac_bio_run.tag_identifier,
tag2_name=prod.pac_bio_run.tag2_identifier,
tag1_name=lib_lims_data[i].tag_identifier,
tag2_name=lib_lims_data[i].tag2_identifier,
deplexing_barcode=prod.barcode4deplexing,
hifi_read_bases=prod.hifi_read_bases,
hifi_num_reads=prod.hifi_num_reads,
hifi_read_length_mean=prod.hifi_read_length_mean,
hifi_bases_percent=prod.hifi_bases_percent,
percentage_total_reads=(
prod.hifi_num_reads / well.hifi_num_reads * 100
if well.hifi_num_reads
if (well.hifi_num_reads and prod.hifi_num_reads)
else None
),
)
for prod in product_metrics
],
)
)

return QCPoolMetrics(pool_coeff_of_variance=cov, products=sample_stats)

return None

def recent_completed_wells(self) -> List[PacBioRunWellMetrics]:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_pac_bio_qc_data_well.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from npg_id_generation.pac_bio import PacBioEntity

from lang_qc.db.helper.wells import WellWh
Expand Down Expand Up @@ -134,3 +135,15 @@ def test_pool_metrics_from_well(mlwhdb_test_session, multiplexed_run):
assert (
int(metrics.products[1].percentage_total_reads) == 66
), "20 of 30 reads is 66.6%"


def test_pool_metrics_from_well(mlwhdb_test_session):

id = PacBioEntity(
run_name="TRACTION-RUN-1140", well_label="C1", plate_number=2
).hash_product_id()
helper = WellWh(session=mlwhdb_test_session)
with pytest.raises(
Exception, match=r"Partially linked LIMS data or no linked LIMS data"
):
helper.get_metrics_by_well_product_id(id)

0 comments on commit 579138b

Please sign in to comment.