def main(args=None):
if args is None:<EOL><INDENT>parser = get_argument_parser()<EOL>args = parser.parse_args()<EOL><DEDENT>input_file = args.annotation_file<EOL>output_file = args.output_file<EOL>species = args.species<EOL>chrom_pat = args.chromosome_pattern<EOL>field_name = args.field_name<EOL>log_file = args.log_file<EOL>quiet = args.quiet<EOL>verbose = args.verbose<EOL>log_stream = sys.stdout<EOL>if output_file == '<STR_LIT:->':<EOL><INDENT>log_stream = sys.stderr<EOL><DEDENT>logger = misc.get_logger(log_stream = log_stream, log_file = log_file,<EOL>quiet = quiet, verbose = verbose)<EOL>if chrom_pat is None:<EOL><INDENT>chrom_pat = re.compile(ensembl.SPECIES_CHROMPAT[species])<EOL><DEDENT>else:<EOL><INDENT>chrom_pat = re.compile(chrom_pat)<EOL><DEDENT>logger.info('<STR_LIT>',<EOL>chrom_pat.pattern)<EOL>chromosomes = set()<EOL>excluded_chromosomes = set()<EOL>i = <NUM_LIT:0><EOL>exons = <NUM_LIT:0><EOL>logger.info('<STR_LIT>')<EOL>if input_file == '<STR_LIT:->':<EOL><INDENT>input_file = None<EOL><DEDENT>with misc.smart_open_read(input_file, mode = '<STR_LIT:rb>', try_gzip = True) as fh,misc.smart_open_write(output_file) as ofh:<EOL><INDENT>reader = csv.reader(fh, dialect = '<STR_LIT>')<EOL>writer = csv.writer(ofh, dialect = '<STR_LIT>', lineterminator = os.linesep,<EOL>quoting = csv.QUOTE_NONE , quotechar = '<STR_LIT:|>')<EOL>for l in reader:<EOL><INDENT>i += <NUM_LIT:1><EOL>if len(l) > <NUM_LIT:1> and l[<NUM_LIT:2>] == field_name:<EOL><INDENT>attr = parse_attributes(l[<NUM_LIT:8>])<EOL>type_ = attr['<STR_LIT>']<EOL>if type_ in ['<STR_LIT>','<STR_LIT>']:<EOL><INDENT>chrom = l[<NUM_LIT:0>]<EOL>m = chrom_pat.match(chrom)<EOL>if m is None:<EOL><INDENT>excluded_chromosomes.add(chrom)<EOL>continue<EOL><DEDENT>chromosomes.add(chrom)<EOL>writer.writerow(l)<EOL>exons += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT><DEDENT>logger.info('<STR_LIT>', i)<EOL>logger.info('<STR_LIT>')<EOL>logger.info('<STR_LIT>', len(chromosomes))<EOL>logger.info('<STR_LIT:\t>' + '<STR_LIT:U+002CU+0020>'.join(sorted(chromosomes)))<EOL>logger.info('<STR_LIT>')<EOL>logger.info('<STR_LIT>', len(excluded_chromosomes))<EOL>logger.info('<STR_LIT:\t>' + '<STR_LIT:U+002CU+0020>'.join(sorted(excluded_chromosomes)))<EOL>logger.info('<STR_LIT>')<EOL>logger.info('<STR_LIT>' %(exons))<EOL>return <NUM_LIT:0><EOL>
Extract all exon annotations of protein-coding genes.