def bioobject(self, id, node_type=None, class_name='BioObject', **params): """ Get a node in a graph and translates it to biomodels datamodel Arguments --------- id identifier or CURIE class_name name of the class in the biomodel data model to instantiate Returns: biomodel.BioObject or subclass """ bio_object = self.get_clique_leader(id) # get nodes connected with edge 'in_taxon' response = self.get_response( "graph/neighbors", q=bio_object.id, format="json", depth=1, relationshipType=IN_TAXON, direction="OUTGOING" ) graph = BBOPGraph(response.json()) bio_object.taxon = None for tax_edge in graph.edges: bio_object.taxon = self.make_NamedObject( **graph.get_node(tax_edge.obj).as_dict() ) # Type specific if node_type == 'disease': # get nodes connected with edge 'has_disposition' response = self.get_response( "graph/neighbors", q=bio_object.id, format="json", depth=1, relationshipType=HAS_DISPOSITION, direction="OUTGOING" ) graph = BBOPGraph(response.json()) bio_object.inheritance = [] bio_object.clinical_modifiers = [] for disposition_edge in graph.edges: disposition = graph.get_node(disposition_edge.obj) if 'inheritance' in disposition.meta.category_list: bio_object.inheritance.append( self.make_NamedObject(**disposition.as_dict()) ) else: bio_object.clinical_modifiers.append( self.make_NamedObject(**disposition.as_dict()) ) return bio_object
def neighbors(self, id=None, **params): """ Get neighbors of a node parameters are directly passed through to SciGraph: e.g. depth, relationshipType Returns a BBOPGraph """ response = self.get_response("graph/neighbors", id, "json", **params) return BBOPGraph(response.json())
def neighbors(self, id=None, **params): """ Get neighbors of a node parameters are directly passed through to SciGraph: e.g. depth, relationshipType Returns a BBOPGraph """ response = self.get_response("graph/neighbors", id, "json", **params) if response.status_code == 404: raise NoResultFoundException('SciGraph graph/neighbors yields no result for {}'.format(id)) return BBOPGraph(response.json())
def extract_subgraph(self, ids=[], relationshipType='subClassOf'): """ Returns subgraph module extracted using list of node IDs as seed """ g=BBOPGraph() visited=[] while len(ids)>0: id = ids.pop() nextg = self.neighbors(id, blankNodes=False, relationshipType=relationshipType, direction='OUTGOING',depth=1) for edge in nextg.edges: next_id = edge.obj if next_id not in visited: ids.append(next_id) visited.append(next_id) g.merge(nextg) return g
def cbd(self, id=None): """ Returns the Concise Bounded Description of a node See https://www.w3.org/Submission/CBD/ """ nodes = [id] g=BBOPGraph() while len(nodes)>0: n = nodes.pop() nextg = self.neighbors(n, params={'blankNodes':True, 'direction':'OUTGOING','depth':1}) for nn in nextg.nodes: if nn.id.startswith("_:"): n.append(nn.id) g.merge(nextg) return g