Ejemplo n.º 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]
Ejemplo n.º 2
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