Esempio n. 1
0
def test_pybel_neighborhood_query():
    bp = bel.process_pybel_neighborhood(['TP63'],
                                        network_type='graph_jsongz_url',
                                        network_file=small_corpus_url)
    assert bp.statements
    for stmt in bp.statements:
        assert_valid_statement(stmt)
    assert all([s.evidence[0].context is not None for s in bp.statements])
    assert all([
        s.evidence[0].context.cell_line.name == 'MCF 10A'
        for s in bp.statements
    ])
    # Locate statement about epidermis development
    stmt = [
        st for st in bp.statements
        if st.agent_list()[1].name == 'epidermis development'
    ][0]
    assert repr(stmt.evidence[0].context) == str(stmt.evidence[0].context)
    assert stmt.evidence[0].context == BioContext(
        location=RefContext(name="Cytoplasm",
                            db_refs={'MESH': 'D003593'}),
        cell_line=RefContext(name="MCF 10A",
                             db_refs={'EFO': '0001200'}),
        cell_type=RefContext(name="keratinocyte",
                             db_refs={'CL': 'CL:0000312'}),
        organ=RefContext(name="colon",
                         db_refs={'UBERON': 'UBERON:0001155'}),
        disease=RefContext(name="cancer",
                           db_refs={'DOID': 'DOID:162'}),
        species=RefContext(name="Rattus norvegicus",
                           db_refs={'TAXONOMY': '10116'})), \
        stmt.evidence[0].context
    # Test annotation manager
    assert bp.annot_manager.get_mapping('Species', '9606') == \
        'H**o sapiens'
Esempio n. 2
0
    def get_bel_stmts(self, filter=False):
        """Get relevant statements from the BEL large corpus.

        Performs a series of neighborhood queries and then takes the union of
        all the statements. Because the query process can take a long time for
        large gene lists, the resulting list of statements are cached in a
        pickle file with the filename `<basename>_bel_stmts.pkl`.  If the
        pickle file is present, it is used by default; if not present, the
        queries are performed and the results are cached.

        Parameters
        ----------
        filter : bool
            If True, includes only those statements that exclusively mention
            genes in :py:attr:`gene_list`. Default is False. Note that the
            full (unfiltered) set of statements are cached.

        Returns
        -------
        list of :py:class:`indra.statements.Statement`
            List of INDRA statements extracted from the BEL large corpus.
        """
        bel_proc = bel.process_pybel_neighborhood(self.gene_list)
        bel_statements = bel_proc.statements
        # Save to pickle file if we're caching
        if self.basename is not None:
            with open('%s_bel_stmts.pkl' % self.basename, 'wb') as f:
                pickle.dump(bel_statements, f)
        # Optionally filter out statements not involving only our gene set
        if filter:
            if len(self.gene_list) > 1:
                bel_statements = ac.filter_gene_list(bel_statements,
                                                     self.gene_list, 'all')
        return bel_statements
Esempio n. 3
0
def test_pybel_neighborhood_query():
    corpus = path_this + '/../../data/small_corpus.bel'
    bp = bel.process_pybel_neighborhood(['TP63'], corpus)
    assert bp.statements
    assert_pmids(bp.statements)
    unicode_strs(bp.statements)
    assert all([
        s.evidence[0].context.cell_line.name == 'MCF 10A'
        for s in bp.statements
    ])
    assert bp.statements[0].evidence[0].context.__repr__() == \
        bp.statements[0].evidence[0].context.__str__()
    assert bp.statements[0].evidence[0].context == \
        BioContext(location=RefContext(name="Cytoplasm",
                                       db_refs={'MESH': 'D003593'}),
                   cell_line=RefContext(name="MCF 10A",
                                        db_refs={'EFO': '0001200'}),
                   cell_type=RefContext(name="keratinocyte",
                                        db_refs={'CL': '0000312'}),
                   organ=RefContext(name="colon",
                                    db_refs={'UBERON': '0001155'}),
                   disease=RefContext(name="cancer",
                                      db_refs={'DOID': '162'}),
                   species=RefContext(name="Rattus norvegicus",
                                      db_refs={'TAXONOMY': '10116'}))
    # Test annotation manager
    assert bp.annot_manager.get_mapping('Species', '9606') == \
        'H**o sapiens'
Esempio n. 4
0
def test_pybel_neighborhood_query():
    corpus = path_this + '/../../data/small_corpus.bel'
    bp = bel.process_pybel_neighborhood(['TP63'], corpus)
    assert bp.statements
    assert_pmids(bp.statements)
    unicode_strs(bp.statements)
    assert all([s.evidence[0].context.cell_line.name == 'MCF 10A'
                for s in bp.statements])
    assert bp.statements[0].evidence[0].context.__repr__() == \
        bp.statements[0].evidence[0].context.__str__()
    assert bp.statements[0].evidence[0].context == \
        BioContext(location=RefContext(name="Cytoplasm",
                                       db_refs={'MESH': 'D003593'}),
                   cell_line=RefContext(name="MCF 10A",
                                        db_refs={'EFO': '0001200'}),
                   cell_type=RefContext(name="keratinocyte",
                                        db_refs={'CL': '0000312'}),
                   organ=RefContext(name="colon",
                                    db_refs={'UBERON': '0001155'}),
                   disease=RefContext(name="cancer",
                                      db_refs={'DOID': '162'}),
                   species=RefContext(name="Rattus norvegicus",
                                      db_refs={'TAXONOMY': '10116'}))
    # Test annotation manager
    assert bp.annot_manager.get_mapping('Species', '9606') == \
        'H**o sapiens'
