Skip to content

Commit

Permalink
Merge branch 'aviti-manifest-dev' of github.com:kedhammar/scilifelab_…
Browse files Browse the repository at this point in the history
…epps into aviti-manifest-dev
  • Loading branch information
kedhammar committed Oct 14, 2024
2 parents 6ef71b7 + 8590674 commit a8a6e21
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
4 changes: 4 additions & 0 deletions VERSIONLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

For AVITI manifest generation: make PhiX manifest variant, fix udf typo, remove unused func, clarify var names

## 20241011.1

New project validator EPP

## 20241009.1

Improve AVITI run manifest generation with sample-level settings. No longer produce submanifests.
Expand Down
79 changes: 79 additions & 0 deletions scripts/project_validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python

import re
import sys
from argparse import ArgumentParser

import psycopg2
import yaml
from genologics.config import BASEURI, PASSWORD, USERNAME
from genologics.entities import Project
from genologics.lims import Lims

with open("/opt/gls/clarity/users/glsai/config/genosqlrc.yaml") as f:
config = yaml.safe_load(f)

DESC = """EPP used to validate a project
Author: Chuan Wang, Science for Life Laboratory, Stockholm, Sweden
"""

# Pre-compile regexes in global scope:
NGISAMPLE_PAT = re.compile("P[0-9]+_[0-9]+")


# 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 = (
"select sample.name from sample "
"inner join project on sample.projectid=project.projectid "
"where project.luid = '{}';"
)
cursor.execute(query.format(project_id))
query_output = cursor.fetchall()

for out in query_output:
sample_id = out[0]
if not NGISAMPLE_PAT.findall(sample_id):
message.append(f"SAMPLE NAME WARNING: Bad sample ID format {sample_id}")
else:
if sample_id.split("_")[0] != project_id:
message.append(
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


def main(lims, pid):
message = []
project = Project(lims, id=pid)

# Validate sample IDs
message += verify_sample_ids(project.id)

if message:
sys.stderr.write("; ".join(message))
sys.exit(2)


if __name__ == "__main__":
parser = ArgumentParser(description=DESC)
parser.add_argument("--pid", help="Project ID for current Project")
args = parser.parse_args()

lims = Lims(BASEURI, USERNAME, PASSWORD)
lims.check_version()
main(lims, args.pid)

0 comments on commit a8a6e21

Please sign in to comment.