def save_txt(fpath, all_rows, potential_scaffolds_assemblies_info=None): # determine width of columns for nice spaces colwidths = [0] * (len(all_rows[0]['values']) + 1) for row in all_rows: for i, cell in enumerate([row['metricName']] + [val_to_str(this) for this in row['values']]): colwidths[i] = max(colwidths[i], len(cell)) # output it txt_file = open(fpath, 'w') if qconfig.min_contig: txt_file.write('All statistics are based on contigs of size >= %d bp, unless otherwise noted ' % qconfig.min_contig + \ '(e.g., "# contigs (>= 0 bp)" and "Total length (>= 0 bp)" include all contigs).\n') if potential_scaffolds_assemblies_info: txt_file.write("Suggestion: " + potential_scaffolds_assemblies_info + " continuous fragments of N's of " \ "length >= 10 bp. You may consider rerunning QUAST using --scaffolds (-s) option!\n") txt_file.write('\n') for row in all_rows: txt_file.write(' '.join( '%-*s' % (colwidth, cell) for colwidth, cell in zip( colwidths, [row['metricName']] + [val_to_str(this) for this in row['values']])) + "\n") txt_file.close()
def print_file(all_rows, fpath, append_to_existing_file=False): colwidths = repeat(0) for row in all_rows: colwidths = [max(len(v), w) for v, w in zip([row['metricName']] + [val_to_str(v) for v in row['values']], colwidths)] txt_file = open(fpath, 'a' if append_to_existing_file else 'w') for row in all_rows: txt_file.write(' '.join('%-*s' % (colwidth, cell) for colwidth, cell in zip(colwidths, [row['metricName']] + [val_to_str(v) for v in row['values']])) + '\n')
def print_file(all_rows, fpath, append_to_existing_file=False): colwidths = repeat(0) for row in all_rows: colwidths = [max(len(v), w) for v, w in zip([row['metricName']] + [val_to_str(v) for v in row['values']], colwidths)] txt_file = open(fpath, 'a' if append_to_existing_file else 'w') for row in all_rows: txt_file.write(' '.join('%-*s' % (colwidth, cell) for colwidth, cell in zip(colwidths, [row['metricName']] + [val_to_str(v) for v in row['values']])) + '\n')
def save_tsv(fpath, all_rows): tsv_file = open(fpath, 'w') for row in all_rows: tsv_file.write('\t'.join([row['metricName']] + [val_to_str(this) for this in row['values']]) + "\n") tsv_file.close()
def save_tsv(fpath, all_rows): tsv_file = open(fpath, 'w') for row in all_rows: tsv_file.write('\t'.join([row['metricName']] + [val_to_str(this) for this in row['values']]) + "\n") tsv_file.close()
def save_txt(fpath, all_rows): # determine width of columns for nice spaces colwidths = [0] * (len(all_rows[0]['values']) + 1) for row in all_rows: for i, cell in enumerate([row['metricName']] + [val_to_str(this) for this in row['values']]): colwidths[i] = max(colwidths[i], len(cell)) # output it txt_file = open(fpath, 'w') if qconfig.min_contig: txt_file.write('All statistics are based on contigs of size >= %d bp, unless otherwise noted ' % qconfig.min_contig + \ '(e.g., "# contigs (>= 0 bp)" and "Total length (>= 0 bp)" include all contigs).\n') txt_file.write('\n') for row in all_rows: txt_file.write(' '.join( '%-*s' % (colwidth, cell) for colwidth, cell in zip( colwidths, [row['metricName']] + [val_to_str(this) for this in row['values']])) + "\n") txt_file.close()
def save_txt(fpath, all_rows, potential_scaffolds_assemblies_info=None): # determine width of columns for nice spaces colwidths = [0] * (len(all_rows[0]['values']) + 1) for row in all_rows: for i, cell in enumerate([row['metricName']] + [val_to_str(this) for this in row['values']]): colwidths[i] = max(colwidths[i], len(cell)) # output it txt_file = open(fpath, 'w') if qconfig.min_contig: txt_file.write('All statistics are based on contigs of size >= %d bp, unless otherwise noted ' % qconfig.min_contig + \ '(e.g., "# contigs (>= 0 bp)" and "Total length (>= 0 bp)" include all contigs).\n') if potential_scaffolds_assemblies_info: txt_file.write("Suggestion: " + potential_scaffolds_assemblies_info + " continuous fragments of N's of " \ "length >= 10 bp. You may consider rerunning QUAST using --scaffolds (-s) option!\n") txt_file.write('\n') for row in all_rows: txt_file.write(' '.join('%-*s' % (colwidth, cell) for colwidth, cell in zip(colwidths, [row['metricName']] + [val_to_str(this) for this in row['values']])) + "\n") txt_file.close()
def save_tex(fpath, all_rows, is_transposed=False): tex_file = open(fpath, 'w') # Header tex_file.write('\\documentclass[12pt,a4paper]{article}\n') tex_file.write('\\begin{document}\n') tex_file.write('\\begin{table}[ht]\n') tex_file.write('\\begin{center}\n') tex_file.write('\\caption{All statistics are based on contigs of size $\geq$ %d bp, unless otherwise noted ' % qconfig.min_contig + \ '(e.g., "\# contigs ($\geq$ 0 bp)" and "Total length ($\geq$ 0 bp)" include all contigs).}\n') rows_n = len(all_rows[0]['values']) tex_file.write('\\begin{tabular}{|l*{' + val_to_str(rows_n) + '}{|r}|}\n') tex_file.write('\\hline\n') # Body for row in all_rows: values = row['values'] quality = row['quality'] if ('quality' in row) else Fields.Quality.EQUAL if is_transposed or quality not in [ Fields.Quality.MORE_IS_BETTER, Fields.Quality.LESS_IS_BETTER ]: cells = _mapme(val_to_str, values) else: # Checking the first value, assuming the others are the same type and format num = get_num_from_table_value(values[0]) if num is None: # Not a number cells = _mapme(val_to_str, values) else: nums = _mapme(get_num_from_table_value, values) best = None if quality == Fields.Quality.MORE_IS_BETTER: best = max(n for n in nums if n is not None) if quality == Fields.Quality.LESS_IS_BETTER: best = min(n for n in nums if n is not None) if len([num for num in nums if num != best]) == 0: cells = _mapme(val_to_str, values) else: cells = [ 'HIGHLIGHTEDSTART' + val_to_str(v) + 'HIGHLIGHTEDEND' if get_num_from_table_value(v) == best else val_to_str(v) for v in values ] row = ' & '.join([row['metricName']] + cells) # escape characters for esc_char in "\\ % $ # _ { } ~ ^".split(): row = row.replace(esc_char, '\\' + esc_char) # more pretty '>=' and '<=', '>' row = row.replace('>=', '$\\geq$') row = row.replace('<=', '$\\leq$') row = row.replace('>', '$>$') # pretty indent if row.startswith(Fields.TAB): row = "\hspace{5mm}" + row.lstrip() if row.startswith(Fields.HALF_TAB): row = "\hspace{2mm}" + row.lstrip() # pretty highlight row = row.replace('HIGHLIGHTEDSTART', '{\\bf ') row = row.replace('HIGHLIGHTEDEND', '}') row += ' \\\\ \\hline' tex_file.write(row + "\n") # Footer tex_file.write('\\end{tabular}\n') tex_file.write('\\end{center}\n') tex_file.write('\\end{table}\n') tex_file.write('\\end{document}\n') tex_file.close() if os.path.basename(fpath) == 'report.tex': pass
def save_tex(fpath, all_rows, is_transposed=False): tex_file = open(fpath, 'w') # Header tex_file.write('\\documentclass[12pt,a4paper]{article}\n') tex_file.write('\\begin{document}\n') tex_file.write('\\begin{table}[ht]\n') tex_file.write('\\begin{center}\n') tex_file.write('\\caption{All statistics are based on contigs of size $\geq$ %d bp, unless otherwise noted ' % qconfig.min_contig + \ '(e.g., "\# contigs ($\geq$ 0 bp)" and "Total length ($\geq$ 0 bp)" include all contigs).}\n') rows_n = len(all_rows[0]['values']) tex_file.write('\\begin{tabular}{|l*{' + val_to_str(rows_n) + '}{|r}|}\n') tex_file.write('\\hline\n') # Body for row in all_rows: values = row['values'] quality = row['quality'] if ('quality' in row) else Fields.Quality.EQUAL if is_transposed or quality not in [Fields.Quality.MORE_IS_BETTER, Fields.Quality.LESS_IS_BETTER]: cells = _mapme(val_to_str, values) else: # Checking the first value, assuming the others are the same type and format num = get_num_from_table_value(values[0]) if num is None: # Not a number cells = _mapme(val_to_str, values) else: nums = _mapme(get_num_from_table_value, values) best = None if quality == Fields.Quality.MORE_IS_BETTER: best = max(n for n in nums if n is not None) if quality == Fields.Quality.LESS_IS_BETTER: best = min(n for n in nums if n is not None) if len([num for num in nums if num != best]) == 0: cells = _mapme(val_to_str, values) else: cells = ['HIGHLIGHTEDSTART' + val_to_str(v) + 'HIGHLIGHTEDEND' if get_num_from_table_value(v) == best else val_to_str(v) for v in values] row = ' & '.join([row['metricName']] + cells) # escape characters for esc_char in "\\ % $ # _ { } ~ ^".split(): row = row.replace(esc_char, '\\' + esc_char) # more pretty '>=' and '<=', '>' row = row.replace('>=', '$\\geq$') row = row.replace('<=', '$\\leq$') row = row.replace('>', '$>$') # pretty indent if row.startswith(Fields.TAB): row = "\hspace{5mm}" + row.lstrip() # pretty highlight row = row.replace('HIGHLIGHTEDSTART', '{\\bf ') row = row.replace('HIGHLIGHTEDEND', '}') row += ' \\\\ \\hline' tex_file.write(row +"\n") # Footer tex_file.write('\\end{tabular}\n') tex_file.write('\\end{center}\n') tex_file.write('\\end{table}\n') tex_file.write('\\end{document}\n') tex_file.close() if os.path.basename(fpath) == 'report.tex': pass