Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented issue part 2 #267

Merged
merged 38 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
684b80d
implemented issue #256 The install scirpt does not create the logs sy…
luissian May 1, 2024
b96dbcb
check if pending migrations exist
luissian May 4, 2024
cbeb98d
added in menu the option for laboratory statisitics
luissian May 5, 2024
b5af725
Displayed recorded samples per researcher
luissian May 5, 2024
76e08cb
added recorded samples vs other researchers
luissian May 5, 2024
40779d0
Implemented sample states graphic
luissian May 5, 2024
d4d1e90
litin
luissian May 5, 2024
f28e46f
fetching lab list to use in form
luissian May 5, 2024
58e9304
Included samples from lab
luissian May 6, 2024
f8c34e0
included state samples in lab
luissian May 6, 2024
933e7d6
included samples in lab vs others
luissian May 6, 2024
6cbb37d
litin
luissian May 6, 2024
77fc0cb
Added the remining graphics for lob
luissian May 8, 2024
3d5432f
Solved issue #266 Too many emails are sent during crontab process
luissian May 8, 2024
437ac5b
corrected litin
luissian May 8, 2024
3d09e7e
included additional field at RunStates
luissian May 8, 2024
b8e2770
Set the cancelled state when run is cancelled
luissian May 17, 2024
a368724
change Pre-Recorded state to snake style
luissian May 17, 2024
ae1181a
Fixed bug after changed the relation of library_pool-runprocess to ma…
luissian May 17, 2024
6d6501d
Update initial tables with run states
luissian May 17, 2024
0c85ca6
Display error when sample sheet has an invalid heading
luissian May 17, 2024
0cf7681
fixing litin
luissian May 17, 2024
cafaead
Do not allow to import sample sheet if not library kits are defined
luissian May 17, 2024
b295f2b
Changes in run state values from issue #260
luissian May 18, 2024
85461c1
Fixed error messages display
luissian May 18, 2024
b6fafd9
added num samples per run and pending changes
luissian May 22, 2024
3a128e9
fixed litin
luissian May 22, 2024
20e19c3
added num samples per lab statistics
luissian May 22, 2024
7895a6c
added checking to allow or not repeated sample names
luissian May 25, 2024
f2f184d
fixin lint
luissian May 25, 2024
0c608e0
Implement in api that samples cannot be repeated
luissian May 25, 2024
0eb8a24
Changed sample name to lowercase to compare with the exisiting samples
luissian May 25, 2024
b9445ac
fixed small issue on import lower function
luissian May 25, 2024
98bb6b8
Added analyzed samples in run graphic
luissian Jun 9, 2024
06768e6
Completed graphic statistics for drylab
luissian Jun 9, 2024
56ac27a
litin
luissian Jun 9, 2024
315eeb1
Changes because PR review
luissian Jun 10, 2024
8fe782c
removed spare values on run states
luissian Jun 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
91 changes: 67 additions & 24 deletions conf/first_install_tables.json
Original file line number Diff line number Diff line change
Expand Up @@ -1512,84 +1512,100 @@
"model": "wetlab.runstates",
"pk": 1,
"fields": {
"run_state_name": "Pre-Recorded"
"run_state_name": "pre_recorded",
"state_display": "Pre Recorded",
"description": "Run name is defined but pending for input data.",
"show_in_stats": false
}
},
{
"model": "wetlab.runstates",
"pk": 2,
"fields": {
"run_state_name": "Recorded"
"run_state_name": "recorded",
"state_display": "Recorded",
"description": "Run name is defined.",
"show_in_stats": true
}
},
{
"model": "wetlab.runstates",
"pk": 3,
"fields": {
"run_state_name": "Sample Sent"
"run_state_name": "sample_sent",
"state_display": "Sample Sent",
"description": "Run has copied sample sheet on remote server.",
"show_in_stats": false
}
},
{
"model": "wetlab.runstates",
"pk": 4,
"fields": {
"run_state_name": "Processing Run"
"run_state_name": "processing_run",
"state_display": "Processing Run",
"description": "Run is handled on the sequencer.",
"show_in_stats": false
}
},
{
"model": "wetlab.runstates",
"pk": 5,
"fields": {
"run_state_name": "Processed Run"
"run_state_name": "processed_run",
"state_display": "Processed Run",
"description": "Run is already processed on sequencer.",
"show_in_stats": false
}
},
{
"model": "wetlab.runstates",
"pk": 6,
"fields": {
"run_state_name": "Processing Bcl2fastq"
"run_state_name": "processing_bcl2fastq",
"state_display": "Processing Bcl2fastq",
"description": "Bcl2fastq is running",
"show_in_stats": false
}
},
{
"model": "wetlab.runstates",
"pk": 7,
"fields": {
"run_state_name": "Processed Bcl2fastq"
"run_state_name": "processed_bcl2fastq",
"state_display": "Processed Bcl2fastq",
"description": "Bcl2fastq already completed",
"show_in_stats": true
}
},
{
"model": "wetlab.runstates",
"pk": 8,
"fields": {
"run_state_name": "Completed"
"run_state_name": "completed",
"state_display": "Completed",
"description": "Run is completed and all processes are finished.",
"show_in_stats": false
}
},
{
"model": "wetlab.runstates",
"pk": 9,
"fields": {
"run_state_name": "Cancelled"
"run_state_name": "cancelled",
"state_display": "Cancelled",
"description": "Run was manually cancelled while running on sequencer.",
"show_in_stats": true
}
},
{
"model": "wetlab.runstates",
"pk": 10,
"fields": {
"run_state_name": "Error"
}
},
{
"model": "wetlab.runstates",
"pk": 11,
"fields": {
"run_state_name": "Processing Metrics"
}
},
{
"model": "wetlab.runstates",
"pk": 12,
"fields": {
"run_state_name": "Processing Demultiplexing"
"run_state_name": "error",
"state_display": "Error",
"description": "There was an issue while processing the run",
"show_in_stats": true
}
},
{
Expand Down Expand Up @@ -1996,6 +2012,33 @@
"generated_at": "2021-01-28T22:59:03.042"
}
},
{
"model": "wetlab.configsetting",
"pk": 15,
"fields": {
"configuration_name": "ALLOW_REPEAT_SAMPLE_NAMES",
"configuration_value": "FALSE",
"generated_at": "2024-05-28T22:59:03.142"
}
},
{
"model": "wetlab.configsetting",
"pk": 16,
"fields": {
"configuration_name": "ALLOW_REPEAT_SAMPLE_NAMES_PER_RESEARCHER",
"configuration_value": "FALSE",
saramonzon marked this conversation as resolved.
Show resolved Hide resolved
"generated_at": "2024-05-28T22:59:04.042"
}
},
{
"model": "wetlab.configsetting",
"pk": 17,
"fields": {
"configuration_name": "ALLOW_SAMPLE_NAMES_WITH_UNDERSCORE",
"configuration_value": "FALSE",
"generated_at": "2024-05-28T22:59:05.042"
}
},
{
"model": "wetlab.collectionindexvalues",
"pk": 2073,
Expand Down
66 changes: 37 additions & 29 deletions core/utils/graphics.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
def preparation_3D_pie(heading, sub_title, theme, source_data):
"""_summary_
def preparation_3D_pie(
heading: str, sub_title: str, theme: str, source_data: dict
) -> dict:
"""Join the parameters to create a dictionary with two keys: chart and data.
The chart key contains the heading, sub_title, theme, numberPrefix, showlegend, placevaluesInside, showpercentvalues, rotatevalues, showCanvasBg, showCanvasBase, canvasBaseDepth, canvasBgDepth, canvasBaseColor, canvasBgColor, exportEnabled.
The data key contains a list of dictionaries with the keys label and value.

Parameters
----------
heading : str
text to insert on top of graphic
sub_title : str
additional text to include in graphic
axis_x_description : str
description of x axis
axis_y_description : str
description
theme : str
name of the available themes to be used for the graphic
source_data : dict
Dictionary containing value for the graphic
Args:
heading (str): title of the chart
sub_title (str): additional information
theme (str): theme of the chart
source_data (dict): dictionary with the data to be displayed

Returns
-------
_type_
_description_
Returns:
dict: dictionary with the keys chart and data
"""
data_source = {}
data_source["chart"] = {
Expand Down Expand Up @@ -58,15 +51,30 @@ def preparation_3D_pie(heading, sub_title, theme, source_data):


def preparation_graphic_data(
heading,
sub_caption,
x_axis_name,
y_axis_name,
theme,
input_data,
label_key=None,
label_value=None,
):
heading: str,
sub_caption: str,
x_axis_name: str,
y_axis_name: str,
theme: str,
input_data: dict,
label_key: str = None,
label_value: str = None,
) -> dict:
"""Join the parameters to create a dictionary with two keys: chart and data.

Args:
heading (str): heading of the chart
sub_caption (str): sub_caption of the chart
x_axis_name (str): name of the x axis
y_axis_name (str): name of the y axis
theme (str): theme of the chart
input_data (dict): data to be displayed
label_key (str, optional): key name from the input dict. Defaults to None.
label_value (str, optional): value field in the innput dict. Defaults to None.

Returns:
dict: dictionary with the keys chart and data
"""
data_source = {}
data_source["chart"] = {
"caption": heading,
Expand Down
55 changes: 42 additions & 13 deletions core/utils/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from django.contrib.auth.models import User
from django.db.models import CharField, Count, F, Func, Prefetch, Value
from django.db.models.functions import Lower

# Local imports
import core.core_config
Expand Down Expand Up @@ -193,20 +194,24 @@ def save_recorded_samples(samples_data, req_user, app_name):
return samples_data


def validate_sample_data(sample_data, req_user, app_name):
"""Sample data validation
def validate_sample_data(
sample_data: json,
req_user: str,
app_name: str,
repeat_allowed: bool = False,
allow_user_repeat: bool = False,
) -> tuple:
"""sample data validation

Parameters
----------
sample_data
sample data formatted in json obtained from jspreadsheet
req_user
requesting user
app_name
application name (wetlab, drylab, core, etc.)
Args:
sample_data (json): sample data formatted in json obtained from jspreadsheet
req_user (str): requested user name
app_name (str): application name (wetlab, drylab, core, etc.)
repeat_allowed (bool, optional): allow or not that sample can be repeated. Defaults to False.
allow_user_repeat (bool, optional): if allowed to be repeated check if same request user is allowed have repeated sample names. Defaults to False.

Returns
-------
Returns:
tuple: returns result as boolean and a dictionary with the following keys
validation
list with validation info for each sample with format:
[{"Sample Name": "test 01",
Expand All @@ -222,6 +227,27 @@ def validate_sample_data(sample_data, req_user, app_name):
sample_name_list = []
line = 0
result = True
not_allowed_sample_names = {}
# collect the sample names already in the database in case that the user
# is not allowed to repeat
if not repeat_allowed:
if not allow_user_repeat:
if core.models.Samples.objects.filter(
sample_user__username__exact=req_user
).exists():
existing_sample_name_list = list(
core.models.Samples.objects.filter(
sample_user__username__iexact=req_user
).values_list("sample_name", flat=True)
)
else:
existing_sample_name_list = list(
core.models.Samples.objects.all().values_list(
Lower("sample_name", flat=True)
)
)
# convert to dict to speed up the search
not_allowed_sample_names = dict.fromkeys(existing_sample_name_list, 0)
for sample in sample_data:
line += 1
sample_dict = {}
Expand All @@ -237,7 +263,10 @@ def validate_sample_data(sample_data, req_user, app_name):
validation.append(sample_dict)
continue

if sample["sample_name"] not in sample_name_list:
if repeat_allowed or (
sample["sample_name"].lower() not in sample_name_list
and sample["sample_name"].lower() not in not_allowed_sample_names
):
sample_name_list.append(sample["sample_name"])
else:
error_cause = core.core_config.ERROR_REPEATED_SAMPLE_NAME.copy()
Expand Down