forked from Galithil/LIMS2DB
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from aanil/master
Add script to update project closure in bioinfo_analysis db
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |