forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.py
More file actions
56 lines (45 loc) · 1.64 KB
/
Copy pathinterface.py
File metadata and controls
56 lines (45 loc) · 1.64 KB
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
import re
from typing import Any, Dict, List, Optional
TERM_PATTERN = re.compile(r"https?://edamontology.org/(.*)")
class ParsedBiotoolsEntry:
"""Provide XML wrapper relevant entities from a bio.tool entry - topics and operations."""
biotoolsID: str
edam_topics: List[str]
edam_operations: List[str]
class BiotoolsEntry:
"""Parse the RAW entries of interest for Galaxy from a bio.tools entry."""
biotoolsID: str
topic: List[dict]
function: List[dict]
@staticmethod
def from_json(from_json: Dict[str, Any]) -> 'BiotoolsEntry':
entry = BiotoolsEntry()
entry.biotoolsID = from_json["biotoolsID"]
entry.topic = from_json.get("topic", [])
entry.function = from_json.get("function", [])
return entry
@property
def edam_info(self) -> ParsedBiotoolsEntry:
parsed = ParsedBiotoolsEntry()
parsed.biotoolsID = self.biotoolsID
parsed.edam_topics = list(set(simplify_edam_dicts(self.topic)))
operations = []
for function in self.function:
if "operation" in function:
operations.extend(simplify_edam_dicts(function["operation"]))
parsed.edam_operations = list(set(operations))
return parsed
def simplify_edam_dicts(a_list: List[Dict[str, str]]):
terms = []
for term in map(simplify_edam_dict, a_list):
if term:
terms.append(term)
return terms
def simplify_edam_dict(as_dict: Dict[str, str]) -> Optional[str]:
uri = as_dict["uri"]
match = TERM_PATTERN.match(uri)
if match:
return match.group(1)
else:
# TODO: log problem...
return None