Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ruff formatting
Browse files Browse the repository at this point in the history
kedhammar committed Oct 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f87693d commit 7bd7dec
Showing 26 changed files with 434 additions and 293 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
"""Setup file and install script SciLife python scripts.
"""
"""Setup file and install script SciLife python scripts."""

from setuptools import find_packages, setup

try:
8 changes: 4 additions & 4 deletions status/applications.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Handlers related to applications
"""
"""Handlers related to applications"""

import json
from collections import Counter

@@ -78,7 +78,7 @@ def list_applications_and_samples(self, start=None, end="z"):
# Projects per application
applications = Counter()
view = self.application.projects_db.view("project/date_applications")
for row in view[[start, ""]:[end, "z"]]:
for row in view[[start, ""] : [end, "z"]]:
if row.key[1] is None:
# This corresponds to StatusDB:s notation
# and avoids conflict with 'None'.
@@ -89,7 +89,7 @@ def list_applications_and_samples(self, start=None, end="z"):
# Samples per application
samples = Counter()
view = self.application.projects_db.view("project/date_samples_applications")
for row in view[[start, ""]:[end, "z"]]:
for row in view[[start, ""] : [end, "z"]]:
if row.key[1] is None:
samples["null"] += row.value
else:
11 changes: 3 additions & 8 deletions status/barcode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Handlers related to test for barcode printing
"""
"""Handlers related to test for barcode printing"""

import re
import subprocess
@@ -52,9 +51,7 @@ def post(self):
for _ in range(copies): # loops over copies to print
print_barcode(linesToPrint)
else: # file submitted is a text file
for (
line
) in (
for line in (
linesToPrint.splitlines()
): # split into the different lines of the text file
if self.get_argument(
@@ -112,9 +109,7 @@ def post(self):
if re.compile(r"^P\d+$").search(user_project_ID):
projectNo_only_extracted = re.search(
"P(.*)", user_project_ID
).group(
1
) # have only the number of the project ID
).group(1) # have only the number of the project ID
for projects in range(0, int(projectNo)):
new_projectNo = int(projectNo_only_extracted) + projects
new_projectID = "P" + str(new_projectNo)
14 changes: 7 additions & 7 deletions status/bioinfo_analysis.py
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ def post(self, project_id):
assert_project_id(project_id)
# Fetching documents one by one generates too many requests to statusdb
# Hopefully fetching all documents at once doesn't require too much memory
view = v[[project_id, "", "", ""]:[project_id, "Z", "Z", "Z"]]
view = v[[project_id, "", "", ""] : [project_id, "Z", "Z", "Z"]]
cached_view = {}
for row in view.rows:
if tuple(row.key) in cached_view:
@@ -117,9 +117,9 @@ def get(self, project_id):
"lanes": {lane_id: bioinfo_qc}
}
elif lane_id not in bioinfo1[sample_id]["flowcells"][flowcell_id]["lanes"]:
bioinfo1[sample_id]["flowcells"][flowcell_id]["lanes"][
lane_id
] = bioinfo_qc
bioinfo1[sample_id]["flowcells"][flowcell_id]["lanes"][lane_id] = (
bioinfo_qc
)
else:
bioinfo1[sample_id]["flowcells"][flowcell_id]["lanes"][lane_id].update(
bioinfo_qc
@@ -136,9 +136,9 @@ def get(self, project_id):
"samples": {sample_id: bioinfo_qc}
}
elif sample_id not in bioinfo2[flowcell_id]["lanes"][lane_id]["samples"]:
bioinfo2[flowcell_id]["lanes"][lane_id]["samples"][
sample_id
] = bioinfo_qc
bioinfo2[flowcell_id]["lanes"][lane_id]["samples"][sample_id] = (
bioinfo_qc
)
else:
bioinfo2[flowcell_id]["lanes"][lane_id]["samples"][sample_id].update(
bioinfo_qc
99 changes: 63 additions & 36 deletions status/clone_project.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


import requests
from genologics import lims
from genologics.config import BASEURI, PASSWORD, USERNAME
@@ -21,58 +19,86 @@ def get(self):
)
)


class LIMSProjectCloningHandler(SafeHandler):
"""Gets and posts the project data from LIMS for cloning it
URL: /api/v1/lims_project_data/([^/]*)$
"""

