Missing sample message after Artic parsing.
This commit is contained in:
@@ -31,6 +31,7 @@ def set_sqlite_pragma(dbapi_connection, connection_record):
|
||||
cursor.execute("PRAGMA foreign_keys=ON")
|
||||
cursor.close()
|
||||
|
||||
|
||||
def store_submission(ctx:dict, base_submission:models.BasicSubmission) -> None|dict:
|
||||
"""
|
||||
Upserts submissions into database
|
||||
@@ -799,9 +800,21 @@ def lookup_discounts_by_org_and_kit(ctx:dict, kit_id:int, lab_id:int):
|
||||
)).all()
|
||||
|
||||
def hitpick_plate(submission:models.BasicSubmission, plate_number:int=0) -> list:
|
||||
"""
|
||||
Creates a list of sample positions and statuses to be used by plate mapping and csv output to biomek software.
|
||||
|
||||
Args:
|
||||
submission (models.BasicSubmission): Input submission
|
||||
plate_number (int, optional): plate position in the series of selected plates. Defaults to 0.
|
||||
|
||||
Returns:
|
||||
list: list of sample dictionaries.
|
||||
"""
|
||||
plate_dicto = []
|
||||
for sample in submission.samples:
|
||||
# have sample report back its info if it's positive, otherwise, None
|
||||
method_list = [func for func in dir(sample) if callable(getattr(sample, func))]
|
||||
logger.debug(f"Method list of sample: {method_list}")
|
||||
samp = sample.to_hitpick()
|
||||
if samp == None:
|
||||
continue
|
||||
@@ -811,6 +824,43 @@ def hitpick_plate(submission:models.BasicSubmission, plate_number:int=0) -> list
|
||||
# if len(dicto) < 88:
|
||||
this_sample = dict(
|
||||
plate_number = plate_number,
|
||||
sample_name = samp['name'],
|
||||
column = samp['col'],
|
||||
row = samp['row'],
|
||||
positive = samp['positive'],
|
||||
plate_name = submission.rsl_plate_num
|
||||
)
|
||||
# append to plate samples
|
||||
plate_dicto.append(this_sample)
|
||||
# append to all samples
|
||||
# image = make_plate_map(plate_dicto)
|
||||
return plate_dicto
|
||||
|
||||
def platemap_plate(submission:models.BasicSubmission) -> list:
|
||||
"""
|
||||
Depreciated. Replaced by new functionality in hitpick_plate
|
||||
|
||||
Args:
|
||||
submission (models.BasicSubmission): Input submission
|
||||
|
||||
Returns:
|
||||
list: list of sample dictionaries
|
||||
"""
|
||||
plate_dicto = []
|
||||
for sample in submission.samples:
|
||||
# have sample report back its info if it's positive, otherwise, None
|
||||
|
||||
try:
|
||||
samp = sample.to_platemap()
|
||||
except AttributeError:
|
||||
continue
|
||||
if samp == None:
|
||||
continue
|
||||
else:
|
||||
logger.debug(f"Item name: {samp['name']}")
|
||||
# plate can handle 88 samples to leave column for controls
|
||||
# if len(dicto) < 88:
|
||||
this_sample = dict(
|
||||
sample_name = samp['name'],
|
||||
column = samp['col'],
|
||||
row = samp['row'],
|
||||
|
||||
@@ -62,8 +62,10 @@ class WWSample(Base):
|
||||
# if well_col > 4:
|
||||
# well
|
||||
if self.ct_n1 != None and self.ct_n2 != None:
|
||||
# logger.debug(f"Using well info in name.")
|
||||
name = f"{self.ww_sample_full_id}\n\t- ct N1: {'{:.2f}'.format(self.ct_n1)} ({self.n1_status})\n\t- ct N2: {'{:.2f}'.format(self.ct_n2)} ({self.n2_status})"
|
||||
else:
|
||||
# logger.debug(f"NOT using well info in name for: {self.ww_sample_full_id}")
|
||||
name = self.ww_sample_full_id
|
||||
return {
|
||||
"well": self.well_number,
|
||||
@@ -85,18 +87,23 @@ class WWSample(Base):
|
||||
except TypeError as e:
|
||||
logger.error(f"Couldn't check positives for {self.rsl_number}. Looks like there isn't PCR data.")
|
||||
return None
|
||||
if positive:
|
||||
try:
|
||||
# The first character of the elution well is the row
|
||||
well_row = row_dict[self.elution_well[0]]
|
||||
# The remaining charagers are the columns
|
||||
well_col = self.elution_well[1:]
|
||||
except TypeError as e:
|
||||
logger.error(f"This sample doesn't have elution plate info.")
|
||||
return None
|
||||
return dict(name=self.ww_sample_full_id, row=well_row, col=well_col)
|
||||
else:
|
||||
return None
|
||||
well_row = row_dict[self.elution_well[0]]
|
||||
well_col = self.elution_well[1:]
|
||||
# if positive:
|
||||
# try:
|
||||
# # The first character of the elution well is the row
|
||||
# well_row = row_dict[self.elution_well[0]]
|
||||
# # The remaining charagers are the columns
|
||||
# well_col = self.elution_well[1:]
|
||||
# except TypeError as e:
|
||||
# logger.error(f"This sample doesn't have elution plate info.")
|
||||
# return None
|
||||
return dict(name=self.ww_sample_full_id,
|
||||
row=well_row,
|
||||
col=well_col,
|
||||
positive=positive)
|
||||
# else:
|
||||
# return None
|
||||
|
||||
|
||||
class BCSample(Base):
|
||||
@@ -134,7 +141,24 @@ class BCSample(Base):
|
||||
"name": f"{self.sample_id} - ({self.organism})",
|
||||
}
|
||||
|
||||
def to_hitpick(self) -> dict|None:
|
||||
"""
|
||||
Outputs a dictionary of locations
|
||||
|
||||
Returns:
|
||||
dict: dictionary of sample id, row and column in elution plate
|
||||
"""
|
||||
# dictionary to translate row letters into numbers
|
||||
row_dict = dict(A=1, B=2, C=3, D=4, E=5, F=6, G=7, H=8)
|
||||
# if either n1 or n2 is positive, include this sample
|
||||
well_row = row_dict[self.well_number[0]]
|
||||
# The remaining charagers are the columns
|
||||
well_col = self.well_number[1:]
|
||||
return dict(name=self.sample_id,
|
||||
row=well_row,
|
||||
col=well_col,
|
||||
positive=False)
|
||||
|
||||
# class ArticSample(Base):
|
||||
# """
|
||||
# base of artic sample
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'''
|
||||
Models for the main submission types.
|
||||
'''
|
||||
import math
|
||||
from . import Base
|
||||
from sqlalchemy import Column, String, TIMESTAMP, INTEGER, ForeignKey, Table, JSON, FLOAT
|
||||
from sqlalchemy.orm import relationship
|
||||
@@ -246,5 +247,24 @@ class WastewaterArtic(BasicSubmission):
|
||||
derivative submission type for artic wastewater
|
||||
"""
|
||||
samples = relationship("WWSample", back_populates="artic_rsl_plate", uselist=True)
|
||||
# Can in use the pcr_info from the wastewater? Cause I can't define pcr_info here due to conflicts with that
|
||||
__mapper_args__ = {"polymorphic_identity": "wastewater_artic", "polymorphic_load": "inline"}
|
||||
# Can it use the pcr_info from the wastewater? Cause I can't define pcr_info here due to conflicts with that
|
||||
# Not necessary because we don't get any results for this procedure.
|
||||
__mapper_args__ = {"polymorphic_identity": "wastewater_artic", "polymorphic_load": "inline"}
|
||||
|
||||
def calculate_base_cost(self):
|
||||
"""
|
||||
This method overrides parent method due to multiple output plates from a single submission
|
||||
"""
|
||||
logger.debug(f"Hello from calculate base cost in WWArtic")
|
||||
try:
|
||||
cols_count_96 = ceil(int(self.sample_count) / 8)
|
||||
except Exception as e:
|
||||
logger.error(f"Column count error: {e}")
|
||||
# Since we have multiple output plates per submission form, the constant cost will have to reflect this.
|
||||
output_plate_count = math.ceil(int(self.sample_count) / 16)
|
||||
logger.debug(f"Looks like we have {output_plate_count} output plates.")
|
||||
const_cost = self.extraction_kit.constant_cost * output_plate_count
|
||||
try:
|
||||
self.run_cost = const_cost + (self.extraction_kit.mutable_cost_column * cols_count_96) + (self.extraction_kit.mutable_cost_sample * int(self.sample_count))
|
||||
except Exception as e:
|
||||
logger.error(f"Calculation error: {e}")
|
||||
|
||||
Reference in New Issue
Block a user