From 00a2d7f0eb33ed115f785f110ae23c9ad63ff0f1 Mon Sep 17 00:00:00 2001 From: mcrowther Date: Tue, 3 Aug 2021 15:06:28 +0100 Subject: [PATCH] Removed instance blacklist from gitignore --- .gitignore | 1 - builder/builders/instance/mode.py | 53 +++++++++++++++++++ builder/builders/instance/view.py | 85 +++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 builder/builders/instance/mode.py create mode 100644 builder/builders/instance/view.py diff --git a/.gitignore b/.gitignore index b6e4761..683c0c9 100644 --- a/.gitignore +++ b/.gitignore @@ -62,7 +62,6 @@ db.sqlite3 db.sqlite3-journal # Flask stuff: -instance/ .webassets-cache # Scrapy stuff: diff --git a/builder/builders/instance/mode.py b/builder/builders/instance/mode.py new file mode 100644 index 0000000..5e68c5e --- /dev/null +++ b/builder/builders/instance/mode.py @@ -0,0 +1,53 @@ +import re + +class ModeBuilder: + def __init__(self,builder): + self._builder = builder + + def tree(self): + tree_edges = [] + node_attrs = {} + seen = [] + max_key = max([node for node in self._builder.v_nodes]) + for n,v,e in self._builder.v_edges: + node_attrs[v] = self._builder.nodes[v] + node_attrs[n] = self._builder.nodes[n] + v_copy = v + if v in seen: + max_key +=1 + v = max_key + node_attrs[v] = self._builder.nodes[v_copy] + seen.append(v) + else: + seen.append(v) + edge = self._create_edge_dict(e) + tree_edges.append((n,v,e,edge)) + tree_graph = self._builder.sub_graph(tree_edges,node_attrs) + return tree_graph + + def network(self): + return self._builder.view + + def _create_edge_dict(self,key,weight=1): + edge = {'weight': weight, + 'display_name': self._get_name(str(key))} + return edge + + def _get_name(self,subject): + split_subject = self._split(subject) + if len(split_subject[-1]) == 1 and split_subject[-1].isdigit(): + return split_subject[-2] + elif len(split_subject[-1]) == 3 and _isfloat(split_subject[-1]): + return split_subject[-2] + else: + return split_subject[-1] + + def _split(self,uri): + return re.split('#|\/|:', uri) + +def _isfloat(x): + try: + float(x) + return True + except ValueError: + return False \ No newline at end of file diff --git a/builder/builders/instance/view.py b/builder/builders/instance/view.py new file mode 100644 index 0000000..b1fd099 --- /dev/null +++ b/builder/builders/instance/view.py @@ -0,0 +1,85 @@ +#from utility.nv_identifiers import identifiers +import re + +class ViewBuilder: + def __init__(self,builder): + self._builder = builder + + def full(self): + return self._builder._graph + + def pruned(self): + edges = [] + node_attrs = {} + w_predicates = [] + for n,v,k,e in self._builder.edges(keys=True,data=True): + if k not in w_predicates: + continue + node_attrs[n] = self._builder.nodes[n] + node_attrs[v] = self._builder.nodes[v] + edges.append((n,v,k,e)) + return self._builder.sub_graph(edges,node_attrs) + + def heirarchy(self): + edges = [] + node_attrs = {} + for entity,data in self._builder.get_entities(): + sub_entities = self._builder.get_entities(entity) + if len(sub_entities) == 0: + continue + node_attrs[entity] = data + + for s_entity in sub_entities: + key = identifiers.predicates.contains + s_entity,s_e_data = s_entity + node_attrs[s_entity] = s_e_data + edge = self._build_edge_attr(key) + edges.append((entity,s_entity,key,edge)) + return self._builder.sub_graph(edges,node_attrs) + + def interaction_verbose(self): + edges = [] + node_attrs = {} + return self._builder.sub_graph(edges,node_attrs) + + def interaction(self): + edges = [] + node_attrs = {} + return self._builder.sub_graph(edges,node_attrs) + + def interaction_genetic(self): + edges = [] + node_attrs = {} + return self._builder.sub_graph(edges,node_attrs) + + def ppi(self): + edges = [] + node_attrs = {} + return self._builder.sub_graph(edges,node_attrs) + + def module(self): + edges = [] + node_attrs = {} + return self._builder.sub_graph(edges,node_attrs) + + def _build_edge_attr(self,key): + return {"display_name" : self._get_name(key)} + + def _get_name(self,subject): + split_subject = self._split(subject) + if len(split_subject[-1]) == 1 and split_subject[-1].isdigit(): + return split_subject[-2] + elif len(split_subject[-1]) == 3 and _isfloat(split_subject[-1]): + return split_subject[-2] + else: + return split_subject[-1] + + def _split(self,uri): + return re.split('#|\/|:', uri) + +def _isfloat(x): + try: + float(x) + return True + except ValueError: + return False \ No newline at end of file