Minor bug fixes.
This commit is contained in:
@@ -194,73 +194,6 @@ def construct_chart(df:pd.DataFrame, modes:list, ytitle:str|None=None) -> Figure
|
||||
fig.add_traces(bar.data)
|
||||
return generic_figure_markers(fig=fig, modes=modes, ytitle=ytitle)
|
||||
|
||||
# Below are the individual construction functions. They must be named "construct_{mode}_chart" and
|
||||
# take only json_in and mode to hook into the main processor.
|
||||
|
||||
# def construct_refseq_chart(df:pd.DataFrame, group_name:str, mode:str) -> Figure:
|
||||
# """
|
||||
# Constructs intial refseq chart for both contains and matches (depreciated).
|
||||
|
||||
# Args:
|
||||
# df (pd.DataFrame): dataframe containing all sample data for the group.
|
||||
# group_name (str): name of the group being processed.
|
||||
# mode (str): contains or matches, overwritten by hardcoding, so don't think about it too hard.
|
||||
|
||||
# Returns:
|
||||
# Figure: initial figure with contains and matches traces.
|
||||
# """
|
||||
# # This overwrites the mode from the signature, might get confusing.
|
||||
# fig = Figure()
|
||||
# modes = ['contains', 'matches']
|
||||
# for ii, mode in enumerate(modes):
|
||||
# bar = px.bar(df, x="submitted_date",
|
||||
# y=f"{mode}_ratio",
|
||||
# color="target",
|
||||
# title=f"{group_name}_{mode}",
|
||||
# barmode='stack',
|
||||
# hover_data=["genus", "name", f"{mode}_hashes"],
|
||||
# text="genera"
|
||||
# )
|
||||
# bar.update_traces(visible = ii == 0)
|
||||
# # Plotly express returns a full figure, so we have to use the data from that figure only.
|
||||
# fig.add_traces(bar.data)
|
||||
# # sys.exit(f"number of traces={len(fig.data)}")
|
||||
# return generic_figure_markers(fig=fig, modes=modes)
|
||||
|
||||
# def construct_kraken_chart(settings:dict, df:pd.DataFrame, group_name:str, mode:str) -> Figure:
|
||||
# """
|
||||
# Constructs intial refseq chart for each mode in the kraken config settings. (depreciated)
|
||||
|
||||
# Args:
|
||||
# settings (dict): settings passed down from click.
|
||||
# df (pd.DataFrame): dataframe containing all sample data for the group.
|
||||
# group_name (str): name of the group being processed.
|
||||
# mode (str): kraken modes retrieved from config file by setup.
|
||||
|
||||
# Returns:
|
||||
# Figure: initial figure with traces for modes
|
||||
# """
|
||||
# df[f'{mode}_count'] = pd.to_numeric(df[f'{mode}_count'],errors='coerce')
|
||||
# df = df.groupby('submitted_date')[f'{mode}_count'].nlargest(2)
|
||||
|
||||
# # The actual percentage from kraken was off due to exclusion of NaN, recalculating.
|
||||
# df[f'{mode}_percent'] = 100 * df[f'{mode}_count'] / df.groupby('submitted_date')[f'{mode}_count'].transform('sum')
|
||||
# modes = settings['modes'][mode]
|
||||
# # This overwrites the mode from the signature, might get confusing.
|
||||
# fig = Figure()
|
||||
# for ii, entry in enumerate(modes):
|
||||
# bar = px.bar(df, x="submitted_date",
|
||||
# y=entry,
|
||||
# color="genus",
|
||||
# title=f"{group_name}_{entry}",
|
||||
# barmode="stack",
|
||||
# hover_data=["genus", "name", "target"],
|
||||
# text="genera",
|
||||
# )
|
||||
# bar.update_traces(visible = ii == 0)
|
||||
# fig.add_traces(bar.data)
|
||||
# return generic_figure_markers(fig=fig, modes=modes)
|
||||
|
||||
def divide_chunks(input_list:list, chunk_count:int):
|
||||
"""
|
||||
Divides a list into {chunk_count} equal parts
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
import numpy as np
|
||||
from tools import check_if_app, jinja_template_loading
|
||||
import logging
|
||||
import logging, sys
|
||||
|
||||
logger = logging.getLogger(f"submissions.{__name__}")
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
'''
|
||||
Constructs main application.
|
||||
TODO: Complete.
|
||||
'''
|
||||
import sys
|
||||
from PyQt6.QtWidgets import (
|
||||
QTabWidget, QWidget, QVBoxLayout,
|
||||
QHBoxLayout, QScrollArea, QMainWindow,
|
||||
@@ -14,14 +12,12 @@ from backend.validators import PydReagent
|
||||
from tools import check_if_app, Settings, Report
|
||||
from .pop_ups import AlertPop
|
||||
from .misc import AddReagentForm, LogParser
|
||||
import logging
|
||||
import logging, webbrowser, sys
|
||||
from datetime import date
|
||||
import webbrowser
|
||||
from .submission_table import SubmissionsSheet
|
||||
from .submission_widget import SubmissionFormContainer
|
||||
from .controls_chart import ControlsViewer
|
||||
from .kit_creator import KitAdder
|
||||
import webbrowser
|
||||
|
||||
logger = logging.getLogger(f'submissions.{__name__}')
|
||||
logger.info("Hello, I am a logger")
|
||||
|
||||
@@ -3,8 +3,8 @@ from PyQt6.QtWidgets import (
|
||||
QWidget, QVBoxLayout, QComboBox, QHBoxLayout,
|
||||
QDateEdit, QLabel, QSizePolicy
|
||||
)
|
||||
from PyQt6.QtCore import QSignalBlocker, QLoggingCategory
|
||||
from backend.db import ControlType, Control, get_control_subtypes
|
||||
from PyQt6.QtCore import QSignalBlocker
|
||||
from backend.db import ControlType, Control#, get_control_subtypes
|
||||
from PyQt6.QtCore import QDate, QSize
|
||||
import logging, sys
|
||||
from tools import Report, Result
|
||||
@@ -88,7 +88,8 @@ class ControlsViewer(QWidget):
|
||||
self.mode = self.mode_typer.currentText()
|
||||
self.sub_typer.clear()
|
||||
# lookup subtypes
|
||||
sub_types = get_control_subtypes(type=self.con_type, mode=self.mode)
|
||||
# sub_types = get_control_subtypes(type=self.con_type, mode=self.mode)
|
||||
sub_types = ControlType.query(name=self.con_type).get_subtypes(mode=self.mode)
|
||||
# sub_types = lookup_controls(ctx=obj.ctx, control_type=obj.con_type)
|
||||
if sub_types != []:
|
||||
# block signal that will rerun controls getter and update sub_typer
|
||||
|
||||
@@ -15,7 +15,6 @@ from PyQt6.QtWidgets import (
|
||||
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
||||
from PyQt6.QtCore import Qt, QAbstractTableModel, QSortFilterProxyModel
|
||||
from PyQt6.QtGui import QAction, QCursor, QPixmap, QPainter
|
||||
from backend.db.functions import submissions_to_df
|
||||
from backend.db.models import BasicSubmission
|
||||
from backend.excel import make_report_html, make_report_xlsx
|
||||
from tools import check_if_app, Report, Result, jinja_template_loading, get_first_blank_df_row, row_map
|
||||
@@ -102,7 +101,8 @@ class SubmissionsSheet(QTableView):
|
||||
"""
|
||||
sets data in model
|
||||
"""
|
||||
self.data = submissions_to_df()
|
||||
# self.data = submissions_to_df()
|
||||
self.data = BasicSubmission.submissions_to_df()
|
||||
try:
|
||||
self.data['id'] = self.data['id'].apply(str)
|
||||
self.data['id'] = self.data['id'].str.zfill(3)
|
||||
|
||||
@@ -5,23 +5,20 @@ from PyQt6.QtWidgets import (
|
||||
from PyQt6.QtCore import pyqtSignal
|
||||
from pathlib import Path
|
||||
from . import select_open_file, select_save_file
|
||||
import logging
|
||||
import logging, difflib, inspect, json, sys
|
||||
from pathlib import Path
|
||||
from tools import Report, Result, check_not_nan
|
||||
from backend.excel.parser import SheetParser, PCRParser
|
||||
from backend.validators import PydSubmission, PydReagent
|
||||
from backend.db import (
|
||||
check_kit_integrity, KitType, Organization, SubmissionType, Reagent,
|
||||
KitType, Organization, SubmissionType, Reagent,
|
||||
ReagentType, KitTypeReagentTypeAssociation, BasicSubmission
|
||||
)
|
||||
from pprint import pformat
|
||||
from .pop_ups import QuestionAsker, AlertPop
|
||||
# from .misc import ReagentFormWidget
|
||||
from typing import List, Tuple
|
||||
import difflib
|
||||
from datetime import date
|
||||
import inspect
|
||||
import json
|
||||
|
||||
logger = logging.getLogger(f"submissions.{__name__}")
|
||||
|
||||
@@ -143,14 +140,14 @@ class SubmissionFormContainer(QWidget):
|
||||
return
|
||||
except AttributeError:
|
||||
self.prsr = SheetParser(ctx=self.app.ctx, filepath=fname)
|
||||
try:
|
||||
logger.debug(f"Submission dictionary:\n{pformat(self.prsr.sub)}")
|
||||
self.pyd = self.prsr.to_pydantic()
|
||||
logger.debug(f"Pydantic result: \n\n{pformat(self.pyd)}\n\n")
|
||||
except Exception as e:
|
||||
report.add_result(Result(msg=f"Problem creating pydantic model:\n\n{e}", status="Critical"))
|
||||
self.report.add_result(report)
|
||||
return
|
||||
# try:
|
||||
logger.debug(f"Submission dictionary:\n{pformat(self.prsr.sub)}")
|
||||
self.pyd = self.prsr.to_pydantic()
|
||||
logger.debug(f"Pydantic result: \n\n{pformat(self.pyd)}\n\n")
|
||||
# except Exception as e:
|
||||
# report.add_result(Result(msg=f"Problem creating pydantic model:\n\n{e}", status="Critical"))
|
||||
# self.report.add_result(report)
|
||||
# return
|
||||
self.form = self.pyd.toForm(parent=self)
|
||||
self.layout().addWidget(self.form)
|
||||
kit_widget = self.form.find_widgets(object_name="extraction_kit")[0].input
|
||||
@@ -265,7 +262,8 @@ class SubmissionFormContainer(QWidget):
|
||||
self.pyd: PydSubmission = self.form.parse_form()
|
||||
logger.debug(f"Submission: {pformat(self.pyd)}")
|
||||
logger.debug("Checking kit integrity...")
|
||||
result = check_kit_integrity(sub=self.pyd)
|
||||
# result = check_kit_integrity(sub=self.pyd)
|
||||
result = self.pyd.check_kit_integrity()
|
||||
report.add_result(result)
|
||||
if len(result.results) > 0:
|
||||
self.report.add_result(report)
|
||||
@@ -417,7 +415,8 @@ class SubmissionFormWidget(QWidget):
|
||||
# self.ignore = [None, "", "qt_spinbox_lineedit", "qt_scrollarea_viewport", "qt_scrollarea_hcontainer",
|
||||
# "qt_scrollarea_vcontainer", "submit_btn"
|
||||
# ]
|
||||
self.ignore = ['filepath', 'samples', 'reagents', 'csv', 'ctx']
|
||||
self.ignore = ['filepath', 'samples', 'reagents', 'csv', 'ctx', 'comment']
|
||||
self.recover = ['filepath', 'samples', 'csv', 'comment']
|
||||
layout = QVBoxLayout()
|
||||
for k, v in kwargs.items():
|
||||
if k not in self.ignore:
|
||||
@@ -448,8 +447,6 @@ class SubmissionFormWidget(QWidget):
|
||||
logger.debug(f"Hello from form parser!")
|
||||
info = {}
|
||||
reagents = []
|
||||
if hasattr(self, 'csv'):
|
||||
info['csv'] = self.csv
|
||||
for widget in self.findChildren(QWidget):
|
||||
# logger.debug(f"Parsed widget of type {type(widget)}")
|
||||
match widget:
|
||||
@@ -463,9 +460,13 @@ class SubmissionFormWidget(QWidget):
|
||||
info[field] = value
|
||||
logger.debug(f"Info: {pformat(info)}")
|
||||
logger.debug(f"Reagents: {pformat(reagents)}")
|
||||
# sys.exit()
|
||||
# logger.debug(f"Attrs not in info: {[k for k, v in self.__dict__.items() if k not in info.keys()]}")
|
||||
for item in self.recover:
|
||||
if hasattr(self, item):
|
||||
info[item] = getattr(self, item)
|
||||
# app = self.parent().parent().parent().parent().parent().parent().parent().parent
|
||||
submission = PydSubmission(filepath=self.filepath, reagents=reagents, samples=self.samples, **info)
|
||||
# submission = PydSubmission(filepath=self.filepath, reagents=reagents, samples=self.samples, **info)
|
||||
submission = PydSubmission(reagents=reagents, **info)
|
||||
return submission
|
||||
|
||||
class InfoItem(QWidget):
|
||||
|
||||
Reference in New Issue
Block a user