def node(self, id=None, **params): """ Get a node in a graph plus its metadata Returns a BBOPGraph Node """ response = self.get_response("graph", q=id, format="json", **params) if response.status_code == 404: raise NoResultFoundException('SciGraph yields no result for {}'.format(id)) nodes = response.json()['nodes'] if len(nodes) == 0: raise NoResultFoundException('SciGraph yields no result for {}'.format(id)) return self.make_NamedObject(**nodes[0])
def get(self, id): """ Returns edges emanating from a given node. """ args = self.parser.parse_args() response = sg.get_response("dynamic/cliqueLeader", q=id, format="json", depth=1) nodes = response.json()['nodes'] if not nodes: raise NoResultFoundException( 'SciGraph dynamic/cliqueLeader yields no result for {}'.format( id)) clique_leader = nodes[0]['id'] final_graph = BBOPGraph({'nodes': [], 'edges': []}) if args.relationship_type: for relationship in args.relationship_type: graph = sg.neighbors(id=clique_leader, relationshipType=relationship, direction=args.direction, depth=args.depth, entail=args.entail) final_graph.merge(graph) else: graph = sg.neighbors(id=clique_leader, depth=args.depth, entail=args.entail) final_graph.merge(graph) return final_graph
def get(self, id): """ Returns edges emanating from a given node. """ args = self.parser.parse_args() if args['graph'] == 'data': scigraph = sg_data elif args['graph'] == 'ontology': scigraph = sg_ont else: raise UnhandledException('{} not supported graph'.format( args['graph'])) try: node = scigraph.get_clique_leader(id) except HTTPError: raise NoResultFoundException( 'SciGraph yields no result for {}'.format(id)) if not node: raise NoResultFoundException( 'SciGraph dynamic/cliqueLeader yields no result for {}'.format( id)) clique_leader = node.id final_graph = BBOPGraph({'nodes': [], 'edges': []}) if args.relationship_type: for relationship in args.relationship_type: graph = scigraph.neighbors(id=clique_leader, relationshipType=relationship, direction=args.direction, depth=args.depth, entail=args.entail) final_graph.merge(graph) else: graph = scigraph.neighbors(id=clique_leader, depth=args.depth, entail=args.entail) final_graph.merge(graph) return final_graph.as_dict()
def get_clique_leader(self, id) -> BioObject: """ :raises NoResultFoundException :return: BioObject """ response = self.get_response("dynamic/cliqueLeader", q=id, format="json") nodes = response.json()['nodes'] if len(nodes) == 0: raise NoResultFoundException('SciGraph dynamic/cliqueLeader yields no result for {}'.format(id)) return self.make_NamedObject(**nodes[0], class_name='BioObject')
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())