Missing sample message after Artic parsing.
This commit is contained in:
@@ -114,6 +114,10 @@ class SubmissionsSheet(QTableView):
|
||||
del self.data['reagents']
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
del self.data['comments']
|
||||
except KeyError:
|
||||
pass
|
||||
proxyModel = QSortFilterProxyModel()
|
||||
proxyModel.setSourceModel(pandasModel(self.data))
|
||||
self.setModel(proxyModel)
|
||||
@@ -226,11 +230,12 @@ class SubmissionsSheet(QTableView):
|
||||
else:
|
||||
logger.error(f"We had to truncate the number of samples to 94.")
|
||||
logger.debug(f"We found {len(dicto)} to hitpick")
|
||||
msg = AlertPop(message=f"We found {len(dicto)} samples to hitpick", status="INFORMATION")
|
||||
msg.exec()
|
||||
# convert all samples to dataframe
|
||||
df = make_hitpicks(dicto)
|
||||
logger.debug(f"Size of the dataframe: {df.size}")
|
||||
df = df[df.positive != False]
|
||||
logger.debug(f"Size of the dataframe: {df.shape[0]}")
|
||||
msg = AlertPop(message=f"We found {df.shape[0]} samples to hitpick", status="INFORMATION")
|
||||
msg.exec()
|
||||
if df.size == 0:
|
||||
return
|
||||
date = datetime.strftime(datetime.today(), "%Y-%m-%d")
|
||||
@@ -264,6 +269,7 @@ class SubmissionDetails(QDialog):
|
||||
interior.setParent(self)
|
||||
# get submision from db
|
||||
data = lookup_submission_by_id(ctx=ctx, id=id)
|
||||
logger.debug(f"Submission details data:\n{data.to_dict()}")
|
||||
self.base_dict = data.to_dict()
|
||||
# don't want id
|
||||
del self.base_dict['id']
|
||||
@@ -308,8 +314,11 @@ class SubmissionDetails(QDialog):
|
||||
platemap = make_plate_map(plate_dicto)
|
||||
logger.debug(f"platemap: {platemap}")
|
||||
image_io = BytesIO()
|
||||
platemap.save(image_io, 'JPEG')
|
||||
platemap.save("test.jpg", 'JPEG')
|
||||
try:
|
||||
platemap.save(image_io, 'JPEG')
|
||||
except AttributeError:
|
||||
logger.error(f"No plate map found for {sub.rsl_plate_num}")
|
||||
# platemap.save("test.jpg", 'JPEG')
|
||||
self.base_dict['platemap'] = base64.b64encode(image_io.getvalue()).decode('utf-8')
|
||||
logger.debug(self.base_dict)
|
||||
html = template.render(sub=self.base_dict)
|
||||
|
||||
@@ -26,7 +26,7 @@ from backend.db.functions import (
|
||||
lookup_all_orgs, lookup_kittype_by_use, lookup_kittype_by_name,
|
||||
construct_submission_info, lookup_reagent, store_submission, lookup_submissions_by_date_range,
|
||||
create_kit_from_yaml, create_org_from_yaml, get_control_subtypes, get_all_controls_by_type,
|
||||
lookup_all_submissions_by_type, get_all_controls, lookup_submission_by_rsl_num, update_ww_sample
|
||||
lookup_all_submissions_by_type, get_all_controls, lookup_submission_by_rsl_num, update_ww_sample, hitpick_plate
|
||||
)
|
||||
from backend.excel.parser import SheetParser, PCRParser
|
||||
from backend.excel.reports import make_report_html, make_report_xlsx, convert_data_list_to_df
|
||||
@@ -35,6 +35,7 @@ from .custom_widgets.pop_ups import AlertPop, QuestionAsker
|
||||
from .custom_widgets import ReportDatePicker, ReagentTypeForm
|
||||
from .custom_widgets.misc import ImportReagent
|
||||
from .visualizations.control_charts import create_charts, construct_html
|
||||
from .visualizations import make_plate_map
|
||||
|
||||
|
||||
logger = logging.getLogger(f"submissions.{__name__}")
|
||||
@@ -60,6 +61,7 @@ def import_submission_function(obj:QMainWindow) -> Tuple[QMainWindow, dict|None]
|
||||
if prsr.sub['rsl_plate_num'] == None:
|
||||
prsr.sub['rsl_plate_num'] = RSLNamer(fname.__str__()).parsed_name
|
||||
logger.debug(f"prsr.sub = {prsr.sub}")
|
||||
obj.current_submission_type = prsr.sub['submission_type']
|
||||
# destroy any widgets from previous imports
|
||||
for item in obj.table_widget.formlayout.parentWidget().findChildren(QWidget):
|
||||
item.setParent(None)
|
||||
@@ -111,7 +113,7 @@ def import_submission_function(obj:QMainWindow) -> Tuple[QMainWindow, dict|None]
|
||||
uses.insert(0, uses.pop(uses.index(prsr.sub[item])))
|
||||
obj.ext_kit = prsr.sub[item]
|
||||
else:
|
||||
logger.error(f"Couldn't find prsr.sub[extraction_kit]")
|
||||
logger.error(f"Couldn't find {prsr.sub['extraction_kit']}")
|
||||
obj.ext_kit = uses[0]
|
||||
add_widget.addItems(uses)
|
||||
case 'submitted_date':
|
||||
@@ -156,6 +158,9 @@ def import_submission_function(obj:QMainWindow) -> Tuple[QMainWindow, dict|None]
|
||||
if hasattr(obj, 'ext_kit'):
|
||||
obj.kit_integrity_completion()
|
||||
logger.debug(f"Imported reagents: {obj.reagents}")
|
||||
if prsr.sample_result != None:
|
||||
msg = AlertPop(message=prsr.sample_result, status="WARNING")
|
||||
msg.exec()
|
||||
return obj, result
|
||||
|
||||
def kit_reload_function(obj:QMainWindow) -> QMainWindow:
|
||||
@@ -263,6 +268,7 @@ def submit_new_sample_function(obj:QMainWindow) -> QMainWindow:
|
||||
# reset form
|
||||
for item in obj.table_widget.formlayout.parentWidget().findChildren(QWidget):
|
||||
item.setParent(None)
|
||||
logger.debug(f"All attributes of obj: {pprint.pprint(obj.__dict__)}")
|
||||
if hasattr(obj, 'csv'):
|
||||
dlg = QuestionAsker("Export CSV?", "Would you like to export the csv file?")
|
||||
if dlg.exec():
|
||||
@@ -271,6 +277,14 @@ def submit_new_sample_function(obj:QMainWindow) -> QMainWindow:
|
||||
obj.csv.to_csv(fname.__str__(), index=False)
|
||||
except PermissionError:
|
||||
logger.debug(f"Could not get permissions to {fname}. Possibly the request was cancelled.")
|
||||
try:
|
||||
delattr(obj, "csv")
|
||||
except AttributeError:
|
||||
pass
|
||||
# if obj.current_submission_type == "Bacterial_Culture":
|
||||
# hitpick = hitpick_plate(base_submission)
|
||||
# image = make_plate_map(hitpick)
|
||||
# image.show()
|
||||
return obj, result
|
||||
|
||||
def generate_report_function(obj:QMainWindow) -> QMainWindow:
|
||||
|
||||
@@ -12,7 +12,7 @@ def make_plate_map(sample_list:list) -> Image:
|
||||
Makes a pillow image of a plate from hitpicks
|
||||
|
||||
Args:
|
||||
sample_list (list): list of positive sample dictionaries from the hitpicks
|
||||
sample_list (list): list of sample dictionaries from the hitpicks
|
||||
|
||||
Returns:
|
||||
Image: Image of the 96 well plate with positive samples in red.
|
||||
@@ -26,12 +26,17 @@ def make_plate_map(sample_list:list) -> Image:
|
||||
except TypeError as e:
|
||||
logger.error(f"No samples for this plate. Nothing to do.")
|
||||
return None
|
||||
# Make a 8 row, 12 column, 3 color ints array, filled with white by default
|
||||
# Make an 8 row, 12 column, 3 color ints array, filled with white by default
|
||||
grid = np.full((8,12,3),255, dtype=np.uint8)
|
||||
# Go through samples and change its row/column to red
|
||||
# Go through samples and change its row/column to red if positive, else blue
|
||||
for sample in sample_list:
|
||||
grid[int(sample['row'])-1][int(sample['column'])-1] = [255,0,0]
|
||||
# Create image from the grid
|
||||
logger.debug(f"sample keys: {list(sample.keys())}")
|
||||
if sample['positive']:
|
||||
colour = [255,0,0]
|
||||
else:
|
||||
colour = [0,0,255]
|
||||
grid[int(sample['row'])-1][int(sample['column'])-1] = colour
|
||||
# Create pixel image from the grid and enlarge
|
||||
img = Image.fromarray(grid).resize((1200, 800), resample=Image.NEAREST)
|
||||
# create a drawer over the image
|
||||
draw = ImageDraw.Draw(img)
|
||||
@@ -58,7 +63,6 @@ def make_plate_map(sample_list:list) -> Image:
|
||||
new_img.paste(img, box)
|
||||
# create drawer over the new image
|
||||
draw = ImageDraw.Draw(new_img)
|
||||
# font = ImageFont.truetype("sans-serif.ttf", 16)
|
||||
if check_if_app():
|
||||
font_path = Path(sys._MEIPASS).joinpath("files", "resources")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user