Updated documentation. Improved import completion.

This commit is contained in:
Landon Wark
2023-03-22 09:36:37 -05:00
parent 9c9c373830
commit cb05ad76e1
13 changed files with 164 additions and 90 deletions

View File

@@ -641,6 +641,16 @@ def lookup_submission_by_rsl_num(ctx:dict, rsl_num:str) -> models.BasicSubmissio
def lookup_submissions_using_reagent(ctx:dict, reagent:models.Reagent) -> list[models.BasicSubmission]:
"""
Retrieves each submission using a specified reagent.
Args:
ctx (dict): settings passed down from gui
reagent (models.Reagent): reagent object in question
Returns:
list[models.BasicSubmission]: list of all submissions using specified reagent.
"""
return ctx['database_session'].query(models.BasicSubmission).join(reagents_submissions).filter(reagents_submissions.c.reagent_id==reagent.id).all()

View File

@@ -35,7 +35,7 @@ class BasicSubmission(Base):
reagents = relationship("Reagent", back_populates="submissions", secondary=reagents_submissions) #: relationship to reagents
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)) #: total cost of running the plate. Set from kit costs at time of creation.
run_cost = Column(FLOAT(2)) #: total cost of running the plate. Set from constant and mutable kit costs at time of creation.
uploaded_by = Column(String(32)) #: user name of person who submitted the submission to the database.
# Allows for subclassing into ex. BacterialCulture, Wastewater, etc.

View File

@@ -27,6 +27,7 @@ class SheetParser(object):
# set attributes based on kwargs from gui ctx
for kwarg in kwargs:
setattr(self, f"_{kwarg}", kwargs[kwarg])
# self.__dict__.update(kwargs)
if filepath == None:
logger.error(f"No filepath given.")
self.xl = None
@@ -38,12 +39,12 @@ class SheetParser(object):
self.xl = None
self.sub = OrderedDict()
# make decision about type of sample we have
self.sub['submission_type'] = self._type_decider()
self.sub['submission_type'] = self.type_decider()
# select proper parser based on sample type
parse_sub = getattr(self, f"_parse_{self.sub['submission_type'].lower()}")
parse_sub = getattr(self, f"parse_{self.sub['submission_type'].lower()}")
parse_sub()
def _type_decider(self) -> str:
def type_decider(self) -> str:
"""
makes decisions about submission type based on structure of excel file
@@ -60,7 +61,7 @@ class SheetParser(object):
return "Unknown"
def _parse_unknown(self) -> None:
def parse_unknown(self) -> None:
"""
Dummy function to handle unknown excel structures
"""
@@ -68,7 +69,7 @@ class SheetParser(object):
self.sub = None
def _parse_generic(self, sheet_name:str) -> pd.DataFrame:
def parse_generic(self, sheet_name:str) -> pd.DataFrame:
"""
Pulls information common to all submission types and passes on dataframe
@@ -89,12 +90,12 @@ class SheetParser(object):
return submission_info
def _parse_bacterial_culture(self) -> None:
def parse_bacterial_culture(self) -> None:
"""
pulls info specific to bacterial culture sample type
"""
def _parse_reagents(df:pd.DataFrame) -> None:
def parse_reagents(df:pd.DataFrame) -> None:
"""
Pulls reagents from the bacterial sub-dataframe
@@ -126,7 +127,7 @@ class SheetParser(object):
else:
expiry = date.today()
self.sub[f"lot_{reagent_type}"] = {'lot':output_var, 'exp':expiry}
submission_info = self._parse_generic("Sample List")
submission_info = self.parse_generic("Sample List")
# iloc is [row][column] and the first row is set as header row so -2
tech = str(submission_info.iloc[11][1])
if tech == "nan":
@@ -139,7 +140,7 @@ class SheetParser(object):
# must be prefixed with 'lot_' to be recognized by gui
# Todo: find a more adaptable way to read reagents.
reagent_range = submission_info.iloc[1:13, 4:8]
_parse_reagents(reagent_range)
parse_reagents(reagent_range)
# get individual sample info
sample_parser = SampleParser(submission_info.iloc[15:111])
sample_parse = getattr(sample_parser, f"parse_{self.sub['submission_type'].lower()}_samples")
@@ -147,12 +148,12 @@ class SheetParser(object):
self.sub['samples'] = sample_parse()
def _parse_wastewater(self) -> None:
def parse_wastewater(self) -> None:
"""
pulls info specific to wastewater sample type
"""
def _parse_reagents(df:pd.DataFrame) -> None:
def parse_reagents(df:pd.DataFrame) -> None:
"""
Pulls reagents from the bacterial sub-dataframe
@@ -180,7 +181,7 @@ class SheetParser(object):
expiry = date.today()
self.sub[f"lot_{output_key}"] = {'lot':output_var, 'exp':expiry}
# parse submission sheet
submission_info = self._parse_generic("WW Submissions (ENTER HERE)")
submission_info = self.parse_generic("WW Submissions (ENTER HERE)")
# parse enrichment sheet
enrichment_info = self.xl.parse("Enrichment Worksheet", dtype=object)
# set enrichment reagent range
@@ -195,9 +196,9 @@ class SheetParser(object):
pcr_reagent_range = qprc_info.iloc[0:5, 9:20]
# compile technician info
self.sub['technician'] = f"Enr: {enrichment_info.columns[2]}, Ext: {extraction_info.columns[2]}, PCR: {qprc_info.columns[2]}"
_parse_reagents(enr_reagent_range)
_parse_reagents(ext_reagent_range)
_parse_reagents(pcr_reagent_range)
parse_reagents(enr_reagent_range)
parse_reagents(ext_reagent_range)
parse_reagents(pcr_reagent_range)
# parse samples
sample_parser = SampleParser(submission_info.iloc[16:40])
sample_parse = getattr(sample_parser, f"parse_{self.sub['submission_type'].lower()}_samples")

View File

@@ -8,11 +8,13 @@ from datetime import date, timedelta
import sys
from pathlib import Path
import re
from tools import check_if_app
logger = logging.getLogger(f"submissions.{__name__}")
# set path of templates depending on pyinstaller/raw python
if getattr(sys, 'frozen', False):
# if getattr(sys, 'frozen', False):
if check_if_app():
loader_path = Path(sys._MEIPASS).joinpath("files", "templates")
else:
loader_path = Path(__file__).parents[2].joinpath('templates').absolute().__str__()