Skip to content

Commit

Permalink
Merge pull request #88 from aanil/master
Browse files Browse the repository at this point in the history
Add script to update project closure in bioinfo_analysis db
  • Loading branch information
chuan-wang authored Jul 30, 2020
2 parents ce56a3e + 5afae8a commit 5848ddf
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions scripts/bioinfo_project_status_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python

import argparse
import os
import yaml
from genologics.lims import Lims
from genologics.entities import Project
from genologics.config import BASEURI, USERNAME, PASSWORD
import LIMS2DB.utils as lutils
from requests.exceptions import HTTPError


def main(args):
log = lutils.setupLog('bioinfologger', args.logfile)
lims = Lims(BASEURI, USERNAME, PASSWORD)
with open(args.conf) as conf_file:
conf = yaml.safe_load(conf_file)
bioinfodb = lutils.setupServer(conf)['bioinfo_analysis']
open_projects = bioinfodb.view('latest_data/sample_id_open')

for row in open_projects.rows:
project_id = row.key[0]
sample_id = row.key[3]
close_date = None
try:
close_date = Project(lims=lims, id=project_id).close_date
except HTTPError as e:
if '404: Project not found' in e.message:
log.error('Project '+project_id+' not found in LIMS')
continue
if close_date is not None:
try:
doc = bioinfodb.get(row.id)
except Exception as e:
log.error(e + 'in Project '+project_id+ ' Sample '+sample_id+ ' while accessing doc from statusdb')
doc['project_closed'] = True
try:
bioinfodb.save(doc)
log.info('Updated Project '+project_id+ ' Sample '+sample_id)
except Exception as e:
log.error(e + 'in Project '+project_id+ ' Sample '+sample_id+ ' while saving to statusdb')



if __name__ == '__main__':
usage = "Usage: python bioinfo_project_status_update.py [options]"
parser = argparse.ArgumentParser(description=usage)

parser.add_argument("-c", "--conf", dest="conf",
default=os.path.join(os.environ['HOME'],'opt/config/post_process.yaml'),
help = "Config file. Default: ~/opt/config/post_process.yaml")

parser.add_argument("-l", "--log", dest="logfile",
default=os.path.join(os.environ['HOME'],'statusdb_bioinfo_closed.log'),
help = "log file. Default: ~/statusdb_bioinfo_closed.log")
args = parser.parse_args()

main(args)

0 comments on commit 5848ddf

Please sign in to comment.