def main(input_peptides, input_vaccine_sequences, output_vaccine_epitopes, verbose, log_file): ''' Reads the vaccine produced by Fischer's online tool and converts it into epitopes ''' global LOGGER LOGGER = utilities.init_logging(verbose, log_file, log_append=False) LOGGER.info('Reading peptides...') with open(input_peptides) as f: peptides = set(r['peptide'] for r in csv.DictReader(f)) LOGGER.info('Read %d peptides', len(peptides)) LOGGER.info('Reading vaccine...') mosaics = FileReader.read_fasta(input_vaccine_sequences, in_type=Protein) LOGGER.info('Vaccine has %d mosaic(s)', len(mosaics)) with open(output_vaccine_epitopes, 'w') as f: writer = csv.writer(f) writer.writerow(('cocktail', 'index', 'epitope')) for c, mos in enumerate(mosaics): pep_count = unk_count = 0 for i in range(0, len(mos) - 8): pep = mos[i:i + 9] assert len(pep) == 9 if pep in peptides: writer.writerow((c, pep_count, pep)) pep_count += 1 else: unk_count += 1 LOGGER.info('Mosaic %d - Recognized: %d Unknown %d', c + 1, pep_count, unk_count)
import utilities if __name__ == "__main__": # Parse commandline arguments cmd_parser = argparse.ArgumentParser("Runs Redbot") cmd_parser.add_argument('--debug', action='store_true', help="Enable debug logging") cmd_parser.add_argument('--token', default=None, help="Discord bot token to run with") args = cmd_parser.parse_args() # Initialise logging logger = utilities.init_logging(args.debug) # Initialise bot logger.debug("Initalising RedBot") _bot = redbot.init(logger=logger) # Assign token logger.debug("Assigning token") token = args.token or utilities.env("DISCORD_REDBOT_TOKEN") if not token: raise ValueError("Token not provided.") del args # Start bot instance logger.debug("Starting instance")
def main(verbose, log_file, bound_what, max_epitopes, max_aminoacids, output_vaccine, **kwargs): global LOGGER LOGGER = utilities.init_logging(verbose, log_file, log_append=False) # add coverage information to the model by enforcing at least 2 proteins covered if bound_what != 'immunogen': kwargs['min_proteins'] = 2 solver, data = utilities.get_mosaic_solver_instance(LOGGER, **kwargs) solver.build_model() # update objective if bound_what == 'coverage': optimize_coverage(solver) LOGGER.info('Optimizing pathogen coverage') elif bound_what == 'conservation': optimize_conservation(solver) LOGGER.info('Optimizing average conservation') else: LOGGER.info('Optimizing immunogenicity') # preserve user sorting # initializing a larger problem with the optimal (and still feasible) solution of a smaller one # usually makes it much faster to solve. however, too small problems could be infeasible, in which # case it usually takes a very long time to prove them so for ep in map(int, max_epitopes): for am in map(int, max_aminoacids): LOGGER.info( 'Solving with at most %d epitopes and most %d aminoacids', ep, am) solver.update_max_vertices(ep) solver.update_max_edge_cost(am) try: result = solver.solve() except RuntimeError: LOGGER.info( 'Problem was found infeasible with %d epitopes and %d aminoacids', ep, am) continue # print info and save fname = output_vaccine.format(a=am, e=ep) LOGGER.info('Saving result to %s', fname) total_ig = 0.0 with open(fname, 'w') as f: writer = csv.writer(f) writer.writerow(('cocktail', 'index', 'epitope')) for i, mosaic in enumerate(result): LOGGER.info('Mosaic #%d', i + 1) for j, (_, vertex) in enumerate(mosaic[:-1]): writer.writerow( (i, j, data['epitope_data'][vertex - 1]['epitope'])) total_ig += data['epitope_data'][vertex - 1]['immunogen'] LOGGER.info( ' %s - IG: %.2f', data['epitope_data'][vertex - 1]['epitope'], data['epitope_data'][vertex - 1]['immunogen']) LOGGER.info('Total immunogenicity: %.3f', total_ig)
def main(verbose, log_file): global LOGGER LOGGER = utilities.init_logging(verbose, log_file, log_append=False)
action='store_true', help='reset global_step to zero') parser.add_argument('--likelihood_loss', choices=['l1', 'vgg_perception']) parser.add_argument('--to_use_imgn', default='true') parser.add_argument('--to_use_mean') parser.add_argument('--loss_test') parser.add_argument('--copy') parser.add_argument('--add_train') parser.set_defaults(retrain=False) opt = parser.parse_args() with open(opt.config) as f: config = yaml.load(f) out_dir, logger = utilities.init_logging(opt.log_dir) logger.info(opt) logger.info(yaml.dump(config)) print('out dir: ', out_dir) if opt.mode == 'train': batch_size = config['batch_size'] img_shape = 2 * [config['spatial_size']] + [3] data_shape = [batch_size] + img_shape init_shape = [config['init_batches'] * batch_size] + img_shape box_factor = config['box_factor'] data_index = config['data_index'] batches = get_batches(data_shape, data_index,
def main(input_epitopes, input_cleavages, output_frontier, cocktail, pareto_steps, verbose, log_file, max_aminoacids, max_epitopes, min_alleles, min_proteins, min_avg_prot_conservation, min_avg_alle_conservation): ''' Explore the trade-off between the immunogenicity and the cleavage likelihood for string-of-beads vaccines. Outputs the Pareto frontier of the two objectives. ''' global LOGGER LOGGER = utilities.init_logging(verbose=verbose, log_file=log_file) # load epitopes epitopes = utilities.load_epitopes(input_epitopes) LOGGER.info('Loaded %d epitopes', len(epitopes)) # read cleavage scores cleavage_epitopes = set() cleavages, spacers = {}, {} with open(input_cleavages) as f: for row in csv.DictReader(f): cleavages[row['from'], row['to']] = float(row['score']) spacers[row['from'], row['to']] = row.get('spacer', '') cleavage_epitopes.add(row['from']) cleavage_epitopes.add(row['to']) LOGGER.info('Loaded %d cleavage scores', len(cleavages)) # compute edge cost edge_cost, vertices, vertices_rewards = [], [], [] vertex_to_epitope = [''] + list(cleavage_epitopes) for ep_from in vertex_to_epitope: vertices.append(ep_from) vertices_rewards.append(0 if ep_from == '' else epitopes[ep_from]['immunogen']) edge_cost.append([ cleavages[ep_from, ep_to] if ep_from != '' and ep_to != '' and ep_from != ep_to else 0.0 for ep_to in vertex_to_epitope ]) LOGGER.info('Graph has %d vertices', len(vertex_to_epitope)) # find optimal design solver_build_time = time.time() solver = TeamOrienteeringIlp( num_teams=cocktail, vertex_reward=vertices_rewards, edge_cost=edge_cost, type_coverage=[], min_type_coverage=[], min_avg_type_conservation=[], max_edge_cost=0, max_vertices=max_epitopes ) solver.build_model() reward_cost = solver.explore_edge_cost_vertex_reward_tradeoff(pareto_steps) with open(output_frontier, 'w') as f: writer = csv.writer(f) writer.writerow(('immunogenicity', 'cleavage', 'epitopes', 'spacers')) for epitopes_index, immunogen, cleavage in reward_cost: vax_epis, vax_spacers = [], [] for a, b in epitopes_index[0]: # FIXME multiple tours? if b != 0: vax_epis.append(vertex_to_epitope[b]) if a != 0 and b != 0: vax_spacers.append(spacers[vertex_to_epitope[a], vertex_to_epitope[b]]) writer.writerow((immunogen, cleavage, ';'.join(vax_epis), ';'.join(vax_spacers))) f.flush() # write progress immediately LOGGER.info('Immunogenicity: %.3f - Cleavage: %.3f - Epitopes: %s - Spacers: %s', immunogen, cleavage, ', '.join(vax_epis), ', '.join(vax_spacers))