def mapsplice_parse(fusion, out):
    """
    Parse fusion junctions from MapSplice aligner
    """
    print('Start parsing fusion junctions from MapSplice...')
    total = 0
    with open(fusion, 'r') as junc_f, open(out, 'w') as outf:
        for i, line in enumerate(junc_f):
            chrom, site1, site2, name, reads, strand = line.split()[:6]
            chr1, chr2 = chrom.split('~')
            if chr1 != chr2:
                continue
            site1 = int(site1)
            site2 = int(site2)
            if strand == '++' and site1 > site2:
                start = site2 - 1
                end = site1
            elif strand == '--' and site1 < site2:
                start = site1 - 1
                end = site2
            else:
                continue
            outf.write('%s\t%d\t%d\tFUSIONJUNC_%d/%s\t0\t+\n' % (chr1,
                start, end, i, reads))
            total += int(reads)
    print('Converted %d fusion reads!' % total)
