Exemple #1
0
from __future__ import absolute_import, print_function, unicode_literals
from builtins import dict, str
import os
from indra.java_vm import autoclass, cast
from indra import biopax
import indra.biopax.processor as bpc
from indra.databases import uniprot_client
from indra.util import unicode_strs
from indra.preassembler import Preassembler
from indra.preassembler.hierarchy_manager import hierarchies

model_path = os.path.dirname(os.path.abspath(__file__)) +\
             '/../../data/biopax_test.owl'

bp = biopax.process_owl(model_path)
uri_prefix = 'http://purl.org/pc2/7/'


def test_paxtools_autoclass():
    autoclass('org.biopax.paxtools.impl.level3.ProteinImpl')


def test_biopaxpattern_autoclass():
    autoclass('org.biopax.paxtools.pattern.PatternBox')


def test_cpath_autoclass():
    autoclass('cpath.client.CPathClient')


def test_listify():
Exemple #2
0
    def get_biopax_stmts(self, filter=False, query='pathsbetween'):
        """Get relevant statements from Pathway Commons.

        Performs a "paths between" query for the genes in :py:attr:`gene_list`
        and uses the results to build statements. This function caches two
        files: the list of statements built from the query, which is cached in
        `<basename>_biopax_stmts.pkl`, and the OWL file returned by the Pathway
        Commons Web API, which is cached in `<basename>_pc_pathsbetween.owl`.
        If these cached files are found, then the results are returned based
        on the cached file and Pathway Commons is not queried again.

        Parameters
        ----------
        filter : bool
            If True, includes only those statements that exclusively mention
            genes in :py:attr:`gene_list`. Default is False.
        query : str
            Defined what type of query is executed. The two options are
            'pathsbetween' which finds paths between the given list of genes
            and only works if more than 1 gene is given, and 'neighborhood'
            which searches the immediate neighborhood of each given gene.

        Returns
        -------
        list of :py:class:`indra.statements.Statement`
            List of INDRA statements extracted from Pathway Commons.
        """
        # If we're using a cache, initialize the appropriate filenames
        if self.basename is not None:
            biopax_stmt_path = '%s_biopax_stmts.pkl' % self.basename
            biopax_ras_owl_path = '%s_pc_pathsbetween.owl' % self.basename
        # Check for cached Biopax stmt file at the given path
        # if it's there, return the statements from the cache
        if self.basename is not None and os.path.isfile(biopax_stmt_path):
            logger.info("Loading Biopax statements from %s" % biopax_stmt_path)
            with open(biopax_stmt_path, 'rb') as f:
                bp_statements = pickle.load(f)
            return bp_statements
        # Check for cached file before querying Pathway Commons Web API
        if self.basename is not None and os.path.isfile(biopax_ras_owl_path):
            logger.info("Loading Biopax from OWL file %s" %
                        biopax_ras_owl_path)
            bp = biopax.process_owl(biopax_ras_owl_path)
        # OWL file not found; do query and save to file
        else:
            if (len(self.gene_list) < 2) and (query == 'pathsbetween'):
                logger.warning('Using neighborhood query for one gene.')
                query = 'neighborhood'
            if query == 'pathsbetween':
                bp = biopax.process_pc_pathsbetween(self.gene_list)
            elif query == 'neighborhood':
                bp = biopax.process_pc_neighborhood(self.gene_list)
            else:
                logger.error('Invalid query type: %s' % query)
                return []
            # Save the file if we're caching
            if self.basename is not None:
                bp.save_model(biopax_ras_owl_path)
        # Save statements to pickle file if we're caching
        if self.basename is not None:
            with open(biopax_stmt_path, 'wb') as f:
                pickle.dump(bp.statements, f, protocol=2)
        # Optionally filter out statements not involving only our gene set
        if filter:
            if len(self.gene_list) > 1:
                bp_statements = ac.filter_gene_list(bp_statements,
                                                    self.gene_list, 'one')
            else:
                bp_statements = ac.filter_gene_list(bp_statements,
                                                    self.gene_list, 'all')
        return bp.statements
Exemple #3
0
from __future__ import absolute_import, print_function, unicode_literals
from builtins import dict, str
import os
from indra.java_vm import autoclass, cast
from indra import biopax
import indra.biopax.processor as bpc
from indra.databases import uniprot_client
from indra.util import unicode_strs
from indra.preassembler import Preassembler
from indra.preassembler.hierarchy_manager import hierarchies

model_path = os.path.dirname(os.path.abspath(__file__)) +\
             '/../../data/biopax_test.owl'

bp = biopax.process_owl(model_path)
uri_prefix = 'http://purl.org/pc2/7/'

def test_paxtools_autoclass():
    autoclass('org.biopax.paxtools.impl.level3.ProteinImpl')

def test_biopaxpattern_autoclass():
    autoclass('org.biopax.paxtools.pattern.PatternBox')

def test_cpath_autoclass():
    autoclass('cpath.client.CPathClient')

def test_listify():
    assert(bpc._listify(1) == [1])
    assert(bpc._listify([1,2] == [1,2]))
    assert(bpc._listify([1] == [1]))
Exemple #4
0
        fname = 'egfr_model_v4.xml'
        print 'Processing parser output from XML file %s...' % fname
        tp = trips.process_xml(open(fname).read())
    else:
        print 'Submitting text to TRIPS parser...'
        tstart = time.time()
        tp = trips.process_text(open('model_text.txt').read())
        tend = time.time()
        print '> TRIPS parser took %d seconds.' % (tend - tstart)
    pa.add_statements(tp.statements)

    # BioPAX processing
    if use_owl:
        fname = 'DUSP.owl'
        print 'Processing OWL file %s...' % fname
        bp = biopax.process_owl('DUSP.owl')
    else:
        print 'Processing output from PathwayCommons query'
        bp = biopax.process_pc_neighborhood(['DUSP4'])
    bp.get_dephosphorylation(force_contains=['MAPK1'])
    pa.add_statements(bp.statements)

    # Assemble model
    model = pa.make_model(initial_conditions=True)


    RAF1 = model.monomers['RAF1']
    HRAS = model.monomers['HRAS']

    r1 = model.rules['RAF1_autophospho_RAF1_T491']
    r1.rule_expression = (RAF1(HRAS=1, T491='u') % HRAS(RAF1=1) >> RAF1(HRAS=1, T491='p') % HRAS(RAF1=1))