-
Notifications
You must be signed in to change notification settings - Fork 1
/
rm-func-from-obs-prot.py
55 lines (48 loc) · 1.38 KB
/
rm-func-from-obs-prot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import csv, os, json, argparse, sys
"""
For all molfunc statements on obsolete proteins:
remove them
"""
# Initiate the parser
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--output_qs", help="output to QS",
action="store_true")
parser.add_argument("-q", "--query", help="perform SPARQL query",
action="store_true")
# Read arguments from the command line
args = parser.parse_args()
# Check for --version or -V
QS = args.output_qs
dontquery = not args.query
script = os.path.basename(sys.argv[0])[:-3]
if dontquery is False:
print('performing query...')
ret = os.popen('wd sparql {}.rq >{}.json'.format(script, script))
if ret.close() is not None:
raise
file = open('{}.json'.format(script))
s = file.read()
jol = json.loads(s)
qhash = {}
for d in jol:
qit = d.get('p')
stmt = d.get('stmt')
if QS:
print('no longer implemented')
else:
s = qhash.get(qit)
if s is None:
qhash[qit] = [stmt]
else:
s.append(stmt)
if not QS:
for qit in qhash.keys():
claims = qhash.get(qit)
s = "'" + claims[0] + "'"
if len(claims) > 1:
for c in claims[1:]:
s = s + " '" + c + "'"
print('{} remove {}'.format(qit, s))
ret = os.popen("wd rc {} >{}.err".format(s, script))
if ret.close() is not None:
print('ERROR')