Beispiel #1
0
    def predict(self, peptides, **kwargs):
        """
        Takes peptides plus their trailing C and N-terminal residues to predict
        the probability that this n-mer was produced by proteasomal cleavage. It returns the score and
        the peptide sequence in a AResult object. Row-IDs are the peitopes column is the prediction score.

        :param peptides: A list of peptide objects or a single peptide object
        :type peptides: list(:class:`~Fred2.Core.Peptide.Peptide`) or :class:`~Fred2.Core.Peptide.Peptide`
        :return: Returns a :class:`Fred2.Core.Result.CleavageFragmentPredictionResult` object
        :rtype: :class:`Fred2.Core.Result.CleavageFragmentPredictionResult`
        """
        def __load_model(length):
            allele_model = "%%s_%i" % (self.name, length)
            return getattr(
                __import__("Fred2.Data.pssms." + self.name + ".mat." +
                           allele_model,
                           fromlist=[allele_model]), allele_model)

        if isinstance(peptides, Peptide):
            pep_seqs = {str(peptides): peptides}
        else:
            pep_seqs = {}
            for p in peptides:
                if not isinstance(p, Peptide):
                    raise ValueError("Input is not of type Protein or Peptide")
                pep_seqs[str(p)] = p

        result = {self.name: {}}
        for length, peps in itertools.groupby(iter(pep_seqs.keys()),
                                              key=lambda x: len(x)):
            peps = list(peps)
            #dynamicaly import prediction PSSMS for alleles and predict
            if length not in self.supportedLength:
                warnings.warn("Peptide length of %i not supported" % length,
                              RuntimeWarning)
                continue

            #load pssm matrices
            try:
                pssm = __load_model(length)
            except ImportError:
                raise KeyError("No model found for %s with length %i" %
                               (self.name, length))

            for p in peps:
                score = sum(pssm[i][aa] for i, aa in enumerate(p)) + pssm.get(
                    -1, {}).get("con", 0)
                pep = pep_seqs[p][self.trailingN:-self.tralingC]
                result[self.name][pep] = score

        if not result:
            raise ValueError(
                "No predictions could be made for the given input.")
        df_result = CleavageFragmentPredictionResult.from_dict(result)
        df_result.index = pandas.MultiIndex.from_tuples(
            [tuple((i, self.name)) for i in df_result.index],
            names=['Seq', 'Method'])
        return df_result
Beispiel #2
0
    def predict(self, peptides,  **kwargs):
        """
        Takes peptides plus their trailing C and N-terminal residues to predict
        the probability that this n-mer was produced by proteasomal cleavage. It returns the score and
        the peptide sequence in a AResult object. Row-IDs are the peitopes column is the prediction score.

        :param peptides: A list of peptide objects or a single peptide object
        :type peptides: list(:class:`~Fred2.Core.Peptide.Peptide`) or :class:`~Fred2.Core.Peptide.Peptide`
        :return: Returns a :class:`Fred2.Core.Result.CleavageFragmentPredictionResult` object
        :rtype: :class:`Fred2.Core.Result.CleavageFragmentPredictionResult`
        """
        def __load_model(length):
            allele_model = "%%s_%i"%(self.name, length)
            return getattr(__import__("Fred2.Data.pssms."+self.name+".mat."+allele_model, fromlist=[allele_model]),
                           allele_model)

        if isinstance(peptides, Peptide):
            pep_seqs = {str(peptides):peptides}
        else:
            pep_seqs = {}
            for p in peptides:
                if not isinstance(p, Peptide):
                    raise ValueError("Input is not of type Protein or Peptide")
                pep_seqs[str(p)] = p

        result = {self.name:{}}
        for length, peps in itertools.groupby(pep_seqs.iterkeys(), key= lambda x: len(x)):
            peps = list(peps)
            #dynamicaly import prediction PSSMS for alleles and predict
            if length not in self.supportedLength:
                warnings.warn("Peptide length of %i not supported"%length, RuntimeWarning)
                continue

            #load pssm matrices
            try:
                pssm = __load_model(length)
            except ImportError:
                raise KeyError("No model found for %s with length %i"%(self.name, length))

            for p in peps:
                score = sum(pssm[i][aa] for i, aa in enumerate(p))+pssm.get(-1, {}).get("con", 0)
                pep = pep_seqs[p][self.trailingN:-self.tralingC]
                result[self.name][pep] = score

        if not result:
            raise ValueError("No predictions could be made for the given input.")
        df_result = CleavageFragmentPredictionResult.from_dict(result)
        df_result.index = pandas.MultiIndex.from_tuples([tuple((i, self.name)) for i in df_result.index],
                                                        names=['Seq', 'Method'])
        return df_result
Beispiel #3
0
    def predict(self, peptides,  **kwargs):
        def __load_model(length):
            allele_model = "%s_%i"%(self.name, length)
            return getattr(__import__("Fred2.Data.pssms."+self.name+".mat."+allele_model, fromlist=[allele_model]),
                           allele_model)

        if isinstance(peptides, Peptide):
            pep_seqs = {str(peptides):peptides}
        else:
            if any(not isinstance(p, Peptide) for p in peptides):
                raise ValueError("Input is not of type Protein or Peptide")
            pep_seqs = {str(p):p for p in peptides}

        result = {self.name:{}}
        for length, peps in itertools.groupby(pep_seqs.iterkeys(), key=lambda x: len(x)):
            peps = list(peps)
            #dynamicaly import prediction PSSMS for alleles and predict
            if length not in self.supportedLength:
                warnings.warn("Peptide length of %i not supported"%length, RuntimeWarning)
                continue

            #load pssm matrices
            try:
                pssm = __load_model(length)
            except ImportError:
                raise KeyError("No model found for %s with length %i"%(self.name, length))


            for p in peps:
                score = pssm[0][p[0]]+pssm[1][p[1]] + sum(pssm[2][aa] for aa in p[2:-2])\
                        + pssm[3][p[-2]] + pssm[4][p[-1]]
                pep = pep_seqs[p][self.trailingN: -self.tralingC]
                result[self.name][pep] = score

        if not result:
            raise ValueError("No predictions could be made for the given input.")
        df_result = CleavageFragmentPredictionResult.from_dict(result)
        return df_result