src/scBONITA/singleCell.py
def __add_pathways(
        self, pathwayList=[], minOverlap=20, writeGraphml=True, removeSelfEdges=False
    ):
        """Add a list of pathways in graphml format to the singleCell object"""
        if hasattr(self, "cvGenes"):
            pathwayGenes = set(self.cvGenes)
        elif not hasattr(self, "cvGenes"):
            print("You have not filtered genes by any criterion.")
            pathwayGenes = set(self.geneList)

        if isinstance(pathwayList, list):
            for (
                x
            ) in (
                pathwayList
            ):  # list(glob.glob("*.graphml")):  # list(glob.glob('*[0-9].graphml')):
                G = nx.read_graphml(x)
                nodes = set(G.nodes())
                test = len(nodes.intersection(pathwayGenes))

                if test >= minOverlap:
                    print(
                        "Pathway: ", x, " Overlap: ", test, " Edges: ", len(G.edges())
                    )
                    nodes = list(G.nodes())
                    if removeSelfEdges:
                        G.remove_edges_from(nx.selfloop_edges(G))  # remove self loops
                    # remove genes not in dataset
                    for pg in list(G.nodes()):
                        if pg not in pathwayGenes:
                            G.remove_node(pg)
                    # graph post-processing
                    # remove singletons/isolates
                    G.remove_nodes_from(list(nx.isolates(G)))
                    # To do: remove complexes, remove dependences of a node on complexes that include that node (which is a form of self-loop)
                    self.pathwayGraphs[x] = G
                    print(
                        "Edges after processing:",
                        len(G.edges()),
                        " Overlap: ",
                        len(set(G.nodes()).intersection(pathwayGenes)),
                    )
                    if writeGraphml:
                        nx.write_graphml(
                            G, x + "_processed.graphml", infer_numeric_types=True
                        )
        else:
            if isinstance(pathwayList, dict):
                for x, G in pathwayList.items():
                    nodes = set(G.nodes())
                    test = len(nodes.intersection(pathwayGenes))

                    if test >= minOverlap:
                        print(
                            "Pathway: ",
                            x,
                            " Overlap: ",
                            test,
                            " Edges: ",
                            len(G.edges()),
                        )
                        nodes = list(G.nodes())
                        if removeSelfEdges:
                            G.remove_edges_from(
                                nx.selfloop_edges(G)
                            )  # remove self loops
                        # remove genes not in dataset
                        for pg in list(G.nodes()):
                            if pg not in pathwayGenes:
                                G.remove_node(pg)
                        # graph post-processing
                        # remove singletons/isolates
                        G.remove_nodes_from(list(nx.isolates(G)))
                        # To do: remove complexes, remove dependences of a node on complexes that include that node (which is a form of self-loop)
                        self.pathwayGraphs[x] = G
                        print(
                            "Edges after processing:",
                            len(G.edges()),
                            " Overlap: ",
                            len(set(G.nodes()).intersection(pathwayGenes)),
                        )
                        if writeGraphml:
                            nx.write_graphml(
                                G, x + "_processed.graphml", infer_numeric_types=True
                            )
Add a list of pathways in graphml format to the singleCell object
Add a list of pathways in graphml format to the singleCell object
Add a list of pathways in graphml format to the singleCell object
def __add_pathways(
        self, pathwayList=[], minOverlap=20, writeGraphml=True, removeSelfEdges=False
    ):
        if hasattr(self, "cvGenes"):
            pathwayGenes = set(self.cvGenes)
        elif not hasattr(self, "cvGenes"):
            print("You have not filtered genes by any criterion.")
            pathwayGenes = set(self.geneList)
        if isinstance(pathwayList, list):
            for (
                x
            ) in (
                pathwayList
            ):  
                G = nx.read_graphml(x)
                nodes = set(G.nodes())
                test = len(nodes.intersection(pathwayGenes))
                if test >= minOverlap:
                    print(
                        "Pathway: ", x, " Overlap: ", test, " Edges: ", len(G.edges())
                    )
                    nodes = list(G.nodes())
                    if removeSelfEdges:
                        G.remove_edges_from(nx.selfloop_edges(G))  
                    for pg in list(G.nodes()):
                        if pg not in pathwayGenes:
                            G.remove_node(pg)
                    G.remove_nodes_from(list(nx.isolates(G)))
                    self.pathwayGraphs[x] = G
                    print(
                        "Edges after processing:",
                        len(G.edges()),
                        " Overlap: ",
                        len(set(G.nodes()).intersection(pathwayGenes)),
                    )
                    if writeGraphml:
                        nx.write_graphml(
                            G, x + "_processed.graphml", infer_numeric_types=True
                        )
        else:
            if isinstance(pathwayList, dict):
                for x, G in pathwayList.items():
                    nodes = set(G.nodes())
                    test = len(nodes.intersection(pathwayGenes))
                    if test >= minOverlap:
                        print(
                            "Pathway: ",
                            x,
                            " Overlap: ",
                            test,
                            " Edges: ",
                            len(G.edges()),
                        )
                        nodes = list(G.nodes())
                        if removeSelfEdges:
                            G.remove_edges_from(
                                nx.selfloop_edges(G)
                            )  
                        for pg in list(G.nodes()):
                            if pg not in pathwayGenes:
                                G.remove_node(pg)
                        G.remove_nodes_from(list(nx.isolates(G)))
                        self.pathwayGraphs[x] = G
                        print(
                            "Edges after processing:",
                            len(G.edges()),
                            " Overlap: ",
                            len(set(G.nodes()).intersection(pathwayGenes)),
                        )
                        if writeGraphml:
                            nx.write_graphml(
                                G, x + "_processed.graphml", infer_numeric_types=True
                            )
