Skip to content

Commit 5848ddf

Browse files
authored
Merge pull request #88 from aanil/master
Add script to update project closure in bioinfo_analysis db
2 parents ce56a3e + 5afae8a commit 5848ddf

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import os
5+
import yaml
6+
from genologics.lims import Lims
7+
from genologics.entities import Project
8+
from genologics.config import BASEURI, USERNAME, PASSWORD
9+
import LIMS2DB.utils as lutils
10+
from requests.exceptions import HTTPError
11+
12+
13+
def main(args):
14+
log = lutils.setupLog('bioinfologger', args.logfile)
15+
lims = Lims(BASEURI, USERNAME, PASSWORD)
16+
with open(args.conf) as conf_file:
17+
conf = yaml.safe_load(conf_file)
18+
bioinfodb = lutils.setupServer(conf)['bioinfo_analysis']
19+
open_projects = bioinfodb.view('latest_data/sample_id_open')
20+
21+
for row in open_projects.rows:
22+
project_id = row.key[0]
23+
sample_id = row.key[3]
24+
close_date = None
25+
try:
26+
close_date = Project(lims=lims, id=project_id).close_date
27+
except HTTPError as e:
28+
if '404: Project not found' in e.message:
29+
log.error('Project '+project_id+' not found in LIMS')
30+
continue
31+
if close_date is not None:
32+
try:
33+
doc = bioinfodb.get(row.id)
34+
except Exception as e:
35+
log.error(e + 'in Project '+project_id+ ' Sample '+sample_id+ ' while accessing doc from statusdb')
36+
doc['project_closed'] = True
37+
try:
38+
bioinfodb.save(doc)
39+
log.info('Updated Project '+project_id+ ' Sample '+sample_id)
40+
except Exception as e:
41+
log.error(e + 'in Project '+project_id+ ' Sample '+sample_id+ ' while saving to statusdb')
42+
43+
44+
45+
if __name__ == '__main__':
46+
usage = "Usage: python bioinfo_project_status_update.py [options]"
47+
parser = argparse.ArgumentParser(description=usage)
48+
49+
parser.add_argument("-c", "--conf", dest="conf",
50+
default=os.path.join(os.environ['HOME'],'opt/config/post_process.yaml'),
51+
help = "Config file. Default: ~/opt/config/post_process.yaml")
52+
53+
parser.add_argument("-l", "--log", dest="logfile",
54+
default=os.path.join(os.environ['HOME'],'statusdb_bioinfo_closed.log'),
55+
help = "log file. Default: ~/statusdb_bioinfo_closed.log")
56+
args = parser.parse_args()
57+
58+
main(args)

0 commit comments

Comments
 (0)