Пример #1
0
 def _get_input_rules(self, subj_mp):
     if subj_mp is None:
         raise ValueError("Cannot take None as an argument for subj_mp.")
     input_rules = _match_lhs(subj_mp, self.model.rules)
     logger.debug('Found %s input rules matching %s' %
                  (len(input_rules), str(subj_mp)))
     # Filter to include only rules where the subj_mp is actually the
     # subject (i.e., don't pick up upstream rules where the subject
     # is itself a substrate/object)
     # FIXME: Note that this will eliminate rules where the subject
     # being checked is included on the left hand side as
     # a bound condition rather than as an enzyme.
     subj_rules = pa.rules_with_annotation(self.model, subj_mp.monomer.name,
                                           'rule_has_subject')
     logger.debug('%d rules with %s as subject' %
                  (len(subj_rules), subj_mp.monomer.name))
     input_rule_set = set([r.name for r in input_rules
                           ]).intersection(set([r.name
                                                for r in subj_rules]))
     logger.debug('Final input rule set contains %d rules' %
                  len(input_rule_set))
     return input_rule_set
Пример #2
0
    def _find_im_paths(self, subj_mp, obj_obs, target_polarity):
        """Check for a source/target path in the influence map.

        Parameters
        ----------
        subj_mp : pysb.MonomerPattern
            MonomerPattern corresponding to the subject of the Statement
            being checked.
        obj_obs : pysb.Observable
            Observable corresponding to the object/target of the Statement
            being checked.
        target_polarity : 1 or -1
            Whether the influence in the Statement is positive (1) or negative
            (-1).

        Returns
        -------
        boolean
            Whether there is a path from a rule matching the subject
            MonomerPattern to the object Observable with the appropriate
            polarity.
        """
        # Reset the observables list
        self.model.observables = ComponentSet([])
        self.model.add_component(obj_obs)
        # Find rules in the model corresponding to the input
        logger.info('Finding paths between %s and %s with polarity %s' %
                    (subj_mp, obj_obs, target_polarity))
        if subj_mp is None:
            input_rule_set = None
        else:
            input_rules = _match_lhs(subj_mp, self.model.rules)
            logger.info('Found %s input rules matching %s' %
                        (len(input_rules), str(subj_mp)))
            # Filter to include only rules where the subj_mp is actually the
            # subject (i.e., don't pick up upstream rules where the subject
            # is itself a substrate/object)
            # FIXME: Note that this will eliminate rules where the subject
            # being checked is included on the left hand side as
            # a bound condition rather than as an enzyme.
            subj_rules = pa.rules_with_annotation(self.model,
                                                  subj_mp.monomer.name,
                                                  'rule_has_subject')
            logger.info('%d rules with %s as subject' %
                        (len(subj_rules), subj_mp.monomer.name))
            input_rule_set = set([r.name for r in input_rules]).intersection(
                set([r.name for r in subj_rules]))
            logger.info('Final input rule set contains %d rules' %
                        len(input_rule_set))
            # If we have enzyme information but there are no input rules
            # matching the enzyme, then there is no path
            if not input_rule_set:
                return False
        # Generate the predecessors to our observable and count the paths
        # TODO: Make it optionally possible to return on the first path?
        num_paths = 0
        for path in _find_sources(self.get_im(), obj_obs.name, input_rule_set,
                                  target_polarity):
            num_paths += 1
        #for path in _find_sources_with_paths(self.get_im(), obj_obs.name,
        #                                     input_rule_set, target_polarity):
        #    num_paths += 1
        if num_paths > 0:
            return True
        else:
            return False
