From 997ad6f470b578b6dfef2911a8f8e9ab5ba4bb5a Mon Sep 17 00:00:00 2001 From: Murray Wham Date: Wed, 17 Oct 2018 17:33:19 +0100 Subject: [PATCH 1/9] Adding `species` and `genomes` endpoints, adding `genomes` page. Refactoring column_formatter to allow dropdown lists without links. Updating Eve to v0.8. --- etc/column_mappings.yaml | 47 ++++++- etc/schema.yaml | 20 +++ reporting_app/__init__.py | 21 +++ reporting_app/static/column_formatter.js | 121 +++++++++++------- .../static/stylesheets/reporting_app.css | 1 + reporting_app/templates/base.html | 1 + requirements.txt | 5 +- rest_api/settings.py | 8 +- tests/js/test_column_formatter.js | 10 ++ tests/test_reporting_app.py | 3 + 10 files changed, 180 insertions(+), 57 deletions(-) diff --git a/etc/column_mappings.yaml b/etc/column_mappings.yaml index bed2abd6..aea4097b 100644 --- a/etc/column_mappings.yaml +++ b/etc/column_mappings.yaml @@ -114,6 +114,20 @@ column_def: trim_r2: { data: 'aggregated.trim_r2', title: 'Read 2 Max length', visible: 'false'} tiles_filtered: { data: 'aggregated.tiles_filtered', title: 'Tile removed', visible: 'false'} family_id: { data: 'Family ID', title: 'Family ID (SGP)', visible: 'false'} + species_name: { data: 'name', title: 'Name' } + species_default_genome: { data: 'default_version', title: 'Default genome version' } + species_taxid: { data: 'taxid', title: 'Taxid' } + genome_assembly: { data: 'assembly_name', title: 'Assembly name' } + genome_species: { data: 'species', title: 'Species' } + genome_data_source: { data: 'data_source', title: 'Data source' } + genome_tools_used: { data: 'tools_used', title: 'Tools used', visible: 'false' } + genome_chromosome_count: { data: 'chromosome_count', title: 'Chromosomes' } + genome_size: { data: 'genome_size', title: 'Genome size' } + genome_goldenpath: { data: 'goldenpath', title: 'GoldenPath' } + genome_projects: { data: 'project_whitelist', title: 'Allowed projects', visible: 'false' } + genome_comments: { data: 'comments', title: 'Comments', visible: 'false' } + genome_analyses: { data: 'analyses_supported', title: 'Analyses supported' } + # Datatables tables definition # the remaining top level entries each define a table with a list of column @@ -343,10 +357,29 @@ sample_run_elements: active_runs: - - run_id - - instrument_id - - run_status - - created_date - - cst_date - - project_ids - - sample_ids + - run_id + - instrument_id + - run_status + - created_date + - cst_date + - project_ids + - sample_ids + + +species: + - species_name + - species_default_genome + - species_taxid + + +genomes: + - genome_assembly + - genome_species + - genome_data_source + - genome_chromosome_count + - genome_size + - genome_goldenpath + - genome_analyses + - genome_tools_used + - genome_projects + - genome_comments diff --git a/etc/schema.yaml b/etc/schema.yaml index 99178664..e0fe6d84 100644 --- a/etc/schema.yaml +++ b/etc/schema.yaml @@ -251,6 +251,7 @@ analysis_driver_stages: date_finished: { type: 'datetime', nullable: True } exit_status: { type: 'integer', nullable: True } + actions: action_id: { type: 'string', required: True, unique: True } action_type: { type: 'string', required: True } @@ -260,3 +261,22 @@ actions: action_info: { type: 'dict' } +species: + name: { type: 'string', required: True, unique: True } + genomes: { type: 'list', schema: { type: 'string', data_relation: { resource: 'genomes', field: 'assembly_name', embeddable: True } } } + default_version: { type: 'string' } + taxid: { type: 'string' } + + +genomes: + assembly_name: { type: 'string', required: True, unique: True } + species: { type: 'string' } + data_files: { type: 'dict', schema: { fasta: { type: 'string' }, variation: { type: 'string' } } } + data_source: { type: 'string' } + tools_used: { type: 'dict' } + chromosome_count: { type: 'integer' } + genome_size: { type: 'integer' } + goldenpath: { type: 'integer' } + project_whitelist: { type: 'list', schema: { type: 'string' } } + comments: { type: 'string' } + analyses_supported: { type: 'list', schema: { type: 'string', allowed: ['qc', 'variant_calling', 'bcbio'] } } diff --git a/reporting_app/__init__.py b/reporting_app/__init__.py index dda2f4ff..81b2f3eb 100644 --- a/reporting_app/__init__.py +++ b/reporting_app/__init__.py @@ -453,3 +453,24 @@ def project_status_reports(prj_status): table_foot='sum_row_per_column' ) ) + + +@app.route('/genomes') +@flask_login.login_required +def genome_page(): + return render_template( + 'untabbed_datatables.html', + 'Genomes', + tables=[ + util.datatable_cfg( + 'Available species', + 'species', + util.construct_url('species', all_pages=True) + ), + util.datatable_cfg( + 'Installed genomes', + 'genomes', + util.construct_url('genomes', all_pages=True) + ) + ] + ) diff --git a/reporting_app/static/column_formatter.js b/reporting_app/static/column_formatter.js index 84a6832e..90250922 100644 --- a/reporting_app/static/column_formatter.js +++ b/reporting_app/static/column_formatter.js @@ -8,7 +8,7 @@ function render_data(data, type, row, meta, fmt) { return null; } if (!fmt) { - return '
' + data + '
'; + fmt = {}; } if (fmt['name']) { data = function_map[fmt['name']](data, fmt) @@ -17,61 +17,96 @@ function render_data(data, type, row, meta, fmt) { } -function string_formatter(data, fmt, row){ - var formatted_data = data; - - if (fmt['type'] == 'percentage') { - formatted_data = Humanize.toFixed(formatted_data, 1) + '%'; - }if (fmt['type'] == 'ratio_percentage') { - formatted_data = Humanize.toFixed(formatted_data * 100, 1) + '%'; - } else if (fmt['type'] == 'int') { - formatted_data = Humanize.intComma(formatted_data); - } else if (fmt['type'] == 'float') { - formatted_data = Humanize.formatNumber(formatted_data, 2); - } else if (fmt['type'] == 'date') { - formatted_data = moment(new Date(formatted_data)).format('YYYY-MM-DD'); - } else if (fmt['type'] == 'datetime') { - formatted_data = moment(new Date(formatted_data)).format('YYYY-MM-DD HH:mm:ss'); - } - if (fmt['link']) { - if (fmt['link_format_function']){ - formatted_link = function_map[fmt['link_format_function']](data, fmt); - } - else{ - formatted_link = data; - } - if (data instanceof Array && data.length > 1 || data != formatted_link) { - data.sort(); - formatted_data = '') +function string_formatter(cell_data, fmt, row){ + if (cell_data instanceof Array) { + cell_data.sort(); + } else if (cell_data instanceof Object) { + var _cell_data = []; + for (k in cell_data) { + _cell_data.push(k + ': ' + cell_data[k]); } - else if (data instanceof Array && data.length == 1){ - formatted_data = '' + data[0] + ''; - } - else { - formatted_data = '' + data + ''; + cell_data = _cell_data; + } else { + cell_data = [cell_data]; + } + + var use_dropdown = false; + if (cell_data.length > 1) { + use_dropdown = true; + } + var formatted_data = []; + + for (var i=0, tot=cell_data.length; i' + data + ''; } + var min, max; - if (fmt['min']){ + if (fmt['min']) { min = resolve_min_max_value(row, fmt['min']) } - if (fmt['max']){ + if (fmt['max']) { max = resolve_min_max_value(row, fmt['max']) } if (min && data < min) { - formatted_data = '
' + formatted_data + '
'; + _formatted_data = '
' + _formatted_data + '
'; } else if (max && !isNaN(max) && data > max) { - formatted_data = '
' + formatted_data + '
'; + _formatted_data = '
' + _formatted_data + '
'; } else if (max && data > max) { - formatted_data = '
' + formatted_data + '
'; + _formatted_data = '
' + _formatted_data + '
'; + } + + formatted_data.push(_formatted_data); + + } + + if (use_dropdown) { + var dropdown = document.createElement('div'); + dropdown.className = 'dropdown'; + + var dropbtn = document.createElement('div'); + dropbtn.className = 'dropbtn'; + if (fmt['link_format_function']) { + dropbtn.innerHTML = function_map[fmt['link_format_function']](cell_data, fmt); + } else { + dropbtn.innerHTML = cell_data; + } + + var dropdown_content = document.createElement('div'); + dropdown_content.className = 'dropdown-content'; + + var div; + for (var i=0, tot=formatted_data.length; i'; - return formatted_data; + return '
' + formatted_data + '
'; } diff --git a/reporting_app/static/stylesheets/reporting_app.css b/reporting_app/static/stylesheets/reporting_app.css index e1aed946..65ef2483 100644 --- a/reporting_app/static/stylesheets/reporting_app.css +++ b/reporting_app/static/stylesheets/reporting_app.css @@ -17,6 +17,7 @@ } .dropdown { + padding: 2px; //display: inline-block; } diff --git a/reporting_app/templates/base.html b/reporting_app/templates/base.html index 3bc629d1..dfebc0eb 100644 --- a/reporting_app/templates/base.html +++ b/reporting_app/templates/base.html @@ -77,6 +77,7 @@
  • Project Status - All
  • +
  • Genomes
  • Charts
  • Project Status - All
  • -
  • Genomes
  • +
  • Species
  • Charts