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

Updating Phenotype DB with updated SQL tables #484

Merged
merged 53 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6f3df24
Add launch config for `POPULATE_PHENOTYPES_DATABASE`
vlagrassa Feb 9, 2024
46e2e32
Add trait display names to Google Sheet > GCP db op
vlagrassa Feb 20, 2024
f066a1b
Add trait display names to datastore entity class
vlagrassa Feb 20, 2024
5a00d1f
Better fallback behavior for display name
vlagrassa Feb 20, 2024
1663022
Display tags column as `flex-row`
vlagrassa Feb 20, 2024
68e4ee6
Render empty table cell if no short description
vlagrassa Feb 20, 2024
2f30540
Remove unused "label" field from trait report & link with "View Repor…
vlagrassa Feb 21, 2024
0e93036
Move trait multiline HTML to new utils file
vlagrassa Feb 23, 2024
27af180
Render trait display name in reports page w new macro
vlagrassa Feb 23, 2024
e6977d7
Move trait JSON query to util function
vlagrassa Feb 28, 2024
ff0756e
When selecting trait, query info from database directly
vlagrassa Feb 28, 2024
948f914
Render trait display name in trait selectors
vlagrassa Feb 28, 2024
ed37d45
Remove repeat listings for display name fields
vlagrassa Feb 28, 2024
9278b1c
Reorganize TraitFile props a bit
vlagrassa Feb 28, 2024
2c44450
Render trait display names in graph axes
vlagrassa Feb 28, 2024
f72fbf2
Move report list individual tool cols to Jinja
vlagrassa Feb 28, 2024
f1615ce
Cache trait display names in report objects
vlagrassa Feb 28, 2024
6b49f96
Render trait display names in reports list w custom renderer
vlagrassa Feb 28, 2024
9538026
Fix initial trait none check (again)
vlagrassa Feb 29, 2024
e46371d
Sort out `PhenotypeReport` trait name fields (see desc)
vlagrassa Feb 29, 2024
40a8dcf
Render report axis labels with styling (bold, italics, etc)
vlagrassa Feb 29, 2024
3c7d1e3
Add DbOp for recomputing cached phenotype report display names
vlagrassa Feb 29, 2024
6577a83
Set full CaeNDR trait name as display name for Zhang traits
vlagrassa Feb 29, 2024
bb48389
Use trait display names in offcanvas header
vlagrassa Feb 29, 2024
315f0db
Fix: render axis labels as HTML in single-trait report
vlagrassa Feb 29, 2024
18e1538
Fix: move display name computation to Trait & use to initialize Zhang…
vlagrassa Feb 29, 2024
6e1f4e1
Set expiration policy for subscription to never
vlagrassa Mar 13, 2024
c7f0734
Move strain labels to first element of result tuples
vlagrassa Feb 19, 2024
0223e86
Add TSV download route for phenotype report
vlagrassa Feb 19, 2024
02b438d
Add code to download SVGs
vlagrassa Feb 19, 2024
7cb18d7
Show download buttons
vlagrassa Feb 19, 2024
a9fbb09
Connect SVG download buttons to download function
vlagrassa Mar 1, 2024
595a4ab
Fix indentation
vlagrassa Mar 1, 2024
cbe9c19
Add download as PDF button
vlagrassa Mar 1, 2024
39cd76f
Changed PDF icon and changed copy
natalieroman Mar 1, 2024
7eee7cc
Removed custom no-print css classes and replaced with Bootstrap no pr…
natalieroman Mar 1, 2024
ce9a2bf
Fixed height of chart container to show ranked barplot "download svg"…
natalieroman Mar 1, 2024
15e1553
Check Google Sheet columns before parsing rows
vlagrassa Apr 10, 2024
6ba326d
Fix: trait lookup request data
vlagrassa Apr 10, 2024
9080429
Flash error message if trait metadata request fails
vlagrassa Apr 10, 2024
35d94be
Merge remote-tracking branch 'refs/remotes/origin/development' into d…
May 9, 2024
25e2382
Merge remote-tracking branch 'origin/development' into development
May 9, 2024
daf5913
Fixing the POST request for trait details, adding off-canvas header ID
May 9, 2024
a01dde6
Changing trait_name -> trait_id when fetching trait details
May 9, 2024
874d050
Updating Phenotype metadata parsing function - setting dataset correctly
May 9, 2024
c592c25
Passing trait_id for zhang traits in analyze link()
May 10, 2024
5b40e07
Updating display name for zhang files
May 10, 2024
758d91d
Update module version of db_operations
May 13, 2024
21c6441
Adding bleach module to db_operations
May 13, 2024
933b36b
Updating analayze_link - changing trait_name to trait_id
May 20, 2024
43b96a0
Update module version
May 20, 2024
deca673
Update the way of fetching the trait
May 20, 2024
2b06b05
Merge branch 'development' into fix/phenotype-db
vlagrassa May 31, 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
2 changes: 1 addition & 1 deletion src/modules/db_operations/module.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MODULE_NAME=caendr-db-operations
MODULE_VERSION=v1.0.41
MODULE_VERSION=v1.0.42
1 change: 1 addition & 0 deletions src/modules/db_operations/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
backoff==2.2.1
bleach==4.1.0
Flask==1.1.2
Flask_SQLAlchemy==2.5.1
SQLAlchemy==1.3.18
Expand Down
6 changes: 6 additions & 0 deletions src/modules/site-v2/base/static/js/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ function render_ranked_barplot(container_selector, data, config={}) {
// Read values from config, filling in default values when not supplied
const fill_color = config['fill_color'] || 'black';

// Create a template function for the tooltip
// By default, show label & value for each axis
const tooltip_id = config['tooltip_id'] || null;
const tooltip_template = config['tooltip_template'] || ((d) => `
<p class="tooltip-body">${d[0]}: ${d[1]}</p>
`);

// Sort data
data.sort(function(b, a) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/site-v2/module.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MODULE_NAME=caendr-site-v2
MODULE_VERSION=v2.0.95
MODULE_VERSION=v2.0.96

PORT=8080
FLASK_APP=main:app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
$('#{{ offcanvas_id }} .btn-close').click()
flashErrorResponse(error.responseJSON, 'There was a problem retrieving this trait. Please try again later.')
})
})
})


