Exemplo n.º 1
0
def solve_ddp_brute(ord_genome_file,
                    all_dupl_genome_file,
                    out_result_file=None,
                    tl=50,
                    mult=2):
    ord_genome = parse_genome_in_grimm_file(ord_genome_file)
    all_dupl_genome = parse_genome_in_grimm_file(all_dupl_genome_file)

    ord_genome = remove_singletons_in_ord_wrt_two_dupl(ord_genome,
                                                       all_dupl_genome)
    all_dupl_genome = remove_singletons_dupl_wrt_gene_set(
        all_dupl_genome, set(ord_genome.get_gene_multiset().keys()))

    config = DoubleDistConf(ordinary_genome=ord_genome,
                            duplicated_genome=all_dupl_genome,
                            name="DDP",
                            log_file="brute_double_dist.log",
                            tl=tl,
                            mult=mult)
    start_time = datetime.now()
    answer = solve(config)
    end_time = datetime.now()
    logging.info(answer)
    if out_result_file:
        write_answer(answer, out_result_file, end_time - start_time)
    return answer
Exemplo n.º 2
0
def solve_restricted_halving_problem(ordinary_genome_file,
                                     all_dupl_genome_file, out_result_file,
                                     out_predup_file, gurobi_log_file,
                                     time_limit):
    logging.info(
        'Start to solve RGGHP problem with time limit equals {0}'.format(
            time_limit))

    ord_genomes = [parse_genome_in_grimm_file(ordinary_genome_file)]
    all_dupl_genome = parse_genome_in_grimm_file(all_dupl_genome_file)

    logging.info('Create ILP config')
    cfg = RestrictedHalvingConf(duplicated_genome=all_dupl_genome,
                                ordinary_genomes=ord_genomes,
                                name="RGGHP",
                                log_file=gurobi_log_file,
                                tl=time_limit,
                                mult=2)

    answer = create_ilp_formulation_for_restricted_phalving(cfg)

    if answer is not None:
        logging.info('Save results.')
        answer.write_stats_file(out_result_file)
        answer.write_genome_file(out_predup_file)
    else:
        logging.info('There are no answers. Please, check log file.')
Exemplo n.º 3
0
def halvings_without_singletons(ordinary_genome_file, all_dupl_genome_file,
                                out_result_file, out_predup_file, problem,
                                gurobi_log_file, time_limit):
    logging.info(
        'Start to solve {0} (excluding singletons) with time limit equals {1}'.
        format(problem, time_limit))

    ord_genomes = [parse_genome_in_grimm_file(ordinary_genome_file)]
    all_dupl_genome = parse_genome_in_grimm_file(all_dupl_genome_file)

    logging.info('Create ILP config')
    if problem == "CGGHP":
        cfg = ConservedHalving(duplicated_genome=all_dupl_genome,
                               ordinary_genomes=ord_genomes,
                               name="CGGHP",
                               log_file=gurobi_log_file,
                               tl=time_limit,
                               mult=2)
    else:
        cfg = ClassicHalving(duplicated_genome=all_dupl_genome,
                             ordinary_genomes=ord_genomes,
                             name="GGHP",
                             log_file=gurobi_log_file,
                             tl=time_limit,
                             mult=2)

    answer = create_ilp_formulation_for_halvings_without_singletons(cfg)

    if answer is not None:
        logging.info('Save results.')
        answer.write_stats_file(out_result_file)
        answer.write_genome_file(out_predup_file)
    else:
        logging.info('There are no answers. Please, check log file.')
