Esempio n. 1
0
def assemble(fasta_file: str, score_file: str, tsp_bool=True, ap_bool=True):
    """
    method for assembly via atsp/LKH or Hungarian Alogrithm
    :param fasta_file:
    :param score_file:
    :param tsp:
    :param ap:
    :return:
    """
    # read scores, reads
    nr_of_reads, scores = read_score_file.read_score_file(score_file)
    reads_with_id = parser.parse_fasta_with_id(fasta_file)
    print('Fasta file read.')
    # detect inclusions
    # inclusions = look_for_included_reads([read[1] for i, read in enumerate(reads)], scores)
    # reduce the scores matrix
    # reduced_scores = remove_included_reads_in_scores(scores, inclusions)

    # TSP
    if tsp_bool:
        lkh_contigs, lkh_time, lkh_value = lkh_assemble(reads_with_id, scores)
    else:
        lkh_contigs, lkh_time, lkh_value = [], -1.0, -1

    if ap_bool:
        # Assignment problem
        reads_str_only = [read[1] for i, read in enumerate(reads_with_id)]
        ap_contigs, ap_time, ap_value = munkres(reads_str_only, scores)
    else:
        ap_contigs, ap_time, ap_value = [], -1.0, -1
    with open(score_file.split('.score')[0] + '.assembly', 'w') as f:
        f.write('LKH: Circular: {}\nLKH_Contigs:\n'.format(circular))
        f.write('\n'.join(lkh_contigs))
        f.write('\nLKH_Objective_Value: {}\n'.format(lkh_value))
        f.write('LKH_Time: {}\n'.format(lkh_time))
        f.write('Assignment Problem:\nAP_Contigs:\n')
        f.write('\n'.join(ap_contigs))
        f.write('\nAP_Objective_Value: {}'.format(ap_value))
        f.write('\nAP_Time: {}'.format(ap_time))
Esempio n. 2
0
def compute_objective_function_value_of_fasta(fasta_file: str) -> int:
    reads = parse_fasta_with_id(fasta_file)
    filtered_reads = filter_included_reads(reads)
    return compute_objective_function_value(filtered_reads)