@@ -0,0 +1,2177 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A%0Aimport sys, re, os, gzip, argparse%0Afrom Bio import SeqIO%0A%0Adef main(inargs):%0A        # setup menu with argparse%0A    class MyFormatter(argparse.ArgumentDefaultsHelpFormatter):%0A        def __init__(self, prog):%0A            super(MyFormatter, self).__init__(prog, max_help_position=48)%0A    parser = argparse.ArgumentParser(prog='get_longest_isoform',%0A                                     description='''Script to extract longest isoform of protein or transcript file from funannotate or where gene is tagged in header.''',%0A                                     epilog=%22%22%22Written by Jason Stajich (2022) @hyphaltip%22%22%22,%0A                                     formatter_class=MyFormatter)%0A    parser.add_argument('-i', '--input', required=True,%0A                        help='fasta formatted transcript or protein file')%0A    parser.add_argument('-o', '--output', help='Output basename')%0A%0A    parser.add_argument('-v', '--verbose', help='Extra verbose output',dest='verbose', default=False, action='store_true')%0A%0A    args = parser.parse_args(inargs)%0A    genes = %7B%7D%0A    if not args.output:%0A        args.output = args.input + %22.longest%22%0A    transmatch = re.compile(r'%5C-T%5Cd+$')%0A    genematch  = re.compile(r'gene%5B:=%5D(%5CS+)')%0A    recCount = 0%0A    handle = args.input%0A    if args.input.endswith('.gz'):%0A        handle =  gzip.open(args.input,%22rt%22)%0A    for rec in SeqIO.parse(handle, %22fasta%22):%0A        id = rec.id%0A        description = rec.description%0A        geneid = id%0A        m = transmatch.search(id)%0A        if m:%0A            geneid = description.split()%5B1%5D%0A        else:%0A            m = genematch.search(description)%0A            if m:%0A                geneid = m.group(1)%0A        if geneid == id:%0A            if args.verbose:%0A                print(%22Warning: could not parse gene name from header '%7B%7D' '%7B%7D'%22.format(id,description))%0A        if geneid not in genes or len(rec) %3E len(genes%5Bgeneid%5D):%0A            genes%5Bgeneid%5D = rec%0A        recCount += 1%0A%0A    print(%22%7B%7D genes and %7B%7D total sequences (isoforms) seen%22.format(len(genes),recCount))%0A    SeqIO.write(genes.values(),args.output,'fasta')%0A%0Aif __name__ == %22__main__%22:%0A    main(sys.argv%5B1:%5D)%0A

add a isoform extraction tool from protein/transcript files