def get(self, projectid):

proj_values = self.get_project_data(projectid, 'get')
proj_values = self.get_project_data(projectid, "get")
if not proj_values:
self.set_status(404)
self.write({"error": "Project not found"})
return
self.set_header("Content-type", "application/json")
self.write(proj_values)

def post(self, projectid):

if not (self.get_current_user().is_proj_coord or self.get_current_user().is_any_admin):
if not (
self.get_current_user().is_proj_coord
or self.get_current_user().is_any_admin
):
self.set_status(401)
return self.write(
"Error: You do not have the permissions for this operation!"
)
new_proj = self.get_project_data(projectid, 'post')
if 'error' in new_proj:

new_proj = self.get_project_data(projectid, "post")
if "error" in new_proj:
self.set_status(400)
self.write({"error": new_proj['error']})
self.write({"error": new_proj["error"]})
return

self.set_status(201)
self.write(new_proj)

def get_project_data(self, projectid, type):
copy_udfs = {
"Customer project reference", "Project Comment", "Type", "Application", "Reference genome",
"Library construction method", "Sequencing setup", "Accredited (Data Analysis)",
"Accredited (Data Processing)", "Accredited (Library Preparation)", "Accredited (Sequencing)", "Delivery type",
"Agreement cost", "Invoice Reference", "Customer Project Description", "Project category", "Sample type",
"Sample units ordered", "Library type (ready-made libraries)", "Sequence units ordered (lanes)", "Sequencing platform",
"Flowcell", "Custom Primer", "Low Diversity", "Best practice bioinformatics", "Funding agency", "Project coordinator",
"Library prep option", "Flowcell", "Organism", "PhiX spike-in (percent)", "Flowcell option", "Ethics permit number"
}
"Customer project reference",
"Project Comment",
"Type",
"Application",
"Reference genome",
"Library construction method",
"Sequencing setup",
"Accredited (Data Analysis)",
"Accredited (Data Processing)",
"Accredited (Library Preparation)",
"Accredited (Sequencing)",
"Delivery type",
"Agreement cost",
"Invoice Reference",
"Customer Project Description",
"Project category",
"Sample type",
"Sample units ordered",
"Library type (ready-made libraries)",
"Sequence units ordered (lanes)",
"Sequencing platform",
"Flowcell",
"Custom Primer",
"Low Diversity",
"Best practice bioinformatics",
"Funding agency",
"Project coordinator",
"Library prep option",
"Flowcell",
"Organism",
"PhiX spike-in (percent)",
"Flowcell option",
"Ethics permit number",
}

lims_instance = lims.Lims(BASEURI, USERNAME, PASSWORD)
uri = lims_instance.get_uri(f"projects/{projectid}")
existing_project = Project(lims=lims_instance, uri=uri)
proj_values = {}
try:
proj_values['name'] = existing_project.name
proj_values["name"] = existing_project.name
except requests.exceptions.HTTPError:
return {}

proj_values["researcher_id"] = existing_project.researcher.id
proj_values["Client"] = existing_project.researcher.name
proj_values["Account"] = existing_project.researcher.lab.name
@@ -81,25 +107,26 @@ def get_project_data(self, projectid, type):
for udf in copy_udfs:
if udf in existing_project.udf:
udfs[udf] = existing_project.udf[udf]
proj_values['udfs'] = udfs
proj_values["udfs"] = udfs

if type=='get':
if type == "get":
return proj_values

else:
new_name = existing_project.name + '_CLONE'
new_name = existing_project.name + "_CLONE"
check_if_new_name_exists = lims_instance.get_projects(name=new_name)

if check_if_new_name_exists:
return {'error': f'A project with the name {new_name} already exists'}
return {"error": f"A project with the name {new_name} already exists"}

try:
new_project = Project.create(lims_instance, udfs=proj_values['udfs'], name=new_name,
researcher=existing_project.researcher)
new_project = Project.create(
lims_instance,
udfs=proj_values["udfs"],
name=new_name,
researcher=existing_project.researcher,
)
except requests.exceptions.HTTPError as e:
return {'error': e.message}

return {'project_id': new_project.id, 'project_name': new_project.name}


return {"error": e.message}

return {"project_id": new_project.id, "project_name": new_project.name}
Loading

0 comments on commit 7bd7dec

Please sign in to comment.