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

Improve project validator EPP #375

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions VERSIONLOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Scilifelab_epps Version Log

## 20241015.1

Improve project validator EPP

## 20241011.1

New project validator EPP
Expand Down
29 changes: 14 additions & 15 deletions scripts/project_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@
# Verify sample IDs
def verify_sample_ids(project_id):
message = []
connection = psycopg2.connect(
user=config["username"],
host=config["url"],
database=config["db"],
password=config["password"],
)
cursor = connection.cursor()
# Query sample names with given project luid
query = (
"select sample.name from sample "
"inner join project on sample.projectid=project.projectid "
"where project.luid = '{}';"
"where project.luid = %s;"
)
cursor.execute(query.format(project_id))
query_output = cursor.fetchall()
with psycopg2.connect(
user=config["username"],
host=config["url"],
database=config["db"],
password=config["password"],
) as connection:
with connection.cursor() as cursor:
cursor.execute(query, (project_id,))
query_output = cursor.fetchall()

# Validate sample name format
for out in query_output:
sample_id = out[0]
if not NGISAMPLE_PAT.findall(sample_id):
Expand All @@ -49,11 +51,6 @@ def verify_sample_ids(project_id):
f"SAMPLE NAME WARNING: Sample ID {sample_id} does not match project ID {project_id}"
)

# Close connections
if connection:
cursor.close()
connection.close()

return message


Expand All @@ -65,6 +62,8 @@ def main(lims, pid):
message += verify_sample_ids(project.id)

if message:
print(f"No issue detected for project {pid}")
else:
sys.stderr.write("; ".join(message))
sys.exit(2)

Expand Down
Loading