def __add_pathways ( self , pathwayList = [ ] , minOverlap = 20 , writeGraphml = True , removeSelfEdges = False ) : if hasattr ( self , "cvGenes" ) : pathwayGenes = set ( self . cvGenes ) elif not hasattr ( self , "cvGenes" ) : print ( "You have not filtered genes by any criterion." ) pathwayGenes = set ( self . geneList ) if isinstance ( pathwayList , list ) : for ( x ) in ( pathwayList ) : G = nx . read_graphml ( x ) nodes = set ( G . nodes ( ) ) test = len ( nodes . intersection ( pathwayGenes ) ) if test >= minOverlap : print ( "Pathway: " , x , " Overlap: " , test , " Edges: " , len ( G . edges ( ) ) ) nodes = list ( G . nodes ( ) ) if removeSelfEdges : G . remove_edges_from ( nx . selfloop_edges ( G ) ) for pg in list ( G . nodes ( ) ) : if pg not in pathwayGenes : G . remove_node ( pg ) G . remove_nodes_from ( list ( nx . isolates ( G ) ) ) self . pathwayGraphs [ x ] = G print ( "Edges after processing:" , len ( G . edges ( ) ) , " Overlap: " , len ( set ( G . nodes ( ) ) . intersection ( pathwayGenes ) ) , ) if writeGraphml : nx . write_graphml ( G , x + "_processed.graphml" , infer_numeric_types = True ) else : if isinstance ( pathwayList , dict ) : for x , G in pathwayList . items ( ) : nodes = set ( G . nodes ( ) ) test = len ( nodes . intersection ( pathwayGenes ) ) if test >= minOverlap : print ( "Pathway: " , x , " Overlap: " , test , " Edges: " , len ( G . edges ( ) ) , ) nodes = list ( G . nodes ( ) ) if removeSelfEdges : G . remove_edges_from ( nx . selfloop_edges ( G ) ) for pg in list ( G . nodes ( ) ) : if pg not in pathwayGenes : G . remove_node ( pg ) G . remove_nodes_from ( list ( nx . isolates ( G ) ) ) self . pathwayGraphs [ x ] = G print ( "Edges after processing:" , len ( G . edges ( ) ) , " Overlap: " , len ( set ( G . nodes ( ) ) . intersection ( pathwayGenes ) ) , ) if writeGraphml : nx . write_graphml ( G , x + "_processed.graphml" , infer_numeric_types = True )
Add a list of pathways in graphml format to the singleCell object
Add a list of pathways in graphml format to the singleCell object
"""Add a list of pathways in graphml format to the singleCell object""" # list(glob.glob("*.graphml")):  # list(glob.glob('*[0-9].graphml')): # remove self loops # remove genes not in dataset # graph post-processing # remove singletons/isolates # To do: remove complexes, remove dependences of a node on complexes that include that node (which is a form of self-loop) # remove self loops # remove genes not in dataset # graph post-processing # remove singletons/isolates # To do: remove complexes, remove dependences of a node on complexes that include that node (which is a form of self-loop)
self
pathwayList
minOverlap
writeGraphml
removeSelfEdges