// Filter table by tag links
Expand Down
2 changes: 1 addition & 1 deletion src/modules/site-v2/templates/_scripts/trait_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function queryTraitByName(trait_id, csrf_token=null) {
// Construct the data object, using the optional CSRF token if provided
let data = {trait_id};
if (csrf_token !== null) data['csrf_token'] = csrf_token;

// Return the AJAX request as a Promise object
return $.ajax({
type: "POST",
Expand Down
16 changes: 16 additions & 0 deletions src/modules/site-v2/templates/tools/phenotype_database/report.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ <h4 class="h5">Description:</h4>
fill_color: '#0719BC',
bins_per_tick: 2,
x_label: trait_label,
tooltip_id: 'tooltip-single-histogram',
tooltip_template: (d, labels) => `
<p class="tooltip-head"><b>Strain: ${d[0]}</b></p>
<p class="tooltip-body">${labels[0]}: ${d[1]}</p>
`,
});
} catch (err) {
console.error(`Could not construct histogram. ${err}`)
Expand All @@ -238,6 +243,11 @@ <h4 class="h5">Description:</h4>
width: 1200,
fill_color: '#0719BC',
y_label: trait_label,
tooltip_id: 'tooltip-single-barplot',
tooltip_template: (d) => `
<p class="tooltip-head"><b>${d[0]}</b></p>
<p class="tooltip-body">Value = ${d[1].toFixed(4)}</p>
`,
});
} catch (err) {
console.error(`Could not construct ranked bar plot. ${err}`)
Expand All @@ -262,6 +272,12 @@ <h4 class="h5">Description:</h4>
y_label: `${trait_label_2}`,
opacity: 0.5,
opacity_hover: 1,
tooltip_id: 'tooltip-double-scatterplot',
tooltip_template: (d, labels) => `
<p class="tooltip-head"><b>${d[0]}</b></p>
<p class="tooltip-body">x = ${d[1].toFixed(4)}</p>
<p class="tooltip-body">y = ${d[2].toFixed(4)}</p>
`,
});
} catch (err) {
console.error(`Could not construct scatterplot. ${err}`)
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/caendr/caendr/models/datastore/phenotype_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def compute_display_name(cls, trait: Union[Trait, TraitFile], trait_name: Option
raise ValueError()

# Use the Trait object to compute the display name
return list(trait.display_name)
return [trait.name,] if trait.dataset == 'zhang' else list(trait.display_name)


@classmethod
Expand Down
30 changes: 26 additions & 4 deletions src/pkg/caendr/caendr/models/trait.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

from caendr.models.datastore import TraitFile
from caendr.models.sql import PhenotypeMetadata, PhenotypeDatabase
from caendr.models.error import NotFoundError
from caendr.utils.data import dataframe_cols_to_dict
from caendr.api.phenotype import get_trait

from caendr.services.cloud.postgresql import db

Expand Down Expand Up @@ -57,9 +59,11 @@ def __init__(self, dataset = None, trait_name = None, trait_file_id = None, trai
raise ValueError('Could not identify a unique trait from the given information')

# Store the dataset value of the trait file
if dataset and self.file['dataset'] and dataset != self.file['dataset']:
raise ValueError('Mismatched dataset values')
self.dataset = self.file['dataset']
# if dataset and self.file['dataset'].value and dataset != self.file['dataset'].value:
# raise ValueError('Mismatched dataset values')
self.dataset = self.file['dataset'].value

self.sql_row = PhenotypeMetadata.query.filter_by(trait_name_caendr = self.name, dataset = self.dataset).one()


#
Expand Down Expand Up @@ -104,6 +108,24 @@ def from_sql(sql_row: PhenotypeMetadata) -> 'Trait':
dataset = sql_row.dataset,
trait_name = sql_row.trait_name_caendr,
)

@classmethod
def from_id(cls, trait_id: str) -> 'Trait':
'''
Instantiate a `Trait` object from a unique trait ID.
The given ID must exist in the PhenotypeMetadata SQL table, otherwise a `ValueError` will be raised.
'''

# Get the SQL row with the given trait ID
sql_row = PhenotypeMetadata.query.get(trait_id)
if sql_row is None:
raise NotFoundError(PhenotypeMetadata, {'id': trait_id})

# Construct a Trait object using the data in the SQL row
return cls(
trait_name = sql_row.trait_name_caendr,
dataset = sql_row.dataset,
)


#
Expand Down Expand Up @@ -145,4 +167,4 @@ def display_name(self):
'''

# For bulk files, store the single trait name, otherwise convert the display_name fields to a list
return (self.name,) if self.file['is_bulk_file'] else self.file.display_name
return (self.sql_row.trait_name_caendr,) if self.file['is_bulk_file'] else self.file.display_name
4 changes: 2 additions & 2 deletions src/pkg/caendr/caendr/services/sql/etl/phenotype_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def parse_phenotype_metadata(species: Species, **files: LocalDatastoreFile):
'capture_date': md['capture_date'],
'created_on': md.created_on,
'modified_on': md.modified_on,
'dataset': md['dataset'],
'dataset': md['dataset'].value,
'is_bulk_file': md['is_bulk_file'],
}
else:
Expand All @@ -83,6 +83,6 @@ def parse_phenotype_metadata(species: Species, **files: LocalDatastoreFile):
'capture_date': md['capture_date'],
'created_on': md.created_on,
'modified_on': md.modified_on,
'dataset': md['dataset'],
'dataset': md['dataset'].value,
'is_bulk_file': md['is_bulk_file'],
}
Loading