def test_path_option_and_optionl_parameters(self): netchop = CleavageSitePredictorFactory("NetChop") exe = netchop.command.split()[0] for try_path in os.environ["PATH"].split(os.pathsep): try_path = try_path.strip('"') exe_try = os.path.join(try_path, exe).strip() if os.path.isfile(exe_try) and os.access(exe_try, os.X_OK): print exe_try netchop.predict(self.seqs, path=exe_try, options="-v 1")
def test_simple_assembly(self): """ Simple test if everything works. Solution manually tested for optimality. :return: """ pred = CleavageSitePredictorFactory("PCM") assembler = EpitopeAssembly(self.peptides, pred, solver="glpk", verbosity=0) r = assembler.solve() self.assertEqual(r, [Peptide("YLYDHLAPM"), Peptide("ALYDVVSTL"), Peptide("KLLPRLPGV")])
def test_pareto_front_assembly(self): cl_pred = CleavageSitePredictorFactory("PCM") ep_pred = EpitopePredictorFactory("SMM") allele = [Allele("HLA-A*02:01")] thresh = {a.name:10000 for a in allele} comp = lambda a,b: a <= b assembler = ParetoEpitopeAssembly(self.peptides,cl_pred, ep_pred, allele, thresh, comp, solver="cbc", verbosity=0) r = assembler.paretosolve() print(r) #print assembler.solve(eps=2.0)
def test_pareto_assembly(self): cl_pred = CleavageSitePredictorFactory("PCM") ep_pred = EpitopePredictorFactory("SMM") allele = [Allele("HLA-A*02:01")] thresh = {a.name:10000 for a in allele} comp = lambda a,b: a <= b print(ep_pred.predict(self.peptides,alleles=allele)) #cl_pred, ep_pred, alleles, threshold, comparator, length=9 assembler = ParetoEpitopeAssembly(self.peptides,cl_pred, ep_pred, allele, thresh, comp, solver="cbc", verbosity=1) r = assembler.solve(eps=1e10, order=(1,0)) print(r)
def test_standart_functions(self): """ Tests default functions needs GLPK installed :return: """ epi_pred = EpitopePredictorFactory("Syfpeithi") cl_pred = CleavageSitePredictorFactory("PCM") sbws = EpitopeAssemblyWithSpacer(self.epis,cl_pred,epi_pred,self.alleles) sol = sbws.solve() print sol assert all(i == str(j) for i,j in zip(["GHRMAWDMM","HH","VYEADDVIL"],sol))
def test_unsupported_allele_length_combination_exception(self): """ Tests default functions needs GLPK installed :return: """ epi_pred = EpitopePredictorFactory("Syfpeithi") cl_pred = CleavageSitePredictorFactory("PCM") alleles = [Allele("HLA-A*26:01", prob=0.5)] sbws = EpitopeAssemblyWithSpacer(self.epis, cl_pred, epi_pred, alleles, solver="cbc") self.assertRaises(ValueError, sbws.solve)
def test_unsupported_allele_length_combination(self): """ Tests default functions needs GLPK installed :return: """ epi_pred = EpitopePredictorFactory("Syfpeithi") cl_pred = CleavageSitePredictorFactory("PCM") alleles = [ Allele("HLA-A*02:01", prob=0.5), Allele("HLA-A*26:01", prob=0.5) ] sbws = EpitopeAssemblyWithSpacer(self.epis, cl_pred, epi_pred, alleles, solver="cbc") sol = sbws.solve() print sol assert all(i == str(j) for i, j in zip(["GHRMAWDMM", "HH", "VYEADDVIL"], sol))
def test_peptide_cleavage_prediction_single_input(self): for m in CleavageSitePredictorFactory.available_methods(): if m.lower() != "netchop": mo = CleavageSitePredictorFactory(m) mo.predict(self.seqs[0]) mo.predict(self.seqs[1])
def test_wrong_input(self): with self.assertRaises(ValueError): mo = CleavageSitePredictorFactory("NetChop") mo.predict(self.seqs[0])
def test_CleavageSite_prediction_specific_version(self): print CleavageSitePredictorFactory("PCM", version="1.0").predict( self.peptides_mhcI)
def test_peptide_cleavage_prediction_mixed_input(self): mo = CleavageSitePredictorFactory("NetChop") mo.predict(self.seqs)
def test_peptide_cleavage_prediction_single_input(self): mo = CleavageSitePredictorFactory("NetChop") mo.predict(self.seqs[0]) mo.predict(self.seqs[1])
def main(): #Specify CTD interface # Every CTD Model has to have at least a name and a version, plus any of the optional attributes below them. model = argparse.ArgumentParser( description='Commandline tool for cleavage site prediction', ) model.add_argument( '-m', '--method', type=str, choices=CleavageSitePredictorFactory.available_methods().keys(), default="pcm", help='The name of the prediction method') model.add_argument('-v', '--version', type=str, default="", help='The version of the prediction method') model.add_argument('-i', '--input', type=str, required=True, help='Path to the input file (in fasta format)') model.add_argument('-l', '--length', type=int, default=0, help='The length of peptides') model.add_argument( '-op', '--options', type=str, default="", help="Additional options that get directly past to the tool") model.add_argument('-o', '--output', type=str, required=True, help='Path to the output file') args = model.parse_args() #fasta protein peptides = read_fasta(args.input, in_type=Protein) if args.version == "": predictor = CleavageSitePredictorFactory(args.method) result = predictor.predict(peptides, options=args.method) else: predictor = CleavageSitePredictorFactory(args.method, version=args.version) result = predictor.predict(peptides, options=args.method) #if length is specified, than generate compact output if int(args.length) > 0: length = int(args.length) with open(args.output, "w") as f: f.write("Sequence\tMethod\tScore\tProtein ID\tPosition\n") for seq_id in set(result.index.get_level_values(0)): seq = "".join(result.ix[seq_id]["Seq"]) for start in xrange(len(seq) - (length - 1)): pep_seq = seq[start:(start + length)] score = result.loc[(seq_id, start + (length - 1)), predictor.name] f.write(pep_seq + "\t" + predictor.name + "\t" + "%.3f" % score + "\t" + seq_id + "\t" + str(start) + "\n") else: result.to_csv(args.output, float_format="%.3f", sep="\t") return 0
def main(): parser = argparse.ArgumentParser(description="""The software is a novel approach to construct epitope-based string-of-beads vaccines in optimal order and with sequence-optimized spacers of flexible length such that the recovery of contained epitopes is maximized and immunogenicity of arising neo-epitopes is reduced. """) parser.add_argument("-i", "--input", required=True, help="File containing epitopes (one peptide per line)" ) parser.add_argument("-a", "--alleles", required=True, help="Specifies file containing HLA alleles with corresponding HLA probabilities (one HLA per line)" ) #parameters of the model parser.add_argument("-k","--max_length", default=6, type=int, help="Specifies the max. length of the spacers (default 6)") parser.add_argument("-al","--alpha", default=0.99, type=float, help="Specifies the first-order preference of the user in the model [0,1] (default 0.99)") parser.add_argument("-be","--beta", default=0.0, type=float, help="Specifies the second-order preference of the user in the model [0,1] (default 0).") parser.add_argument("-cp","--cleavage_prediction", default="PCM", help="Specifies the used cleavage prediction method (default PCM) [available: PCM, PROTEASMM_C, PROTEASMM_S]" ) parser.add_argument("-ep","--epitope_prediction", default="Syfpeithi", help="Specifies the used epitope prediction method (default Syfpeithi) [available: Syfpeithi, BIMAS, SMM, SMMPMBEC]" ) parser.add_argument("-thr","--threshold", default=20, type=float, help="Specifies epitope prediction threshold for SYFPEITHI (default 20).") parser.add_argument("-o", "--output", required=True, help="Specifies the output file.") parser.add_argument("-t", "--threads", type=int, default=None, help="Specifies number of threads. If not specified all available logical cpus are used.") args = parser.parse_args() #parse input peptides = list(FileReader.read_lines(args.input, in_type=Peptide)) #read in alleles alleles = generate_alleles(args.alleles) if args.cleavage_prediction.upper() not in ["PCM", "PROTEASMM_C", "PROTEASMM_S"]: print "Specified cleavage predictor is currently not supported. Please choose either PCM, PROTEASMM_C, or PROTEASMM_S" sys.exit(-1) if args.epitope_prediction.upper() not in ["SYFPEITHI", "BIMAS", "SMM", "SMMPMBEC"]: print "Specified cleavage predictor is currently not supported. Please choose either Syfpeithi, BIMAS, SMM, SMMPMBEC" sys.exit(-1) #set-up model cl_pred = CleavageSitePredictorFactory(args.cleavage_prediction) epi_pred = EpitopePredictorFactory(args.epitope_prediction) thr = {a.name:args.threshold for a in alleles} solver = EpitopeAssemblyWithSpacer(peptides,cl_pred,epi_pred,alleles, k=args.max_length,en=9,threshold=thr, solver="cplex", alpha=args.alpha, beta=args.beta, verbosity=0) #solve #pre-processing has to be disable otherwise many solver will destroy the symmetry of the problem #how to do this is dependent on the solver used. For CPLEX it is preprocessing_presolve=n threads = mp.cpu_count() if args.threads is None else args.threads svbws = solver.approximate(threads=threads,options={"preprocessing_presolve":"n","threads":1}) print print "Resulting String-of-Beads: ","-".join(map(str,svbws)) print with open(args.output, "w") as f: f.write("-".join(map(str,svbws)))
def main(): parser = argparse.ArgumentParser( description= 'The software is a novel approach to construct epitope-based string-of-beads \ vaccines in optimal order and with sequence-optimized spacers of flexible length \ such that the recovery of contained epitopes is maximized and immunogenicity of \ arising neo-epitopes is reduced.', ) parser.add_argument('-i', "--input", required=True, help="File containing epitopes (one peptide per line)", type=str) parser.add_argument( '-a', "--alleles", required=True, help= "Specifies file containing HLA alleles with corresponding HLA probabilities (one HLA per line)", type=str) #parameters of the model parser.add_argument( '-l', "--max_length", default=6, type=int, help="Specifies the max. length of the spacers (default 6)", ) parser.add_argument( '-al', "--alpha", default=0.99, type=float, help= "Specifies the first-order preference of the user in the model [0,1] (default 0.99)", ) parser.add_argument( '-be', "--beta", default=0.0, type=float, help= "Specifies the second-order preference of the user in the model [0,1] (default 0).", ) parser.add_argument( '-cp', "--cleavage_prediction", default="pcm", choices=["pcm", "proteasmm_c", "proteasmm_i"], help= "Specifies the used cleavage prediction method (default PCM) [available: PCM, PROTEASMM_C, PROTEASMM_I]", type=str) parser.add_argument( '-ep', "--epitope_prediction", default="syfpeithi", choices=["syfpeithi", "smm", "smmpmbec", "bimas"], help= "Specifies the used epitope prediction method (default Syfpeithi) [available: Syfpeithi, BIMAS, SMM, SMMPMBEC]", type=str) parser.add_argument( '-t', "--threshold", default=20, type=float, help= "Specifies epitope prediction threshold for SYFPEITHI (default 20).", ) parser.add_argument( '-o', "--output", required=True, type=str, help="Specifies the output file.", ) parser.add_argument( '-p', "--threads", type=int, default=1, help= "Specifies number of threads. If not specified all available logical cpus are used.", ) parser.add_argument( '-apx', "--approximate", action="store_true", help= "Specifies number of threads. If not specified all available logical cpus are used.", ) args = parser.parse_args() #parse input peptides = read_lines(args.input) #read in alleles alleles = generate_alleles(args.alleles) if args.cleavage_prediction.upper() not in [ "PCM", "PROTEASMM_C", "PROTEASMM_I" ]: sys.stderr.write( "Specified cleavage predictor is currently not supported. \ Please choose either PCM, PROTEASMM_C, or PROTEASMM_I" ) sys.exit(-1) if args.epitope_prediction.upper() not in [ "SYFPEITHI", "BIMAS", "SMM", "SMMPMBEC" ]: sys.stderr.write( "Specified cleavage predictor is currently not supported. \ Please choose either Syfpeithi, BIMAS, SMM, SMMPMBEC") sys.exit(-1) #set-up model cl_pred = CleavageSitePredictorFactory(args.cleavage_prediction) epi_pred = EpitopePredictorFactory(args.epitope_prediction) thr = {a.name: args.threshold for a in alleles} solver = EpitopeAssemblyWithSpacer(peptides, cl_pred, epi_pred, alleles, k=args.max_length, en=9, threshold=thr, solver="cbc", alpha=args.alpha, beta=args.beta, verbosity=1) #solve #pre-processing has to be disable otherwise many solver will destroy the symmetry of the problem #how to do this is dependent on the solver used. For CPLEX it is preprocessing_presolve=n #TODO:CBC should be shipped with the node #TODO: has to be tested with CBC #TODO: LHK has to be shipped as well -> only academic license! #"preprocess":"off", "threads":1} threads = mp.cpu_count() if args.threads is None else args.threads if args.approximate: svbws = solver.approximate(threads=threads, options={ "preprocess": "off", "threads": 1 }) if not svbws: svbws = solver.solve(threads=threads, options={ "preprocess": "off", "threads": 1 }) else: svbws = solver.solve(threads=threads, options={ "preprocess": "off", "threads": 1 }) with open(args.output, "w") as f: f.write(">assembled_spacer_design\n") f.write("".join(map(str, svbws))) return 0
def test_CleavageSite_prediction_no_version(self): print CleavageSitePredictorFactory("PCM").predict(self.peptides_mhcI)
def test_CleavageSite_prediction_unsupported_version(self): print CleavageSitePredictorFactory("PCM", version="2341.0").predict( self.peptides_mhcI)
def main(): model = argparse.ArgumentParser( description='Commandline tool for string-of-beads epitope assembly', ) model.add_argument('-i', '--input', type=str, required=True, help='Path to the input file' ) model.add_argument('-m', '--method', type=str, choices=CleavageSitePredictorFactory.available_methods().keys(), default="pcm", help='The name of the prediction method' ) model.add_argument('-v', '--version', type=str, default="", help='The version of the prediction method' ) model.add_argument('-w', '--weight', type=float, default=0.0, help="Specifies how strong unwanted cleavage sites should be punished [0,1], \ where 0 means they will be ignored, and 1 the sum of all unwanted cleave sites is \ subtracted from the cleave site between two epitopes" ) model.add_argument('-a', '--approximate', action="store_true", help="Flag whether epitope ordering should be approximated" ) model.add_argument('-s', '--solver', type=str, default="cbc", help="The ILP solver to be used by Pyomo (must be in PATH)" ) model.add_argument('-so', '--solver_options', type=str, default="", help="Solver specific options (will not be checked for correctness)" ) model.add_argument('-o', '--output', type=str, required=True, help='Path to the output file' ) args = model.parse_args() try: peptides = read_lines(args.input) except Exception as e: print e sys.stderr.write("Input file could not be read. Please check the existence and input format.") return -1 try: if args.version == "": predictor = CleavageSitePredictorFactory(args.method) else: predictor = CleavageSitePredictorFactory(args.method, version=args.version) except ValueError as e: sys.stderr.write(str(e)) return -1 try: assembler = EpitopeAssembly(peptides, predictor, solver=args.solver, weight=args.weight) except Exception as e: sys.stderr.write(str(e)) return -1 try: if args.approximate: assembly = assembler.approximate() else: options = {} for opt in args.solver_options.split(): name,value = opt.partition("=")[::2] try: options[name] = float(value) except Exception: options[name] = value assembly = assembler.solve(options=options) except Exception as e: sys.stderr.write(str(e)) return -1 try: with open(args.output, "w") as f: f.write(">assembled_polypeptide\n"+"".join(str(p) for p in assembly)) except IOError as e: sys.stderr.write(str(e)) return -1 return 0
def main(): parser = argparse.ArgumentParser( description= """The software is a novel approach to construct epitope-based string-of-beads vaccines in optimal order and with sequence-optimized spacers of flexible length such that the recovery of contained epitopes is maximized and immunogenicity of arising neo-epitopes is reduced. """) parser.add_argument("-i", "--input", required=True, help="File containing epitopes (one peptide per line)") parser.add_argument( "-a", "--alleles", required=True, help= "Specifies file containing HLA alleles with corresponding HLA probabilities (one HLA per line)" ) #parameters of the model parser.add_argument( "-k", "--max_length", default=6, type=int, help="Specifies the max. length of the spacers (default 6)") parser.add_argument( "-al", "--alpha", default=0.99, type=float, help= "Specifies the first-order preference of the user in the model [0,1] (default 0.99)" ) parser.add_argument( "-be", "--beta", default=0.0, type=float, help= "Specifies the second-order preference of the user in the model [0,1] (default 0)." ) parser.add_argument( "-cp", "--cleavage_prediction", default="PCM", help= "Specifies the used cleavage prediction method (default PCM) [available: PCM, PROTEASMM_C, PROTEASMM_S]" ) parser.add_argument( "-ep", "--epitope_prediction", default="Syfpeithi", help= "Specifies the used epitope prediction method (default Syfpeithi) [available: Syfpeithi, BIMAS, SMM, SMMPMBEC]" ) parser.add_argument( "-thr", "--threshold", default=20, type=float, help= "Specifies epitope prediction threshold for SYFPEITHI (default 20).") parser.add_argument("-o", "--output", required=True, help="Specifies the output file.") parser.add_argument( "-t", "--threads", type=int, default=None, help= "Specifies number of threads. If not specified all available logical cpus are used." ) parser.add_argument( "--ips-solver", default="cplex", choices=["cplex", "cbc"], help= "Executable name of the IPS solver. Executable needs to be available in PATH." ) parser.add_argument("--tsp-solution", default="approximate", choices=["approximate", "optimal"], help="Type of solution of the TSP") parser.add_argument( "--random-order", action="store_true", help= "Indicate whether to generate a random ordered string-of-beads polypeptide" ) parser.add_argument( "--seed", type=int, default=1, help="Seed for random ordering of string-of-beads polypeptide") args = parser.parse_args() #parse input peptides = list(FileReader.read_lines(args.input, in_type=Peptide)) #read in alleles alleles = generate_alleles(args.alleles) if args.cleavage_prediction.upper() not in [ "PCM", "PROTEASMM_C", "PROTEASMM_S" ]: print "Specified cleavage predictor is currently not supported. Please choose either PCM, PROTEASMM_C, or PROTEASMM_S" sys.exit(-1) if args.epitope_prediction.upper() not in [ "SYFPEITHI", "BIMAS", "SMM", "SMMPMBEC" ]: print "Specified cleavage predictor is currently not supported. Please choose either Syfpeithi, BIMAS, SMM, SMMPMBEC" sys.exit(-1) #set-up model cl_pred = CleavageSitePredictorFactory(args.cleavage_prediction) epi_pred = EpitopePredictorFactory(args.epitope_prediction) thr = {a.name: args.threshold for a in alleles} solver = EpitopeAssemblyWithSpacer(peptides, cl_pred, epi_pred, alleles, k=args.max_length, en=9, threshold=thr, solver=args.ips_solver, alpha=args.alpha, beta=args.beta, verbosity=0) #solve #pre-processing has to be disable otherwise many solver will destroy the symmetry of the problem #how to do this is dependent on the solver used. For CPLEX it is preprocessing_presolve=n threads = mp.cpu_count() if args.threads is None else args.threads if args.tsp_solution == "approximate": svbws = solver.approximate(threads=threads, options={ "preprocessing_presolve": "n", "threads": 1 }) else: svbws = solver.solve(threads=threads, options={ "preprocessing_presolve": "n", "threads": 1 }) # Generate random ordered string-of-breads, but still uses optimal spacers # determined from the above solve function. if args.random_order: print "Generating a randomly ordered polypeptide" random.seed(args.seed) random_order_sob = [] random.shuffle(peptides) for i in range(len(peptides)): # Break from loop once we hit the last peptide if i == len(peptides) - 1: random_order_sob.extend([Peptide(str(peptides[i]))]) break left_peptide = str(peptides[i]) right_peptide = str(peptides[i + 1]) opt_spacer = solver.spacer[(left_peptide, right_peptide)] # Right peptide gets added in the next iteration random_order_sob.extend( [Peptide(left_peptide), Peptide(opt_spacer)]) svbws = random_order_sob print print "Resulting String-of-Beads: ", "-".join(map(str, svbws)) print with open(args.output, "w") as f: f.write("-".join(map(str, svbws)))