def asn(args):
    """
    %prog asn asnfiles

    Mainly to get this block, and extract `str` field:

        general {
          db "TIGR" ,
          tag
            str "mtg2_12952" } ,
        genbank {
          accession "AC148996" ,
    """
    from jcvi.formats.base import must_open

    p = OptionParser(asn.__doc__)
    p.set_outfile()
    opts, args = p.parse_args(args)

    if 1 < len(args):
        sys.exit(not p.print_help())

    fw = must_open(opts.outfile, "w")
    for asnfile in args:
        fp = open(asnfile)
        ingeneralblock = False
        ingenbankblock = False
        gb, name = None, None
        for row in fp:
            if row.strip() == "":
                continue

            tag = row.split()[0]

            if tag == "general":
                ingeneralblock = True
            if ingeneralblock and tag == "str":
                if name is None:  # Only allow first assignment
                    name = row.split("\"")[1]
                ingeneralblock = False

            if tag == "genbank":
                ingenbankblock = True
            if ingenbankblock and tag == "accession":
                if gb is None:
                    gb = row.split("\"")[1]
                ingenbankblock = False

        assert gb and name
        print >> fw, "{0}\t{1}".format(gb, name)
dataset/ETHPy150Open tanghaibao/jcvi/apps/gbsubmit.py/asn/swapped operands of `<`