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

Add queries to get current step a sample is in #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 30 additions & 1 deletion genologics_sql/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def get_all_samples_in_a_workflow(session, workflow):
labworkflow lwf, artifact_sample_map asm, sample sa \
where st.stageid=stg.stageid and stg.membershipid=wfs.sectionid \
and wfs.workflowid=lwf.workflowid and wfs.protocolid=lpt.protocolid \
and st.artifactid=asm.artifactid and asm.processid=sa.processid and st.completedbyid is null \
and st.artifactid=asm.artifactid and asm.processid=sa.processid and st.workflowrunid > 0 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain this one? It feels a bit out of context?

and lwf.workflowstatus='ACTIVE' and lwf.workflowname='{workflow}';"

return session.execute(text(query)).all()
Expand Down Expand Up @@ -333,3 +333,32 @@ def get_reagentlabel_for_sample(session, sampleid):
and sa.name=art.name and sa.sampleid={sampleid};"

return session.execute(text(query)).all()


def get_currentsteps_protocol_for_sample(session, sampleid):
"""returns the current protocolstep and protocol for a sample

:param session: the current SQLAlchemy session to the db
:param sampleid: sampleid from sample table
:returns: all protocolstep ids a sample is in
"""
query = f"select distinct(sc.stepid) \
from samplecheckout sc, artifact_sample_map asm, sample sa, stagetransition st \
where sc.artifactid=asm.artifactid and asm.processid=sa.processid and asm.artifactid=st.artifactid \
and st.workflowrunid>0 and sa.sampleid={sampleid};"

return session.execute(text(query)).all()


def get_protocolstep_details(session, stepid):
"""returns the name of the protocolstep

:param session: the current SQLAlchemy session to the db
:param stepid: the id of the protocolstep
:returns: protocolstep name
"""
query = f"select ps.name, lp.protocolname, lp.qcprotocol \
from protocolstep ps, labprotocol lp \
where ps.protocolid=lp.protocolid and ps.stepid={stepid};"

return session.execute(text(query)).all()
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from setuptools import setup, find_packages
import sys, os
import os
import subprocess
import glob

Expand Down Expand Up @@ -44,7 +44,7 @@
author_email='[email protected]',
maintainer='Denis Moreno',
maintainer_email='[email protected]',
url='https://github.com/SciLifeLab/genologics_sql',
url='https://github.com/NationalGenomicsInfrastructure/genologics_sql',
license='MIT',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
scripts=glob.glob("scripts/*.py"),
Expand Down