@@ -0,0 +1,2604 @@
+%22%22%22%0Athis script takes a GTF and converts it into event level files for use%0Awith MISO. This does no sanitizing of the GTF or sanity checking or anything,%0Ait is totally stupid, like me. If you run into problems using this post an%0Aissue at https://github.com/roryk/junkdrawer and I'll try to help straighten%0Ait out.%0A%0AThis assumes you have the following installed and in your path:%0AgtfToGenePred:%0Aconda install -c bioconda ucsc-gtftogenepred%0A%0Agff_make_annotation.py:%0Awget https://raw.githubusercontent.com/yarden/rnaseqlib/clip/rnaseqlib/gff/gff_make_annotation.py)%0A%0Aand%0A%0Apip install misopy%0A%22%22%22%0A%0Aimport os%0Aimport subprocess%0Afrom argparse import ArgumentParser%0A%0Adef swapdir(filepath, dirname):%0A    return os.path.join(dirname, os.path.basename(filepath))%0A%0Adef safe_makedir(dirname):%0A    if not os.path.exists(dirname):%0A        os.makedirs(dirname)%0A%0Adef gtf_to_genepred(gtf, outdir):%0A    out_file = os.path.splitext(swapdir(gtf, outdir))%5B0%5D + %22.genePred%22%0A    if os.path.exists(out_file):%0A        return out_file%0A    cmd = (%22gtfToGenePred -allErrors -ignoreGroupsWithoutExons -genePredExt %7Bgtf%7D %22%0A           %22%7Bout_file%7D%22)%0A    subprocess.check_call(cmd.format(**locals()), shell=True)%0A    return out_file%0A%0Adef genepred_to_UCSC_table(genepred, outdir):%0A    header = %5B%22#bin%22, %22name%22, %22chrom%22, %22strand%22,%0A              %22txStart%22, %22txEnd%22, %22cdsStart%22, %22cdsEnd%22,%0A              %22exonCount%22, %22exonStarts%22, %22exonEnds%22, %22score%22,%0A              %22name2%22, %22cdsStartStat%22, %22cdsEndStat%22,%0A              %22exonFrames%22%5D%0A    out_file = os.path.join(outdir, %22ensGene.txt%22)%0A    if os.path.exists(out_file):%0A        return out_file%0A    with open(genepred) as in_handle, open(out_file, %22w%22) as out_handle:%0A        counter = -1%0A        current_item = None%0A        out_handle.write(%22%5Ct%22.join(header) + %22%5Cn%22)%0A        for l in in_handle:%0A            item = l.split(%22%5Ct%22)%5B0%5D%0A            if current_item != item:%0A                current_item = item%0A                counter = counter + 1%0A            out_handle.write(%22%5Ct%22.join(%5Bstr(counter), l%5D))%0A    return out_file%0A%0Adef make_miso_annotation(ucsc, outdir):%0A    cmd = (%22python gff_make_annotation.py %7Boutdir%7D %7Boutdir%7D%22)%0A    subprocess.check_call(cmd.format(**locals()), shell=True)%0A%0Aif __name__ == %22__main__%22:%0A    parser = ArgumentParser()%0A    parser.add_argument(%22gtf%22, help=%22GTF file to convert%22)%0A    parser.add_argument(%22outdir%22, help=%22output directory%22)%0A    args = parser.parse_args()%0A%0A    gtf = args.gtf%0A    outdir = args.outdir%0A    safe_makedir(outdir)%0A    genepred = gtf_to_genepred(gtf, outdir)%0A    ucsc = genepred_to_UCSC_table(genepred, outdir)%0A    make_miso_annotation(ucsc, outdir)%0A

Add script to make MISO event files from a GTF.