Пример #3
0
    def _find_im_paths(self, subj_mp, obs_name, target_polarity,
                       max_paths=1, max_path_length=5):
        """Check for a source/target path in the influence map.

        Parameters
        ----------
        subj_mp : pysb.MonomerPattern
            MonomerPattern corresponding to the subject of the Statement
            being checked.
        obs_name : string
            Name of the PySB model Observable corresponding to the
            object/target of the Statement being checked.
        target_polarity : 1 or -1
            Whether the influence in the Statement is positive (1) or negative
            (-1).

        Returns
        -------
        boolean or list of str
            Whether there is a path from a rule matching the subject
            MonomerPattern to the object Observable with the appropriate
            polarity.
        """
        # Find rules in the model corresponding to the input
        obs_mp = self.model.all_components()[obs_name].reaction_pattern
        logger.info('Finding paths between %s and %s with polarity %s' %
                    (subj_mp, obs_mp, target_polarity))
        if subj_mp is None:
            input_rule_set = None
        else:
            input_rules = _match_lhs(subj_mp, self.model.rules)
            logger.debug('Found %s input rules matching %s' %
                         (len(input_rules), str(subj_mp)))
            # Filter to include only rules where the subj_mp is actually the
            # subject (i.e., don't pick up upstream rules where the subject
            # is itself a substrate/object)
            # FIXME: Note that this will eliminate rules where the subject
            # being checked is included on the left hand side as 
            # a bound condition rather than as an enzyme.
            subj_rules = pa.rules_with_annotation(self.model,
                                                  subj_mp.monomer.name,
                                                  'rule_has_subject')
            logger.debug('%d rules with %s as subject' %
                         (len(subj_rules), subj_mp.monomer.name))
            input_rule_set = set([r.name for r in input_rules]).intersection(
                                 set([r.name for r in subj_rules]))
            logger.debug('Final input rule set contains %d rules' %
                         len(input_rule_set))
            # If we have enzyme information but there are no input rules
            # matching the enzyme, then there is no path
            if not input_rule_set:
                return PathResult(False, 'INPUT_RULES_NOT_FOUND',
                                  max_paths, max_path_length)
        # Generate the predecessors to our observable and count the paths
        # TODO: Make it optionally possible to return on the first path?
        path_lengths = []
        path_metrics = []
        for source, polarity, path_length in \
                    _find_sources(self.get_im(), obs_name, input_rule_set,
                                  target_polarity):
            pm = PathMetric(source, obs_name, polarity, path_length)
            path_metrics.append(pm)
            path_lengths.append(path_length)
        # Now, look for paths
        paths = []
        if path_metrics:
            if min(path_lengths) <= max_path_length:
                pr = PathResult(True, 'PATHS_FOUND', max_paths, max_path_length)
                pr.path_metrics = path_metrics
                # Get the first path
                path_iter = enumerate(_find_sources_with_paths(
                                           self.get_im(), obs_name,
                                           input_rule_set, target_polarity))
                for path_ix, path in path_iter:
                    flipped = _flip(self.get_im(), path)
                    pr.add_path(flipped)
                    if len(pr.paths) >= max_paths:
                        break
                return pr
            # There are no paths shorter than the max path length, so we
            # don't bother trying to get them
            else:
                pr = PathResult(True, 'MAX_PATH_LENGTH_EXCEEDED',
                                max_paths, max_path_length)
                pr.path_metrics = path_metrics
                return pr
        else:
            return PathResult(False, 'NO_PATHS_FOUND',
                              max_paths, max_path_length)
Пример #4
0
    def _find_im_paths(self, subj_mp, obj_obs, target_polarity):
        """Check for a source/target path in the influence map.

        Parameters
        ----------
        subj_mp : pysb.MonomerPattern
            MonomerPattern corresponding to the subject of the Statement
            being checked.
        obj_obs : pysb.Observable
            Observable corresponding to the object/target of the Statement
            being checked.
        target_polarity : 1 or -1
            Whether the influence in the Statement is positive (1) or negative
            (-1).

        Returns
        -------
        boolean
            Whether there is a path from a rule matching the subject
            MonomerPattern to the object Observable with the appropriate
            polarity.
        """
        # Reset the observables list
        self.model.observables = ComponentSet([])
        self.model.add_component(obj_obs)
        # Find rules in the model corresponding to the input
        logger.info('Finding paths between %s and %s with polarity %s' %
                    (subj_mp, obj_obs, target_polarity))
        if subj_mp is None:
            input_rule_set = None
        else:
            input_rules = _match_lhs(subj_mp, self.model.rules)
            logger.info('Found %s input rules matching %s' %
                        (len(input_rules), str(subj_mp)))
            # Filter to include only rules where the subj_mp is actually the
            # subject (i.e., don't pick up upstream rules where the subject
            # is itself a substrate/object)
            # FIXME: Note that this will eliminate rules where the subject
            # being checked is included on the left hand side as 
            # a bound condition rather than as an enzyme.
            subj_rules = pa.rules_with_annotation(self.model,
                                                  subj_mp.monomer.name,
                                                  'rule_has_subject')
            logger.info('%d rules with %s as subject' %
                        (len(subj_rules), subj_mp.monomer.name))
            input_rule_set = set([r.name for r in input_rules]).intersection(
                                 set([r.name for r in subj_rules]))
            logger.info('Final input rule set contains %d rules' %
                        len(input_rule_set))
            # If we have enzyme information but there are no input rules
            # matching the enzyme, then there is no path
            if not input_rule_set:
                return False
        # Generate the predecessors to our observable and count the paths
        # TODO: Make it optionally possible to return on the first path?
        num_paths = 0
        for path in _find_sources(self.get_im(), obj_obs.name, input_rule_set,
                                  target_polarity):
            num_paths += 1
        #for path in _find_sources_with_paths(self.get_im(), obj_obs.name,
        #                                     input_rule_set, target_polarity):
        #    num_paths += 1
        if num_paths > 0:
            return True
        else:
            return False