Skip to content

Commit

Permalink
Do not allow to import sample sheet if not library kits are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
luissian committed May 17, 2024
1 parent ce12e20 commit 04aae94
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 208 deletions.
2 changes: 1 addition & 1 deletion test/test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -9165,7 +9165,7 @@
"model": "wetlab.runstates",
"pk": 2,
"fields": {
"run_state_name": "Recorded"
"run_state_name": "recorded"
}
},
{
Expand Down
7 changes: 7 additions & 0 deletions wetlab/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class AdditionaKitsLibraryPreparationAdmin(admin.ModelAdmin):
list_display = ["kit_name", "protocol_id", "commercial_kit_id"]


class LibraryKitAdmin(admin.ModelAdmin):
list_display = [
"library_name",
]


class AdditionalUserLotKitAdmin(admin.ModelAdmin):
list_display = ["lib_prep_id", "additional_lot_kits", "user_lot_kit_id"]

Expand Down Expand Up @@ -290,6 +296,7 @@ class RunConfigurationTestAdmin(admin.ModelAdmin):
admin.site.register(wetlab.models.RunErrors, RunErrorsAdmin)
admin.site.register(wetlab.models.RunStates, RunStatesAdmin)
admin.site.register(wetlab.models.LibPrepareStates, StatesForLibraryPreparationAdmin)
admin.site.register(wetlab.models.LibraryKit, LibraryKitAdmin)
admin.site.register(wetlab.models.PoolStates, StatesForPoolAdmin)
admin.site.register(wetlab.models.SamplesInProject, SamplesInProjectAdmin)
admin.site.register(wetlab.models.StatsRunSummary, StatsRunSummaryAdmin)
Expand Down
1 change: 1 addition & 0 deletions wetlab/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
"[Settings]",
"[I7]",
]
ERROR_NO_LIBRARY_KIT_DEFINED = ["Library Kits are not defined yet"]
##############################################################

MIGRATION_DIRECTORY_FILES = "wetlab/BaseSpaceMigrationFiles/"
Expand Down
2 changes: 1 addition & 1 deletion wetlab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def get_run_state_name(self):

class RunProcessManager(models.Manager):
def create_new_run_from_crontab(self, run_data):
run_state = RunStates.objects.get(run_state_name__exact="Recorded")
run_state = RunStates.objects.get(run_state_name__exact="recorded")
new_run = self.create(state=run_state, run_name=run_data["experiment_name"])
return new_run

