Example #1
0
 def test_epitope_conservation_constraint(self):
     import random
     self.result = EpitopePredictorFactory("BIMAS").predict(self.peptides, self.alleles)
     conservation = {}
     for e in self.result.index.levels[0]:
         conservation[str(e)] = random.random()
     pt = OptiTope(self.result, self.thresh, k=3, solver="cbc", verbosity=0)
     pt.activate_epitope_conservation_const(0.5, conservation=conservation)
     for e in pt.solve():
         print e, conservation[e]
Example #2
0
    def test_selection_without_constraints(self):
        """
        tests if minimal selection withotu additional constraints (except the knapsack capacity) works

        #peptides obtainedn by perfroming optimization with same input and parameters by
        etk.informatik.uni-tuebingen.de/optitope

        :return:
        """
        opt = OptiTope(self.result, self.thresh, k=3, solver="cplex", verbosity=0)
        r =opt.solve()
        self.assertTrue(len(set(str(p) for p in r) - set(["GPTPLLYRL", "QYLAGLSTL", "ALYDVVSTL"])) == 0 )
Example #3
0
    def test_selection_without_constraints(self):
        """
        tests if minimal selection withotu additional constraints (except the knapsack capacity) works

        #peptides obtainedn by perfroming optimization with same input and parameters by
        etk.informatik.uni-tuebingen.de/optitope

        :return:
        """
        opt = OptiTope(self.result, self.thresh, k=3, solver="cbc", verbosity=0)
        r =opt.solve()

        self.assertTrue(len(set(str(p) for p in r) - set(["GPTPLLYRL", "QYLAGLSTL", "ALYDVVSTL"])) == 0)
Example #4
0
    def test_allele_cov_constraint(self):
        """
        tests the allele converage constraints

        :return:
        """
        # self.alleles.extend([Allele("HLA-A*02:01"),Allele("HLA-B*15:01")])
        # self.thresh.update({"A*02:01":0,"B*15:01":0})
        self.result = EpitopePredictorFactory("BIMAS").predict(self.peptides, self.alleles)
        opt = OptiTope(self.result, self.thresh, k=3, solver="glpk", verbosity=0)
        opt.activate_allele_coverage_const(0.99)
        r = opt.solve()

        self.assertTrue(len(set(str(p) for p in r) - set(["GPTPLLYRL", "QYLAGLSTL", "ALYDVVSTL"])) == 0)
Example #5
0
    def test_allele_cov_constraint(self):
        """
        tests the allele converage constraints

        :return:
        """
        #self.alleles.extend([Allele("HLA-A*02:01"),Allele("HLA-B*15:01")])
        #self.thresh.update({"A*02:01":0,"B*15:01":0})
        self.result= EpitopePredictorFactory("BIMAS").predict(self.peptides, self.alleles)
        opt = OptiTope(self.result, self.thresh, k=3, solver="cbc", verbosity=0)
        opt.activate_allele_coverage_const(0.99)
        r = opt.solve()

        self.assertTrue(len(set(str(p) for p in r) - set(["GPTPLLYRL", "QYLAGLSTL", "ALYDVVSTL"])) == 0 )
Example #6
0
    def test_allele_cov_constraint(self):
         """
         tests the allele converage constraints

         :return:
         """
         #self.alleles.extend([Allele("HLA-A*02:01"),Allele("HLA-B*15:01")])
         #self.thresh.update({"A*02:01":0,"B*15:01":0})
         self.result= EpitopePredictorFactory("BIMAS").predict(self.peptides, self.alleles)
         print self.result[self.alleles[0:2]]
         opt = OptiTope(self.result,self.thresh,k=3,solver="cplex",verbosity=1)
         opt.activate_allele_coverage_const(0.8)
         r = opt.solve()
         res_df = self.result.xs(self.result.index.values[0][1], level="Method")
         peps = [str(p) for p in r]

         probs = {"A*01:01":1, "A*02:01":1, "B*07:02":1,"B*15:01":1,"C*03:01":1.0}
         res_df = res_df.loc[peps, :]
         res_df = res_df[[a for a in self.alleles]]
         res_df = res_df[res_df.apply(lambda x: any(x[a] > self.thresh[a.name] for a in self.alleles), axis=1)]

         print res_df.apply(lambda x: sum( x[c]*probs[c.name] for c in res_df.columns),axis=1)

         self.assertTrue(len(set(str(p) for p in r) - set(["ALYDVVSTL", "KLLPRLPGV", "GPTPLLYRL"])) == 0 )
Example #7
0
def main():
    '''
        some input stuff
    '''
    parser = argparse.ArgumentParser(
                      description="Epitope Selection for vaccine design.",

    )
    parser.add_argument("-i","--input",
               required=True,
               type=str,
               help="Peptide with immunogenicity file (from epitopeprediction)",
    )
    parser.add_argument("-a","--alleles",
               required=True,
               type=str,
               help="Allele file with frequencies (one allele and frequency per line)",
    )

    parser.add_argument("-k","--k",
               required=False,
               type=int,
               default=10,
               help="Specifies the number of epitopes to select",
    )
    parser.add_argument("-t", "--threshold",
               type=float,
               default=0.,
               help="Specifies the binding threshold for all alleles",
    )
    parser.add_argument("-o", "--output",
               required=True,
               type=str,
               help="Specifies the output path. Results will be written to CSV",
    )

    parser.add_argument("-s","--solver",
               type=str,
               default="cbc",
               help="Specifies the ILP solver")

    parser.add_argument("-c_al", "--cons_allele",
               required=False,
               type=float,
               default=0.0,
               help="Activates allele coverage constraint with specified threshold",
    )

    parser.add_argument("-c_a", "--cons_antigen",
               required=False,
               type=float,
               default=0.0,
               help="Activates antigen coverage constraint with specified threshold",
    )

    c_c = parser.add_argument("-c_c", "--cons_conservation",
               required=False,
               type=float,
               help="Activates conservation constraint with specified threshold",
    )

    parser.add_argument("-c", "--conservation",
               required=False,
               type=str,
               help="Specifies a Conservation file. First column is the peptide seq second column the conservation.",
               )

    args = parser.parse_args()

    epitopePrediciton, method = generate_epitope_result(args.input, args.alleles)
    thresh = {a.name: float(args.threshold) for a in epitopePrediciton.columns}
    opti = OptiTope(epitopePrediciton, threshold=thresh, k=int(args.k), solver=args.solver, verbosity=0)

    # set constraints
    if args.cons_allele > 0:
        #print "allele constraint enforced"
        opti.activate_allele_coverage_const(float(args.cons_allele) / 100.0)

    if args.cons_antigen > 0:
        opti.activate_antigen_coverage_const(float(args.cons_antigen) / 100.0)

    if args.cons_conservation > 0:
        if args.conservation:
            conservation = {}
            with open(args.conservation, "r") as f:
                for l in f:
                    if l != "":
                        seq, cons = l.replace(",", " ").replace(";", " ").split()
                        conservation[seq.strip().upper()] = float(cons.strip())
            opti.activate_epitope_conservation_const(float(args.cons_conservation)/100.0, conservation=conservation)
        else:
            opti.activate_epitope_conservation_const(float(args.cons_conservation)/100.0)
    try:
        result = opti.solve(options={"threads": 1})

        to_csv(args.output, result, opti.instance, method)
        return 0
    except ValueError as e:
        sys.stderr.write("Could not optimally solve the problem. Please modify your constraints.\n"+str(e))
        return -1
    except Exception as e:
        sys.stderr.write(str(e))
        return -1