コード例 #1
0
    def test_complex_expansion(self):

        input_param = {'Signor': data_formats.pathway['signor']}

        settings.setup(network_pickle_cache=False)
        # a network with all complexes expanded to single proteins
        settings.setup(network_expand_complexes=True)
        netw_complex_expanded = main.PyPath()
        netw_complex_expanded.keep_raw = True
        netw_complex_expanded.init_network(input_param)

        # a network with complexes as entities (vertices) in it
        settings.setup(network_expand_complexes=False)
        netw_complex_entities = main.PyPath()
        netw_complex_entities.init_network(input_param)

        # collecting all interactions of the complexes
        expanded_connections = set()

        for v in netw_complex_entities.graph.vs:

            if v['type'] != 'complex':

                continue

            for vid_nb in netw_complex_entities.graph.neighbors(v.index):

                names_nb = netw_complex_entities.graph.vs[vid_nb]['name']
                # if the neighbor is another complex
                uniprots_nb = (names_nb.components.keys() if hasattr(
                    names_nb, 'components') else (names_nb, ))

                for uniprot_nb in uniprots_nb:

                    for uniprot_comp in v['name'].components.keys():

                        expanded_connections.add(
                            tuple(sorted((
                                uniprot_nb,
                                uniprot_comp,
                            ))))

        # checking if all these connections exist in the expanded network
        missing = set()

        for uniprot1, uniprot2 in expanded_connections:

            if (not netw_complex_expanded.get_edge(uniprot1, uniprot2)
                    and uniprot1 != uniprot2):

                missing.add((uniprot1, uniprot2))

        assert not missing
コード例 #2
0
ファイル: bel.py プロジェクト: kkaris/pypath
 def get_resource(dataset: str):
     
     if dataset == 'graph':
         
         from pypath import main
         from pypath import data_formats
         pa = main.PyPath()
         pa.init_network(data_formats.pathway)
         return pa
     # TODO add more options
     elif dataset == 'complexes':
         
         from pypath import complexes
         co = complexes.ComplexAggregator()
         return co
         
     elif dataset == 'ptms':
         
         from pypath import ptm
         es = ptm.PtmAggregator()
         return es
         
     elif dataset == 'annotations':
         
         from pypath import annot
         an = ptm.AnnotationTable(keep_annotators = True)
         return an
         
     else:
         
         _logger._log('Unknown resource type: `%s`.' % dataset)
コード例 #3
0
    def setup_network(self):

        if self.network is None:

            if not self.omnipath and 'lst' not in self.network_param:

                self.network_param['lst'] = data_formats.pathway

            self.network = main_mod.PyPath()

            if self.omnipath:

                self.network.load_omnipath(**self.network_param)

            else:

                self.network.init_network(**self.network_param)

        if isinstance(self.network, main_mod.PyPath):
            
            self.network = network_mod.Network.from_igraph(self.network)
        
        if isinstance(self.network, network_mod.Network):

            pass
コード例 #4
0
ファイル: test_interaction.py プロジェクト: rfour92/pypath
    def test_filter_via(self):

        pa = main.PyPath()
        pa.init_network(netres.ptm_misc)

        assert any(
            len(list(a.evidences.filter(via='MIMP')))
            for a in pa.graph.es['attrs'])
コード例 #5
0
ファイル: test_interaction.py プロジェクト: rfour92/pypath
    def test_contains(self):

        sr = netres.pathway['signor']
        sk = sr.key
        si = 'SIGNOR'

        pa = main.PyPath()
        pa.init_network(netres.pathway)

        assert ([sr in a for a in pa.graph.es['attrs']] == [
            sk in a for a in pa.graph.es['attrs']
        ] == [si in a for a in pa.graph.es['attrs']])
コード例 #6
0
    def setup_network(self):

        if self.network is None:

            if not self.omnipath and 'lst' not in self.network_param:

                self.network_param['lst'] = data_formats.pathway

            self.network = main_mod.PyPath()
            self.network.init_network(**self.network_param)

        if isinstance(self.network, main_mod.PyPath):

            self.network = network_mod.Network(records=self.network)

        if isinstance(self.network, network_mod.Network):

            pass
