Skip to content

Commit

Permalink
Metaquast: show all references in summary plots
Browse files Browse the repository at this point in the history
  • Loading branch information
almiheenko committed Feb 17, 2017
1 parent 4e44d9b commit ad25040
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
4 changes: 2 additions & 2 deletions metaquast.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ def main(args):
misassembl_metrics = [reporting.Fields.MIS_RELOCATION, reporting.Fields.MIS_TRANSLOCATION, reporting.Fields.MIS_INVERTION,
reporting.Fields.MIS_ISTRANSLOCATIONS]
if no_unaligned_contigs:
full_ref_names = ref_names
full_ref_names = [qutils.name_from_fpath(ref_fpath) for ref_fpath in corrected_ref_fpaths]
else:
full_ref_names = ref_names + [qconfig.not_aligned_name]
full_ref_names = [qutils.name_from_fpath(ref_fpath) for ref_fpath in corrected_ref_fpaths] + [qconfig.not_aligned_name]
create_meta_summary.do(html_summary_report_fpath, summary_output_dirpath, combined_output_dirpath,
output_dirpath_per_ref, metrics_for_plots, misassembl_metrics, full_ref_names)
if html_report and json_texts:
Expand Down
52 changes: 26 additions & 26 deletions quast_libs/create_meta_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,41 @@
logger = get_logger(qconfig.LOGGER_META_NAME)


def get_results_for_metric(ref_names, metric, contigs_num, labels, output_dirpath, report_fname):
def get_results_for_metric(full_ref_names, metric, contigs_num, labels, output_dirpath, report_fname):
all_rows = []
cur_ref_names = []
row = {'metricName': 'References', 'values': cur_ref_names}
ref_names = full_ref_names
row = {'metricName': 'References', 'values': ref_names}
all_rows.append(row)
results = []
for i in range(contigs_num):
row = {'metricName': labels[i], 'values': []}
all_rows.append(row)
for i, ref_name in enumerate(ref_names):
results_fpath = os.path.join(output_dirpath, ref_name, report_fname)
if not os.path.exists(results_fpath):
all_rows[0]['values'] = cur_ref_names
continue
results_file = open(results_fpath, 'r')
columns = [s.strip() for s in results_file.readline().split('\t')]
if metric not in columns:
all_rows[0]['values'] = cur_ref_names
continue
for i, ref_name in enumerate(full_ref_names):
results.append([])
cur_ref_names.append(ref_name)
next_values = [s.strip() for s in results_file.readline().split('\t')]
cur_results = [None] * len(labels)
for j in range(contigs_num):
values = next_values
if values[0]:
metr_res = values[columns.index(metric)].split()[0]
results_fpath = os.path.join(output_dirpath, ref_name, report_fname)
if ref_name == qconfig.not_aligned_name:
results_fpath = os.path.join(os.path.dirname(output_dirpath), ref_name, report_fname)
if os.path.exists(results_fpath):
results_file = open(results_fpath, 'r')
columns = [s.strip() for s in results_file.readline().split('\t')]
if metric in columns:
next_values = [s.strip() for s in results_file.readline().split('\t')]
index_contig = labels.index(values[0])
cur_results[index_contig] = metr_res
cur_results = [None] * len(labels)
for j in range(contigs_num):
values = next_values
if values[0]:
metr_res = values[columns.index(metric)].split()[0]
next_values = [s.strip() for s in results_file.readline().split('\t')]
index_contig = labels.index(values[0])
cur_results[index_contig] = metr_res
elif ref_name == qconfig.not_aligned_name:
ref_names.pop(i)
continue
for j in range(contigs_num):
all_rows[j + 1]['values'].append(cur_results[j])
results[-1].append(cur_results[j])
if not cur_ref_names:
cur_ref_names = ref_names
return results, all_rows, cur_ref_names
return results, all_rows, ref_names


def get_labels(combined_output_dirpath, report_fname):
Expand All @@ -70,7 +69,7 @@ def do(html_fpath, output_dirpath, combined_output_dirpath, output_dirpath_per_r
summary_txt_fpath = os.path.join(output_dirpath, 'TXT', metric.replace(' ', '_') + '.txt')
summary_tex_fpath = os.path.join(output_dirpath, 'TEX', metric.replace(' ', '_') + '.tex')
summary_tsv_fpath = os.path.join(output_dirpath, 'TSV', metric.replace(' ', '_') + '.tsv')
summary_png_fpath = os.path.join(output_dirpath, plots_dirname, metric.replace(' ', '_') + '.' + qconfig.plot_extension)
summary_plot_fpath = os.path.join(output_dirpath, plots_dirname, metric.replace(' ', '_') + '.' + qconfig.plot_extension)
results, all_rows, cur_ref_names = get_results_for_metric(ref_names, metric, contigs_num, labels, output_dirpath_per_ref, qconfig.transposed_report_prefix + '.tsv')
if not results or not results[0]:
continue
Expand Down Expand Up @@ -102,7 +101,8 @@ def do(html_fpath, output_dirpath, combined_output_dirpath, output_dirpath_per_r
elif metric == reporting.Fields.LARGALIGN:
y_label = 'Alignment length '
plotter.draw_meta_summary_plot(html_fpath, output_dirpath, labels, cur_ref_names, all_rows, results,
summary_png_fpath, title=metric, reverse=reverse, yaxis_title=y_label)
summary_plot_fpath, title=metric, reverse=reverse, yaxis_title=y_label,
print_all_refs=True)
if metric == reporting.Fields.MISASSEMBL:
mis_results = []
report_fname = os.path.join('contigs_reports', qconfig.transposed_report_prefix + '_misassemblies' + '.tsv')
Expand Down
9 changes: 5 additions & 4 deletions quast_libs/html_saver/static/scripts/draw_metasummary_plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,13 @@ function getSortOrder() {
function sortReferences(sortOrder, info) {
if (sortOrder == 'alphabet') {
refNames = sortedRefs;
for (var i = 0; i < sortedRefs.length; i++)
refTicks[i][1] = sortedRefs[i];
}
else if (sortOrder == 'value') {
refNames = info.references;
for (var i = 0; i < info.references.length; i++)
refTicks[i][1] = info.references[i];
}
refTicks = [];
for (var i = 0; i < refNames.length; i++)
{
refTicks.push([i + 1, refNames[i]]);
}
}

0 comments on commit ad25040

Please sign in to comment.