def main(args):
(ribo_file, rna_file, transcript_name, transcriptome_fasta, read_lengths,<EOL>read_offsets, output_path, html_file) = (<EOL>args.ribo_file, args.rna_file, args.transcript_name, args.transcriptome_fasta,<EOL>args.read_lengths, args.read_offsets, args.output_path, args.html_file)<EOL>fh = logging.FileHandler(html_file)<EOL>fh.setLevel(logging.ERROR)<EOL>fh.setFormatter(ErrorLogFormatter('<STR_LIT>'))<EOL>log.addHandler(fh)<EOL>log.debug('<STR_LIT>'.format(<EOL>'<STR_LIT:\n>'.join(['<STR_LIT>'.format(k, v) for k, v in vars(args).items()])))<EOL>log.debug('<STR_LIT>')<EOL>log.info('<STR_LIT>')<EOL>ribocore.check_required_arguments(<EOL>ribo_file=ribo_file, transcriptome_fasta=transcriptome_fasta, transcript_name=transcript_name)<EOL>log.info('<STR_LIT>')<EOL>if rna_file:<EOL><INDENT>log.info('<STR_LIT>')<EOL>ribocore.check_rna_file(rna_file=rna_file)<EOL>log.info('<STR_LIT>')<EOL><DEDENT>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>log.info('<STR_LIT>')<EOL>record = ribocore.get_fasta_record(transcriptome_fasta, transcript_name)<EOL>transcript_sequence = record[transcript_name]<EOL>transcript_length = len(transcript_sequence)<EOL>log.info('<STR_LIT>')<EOL>with ribocore.open_pysam_file(fname=ribo_file, ftype='<STR_LIT>') as bam_fileobj:<EOL><INDENT>ribo_counts, total_reads = ribocore.get_ribo_counts(<EOL>ribo_fileobj=bam_fileobj, transcript_name=transcript_name,<EOL>read_lengths=read_lengths, read_offsets=read_offsets)<EOL><DEDENT>if not ribo_counts:<EOL><INDENT>msg = ('<STR_LIT>'<EOL>'<STR_LIT>'.format(transcript_name))<EOL>log.error(msg)<EOL>raise ribocore.RiboPlotError(msg)<EOL><DEDENT>else:<EOL><INDENT>log.info('<STR_LIT>')<EOL>mrna_counts = {}<EOL>if rna_file:<EOL><INDENT>try:<EOL><INDENT>mrna_counts = get_rna_counts(rna_file, transcript_name)<EOL><DEDENT>except OSError as e:<EOL><INDENT>log.error(e)<EOL>raise<EOL><DEDENT>if not mrna_counts:<EOL><INDENT>log.warn('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>log.debug('<STR_LIT>')<EOL><DEDENT>log.info('<STR_LIT>')<EOL>codon_positions = get_start_stops(transcript_sequence)<EOL>if not os.path.exists(output_path):<EOL><INDENT>os.mkdir(output_path)<EOL><DEDENT>log.info('<STR_LIT>'.format(transcript_name))<EOL>with open(os.path.join(output_path, '<STR_LIT>'), '<STR_LIT:w>') as f:<EOL><INDENT>f.write('<STR_LIT>')<EOL>for pos in range(<NUM_LIT:1>, transcript_length + <NUM_LIT:1>):<EOL><INDENT>if pos in ribo_counts:<EOL><INDENT>f.write('<STR_LIT>'.format(<EOL>pos, transcript_sequence[pos - <NUM_LIT:1>], ribo_counts[pos][<NUM_LIT:1>], ribo_counts[pos][<NUM_LIT:2>], ribo_counts[pos][<NUM_LIT:3>]))<EOL><DEDENT>else:<EOL><INDENT>f.write('<STR_LIT>'.format(pos, transcript_sequence[pos - <NUM_LIT:1>], <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>))<EOL><DEDENT><DEDENT><DEDENT>log.info('<STR_LIT>')<EOL>plot_profile(ribo_counts, transcript_name, transcript_length,<EOL>codon_positions, read_lengths, read_offsets, mrna_counts,<EOL>color_scheme=args.color_scheme,<EOL>html_file=args.html_file, output_path=args.output_path)<EOL><DEDENT>log.info('<STR_LIT>')<EOL>
Main program