-
Notifications
You must be signed in to change notification settings - Fork 5
/
qryinterpro.py
executable file
·40 lines (36 loc) · 1.29 KB
/
qryinterpro.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
#!/usr/bin/env python
""" Query InterPro data indexed with MongoDB """
from nosqlbiosets.qryutils import Query
class QueryInterPro(Query):
def id2names(self, ids):
assert self.dbc.db == "MongoDB"
qc = [
{"$match":
{"$or": [
{"external_doc_list.db_xref": {
'$elemMatch': {"dbkey": {"$in": list(ids)}
}}},
{"member_list.db_xref.dbkey": {"$in": list(ids)}
}
]}},
{"$facet": {
"external": [
{"$unwind": "$external_doc_list.db_xref"},
{"$project": {
"_id": "$external_doc_list.db_xref.dbkey",
"name": "$name"}}
],
"member": [
{"$unwind": "$member_list.db_xref"},
{"$project": {
"_id": "$member_list.db_xref.dbkey",
"name": "$name"}}
]
}}
]
r = list(self.aggregate_query(qc))
names = dict()
for facet in [r[0]['external'], r[0]['member']]:
j = {i['_id']: i['name'] for i in facet}
names.update(j)
return names