Expand Down
427 changes: 258 additions & 169 deletions wetlab/templates/wetlab/create_next_seq_run.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions wetlab/utils/crontab_update_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def search_update_new_runs(request_reason):
logger.debug(
"%s : Found the experiment name called : %s", new_run, experiment_name
)
exclude_states = ["Error", "Recorded"]
exclude_states = ["Error", "recorded"]
if (
wetlab.models.RunProcess.objects.filter(run_name__exact=experiment_name)
.exclude(state__run_state_name__in=exclude_states)
Expand Down Expand Up @@ -417,9 +417,9 @@ def handle_not_completed_run():
runs_to_handle = {}

# state_list_be_processed = ['Sample Sent','Processing Run','Processed Run', 'Processing Bcl2fastq',
# 'Processed Bcl2fastq', 'Recorded']
# 'Processed Bcl2fastq', 'recorded']
state_list_be_processed = [
"Recorded",
"recorded",
"Sample Sent",
"Processing Run",
"Processed Run",
Expand All @@ -442,7 +442,7 @@ def handle_not_completed_run():

for state in runs_to_handle.keys():
logger.info("Start processing the run found for state %s", state)
if state == "Recorded":
if state == "recorded":
manage_run_in_recorded_state(conn, runs_to_handle[state])

elif state == "Sample Sent":
Expand Down
12 changes: 6 additions & 6 deletions wetlab/utils/fetch_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def graphics_state(state):
"""
state_list = [
"Error",
"Recorded",
"recorded",
"Sample Sent",
"Processing Run",
"Processed Run",
Expand Down Expand Up @@ -512,7 +512,7 @@ def get_information_for_incompleted_run():
"""
Description:
The function will get the information from the runs that are incompleted.
It creates a 4 groups. Recorded, Error, Canceled and rest of the states.
It creates a 4 groups. recorded, Error, Canceled and rest of the states.
Creates a pie graphic
Functions:
graphic_3D_pie # located at wetlab/utils/stats_graphics
Expand All @@ -522,11 +522,11 @@ def get_information_for_incompleted_run():
run_information = {}
today = datetime.today().date()
if wetlab.models.RunProcess.objects.filter(
state__run_state_name="Recorded"
state__run_state_name="recorded"
).exists():
run_information["recorded"] = []
run_objs = wetlab.models.RunProcess.objects.filter(
state__run_state_name="Recorded"
state__run_state_name="recorded"
).order_by("run_name")
for run_obj in run_objs:
data = []
Expand Down Expand Up @@ -577,7 +577,7 @@ def get_information_for_incompleted_run():
data.append(str((today - run_date).days))
run_information["cancelled"].append(data)

exclude_state = ["Recorded", "Error", "Cancelled", "Completed", "pre_recorded"]
exclude_state = ["recorded", "Error", "Cancelled", "Completed", "pre_recorded"]

if (
wetlab.models.RunProcess.objects.all()
Expand Down Expand Up @@ -685,7 +685,7 @@ def get_information_run(run_object):
return info_dict

# allow to change the run name in case that run state was recorded or Sample Sent
if run_state == "Recorded" or run_state == "Sample Sent":
if run_state == "recorded" or run_state == "Sample Sent":
info_dict["change_run_name"] = [
[run_object.get_run_name(), run_object.get_run_id()]
]
Expand Down
50 changes: 26 additions & 24 deletions wetlab/utils/samplesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,35 +373,37 @@ def get_projects_in_run(in_file: str) -> dict:
"""
header_found = False
projects = {}
fh = open(in_file, "r")
for line in fh:
line = line.rstrip()
if line == "":
continue
found_header = re.search("^Sample_ID,Sample_Name", line)
if found_header:
# found the index for projects and description
if not "Sample_Project" and "Description" not in line:
break
split_line = line.split(",")
p_index = split_line.index("Sample_Project")
description_index = split_line(",").index("Description")
header_found = True
continue
if header_found:
# ignore the empty lines separated by commas
valid_line = re.search("^\w+", line)
if not valid_line:
with open(in_file, "r") as fh:
for line in fh:
line = line.rstrip()
if line == "":
continue
# store the project name and the user name (Description) inside projects dict
projects[line.split(",")[p_index]] = line.split(",")[description_index]
fh.close()
if not found_header:
if not header_found:
header = re.search("^Sample_ID,Sample_Name", line)
if header:
# match line with the header
# look for projects and description indexes
if not "Sample_Project" and "Description" not in line:
break
split_line = line.split(",")
p_index = split_line.index("Sample_Project")
description_index = split_line.index("Description")
header_found = True
continue
else:
# ignore the empty lines separated by commas
valid_line = re.search("^\w+", line)
if not valid_line:
continue
# store the project name and the user name (Description) inside projects dict
projects[line.split(",")[p_index]] = line.split(",")[description_index]

if not header_found:
return {"ERROR": wetlab.config.ERROR_SAMPLE_SHEET_HAS_INVALID_HEADING}
if not projects:
return {"ERROR": wetlab.config.ERROR_SAMPLE_SHEET_DOES_NOT_HAVE_PROJECTS}

return {"projects": projects}
return projects


def get_index_library_name(in_file):
Expand Down
14 changes: 11 additions & 3 deletions wetlab/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ def create_nextseq_run(request):

# Check if the projects are already defined on database.
# Error page is showed if projects are already defined on database

project_already_defined = []
project_in_several_runs = wetlab.utils.common.get_configuration_value(
"PROJECTS_ALLOWED_IN_MULTIPLE_RUNS"
Expand All @@ -448,7 +447,7 @@ def create_nextseq_run(request):
return render(
request,
"wetlab/create_next_seq_run.html",
{"error_message": display_project + " already defined"},
{"error_message": [display_project, " already defined"]},
)

# Once the information looks good. it will be stores in runProcess and projects table
Expand Down Expand Up @@ -607,7 +606,16 @@ def create_nextseq_run(request):
"wetlab/create_next_seq_run.html",
{"completed_form": results},
)

# check if library kit is already defined
if len(wetlab.models.LibraryKit.objects.all()) == 0:
return render(
request,
"wetlab/create_next_seq_run.html",
{
"error_message": wetlab.config.ERROR_NO_LIBRARY_KIT_DEFINED,
"disable_submit_form": True,
},
)
return render(request, "wetlab/create_next_seq_run.html")


Expand Down

0 comments on commit 04aae94

Please sign in to comment.