Skip to content

Commit

Permalink
reorganisation of project selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Galithil committed Aug 22, 2016
1 parent adc5afc commit 6754e80
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 43 deletions.
70 changes: 35 additions & 35 deletions LIMS2DB/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,45 +715,45 @@ def get_library_preps(self, sample):
except AttributeError:
self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['sequencing_start_date']=seqstarts[0].createdddate.strftime("%Y-%m-%d")
self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['sample_run_metrics_id']=self.find_couch_sampleid(samp_run_met_id)
except:
self.log.info("no run id for sequencing process {}".format(seq.luid))
try:
self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['dillution_and_pooling_start_date']=dilstarts[0].daterun.strftime("%Y-%m-%d")
except IndexError:
self.log.info("no dilution found for sequencing {} of sample {}".format(seq.processid, sample.name))
#get the associated demultiplexing step
query="select pr.* from process pr \
inner join processiotracker piot on piot.processid=pr.processid \
where pr.typeid={dem} and piot.inputartifactid={iaid};".format(dem=pc_cg.DEMULTIPLEX.keys()[0], iaid=art.artifactid)
try:
dem=self.session.query(Process).from_statement(text(query)).one()
try:
self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['sequencing_run_QC_finished']=dem.daterun.strftime("%Y-%m-%d")
except AttributeError:
self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['sequencing_run_QC_finished']=dem.createddate.strftime("%Y-%m-%d")

#get output resultfile named like the sample of a Demultiplex step
query="select art.* from artifact art \
inner join artifact_sample_map asm on art.artifactid=asm.artifactid \
inner join outputmapping om on art.artifactid=om.outputartifactid \
inner join processiotracker piot on piot.trackerid=om.trackerid \
inner join sample sa on sa.processid=asm.processid \
where art.artifacttypeid = 1 and art.name like '%{saname}%'and sa.processid = {sapid} and piot.processid = {dem}".format(saname=sample.name, sapid=sample.processid, dem=dem.processid)
out_arts=self.session.query(Artifact).from_statement(text(query)).all()
cumulated_flag='FAILED'
for art in out_arts:
if art.qc_flag == 'PASSED':
cumulated_flag='PASSED'

self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['dem_qc_flag']=cumulated_flag

except NoResultFound:
self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['dillution_and_pooling_start_date']=dilstarts[0].daterun.strftime("%Y-%m-%d")
except IndexError:
self.log.info("no dilution found for sequencing {} of sample {}".format(seq.processid, sample.name))
#get the associated demultiplexing step
query="select pr.* from process pr \
inner join processiotracker piot on piot.processid=pr.processid \
where pr.typeid={dem} and piot.inputartifactid={iaid};".format(dem=pc_cg.DEMULTIPLEX.keys()[0], iaid=art.artifactid)
try:
self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['sequencing_run_QC_finished']=seq.daterun.strftime("%Y-%m-%d")
except AttributeError:
self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['sequencing_run_QC_finished']=seq.createddate.strftime("%Y-%m-%d")
dem=self.session.query(Process).from_statement(text(query)).one()
try:
self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['sequencing_run_QC_finished']=dem.daterun.strftime("%Y-%m-%d")
except AttributeError:
self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['sequencing_run_QC_finished']=dem.createddate.strftime("%Y-%m-%d")

#get output resultfile named like the sample of a Demultiplex step
query="select art.* from artifact art \
inner join artifact_sample_map asm on art.artifactid=asm.artifactid \
inner join outputmapping om on art.artifactid=om.outputartifactid \
inner join processiotracker piot on piot.trackerid=om.trackerid \
inner join sample sa on sa.processid=asm.processid \
where art.artifacttypeid = 1 and art.name like '%{saname}%'and sa.processid = {sapid} and piot.processid = {dem}".format(saname=sample.name, sapid=sample.processid, dem=dem.processid)
out_arts=self.session.query(Artifact).from_statement(text(query)).all()
cumulated_flag='FAILED'
for art in out_arts:
if art.qc_flag == 'PASSED':
cumulated_flag='PASSED'

self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['dem_qc_flag']=cumulated_flag

except NoResultFound:
try:
self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['sequencing_run_QC_finished']=seq.daterun.strftime("%Y-%m-%d")
except AttributeError:
self.obj['samples'][sample.name]['library_prep'][prepname]['sample_run_metrics'][samp_run_met_id]['sequencing_run_QC_finished']=seq.createddate.strftime("%Y-%m-%d")

self.log.info("no demultiplexing found for sample {}, sequencing {}".format(sample.name, seq.processid))
except:
self.log.info("no run id for sequencing process {}".format(seq.luid))

def extract_barcode(self, chain):
bcp=re.compile("[ATCG\-]{4,}")
Expand Down
28 changes: 20 additions & 8 deletions scripts/project_summary_upload_LIMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,32 @@ def main(options):
pj_id=lims_db.query(DBProject.luid).filter(DBProject.name == options.project_name).scalar()
P = ProjectSQL(lims_db, mainlog, pj_id, host, couch)
else :
projects=create_projects_list(options, mainlims, mainlog)
projects=create_projects_list(options, lims_db, mainlims, mainlog)
lims_db.commit()
lims_db.close()
masterProcess(options,projects, mainlims, mainlog)

def create_projects_list(options, lims, log):
def create_projects_list(options, db_session,lims, log):
projects=[]
if options.all_projects:
projects = lims.get_projects()
if options.hours:
postgres_string="{} hours".format(options.hours)
db_session=get_session()
project_ids=get_last_modified_projectids(db_session, postgres_string)
valid_projects=[Project(lims, id=x) for x in project_ids]
log.info("project list : {0}".format(" ".join([p.id for p in valid_projects])))
if options.old:
projects=lims.get_projects()
valid_projects=[Project(lims, id=x) for x in project_ids]
log.info("project list : {0}".format(" ".join([p.id for p in valid_projects])))
else:
valid_projects=db_session.query(DBProject).filter(DBProject.luid in project_ids)
log.info("project list : {0}".format(" ".join([p.luid for p in valid_projects])))
return valid_projects
else:
log.info("project list : {0}".format(" ".join([p.id for p in projects])))
if options.old:
projects=lims.get_projects()
log.info("project list : {0}".format(" ".join([p.id for p in projects])))
else:
projects = db_session.query(DBProject).all()
log.info("project list : {0}".format(" ".join([p.luid for p in projects])))
return projects

elif options.input:
Expand All @@ -163,6 +173,7 @@ def processPSUL(options, queue, logqueue):
proj_db = couch['projects']
samp_db = couch['samples']
mylims = Lims(BASEURI, USERNAME, PASSWORD)
db_session=get_session()
work=True
procName=mp.current_process().name
proclog=logging.getLogger(procName)
Expand Down Expand Up @@ -208,7 +219,6 @@ def processPSUL(options, queue, logqueue):
proclog.error("{0}:{1}\n{2}".format(error[0], error[1], formatStack(stack)))
else:
try:
db_session=get_session()
pj_id=db_session.query(DBProject.luid).filter(DBProject.name == projname).scalar()
host=get_configuration()['url']
P = ProjectSQL(db_session, proclog, pj_id, host, couch)
Expand All @@ -228,6 +238,8 @@ def processPSUL(options, queue, logqueue):

#signals to queue job is done
queue.task_done()
db_session.commit()
db_session.close()

def masterProcess(options,projectList, mainlims, logger):
projectsQueue=mp.JoinableQueue()
Expand Down

0 comments on commit 6754e80

Please sign in to comment.