def getChildren(root_id, maxDepth=100, relationshipType="subClassOf", 
                 alwaysFetch=False):
    """
     Accessing web-based ontology service is too long, so we cache the 
     information in a pickle file and query the services only if the info
     has not already been cached. 
    """
    childrenDic = {}
    fileName = os.path.join(os.path.dirname(__file__), "children.bin") 

    #### CHECK FOR CASE OF BBP TAGS
    if root_id[:4] == "BBP_":

        if not alwaysFetch:
            try:
                with open(fileName, "rb") as childrenFile:
                    childrenDic = pickle.load(childrenFile)
                    
                if root_id in childrenDic:
                    return childrenDic[root_id]                
            except:
                pass        

        childrenDic[root_id] = getBBPChildren(root_id)        
        
        if not alwaysFetch:
            try:
                with open(fileName, "wb") as childrenFile:
                    pickle.dump(childrenDic, childrenFile)
            except:
                pass      
            
        return childrenDic[root_id]

    ## TODO: should also check for BBP children of online onto terms

    if root_id in nlx2ks:
        root_id = nlx2ks[root_id]

    if not alwaysFetch:
        try:
            with open(fileName, "rb") as childrenFile:
                childrenDic = pickle.load(childrenFile)
                
            if root_id in childrenDic:
                return childrenDic[root_id]                
        except:
            pass

    direction="INCOMING"
    #neighbors = graph.getNeighbors(root_id, depth=maxDepth, 
    #                               relationshipType=relationshipType, 
    #                               direction=direction)
 
    baseKS  = "http://matrix.neuinfo.org:9000"
    response = requests.get(baseKS + "/scigraph/graph/neighbors/" + 
                            root_id + "?direction=" + direction + 
                            "&depth=" + str(maxDepth) + 
                            "&project=%2A&blankNodes=false&relationshipType=" 
                            + relationshipType)

    if not response.ok:
        return {}
        
    neighbors = response.json()

    if neighbors is None:
        return {}

    nodes = neighbors["nodes"]
    #for node in np.array(nodes):
    #    node["lbl"] = node["lbl"].encode('utf-8').decode('utf-8')
        
    #try:
    #    assert(np.all([not node["lbl"] is None for node in np.array(nodes)]))
    #except AssertionError: 
    #    for node in np.array(nodes):
    #        if node["lbl"] is None:
    #            print(node["id"])
    #    raise        
    
    # TODO: replace by the commented line below. This patch is only to 
    #       accomodate for a current issue with the knowledge-space endpoint.          
    #childrenDic[root_id]  = OntoDic({node["id"]:node["lbl"] for node in np.array(nodes)})        
    childrenDic[root_id]  = OntoDic({node["id"]:node["lbl"] for node in np.array(nodes) if not node["lbl"] is None})
    
    if not alwaysFetch:    
        try:
            with open(fileName, "wb") as childrenFile:
                pickle.dump(childrenDic, childrenFile)
        except:
            pass        

    return childrenDic[root_id]
def getChildren ( root_id , maxDepth = 100 , relationshipType = "subClassOf" , alwaysFetch = False ) : childrenDic = { } fileName = os . path . join ( os . path . dirname ( __file__ ) , "children.bin" ) if root_id [ : 4 ] == "BBP_" : if not alwaysFetch : try : with open ( fileName , "rb" ) as childrenFile : childrenDic = pickle . load ( childrenFile ) if root_id in childrenDic : return childrenDic [ root_id ] except : pass childrenDic [ root_id ] = getBBPChildren ( root_id ) if not alwaysFetch : try : with open ( fileName , "wb" ) as childrenFile : pickle . dump ( childrenDic , childrenFile ) except : pass return childrenDic [ root_id ] if root_id in nlx2ks : root_id = nlx2ks [ root_id ] if not alwaysFetch : try : with open ( fileName , "rb" ) as childrenFile : childrenDic = pickle . load ( childrenFile ) if root_id in childrenDic : return childrenDic [ root_id ] except : pass direction = "INCOMING" baseKS = "http://matrix.neuinfo.org:9000" response = requests . get ( baseKS + "/scigraph/graph/neighbors/" + root_id + "?direction=" + direction + "&depth=" + str ( maxDepth ) + "&project=%2A&blankNodes=false&relationshipType=" + relationshipType ) if not response . ok : return { } neighbors = response . json ( ) if neighbors is None : return { } nodes = neighbors [ "nodes" ] childrenDic [ root_id ] = OntoDic ( { node [ "id" ] : node [ "lbl" ] for node in np . array ( nodes ) if not node [ "lbl" ] is None } ) if not alwaysFetch : try : with open ( fileName , "wb" ) as childrenFile : pickle . dump ( childrenDic , childrenFile ) except : pass return childrenDic [ root_id ]
Accessing web-based ontology service is too long, so we cache the 
     information in a pickle file and query the services only if the info
     has not already been cached.