import csv


def sj_out_to_jxs(sj_out):
    """Accepts STAR-generated SJ.out.tab file & returns list of its junctions.

    Input: sj_out (str) string pointing to STAR output __SJ.out file containing
        junction calls from a STAR alignment.

    Returns a list of the file's unique junctions in 0-based closed coordinates
    """
    all_junctions = []
    strand_mapper = ['?', '+', '-']
    with open(sj_out) as sj:
        jx_file = csv.reader(sj, delimiter='\t')
        for line in jx_file:
            chrom, left, right, strand = line[0], line[1], line[2], line[3]
            strand = strand_mapper[int(strand)]
            if strand == '?':
                continue
            if 'chr' not in chrom:
                chrom = 'chr' + chrom
            left = str(int(left) - 1)
            right = str(int(right) - 1)
            jx = ';'.join([chrom, left, right, strand])
            all_junctions.append(jx)
    return list(set(all_junctions))