-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadAseqsJson.py
executable file
·82 lines (66 loc) · 1.58 KB
/
loadAseqsJson.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python3
import os
import sys
from pymongo import MongoClient
import json
import datetime
from Common import *
usage = """
Usage: $0 <database json>
<database json> should consist of an entire json object per line
Loads into the aseqs collection.
-id "TheId" cross reference identifier: gi uni ENS
"""
g_File = sys.argv[1]
if '-col' in sys.argv:
col = sys.argv[sys.argv.index('-col') + 1]
else:
print("-col not given")
sys.exit()
aseqs = seqdepotDB[col]
if '-id' in sys.argv:
identifier = sys.argv[sys.argv.index('-id') + 1]
cross = 1
else:
cross = 0
if '--meta' in sys.argv:
metaFlag = 1
else:
metaFlag = 0
#identifier = sys.argv[2]
if not g_File:
print("No input")
sys.exit()
count = 0;
ptime = datetime.time
#print(ptime)
filein = open(g_File,"r");
for line in filein:
# print(line.split('\t')[1])
myjson = json.loads(line.split('\t')[1])
#print("hey");
# my $son = substr($json,23);
# print($son);
# $json = $son;
#my $aseq = from_json(substr($json,23));
#print("$aseq->{_id}\n");
count += 1
foundAseq = aseqs.find_one({"_id":myjson["_id"]})
if foundAseq:
#print(foundAseq["_id"])
addedDict = {}
#if ((not metaFlag) and ('m' in foundAseq.keys()) and (foundAseq["m"]==1)):
# aseqs.update({"_id":myjson["_id"]},{"$set":{"m":0}})
if cross == 1:
theXfield = "x." + identifier
for idElement in myjson["x"][identifier]:
aseqs.update({"_id":myjson["_id"]},{"$addToSet":{theXfield:idElement}})
else:
print(count)
#print(".")
if metaFlag:
myjson["m"] = 1
else:
myjson["m"] = 0
#print(myjson)
aseqs.insert(myjson)