Esempio n. 5
0
def bel_process_pybel_neighborhood():
    """Process BEL Large Corpus neighborhood and return INDRA Statements."""
    if request.method == 'OPTIONS':
        return {}
    response = request.body.read().decode('utf-8')
    body = json.loads(response)
    genes = body.get('genes')
    bp = bel.process_pybel_neighborhood(genes)
    return _stmts_from_proc(bp)
Esempio n. 6
0
def bel_process_pybel_neighborhood():
    """Process BEL Large Corpus neighborhood and return INDRA Statements."""
    if request.method == 'OPTIONS':
        return {}
    response = request.body.read().decode('utf-8')
    body = json.loads(response)
    genes = body.get('genes')
    bp = bel.process_pybel_neighborhood(genes)
    return _stmts_from_proc(bp)
Esempio n. 7
0
File: api.py Progetto: budakn/INDRA
def bel_process_pybel_neighborhood():
    """Process BEL Large Corpus neighborhood and return INDRA Statements."""
    if request.method == 'OPTIONS':
        return {}
    response = request.body.read().decode('utf-8')
    body = json.loads(response)
    genes = body.get('genes')
    bp = bel.process_pybel_neighborhood(genes)
    if bp and bp.statements:
        stmts = stmts_to_json(bp.statements)
        res = {'statements': stmts}
        return res
    else:
        res = {'statements': []}
    return res
Esempio n. 8
0
    def get_bel_stmts(self, filter=False):
        """Get relevant statements from the BEL large corpus.

        Performs a series of neighborhood queries and then takes the union of
        all the statements. Because the query process can take a long time for
        large gene lists, the resulting list of statements are cached in a
        pickle file with the filename `<basename>_bel_stmts.pkl`.  If the
        pickle file is present, it is used by default; if not present, the
        queries are performed and the results are cached.

        Parameters
        ----------
        filter : bool
            If True, includes only those statements that exclusively mention
            genes in :py:attr:`gene_list`. Default is False. Note that the
            full (unfiltered) set of statements are cached.

        Returns
        -------
        list of :py:class:`indra.statements.Statement`
            List of INDRA statements extracted from the BEL large corpus.
        """
        if self.basename is not None:
            bel_stmt_path = '%s_bel_stmts.pkl' % self.basename
        # Check for cached BEL stmt file
        if self.basename is not None and os.path.isfile(bel_stmt_path):
            logger.info("Loading BEL statements from %s" % bel_stmt_path)
            with open(bel_stmt_path, 'rb') as f:
                bel_statements = pickle.load(f)
        # No cache, so perform the queries
        else:
            bel_proc = bel.process_pybel_neighborhood(self.gene_list,
                network_file=self.bel_corpus)
            bel_statements = bel_proc.statements
            # Save to pickle file if we're caching
            if self.basename is not None:
                with open(bel_stmt_path, 'wb') as f:
                    pickle.dump(bel_statements, f)
        # Optionally filter out statements not involving only our gene set
        if filter:
            if len(self.gene_list) > 1:
                bel_statements = ac.filter_gene_list(bel_statements,
                                                     self.gene_list, 'all')
        return bel_statements
Esempio n. 9
0
File: api.py Progetto: steppi/indra
    def post(self):
        """Process BEL Large Corpus neighborhood and return INDRA Statements.

        Parameters
        ----------
        genes : list[str]
            A list of entity names (e.g., gene names) which will be used as the
            basis of filtering the result. If any of the Agents of an extracted
            INDRA Statement has a name appearing in this list, the Statement is
            retained in the result.

        Returns
        -------
        statements : list[indra.statements.Statement.to_json()]
            A list of extracted INDRA Statements.
        """
        args = request.json
        genes = args.get('genes')
        bp = bel.process_pybel_neighborhood(genes)
        return _stmts_from_proc(bp)
Esempio n. 10
0
def test_pybel_readme_example():
    bel_processor = bel.process_pybel_neighborhood(['KRAS', 'BRAF'])
    assert bel_processor.statements
Esempio n. 11
0
def test_readme_using_indra4():
    from indra.sources import bel
    # Process the neighborhood of BRAF and MAP2K1
    bel_processor = bel.process_pybel_neighborhood(['BRAF', 'MAP2K1'])
    assert bel_processor.statements
Esempio n. 12
0
def test_getting_started5():
    # Chunk 5
    from indra.sources import bel
    bel_processor = bel.process_pybel_neighborhood(['KRAS', 'BRAF'])
    assert bel_processor.statements
Esempio n. 13
0
def test_pybel_neighborhood_query():
    corpus = path_this + '/../../data/small_corpus.bel'
    bp = bel.process_pybel_neighborhood(['TP63'], corpus)
    assert bp.statements
    assert_pmids(bp.statements)
    unicode_strs(bp.statements)