コード例 #7
0
 def setup_network(self):
     
     if self.network is None:
         
         if not self.use_omnipath and 'lst' not in self.network_param:
             
             resources = copy.deepcopy(data_formats.pathway_all)
             resources.update(copy.deepcopy(data_formats.ligand_receptor))
             self.network_param['lst'] = resources
         
         self.network = main_mod.PyPath()
         self.network.init_network(**self.network_param)
     
     if isinstance(self.network, main_mod.PyPath):
         
         self.network = network_mod.Network(records = self.network)
         
     if isinstance(self.network, network_mod.Network):
         
         pass
コード例 #8
0
    def load_network(self):

        if not self.do_load_network:

            return

        self.network = main.PyPath()

        if os.path.exists(self.network_pickle):

            self.network.init_network(pfile=self.network_pickle)

        else:

            network_input = copy.deepcopy(data_formats.omnipath)
            network_input.update(data_formats.ligand_receptor)
            network_input.update(data_formats.ptm_misc)
            self.network.load_omnipath(
                omnipath=network_input,
                remove_htp=False,
            )
コード例 #9
0
    def test_orthology_translation(self):
        """
        We test this on a nice complicated example case when 3 human
        genes map to 4 mouse orthologues. We select one interacting partner
        and check if it has one and only one interaction with this partner
        with the correct direction and sign.
        """

        pa = main.PyPath()
        pa.init_network({'s': data_formats.pathway['signor']})
        pa.homology_translation(target=10090)

        adcy1_vs = pa.graph.vs.select(name='O88444')
        gnas_1_vs = pa.graph.vs.select(name='P63094')
        gnas_2_vs = pa.graph.vs.select(name='Q6R0H7')
        gnas_3_vs = pa.graph.vs.select(name='Q6R0H6')
        gnas_4_vs = pa.graph.vs.select(name='Q9Z0F1')

        assert all(
            len(vs) == 1
            for vs in (adcy1_vs, gnas_1_vs, gnas_2_vs, gnas_3_vs, gnas_4_vs))

        adcy1_i = adcy1_vs[0].index

        for gnas_vs in (gnas_1_vs, gnas_2_vs, gnas_3_vs, gnas_4_vs):

            gnas_i = gnas_vs[0].index

            es = pa.graph.es.select(_between=((gnas_i, ), (adcy1_i, )))

            assert len(es) == 1

            edge = es[0]

            assert edge['dirs'].which_dirs()[0][1] == 'O88444'
            assert (edge['dirs'].get_sign(*edge['dirs'].which_dirs()) == [
                True, False
            ])
コード例 #10
0
 def interactions(self):
     
     self._log('Building `interactions` data frame.')
     dataframes = []
     
     tfregulons = copy.deepcopy(data_formats.transcription)
     tfregulons['tfregulons'].input_args['levels'] = {
         'A', 'B', 'C', 'D', 'E'
     }
     
     param = (
         ('load_omnipath', {
                 'kinase_substrate_extra': True,
                 'ligand_receptor_extra': True,
                 'pathway_extra': True,
             }
         ),
         ('init_network',  {'lst': tfregulons}),
         ('init_network',  {'lst': data_formats.mirna_target})
     )
     
     for to_call, kwargs in param:
         
         pa = main.PyPath()
         getattr(pa, to_call)(**kwargs)
         
         e = export.Export(pa)
         e.webservice_interactions_df()
         dataframes.append(e.df)
         
         if not self.only_human:
             
             graph_human = None
             
             for rodent in (10090, 10116):
                 
                 if pa.ncbi_tax_id == 9606:
                     
                     if pa.graph.ecount() < 100000:
                         
                         graph_human = copy.deepcopy(pa.graph)
                     
                 else:
                     
                     if graph_human:
                         
                         pa.graph = graph_human
                         pa.ncbi_tax_id = 9606
                         pa.genesymbol_labels(remap_all = True)
                         pa.update_vname()
                         
                     else:
                         
                         del e
                         del pa
                         pa = main.PyPath()
                         getattr(pa, to_call)(**kwargs)
                 
                 pa.orthology_translation(rodent)
                 e = export.Export(pa)
                 e.webservice_interactions_df()
                 dataframes.append(e.df)
     
     del e
     del pa
     
     self.df_interactions = pd.concat(dataframes)
     self.df_interactions.to_csv(
         self.outfile_interactions,
         sep = '\t',
         index = False
     )
     self._log('Data frame `interactions` has been exported to `%s`.' % (
         self.outfile_interactions,
     ))