Exemplo n.º 4
0
def solve_double_distance_problem(ord_genome_file,
                                  all_dupl_genome_file,
                                  out_result_file,
                                  gurobi_log_file,
                                  mult=2,
                                  time_limit=7200,
                                  ilp_type='improved'):
    logging.info(
        'Start to solve DDP problem with time limit equals {0} and solver type "{1}"'
        .format(time_limit, ilp_type))

    ord_genome = parse_genome_in_grimm_file(ord_genome_file)
    all_dupl_genome = parse_genome_in_grimm_file(all_dupl_genome_file)

    ord_genome = remove_singletons_in_ord_wrt_two_dupl(ord_genome,
                                                       all_dupl_genome)
    all_dupl_genome = remove_singletons_dupl_wrt_gene_set(
        all_dupl_genome, set(ord_genome.get_gene_multiset().keys()))

    logging.info('Create ILP config')
    config = DoubleDistConf(ordinary_genome=ord_genome,
                            duplicated_genome=all_dupl_genome,
                            name="DDP_" + ilp_type,
                            log_file=gurobi_log_file,
                            tl=time_limit,
                            mult=mult)

    answer = create_ilp_formulation_for_ddp(config=config, ilp_type=ilp_type)
    if answer is not None:
        logging.info('Save results.')
        answer.write_stats_file(out_result_file)
        return answer.obj_val, answer.score
    else:
        logging.info('There are no answers. Please, check log file.')
        return None
Exemplo n.º 5
0
def medians_without_singletons(genome_files, out_result_file, out_median_file,
                               problem, gurobi_log_file, time_limit):
    logging.info(
        'Start to solve {0} (excluding singletons) with time limit equals {1}'.
        format(problem, time_limit))
    genomes = [
        parse_genome_in_grimm_file(genome_file) for genome_file in genome_files
    ]

    logging.info('Create ILP config')
    if problem == "CGMP":
        cfg = ConservedMedian(genomes=genomes,
                              name="CGMP",
                              log_file=gurobi_log_file,
                              tl=time_limit)
    else:
        cfg = ClassicMedian(genomes=genomes,
                            name="GMP",
                            log_file=gurobi_log_file,
                            tl=time_limit)

    answer = create_ilp_formulation_for_medians_without_singletons(cfg)

    if answer is not None:
        logging.info('Save results.')
        answer.write_stats_file(out_result_file)
        answer.write_genome_file(out_median_file)
    else:
        logging.info('There are no answers. Please, check log file.')
Exemplo n.º 6
0
def solve_restricted_median_problem(genome_files,
                                    out_result_file,
                                    out_median_file,
                                    gurobi_log_file,
                                    time_limit=7200):
    logging.info(
        'Start to solve IGMP problem with time limit equals {0}'.format(
            time_limit))

    genomes = [
        parse_genome_in_grimm_file(genome_file) for genome_file in genome_files
    ]

    logging.info('Create ILP config')
    cfg = RestrictedMedianConf(genomes=genomes,
                               name="IGMP",
                               log_file=gurobi_log_file,
                               tl=time_limit)

    answer = create_ilp_formulation_for_restricted_median(cfg)

    if answer is not None:
        logging.info('Save results.')
        answer.write_stats_file(out_result_file)
        answer.write_genome_file(out_median_file)
    else:
        logging.info('There are no answers. Please, check log file.')
def medians_with_singletons(genome_files, out_result_file, out_median_file,
                            problem, gurobi_log_file, time_limit):
    """Creates and calculates the ILP instance for GMP or CGMP with assumption of singleton existance in the
        ancestral genome.

    Args:
        TBA
    """

    logging.info(
        'Start to solve {0} (including singletons) with time limit equals {1}'.
        format(problem, time_limit))

    genomes = [
        parse_genome_in_grimm_file(genome_file) for genome_file in genome_files
    ]
    genomes, numb_of_singletons = remove_known_singletons(genomes)

    logging.info('Create ILP config')
    if problem == "CGMP":
        cfg = ConservedMedian(genomes=genomes,
                              name="CGMP",
                              log_file=gurobi_log_file,
                              tl=time_limit)
    else:
        cfg = ClassicMedian(genomes=genomes,
                            name="GMP",
                            log_file=gurobi_log_file,
                            tl=time_limit)

    answer = create_ilp_formulation_for_medians_with_singletons(cfg)

    if answer is not None:
        answer.update_score_by_singletons(numb_of_singletons)

        logging.info('Save results.')
        answer.write_stats_file(out_result_file)
        answer.write_genome_file(out_median_file)
    else:
        logging.info('Solution was not found. Please, check log file.')