def main(args):
(ribo_file, transcriptome_fasta, read_lengths, read_offsets, count_five, count_three,<EOL>output_path, html_file) =(args.ribo_file, args.transcriptome_fasta, args.read_lengths, args.read_offsets,<EOL>args.count_five, args.count_three, args.output_path, args.html_file)<EOL>log.debug('<STR_LIT>'.format(<EOL>'<STR_LIT:\n>'.join(['<STR_LIT>'.format(k, v) for k, v in vars(args).items()])))<EOL>fh = logging.FileHandler(html_file)<EOL>fh.setLevel(logging.ERROR)<EOL>fh.setFormatter(ErrorLogFormatter('<STR_LIT>'))<EOL>log.addHandler(fh)<EOL>log.info('<STR_LIT>')<EOL>ribocore.check_required_arguments(ribo_file=ribo_file, transcriptome_fasta=transcriptome_fasta)<EOL>log.info('<STR_LIT>')<EOL>ribocore.check_read_lengths(ribo_file=ribo_file, read_lengths=read_lengths)<EOL>log.info('<STR_LIT>')<EOL>log.info('<STR_LIT>')<EOL>ribocore.check_read_offsets(read_offsets=read_offsets)<EOL>log.info('<STR_LIT>')<EOL>log.info('<STR_LIT>')<EOL>ribocore.check_read_lengths_offsets(read_lengths=read_lengths, read_offsets=read_offsets)<EOL>log.info('<STR_LIT>')<EOL>with ribocore.open_pysam_file(fname=ribo_file, ftype='<STR_LIT>') as b, ribocore.open_pysam_file(fname=transcriptome_fasta, ftype='<STR_LIT>') as f:<EOL><INDENT>count = <NUM_LIT:0><EOL>prime = None<EOL>table_body = '<STR_LIT>'  <EOL>if count_five:<EOL><INDENT>log.info('<STR_LIT>')<EOL>prime = '<STR_LIT:5>'<EOL><DEDENT>elif count_three:<EOL><INDENT>log.info('<STR_LIT>')<EOL>prime = '<STR_LIT:3>'<EOL><DEDENT>if not os.path.exists(output_path):<EOL><INDENT>os.mkdir(output_path)<EOL><DEDENT>zip_dir = os.path.join(output_path, '<STR_LIT>')<EOL>if not os.path.exists(zip_dir):<EOL><INDENT>os.mkdir(zip_dir)<EOL><DEDENT>csv_dir = os.path.join(zip_dir, '<STR_LIT>')<EOL>if not os.path.exists(csv_dir):<EOL><INDENT>os.mkdir(csv_dir)<EOL><DEDENT>log.info('<STR_LIT>')<EOL>for transcript in f.references:<EOL><INDENT>ribo_counts, ribo_reads = ribocore.get_ribo_counts(ribo_fileobj=b, transcript_name=transcript,<EOL>read_lengths=read_lengths, read_offsets=read_offsets)<EOL>if not ribo_reads:  <EOL><INDENT>continue<EOL><DEDENT>transcript_sequence = f[transcript]<EOL>write_counts = ribo_counts<EOL>log.debug('<STR_LIT>'.format(ribo_reads))<EOL>longest_orf = {}<EOL>if count_five or count_three:<EOL><INDENT>orfs = ribocore.get_three_frame_orfs(sequence=transcript_sequence)<EOL>if not len(orfs):<EOL><INDENT>log.debug('<STR_LIT>'.format(transcript))<EOL>continue<EOL><DEDENT>longest_orf = ribocore.get_longest_orf(orfs=orfs)<EOL>orf_start, orf_stop = longest_orf['<STR_LIT:start>'], longest_orf['<STR_LIT>']<EOL>log.info('<STR_LIT>'.format(transcript, orf_start, orf_stop))<EOL>if count_five:<EOL><INDENT>write_counts, five_reads = ribocore.filter_ribo_counts(counts=ribo_counts, orf_start=orf_start)<EOL>log.debug('<STR_LIT>'.format(five_reads))<EOL><DEDENT>elif count_three:<EOL><INDENT>write_counts, three_reads = ribocore.filter_ribo_counts(counts=ribo_counts, orf_stop=orf_stop)<EOL>log.debug('<STR_LIT>'.format(three_reads))<EOL><DEDENT><DEDENT>if not len(write_counts):<EOL><INDENT>continue<EOL><DEDENT>log.debug('<STR_LIT>'.format(transcript))<EOL>count += <NUM_LIT:1><EOL>csv_file = '<STR_LIT>'.format(count)<EOL>with open(os.path.join(csv_dir, csv_file), '<STR_LIT:w>') as cw:<EOL><INDENT>cw.write('<STR_LIT>')<EOL>for pos in range(<NUM_LIT:1>, len(transcript_sequence) + <NUM_LIT:1>):<EOL><INDENT>nucleotide = transcript_sequence[pos - <NUM_LIT:1>]<EOL>if pos in write_counts:<EOL><INDENT>cw.write('<STR_LIT>'.format(<EOL>pos, nucleotide, write_counts[pos][<NUM_LIT:1>], write_counts[pos][<NUM_LIT:2>], write_counts[pos][<NUM_LIT:3>]))<EOL><DEDENT>else:<EOL><INDENT>cw.write('<STR_LIT>'.format(pos, nucleotide, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>))<EOL><DEDENT><DEDENT><DEDENT>table_body += '<STR_LIT>'.format(transcript, ribo_reads)<EOL>if count_five:<EOL><INDENT>table_body += '<STR_LIT>'.format(five_reads)<EOL><DEDENT>elif count_three:<EOL><INDENT>table_body += '<STR_LIT>'.format(three_reads)<EOL><DEDENT>table_body += '<STR_LIT>'.format(csv_file)<EOL><DEDENT>table_body += '<STR_LIT>'<EOL><DEDENT>valid_lengths = ['<STR_LIT:{}>'.format(item) for item in read_lengths]<EOL>if len(valid_lengths) == <NUM_LIT:1> and valid_lengths[<NUM_LIT:0>] == '<STR_LIT:0>':<EOL><INDENT>valid_lengths = ['<STR_LIT>']<EOL><DEDENT>if not count:<EOL><INDENT>if len(valid_lengths) >= <NUM_LIT:1>:<EOL><INDENT>log.info('<STR_LIT>'.format('<STR_LIT:U+002CU+0020>'.join(valid_lengths)))<EOL><DEDENT>else:<EOL><INDENT>log.info('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if prime:<EOL><INDENT>template = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>template = '<STR_LIT>'<EOL><DEDENT>with open(os.path.join(CONFIG.PKG_DATA_DIR, template)) as g,open(os.path.join(zip_dir, '<STR_LIT>'), '<STR_LIT:w>') as h:<EOL><INDENT>h.write(g.read().format(count=count, length='<STR_LIT:{}>'.format('<STR_LIT:U+002CU+0020>'.join(valid_lengths)),<EOL>prime=prime, table_body=table_body))<EOL><DEDENT>for asset in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>asset_dir = os.path.join(zip_dir, asset)<EOL>if not os.path.exists(asset_dir):<EOL><INDENT>os.mkdir(asset_dir)<EOL><DEDENT>asset_data_dir = os.path.join(CONFIG.PKG_DATA_DIR, asset)<EOL>for fname in os.listdir(asset_data_dir):<EOL><INDENT>shutil.copy(os.path.join(asset_data_dir, fname),<EOL>os.path.join(zip_dir, asset, fname))<EOL><DEDENT><DEDENT>log.info('<STR_LIT>')<EOL>os.chdir(output_path)<EOL>with zipfile.ZipFile('<STR_LIT>', '<STR_LIT:w>', allowZip64=True) as zipf:<EOL><INDENT>for root, d, f in os.walk('<STR_LIT>'):<EOL><INDENT>for name in f:<EOL><INDENT>zipf.write(os.path.join(root, name))<EOL><DEDENT><DEDENT><DEDENT>shutil.rmtree('<STR_LIT>')<EOL>os.chdir('<STR_LIT>')<EOL>log.debug('<STR_LIT>')<EOL>with open(os.path.join(CONFIG.PKG_DATA_DIR, '<STR_LIT>')) as j, open(args.html_file, '<STR_LIT:w>') as k:<EOL><INDENT>k.write(j.read().format(count=count, read_length='<STR_LIT:U+002CU+0020>'.join(valid_lengths)))<EOL><DEDENT><DEDENT>log.info('<STR_LIT>')<EOL>
Main program