Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render trait display names everywhere #472

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
776892d
Add launch config for `POPULATE_PHENOTYPES_DATABASE`
vlagrassa Feb 9, 2024
8a057e7
Merge branch 'development' into enhancement/phenotype-datastore-multi…
vlagrassa Feb 20, 2024
527b169
Add trait display names to Google Sheet > GCP db op
vlagrassa Feb 20, 2024
eec1ba4
Add trait display names to datastore entity class
vlagrassa Feb 20, 2024
8e01dd2
Better fallback behavior for display name
vlagrassa Feb 20, 2024
a31c172
Display tags column as `flex-row`
vlagrassa Feb 20, 2024
0cfa693
Render empty table cell if no short description
vlagrassa Feb 20, 2024
9918388
Remove unused "label" field from trait report & link with "View Repor…
vlagrassa Feb 21, 2024
7e8f463
Merge branch 'fix/trait-name-styling' into enhancement/phenotype-data…
vlagrassa Feb 23, 2024
1b258b8
Move trait multiline HTML to new utils file
vlagrassa Feb 23, 2024
efec6a9
Render trait display name in reports page w new macro
vlagrassa Feb 23, 2024
cd5736e
Move trait JSON query to util function
vlagrassa Feb 28, 2024
3d21dac
When selecting trait, query info from database directly
vlagrassa Feb 28, 2024
5f5c8e7
Render trait display name in trait selectors
vlagrassa Feb 28, 2024
ff72030
Remove repeat listings for display name fields
vlagrassa Feb 28, 2024
c356254
Reorganize TraitFile props a bit
vlagrassa Feb 28, 2024
7726bb9
Render trait display names in graph axes
vlagrassa Feb 28, 2024
efe677b
Move report list individual tool cols to Jinja
vlagrassa Feb 28, 2024
38127cd
Cache trait display names in report objects
vlagrassa Feb 28, 2024
84bcdf2
Render trait display names in reports list w custom renderer
vlagrassa Feb 28, 2024
881298d
Fix initial trait none check (again)
vlagrassa Feb 29, 2024
5cb6222
Sort out `PhenotypeReport` trait name fields (see desc)
vlagrassa Feb 29, 2024
7c3de83
Render report axis labels with styling (bold, italics, etc)
vlagrassa Feb 29, 2024
42741be
Add DbOp for recomputing cached phenotype report display names
vlagrassa Feb 29, 2024
958bd5a
Set full CaeNDR trait name as display name for Zhang traits
vlagrassa Feb 29, 2024
a547a41
Use trait display names in offcanvas header
vlagrassa Feb 29, 2024
230c61f
Fix: render axis labels as HTML in single-trait report
vlagrassa Feb 29, 2024
db868e2
Fix: move display name computation to Trait & use to initialize Zhang…
vlagrassa Feb 29, 2024
8d09fda
Merge branch 'development' into enhancement/phenotype-datastore-multi…
vlagrassa Feb 29, 2024
997252e
Merge branch 'development' into enhancement/phenotype-datastore-multi…
vlagrassa Apr 10, 2024
011de8d
Check Google Sheet columns before parsing rows
vlagrassa Apr 10, 2024
db31f33
Fix: trait lookup request data
vlagrassa Apr 10, 2024
75e9873
Flash error message if trait metadata request fails
vlagrassa Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,28 @@
"SITE_BASE_URL": "https://localhost:8080"
}
},
{
"name": "Run POPULATE_PHENOTYPES_DATASTORE",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/src/modules/db_operations/main.py",
"console": "integratedTerminal",
"python": "${workspaceFolder}/src/modules/db_operations/venv/bin/python",
"justMyCode": true,
"envFile": "${workspaceFolder}/src/modules/db_operations/.env",
"env": {
"DATABASE_OPERATION": "POPULATE_PHENOTYPES_DATASTORE",
"USE_MEMOIZATION": "1",
// "MODULE_DB_OPERATIONS_CONNECTION_TYPE": "localhost",
// "MODULE_DB_OPERATIONS_CONNECTION_TYPE": "memory",
"MODULE_DB_OPERATIONS_CONNECTION_TYPE": "file",
"MODULE_DB_OPERATIONS_CONNECTION_FILE": "${workspaceFolder}/temp/local.db",
"MODULE_DB_TIMEOUT": "300",
"CAENDR_USE_SSL": "1",
"SENTRY_URL": "",
"SITE_BASE_URL": "https://localhost:8080",
},
},
{
"name": "DB_OP TEST_ECHO",
"type": "python",
Expand All @@ -348,6 +370,24 @@
"SITE_BASE_URL": "https://localhost:8080",
}
},
{
"name": "DbOp: Recompute Phenotype Report Cached Names",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/src/modules/db_operations/main.py",
"console": "integratedTerminal",
"python": "${workspaceFolder}/src/modules/db_operations/venv/bin/python",
"justMyCode": true,
"envFile": "${workspaceFolder}/src/modules/db_operations/.env",
"env": {
"DATABASE_OPERATION": "RECOMPUTE_PHENOTYPE_REPORT_CACHED_NAMES",
"RELOAD_FILES": "false",
"MODULE_DB_TIMEOUT": "300",
"CAENDR_USE_SSL": "1",
"SENTRY_URL": "",
"SITE_BASE_URL": "https://localhost:8080",
}
},
{
"name": "Test Indel Finder",
"type": "python",
Expand Down
5 changes: 4 additions & 1 deletion src/modules/db_operations/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from caendr.services.cloud.postgresql import health_database_status
from caendr.services.logger import logger

from caendr.models.datastore import Species
from caendr.models.datastore import Species, PhenotypeReport
from caendr.models.sql import DbOp, WormbaseGene, WormbaseGeneSummary, Strain, StrainAnnotatedVariant, PhenotypeDatabase, PhenotypeMetadata
from caendr.services.sql.db import backup_external_db
from caendr.services.sql.etl import ETLManager
Expand Down Expand Up @@ -49,6 +49,9 @@ def execute_operation(app, db, db_op: DbOp, species=None, reload_files=True):
logger.info("Using MOCK DATA")
drop_and_populate_all_tables(app, db, species)

elif db_op == DbOp.RECOMPUTE_PHENOTYPE_REPORT_CACHED_NAMES:
PhenotypeReport.recompute_cached_display_names()



def drop_and_populate_strains(app, db, species, reload_files=True):
Expand Down
50 changes: 44 additions & 6 deletions src/modules/db_operations/seed_trait_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from caendr.services.cloud.secret import get_secret

from caendr.models.datastore import TraitFile
from caendr.models.error import NotFoundError, NonUniqueEntity
from caendr.models.error import NotFoundError, NonUniqueEntity, GoogleSheetsParseError
from caendr.models.status import PublishStatus
from caendr.services.cloud.sheets import get_field_from_record
from caendr.services.cloud.sheets import check_missing_columns, get_field_from_record
from caendr.utils.data import unique_id
from caendr.utils.local_files import LocalGoogleSheet

Expand All @@ -13,6 +13,31 @@
ANDERSEN_LAB_TRAIT_SHEET = get_secret(f'ANDERSEN_LAB_TRAIT_SHEET')


# Set of column headers that must exist in the sheet
# NOTE: Not every entry needs to define all of these fields -- these are just the columns that should be available in the sheet.
REQUIRED_SHEET_HEADERS = frozenset({
'Trait_Name_CaeNDR',
'Trait_Name_User',
'Species',
'Trait_Name_Display1',
'Trait_Name_Display2',
'Trait_Name_Display3',
'Short_Description',
'Long_Description',
'Units',
'Publication',
'Protocol',
'Institution',
'Captured_By_UserID',
'Capture_Date',

# TODO: How should we handle category tags?
r-vieira marked this conversation as resolved.
Show resolved Hide resolved
# 'Category1',
# 'Category2',
# 'Category3',
})



def populate_andersenlab_trait_files():
'''
Expand All @@ -27,7 +52,17 @@ def populate_andersenlab_trait_files():

# Fetch the Google Sheet and loop through all records
trait_sheet = LocalGoogleSheet( 'TRAITS', ANDERSEN_LAB_TRAIT_SHEET )
for record in trait_sheet.fetch_resource().get_all_records():
resource = trait_sheet.fetch_resource()

# Make sure the Google Sheet has all the required columns
missing_columns = check_missing_columns(resource, REQUIRED_SHEET_HEADERS)
if len(missing_columns):
msg = f'{trait_sheet} (ID: {trait_sheet._sheet_id}) is missing columns: [{", ".join(missing_columns)}]'
logger.error(msg)
raise GoogleSheetsParseError(msg)

# Loop through rows in the sheet
for record in resource.get_all_records():

# Require that unique CaeNDR trait name is defined
trait_unique_name = record.get('Trait_Name_CaeNDR')
Expand Down Expand Up @@ -61,9 +96,12 @@ def populate_andersenlab_trait_files():
'species': get_field_from_record(record, 'Species', nullable=False),

# About trait
'description_short': get_field_from_record(record, 'Short_Description'),
'description_long': get_field_from_record(record, 'Long_Description'),
'units': get_field_from_record(record, 'Units'),
'trait_name_display_1': get_field_from_record(record, 'Trait_Name_Display1'),
r-vieira marked this conversation as resolved.
Show resolved Hide resolved
'trait_name_display_2': get_field_from_record(record, 'Trait_Name_Display2'),
'trait_name_display_3': get_field_from_record(record, 'Trait_Name_Display3'),
'description_short': get_field_from_record(record, 'Short_Description'),
'description_long': get_field_from_record(record, 'Long_Description'),
'units': get_field_from_record(record, 'Units'),

# Tag list (categories)
'tags': list(filter(
Expand Down
8 changes: 4 additions & 4 deletions src/modules/site-v2/base/static/js/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function render_scatterplot_histograms(container_selector, data, config={}) {
.attr('x', margin.left + (width / 2))
.attr('y', height + margin.top + hist_height + 36)
.attr('text-anchor', 'middle')
.text(config['x_label'])
.html(config['x_label'])
}

// Add label for y-axis, if one is provided
Expand All @@ -216,7 +216,7 @@ function render_scatterplot_histograms(container_selector, data, config={}) {
.attr('y', 0)
.attr('dy', '.75em')
.attr('text-anchor', 'middle')
.text(config['y_label'])
.html(config['y_label'])

}

Expand Down Expand Up @@ -349,7 +349,7 @@ function render_histogram(container_selector, data, config={}) {
.attr('x', margin.left + (width / 2))
.attr('y', height + margin.top + 36)
.attr('text-anchor', 'middle')
.text(config['x_label'])
.html(config['x_label'])
}

// Add the histogram
Expand Down Expand Up @@ -501,7 +501,7 @@ function render_ranked_barplot(container_selector, data, config={}) {
.attr('y', 0)
.attr('dy', '.75em')
.attr('text-anchor', 'middle')
.text(config['y_label'])
.html(config['y_label'])
}
//Render tooltips
setTooltips();
Expand Down
19 changes: 0 additions & 19 deletions src/modules/site-v2/base/views/tools/genetic_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,6 @@



def results_columns():
return [
{
'title': 'Description',
'class': 'label',
'field': 'label',
'width': 0.6,
'link_to_data': True,
},
{
'title': 'Trait',
'class': 'trait',
'field': 'trait',
'width': 0.4,
},
]


@genetic_mapping_bp.route('', methods=['GET'])
@jwt_required()
def genetic_mapping():
Expand Down Expand Up @@ -162,7 +144,6 @@ def list_results():
# Table info
'species_list': Species.all(),
'items': list_reports(NemascanReport, None if show_all else user, filter_errs),
'columns': results_columns(),

'JobStatus': JobStatus,
})
Expand Down
18 changes: 0 additions & 18 deletions src/modules/site-v2/base/views/tools/heritability_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,6 @@
)


def results_columns():
return [
{
'title': 'Description',
'class': 'label',
'field': 'label',
'width': 0.6,
'link_to_data': True,
},
{
'title': 'Trait',
'class': 'trait',
'field': 'trait',
'width': 0.4,
},
]


@heritability_calculator_bp.route('')
@jwt_required()
Expand Down Expand Up @@ -136,7 +119,6 @@ def list_results():
# Table info
'species_list': Species.all(),
'items': list_reports(HeritabilityReport, None if show_all else user, filter_errs),
'columns': results_columns(),

'JobStatus': JobStatus,
})
Expand Down
25 changes: 0 additions & 25 deletions src/modules/site-v2/base/views/tools/pairwise_indel_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,6 @@



def results_columns():
return [
{
'title': 'Site',
'class': 'site',
'field': 'site',
'width': 0.5,
'link_to_data': True,
'data_order': lambda e: e['site'],
},
{
'title': 'Strain 1',
'class': 's1',
'field': 'strain_1',
'width': 0.25,
},
{
'title': 'Strain 2',
'class': 's2',
'field': 'strain_2',
'width': 0.25,
},
]

def try_get_sv_strains(species):
try:
return get_sv_strains(species)
Expand Down Expand Up @@ -185,7 +161,6 @@ def list_results():
# Table info
'species_list': Species.all(),
'items': list_reports(IndelPrimerReport, None if show_all else user, filter_errs),
'columns': results_columns(),

'JobStatus': JobStatus,
})
Expand Down
28 changes: 1 addition & 27 deletions src/modules/site-v2/base/views/tools/phenotype_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,6 @@ def check_bp_enabled():



def results_columns():
return [
{
'title': 'Description',
'class': 'label',
'field': 'label',
'width': 0.2,
'link_to_data': True,
},
{
'title': 'Trait 1',
'class': 's1',
'field': 'trait_1_name',
'width': 0.4,
},
{
'title': 'Trait 2',
'class': 's2',
'field': 'trait_2_name',
'width': 0.4,
},
]



#
# Main Endpoint
#
Expand Down Expand Up @@ -253,7 +228,7 @@ def submit():
# Read & clean fields from JSON data
data = {
field: bleach.clean(request.json.get(field))
for field in {'label', 'species', 'trait_1', 'trait_1_dataset'}
for field in {'species', 'trait_1', 'trait_1_dataset'}
}

# Read & clean values for trait 2, if given
Expand Down Expand Up @@ -312,7 +287,6 @@ def list_results():
# Table info
'species_list': Species.all(),
'items': list_reports(PhenotypeReport, user = None if show_all else user, filter_errs=filter_errs),
'columns': results_columns(),

'JobStatus': JobStatus,
})
Expand Down
5 changes: 0 additions & 5 deletions src/modules/site-v2/templates/_includes/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,3 @@
<em>Unable to retrieve files.</em>
{%- endif %}
{%- endmacro %}


{%- macro label_string_units(name, units=null) %}
{%- if units -%} "{{ name }} ({{ units }})" {%- else -%} "{{ name }}" {%- endif -%}
{%- endmacro %}
Loading