def read_quast_file(file):
    """
    Extracts misassembly regions from QUAST file, usually located in /QUAST_output/contig_reports/all_alignments_$$.tsv
    :param file:
    :return:
    """
    total_count = 0
    relocation_count = 0
    translocation_count = 0
    inversion_count = 0
    misassemblies = []
    with open(file) as f:
        prev_line = ''
        for line in f:
            line = line.rstrip().replace(',', '')
            splits = line.split('\t')
            if splits[0].split(' ')[0] == 'relocation':
                s_ref, e_ref, s_con, e_con, ref, con, idn, ambi, bg = (
                    prev_line.split('\t'))
                misassemblies.append([ref, s_ref, e_ref, splits[0].split(
                    ' ')[0]])
                relocation_count += 1
                total_count += 1
            elif splits[0] == 'translocation':
                s_ref, e_ref, s_con, e_con, ref, con, idn, ambi, bg = (
                    prev_line.split('\t'))
                misassemblies.append([ref, s_ref, e_ref, splits[0]])
                translocation_count += 1
                total_count += 1
            elif splits[0] == 'inversion':
                s_ref, e_ref, s_con, e_con, ref, con, idn, ambi, bg = (
                    prev_line.split('\t'))
                misassemblies.append([ref, s_ref, e_ref, splits[0]])
                inversion_count += 1
                total_count += 1
            prev_line = line
    print('#####--TOTAL MISSASSEMBLIES: REPORTED BY QUAST--#####')
    print('Total Misassemblies:\t', total_count)
    print('Total relocations:\t', relocation_count)
    print('Total translocations:\t', translocation_count)
    print('Total inversions:\t', inversion_count)
    print('#####################################################\n')
    return misassemblies
