Pre code clean-up
This commit is contained in:
@@ -135,7 +135,7 @@ class BaseClass(Base):
|
||||
singles = model.get_default_info('singles')
|
||||
logger.info(f"Querying: {model}, with kwargs: {kwargs}")
|
||||
for k, v in kwargs.items():
|
||||
logger.debug(f"Using key: {k} with value: {v}")
|
||||
logger.info(f"Using key: {k} with value: {v}")
|
||||
try:
|
||||
attr = getattr(model, k)
|
||||
query = query.filter(attr == v)
|
||||
|
||||
@@ -12,7 +12,7 @@ import logging, re
|
||||
from operator import itemgetter
|
||||
|
||||
from . import BaseClass
|
||||
from tools import setup_lookup, report_result, Result, Report, Settings, get_unique_values_in_df_column
|
||||
from tools import setup_lookup, report_result, Result, Report, Settings, get_unique_values_in_df_column, super_splitter
|
||||
from datetime import date, datetime, timedelta
|
||||
from typing import List, Literal, Tuple, Generator
|
||||
from dateutil.parser import parse
|
||||
@@ -81,31 +81,33 @@ class ControlType(BaseClass):
|
||||
return []
|
||||
# NOTE: remove items that don't have relevant data
|
||||
subtypes = [item for item in jsoner[genera] if "_hashes" not in item and "_ratio" not in item]
|
||||
logger.debug(f"subtypes out: {pformat(subtypes)}")
|
||||
# logger.debug(f"subtypes out: {pformat(subtypes)}")
|
||||
return subtypes
|
||||
|
||||
def get_instance_class(self):
|
||||
return Control.find_polymorphic_subclass(polymorphic_identity=self.name)
|
||||
|
||||
@classmethod
|
||||
def get_positive_control_types(cls) -> Generator[ControlType, None, None]:
|
||||
def get_positive_control_types(cls, control_type: str) -> Generator[str, None, None]:
|
||||
"""
|
||||
Gets list of Control types if they have targets
|
||||
|
||||
Returns:
|
||||
List[ControlType]: Control types that have targets
|
||||
"""
|
||||
return (item for item in cls.query() if item.targets)
|
||||
ct = cls.query(name=control_type).targets
|
||||
return (item for item in ct.keys() if ct[item])
|
||||
|
||||
@classmethod
|
||||
def build_positive_regex(cls) -> Pattern:
|
||||
def build_positive_regex(cls, control_type:str) -> Pattern:
|
||||
"""
|
||||
Creates a re.Pattern that will look for positive control types
|
||||
|
||||
Returns:
|
||||
Pattern: Constructed pattern
|
||||
"""
|
||||
strings = list(set([item.name.split("-")[0] for item in cls.get_positive_control_types()]))
|
||||
# strings = list(set([item.name.split("-")[0] for item in cls.get_positive_control_types()]))
|
||||
strings = list(set([super_splitter(item, "-", 0) for item in cls.get_positive_control_types(control_type)]))
|
||||
return re.compile(rf"(^{'|^'.join(strings)})-.*", flags=re.IGNORECASE)
|
||||
|
||||
|
||||
@@ -298,7 +300,8 @@ class PCRControl(Control):
|
||||
parent.mode_typer.clear()
|
||||
parent.mode_typer.setEnabled(False)
|
||||
report = Report()
|
||||
controls = cls.query(sub_type=chart_settings['sub_type'], start_date=chart_settings['start_date'], end_date=chart_settings['end_date'])
|
||||
controls = cls.query(sub_type=chart_settings['sub_type'], start_date=chart_settings['start_date'],
|
||||
end_date=chart_settings['end_date'])
|
||||
data = [control.to_sub_dict() for control in controls]
|
||||
df = DataFrame.from_records(data)
|
||||
try:
|
||||
|
||||
@@ -198,7 +198,7 @@ class KitType(BaseClass):
|
||||
# logger.debug("Get all KitTypeReagentTypeAssociation for SubmissionType")
|
||||
for assoc in assocs:
|
||||
try:
|
||||
logger.debug(f"Yielding: {assoc.reagent_role.name}, {assoc.uses}")
|
||||
# logger.debug(f"Yielding: {assoc.reagent_role.name}, {assoc.uses}")
|
||||
yield assoc.reagent_role.name, assoc.uses
|
||||
except TypeError:
|
||||
continue
|
||||
@@ -1156,7 +1156,7 @@ class KitTypeReagentRoleAssociation(BaseClass):
|
||||
base_dict[k] = v
|
||||
return base_dict
|
||||
|
||||
def get_all_relevant_reagents(self) -> Generator[Reagent, None, None]:
|
||||
def get_all_relevant_reagents(self, override:Reagent|None=None) -> Generator[Reagent, None, None]:
|
||||
"""
|
||||
Creates a generator that will resolve in to a list filling the role associated with this object.
|
||||
|
||||
|
||||
@@ -102,7 +102,6 @@ class Organization(BaseClass):
|
||||
else:
|
||||
raise Exception(f"Filetype {filepath.suffix} not supported.")
|
||||
data = import_dict['orgs']
|
||||
logger.debug(pformat(import_dict))
|
||||
for org in data:
|
||||
organ = Organization.query(name=org['name'])
|
||||
if organ is None:
|
||||
|
||||
@@ -235,7 +235,7 @@ class BasicSubmission(BaseClass):
|
||||
Returns:
|
||||
SubmissionType: SubmissionType with name equal to this polymorphic identity
|
||||
"""
|
||||
logger.debug(f"Running search for {sub_type}")
|
||||
# logger.debug(f"Running search for {sub_type}")
|
||||
if isinstance(sub_type, dict):
|
||||
try:
|
||||
sub_type = sub_type['value']
|
||||
@@ -521,7 +521,7 @@ class BasicSubmission(BaseClass):
|
||||
Returns:
|
||||
pd.DataFrame: Pandas Dataframe of all relevant submissions
|
||||
"""
|
||||
logger.debug(f"Querying Type: {submission_type}")
|
||||
# logger.debug(f"Querying Type: {submission_type}")
|
||||
# logger.debug(f"Using limit: {limit}")
|
||||
# NOTE: use lookup function to create list of dicts
|
||||
subs = [item.to_dict() for item in
|
||||
@@ -827,7 +827,7 @@ class BasicSubmission(BaseClass):
|
||||
return input_dict
|
||||
|
||||
@classmethod
|
||||
def custom_validation(cls, pyd: "PydSubmission") -> dict:
|
||||
def custom_validation(cls, pyd: "PydSubmission") -> "PydSubmission":
|
||||
"""
|
||||
Performs any final custom parsing of the excel file.
|
||||
|
||||
@@ -1412,14 +1412,16 @@ class BacterialCulture(BasicSubmission):
|
||||
dict: Updated dictionary.
|
||||
"""
|
||||
from . import ControlType
|
||||
# logger.debug(f"\n\nHello from BacterialCulture custom_validation")
|
||||
pyd = super().custom_validation(pyd)
|
||||
# NOTE: build regex for all control types that have targets
|
||||
regex = ControlType.build_positive_regex()
|
||||
regex = ControlType.build_positive_regex(control_type="Irida Control")
|
||||
logger.debug(regex)
|
||||
# NOTE: search samples for match
|
||||
for sample in pyd.samples:
|
||||
matched = regex.match(sample.submitter_id)
|
||||
if bool(matched):
|
||||
# logger.debug(f"Control match found: {sample['submitter_id']}")
|
||||
# logger.debug(f"Control match found: {sample.submitter_id}")
|
||||
new_lot = matched.group()
|
||||
try:
|
||||
pos_control_reg = \
|
||||
@@ -1429,6 +1431,7 @@ class BacterialCulture(BasicSubmission):
|
||||
return pyd
|
||||
pos_control_reg.lot = new_lot
|
||||
pos_control_reg.missing = False
|
||||
# logger.debug(f"Got positive control: {pos_control_reg}")
|
||||
return pyd
|
||||
|
||||
@classmethod
|
||||
@@ -1785,6 +1788,7 @@ class WastewaterArtic(BasicSubmission):
|
||||
ii in
|
||||
range(source_plates_section['start_row'], source_plates_section['end_row'] + 1)]
|
||||
for datum in data:
|
||||
logger.debug(f"Datum: {datum}")
|
||||
if datum['plate'] in ["None", None, ""]:
|
||||
continue
|
||||
else:
|
||||
@@ -1869,7 +1873,13 @@ class WastewaterArtic(BasicSubmission):
|
||||
dict: Updated sample dictionary
|
||||
"""
|
||||
input_dict = super().parse_samples(input_dict)
|
||||
logger.debug(f"WWA input dict: {pformat(input_dict)}")
|
||||
input_dict['sample_type'] = "Wastewater Sample"
|
||||
# NOTE: Stop gap solution because WW is sloppy with their naming schemes
|
||||
try:
|
||||
input_dict['source_plate'] = input_dict['source_plate'].replace("WW20", "WW-20")
|
||||
except KeyError:
|
||||
pass
|
||||
# NOTE: Because generate_sample_object needs the submitter_id and the artic has the "({origin well})"
|
||||
# at the end, this has to be done here. No moving to sqlalchemy object :(
|
||||
input_dict['submitter_id'] = re.sub(r"\s\(.+\)\s?$", "", str(input_dict['submitter_id'])).strip()
|
||||
|
||||
Reference in New Issue
Block a user