added kraken data to details.
This commit is contained in:
@@ -341,6 +341,12 @@ def submissions_to_df(ctx:dict, type:str|None=None) -> pd.DataFrame:
|
||||
# pass to lookup function
|
||||
subs = [item.to_dict() for item in lookup_all_submissions_by_type(ctx=ctx, type=type)]
|
||||
df = pd.DataFrame.from_records(subs)
|
||||
# logger.debug(f"Pre: {df['Technician']}")
|
||||
try:
|
||||
df = df.drop("controls", axis=1)
|
||||
except:
|
||||
logger.warning(f"Couldn't drop 'controls' column from submissionsheet df.")
|
||||
# logger.debug(f"Post: {df['Technician']}")
|
||||
return df
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
from . import Base
|
||||
from sqlalchemy import Column, String, TIMESTAMP, JSON, INTEGER, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
import logging
|
||||
from operator import itemgetter
|
||||
import json
|
||||
|
||||
logger = logging.getLogger(f"submissions.{__name__}")
|
||||
|
||||
class ControlType(Base):
|
||||
"""
|
||||
@@ -35,3 +40,24 @@ class Control(Base):
|
||||
submission_id = Column(INTEGER, ForeignKey("_submissions.id")) #: parent submission id
|
||||
submission = relationship("BacterialCulture", back_populates="controls", foreign_keys=[submission_id]) #: parent submission
|
||||
|
||||
|
||||
def to_sub_dict(self):
|
||||
kraken = json.loads(self.kraken)
|
||||
kraken_cnt_total = sum([kraken[item]['kraken_count'] for item in kraken])
|
||||
new_kraken = []
|
||||
for item in kraken:
|
||||
kraken_percent = kraken[item]['kraken_count'] / kraken_cnt_total
|
||||
new_kraken.append({'name': item, 'kraken_count':kraken[item]['kraken_count'], 'kraken_percent':"{0:.0%}".format(kraken_percent)})
|
||||
new_kraken = sorted(new_kraken, key=itemgetter('kraken_count'), reverse=True)
|
||||
if self.controltype.targets == []:
|
||||
targets = ["None"]
|
||||
else:
|
||||
targets = self.controltype.targets
|
||||
output = {
|
||||
"name" : self.name,
|
||||
"type" : self.controltype.name,
|
||||
"targets" : " ,".join(targets),
|
||||
"kraken" : new_kraken[0:5]
|
||||
}
|
||||
return output
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@ from . import Base
|
||||
from sqlalchemy import Column, String, TIMESTAMP, INTEGER, ForeignKey, Table, JSON, FLOAT
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime as dt
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(f"submissions.{__name__}")
|
||||
|
||||
# table containing reagents/submission relationships
|
||||
reagents_submissions = Table("_reagents_submissions", Base.metadata, Column("reagent_id", INTEGER, ForeignKey("_reagents.id")), Column("submission_id", INTEGER, ForeignKey("_submissions.id")))
|
||||
@@ -28,6 +31,7 @@ class BasicSubmission(Base):
|
||||
reagents_id = Column(String, ForeignKey("_reagents.id", ondelete="SET NULL", name="fk_BS_reagents_id")) #: id of used reagents
|
||||
extraction_info = Column(JSON) #: unstructured output from the extraction table logger.
|
||||
run_cost = Column(FLOAT(2))
|
||||
uploaded_by = Column(String(32))
|
||||
|
||||
__mapper_args__ = {
|
||||
"polymorphic_identity": "basic_submission",
|
||||
@@ -77,6 +81,7 @@ class BasicSubmission(Base):
|
||||
"Technician": self.technician,
|
||||
"Cost": self.run_cost,
|
||||
}
|
||||
logger.debug(f"{self.rsl_plate_num} technician: {output['Technician']}")
|
||||
return output
|
||||
|
||||
|
||||
@@ -107,6 +112,7 @@ class BasicSubmission(Base):
|
||||
# cost = self.extraction_kit.cost_per_run
|
||||
# except AttributeError:
|
||||
# cost = None
|
||||
|
||||
output = {
|
||||
"id": self.id,
|
||||
"Plate Number": self.rsl_plate_num,
|
||||
@@ -131,6 +137,13 @@ class BacterialCulture(BasicSubmission):
|
||||
samples = relationship("BCSample", back_populates="rsl_plate", uselist=True)
|
||||
# bc_sample_id = Column(INTEGER, ForeignKey("_bc_samples.id", ondelete="SET NULL", name="fk_BC_sample_id"))
|
||||
__mapper_args__ = {"polymorphic_identity": "bacterial_culture", "polymorphic_load": "inline"}
|
||||
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
output = super().to_dict()
|
||||
output['controls'] = [item.to_sub_dict() for item in self.controls]
|
||||
# logger.debug(f"{self.rsl_plate_num} technician: {output}")
|
||||
return output
|
||||
|
||||
|
||||
class Wastewater(BasicSubmission):
|
||||
|
||||
Reference in New Issue
Block a user