Skip to content

Commit

Permalink
Merge pull request #35 from dms-viz/give-more-control-over-color-scale
Browse files Browse the repository at this point in the history
Allow the user to set the heatmap color scale limits and center
  • Loading branch information
WillHannon-MCB authored May 17, 2024
2 parents bfc53a1 + 39eab40 commit ff96533
Show file tree
Hide file tree
Showing 13 changed files with 4,513 additions and 12 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,23 @@
### Removed

- N/A

## [1.4.0] - 2024-05-16

### Added

- Added a flag (--heatmap-limits) to allow users to set the limits of the color scale.
- Added a human dataset (PTEN VAMPseq)
- Attempt to sort the reference sites when no sitemap is provided

### Changed

- N/A

### Deprecated

- N/A

### Removed

- N/A
65 changes: 60 additions & 5 deletions configure_dms_viz/configure_dms_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def make_experiment_dictionary(
join_data=None,
filter_cols=None,
filter_limits=None,
heatmap_limits=None,
tooltip_cols=None,
metric_name=None,
condition_col=None,
Expand Down Expand Up @@ -396,6 +397,8 @@ def make_experiment_dictionary(
A dictionary of column names and formatted names to designate as filters.
filter_limits: dict or None
A dictionary of the desired min and max values for each filter column slider range.
heatmap_limits: list or None
A list of the desired min, max, and center values for the metric to be used for the heatmap's color scale.
tooltip_cols: dict or None
A dictionary of column names and formatted names to designate as tooltips.
included_chains: str or None
Expand Down Expand Up @@ -443,15 +446,14 @@ def make_experiment_dictionary(
# If there is no sitemap dataframe, create a default one
if sitemap_df is None:
click.secho(
message="Warning: No sitemap dataframe was provided. Creating a default sitemap.",
message="Warning: No sitemap dataframe was provided. Creating a default sitemap.\n If no site map is provided, the reference sites will be sorted but may appear out of order.",
fg="yellow",
)
reference_sites = sorted(list(set(mut_metric_df["reference_site"].to_list())))
sitemap_df = pd.DataFrame(
{
"reference_site": mut_metric_df["reference_site"].unique(),
"sequential_site": range(
1, len(mut_metric_df["reference_site"].unique()) + 1
),
"reference_site": reference_sites,
"sequential_site": range(1, len(reference_sites) + 1),
}
)

Expand All @@ -469,6 +471,49 @@ def make_experiment_dictionary(
if condition_col:
cols_to_keep.append(condition_col)

# Check that the heatmap limits are in the correct format
if heatmap_limits:
# Check that the values are all able to be coerced into numbers
for value in heatmap_limits:
try:
pd.to_numeric(value)
except ValueError as err:
raise ValueError(
f"The heatmap limit '{value}' cannot be coerced into a number."
) from err
# Only the center of the scale is provided
if len(heatmap_limits) == 1:
click.secho(
message="One value was provided for heatmap limits, this will be the center value of the scale.\n",
fg="green",
)
# The min and max are provided
elif len(heatmap_limits) == 2:
click.secho(
message="Two values were provided for heatmap limits, these will be the min and max of the scale.\n",
fg="green",
)
# Check that the values are in the correct order
if heatmap_limits[0] > heatmap_limits[1]:
raise ValueError(
"The heatmap limits are not specified correctly. The min value must be less than the max value."
)
# The min, center, and max are provided
elif len(heatmap_limits) == 3:
click.secho(
message="Three values were provided for heatmap limits, these will be the min, center, and max of the scale.\n",
fg="green",
)
# Check that the values are in the correct order
if not heatmap_limits[0] < heatmap_limits[1] < heatmap_limits[2]:
raise ValueError(
"The heatmap limits are not specified correctly. The min value must be less than the max value and the center value must be in between."
)
else:
raise ValueError(
"The heatmap limits must be a list of one, two, or three values."
)

# Add the filter columns to the required columns
if filter_cols:
cols = check_filter_columns(mut_metric_df, filter_cols)
Expand Down Expand Up @@ -657,6 +702,7 @@ def make_experiment_dictionary(
"excludeChains": excluded_chains.split(" "),
"filter_cols": filter_cols,
"filter_limits": filter_limits,
"heatmap_limits": heatmap_limits,
"tooltip_cols": tooltip_cols,
"excludedAminoAcids": exclude_amino_acids,
"description": description,
Expand Down Expand Up @@ -770,6 +816,13 @@ def cli():
default=None,
help="Optionally, a space separated list of columns to use as filters in the visualization. Example: \"{'effect': [min, max], 'times_seen': [min, max]}\"",
)
@click.option(
"--heatmap-limits",
type=ListParamType(),
required=False,
default=None,
help='Optionally, a list of the min, center, and max values for the metric to be used for the heatmap\'s color scale. Example: "[min, center, max]"',
)
@click.option(
"--tooltip-cols",
type=DictParamType(),
Expand Down Expand Up @@ -859,6 +912,7 @@ def format(
condition_name,
filter_cols,
filter_limits,
heatmap_limits,
tooltip_cols,
join_data,
included_chains,
Expand Down Expand Up @@ -905,6 +959,7 @@ def format(
join_data_dfs,
filter_cols,
filter_limits,
heatmap_limits,
tooltip_cols,
metric_name,
condition,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "configure-dms-viz"
version = "1.3.4"
version = "1.4.0"
description = "Configure your data for visualization with dms-viz.github.io"
authors = ["Will Hannon <[email protected]>"]
maintainers = ["Will Hannon <[email protected]>"]
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/IAV-PB1-DMS/output/IAV-PB1-DMS.json

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions tests/PTEN-VAMPseq/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# VAMPseq mutational scan of the PTEN tumor suppressor

The `configure-dms-viz` command used to generate this visualization is:

```bash
configure-dms-viz format \
--input tests/PTEN-VAMPseq/input/PTEN-VAMPseq.csv \
--output tests/PTEN-VAMPseq/output/PTEN-VAMPseq.json \
--name "PTEN-VAPseq" \
--metric "score" \
--metric-name "Score" \
--heatmap-limits "-.5, 1, 1.5" \
--structure "1D5R"
```
2 changes: 2 additions & 0 deletions tests/PTEN-VAMPseq/datasets.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
input,name,metric,metric_name,structure,heatmap_limits
tests/PTEN-VAMPseq/input/PTEN-VAMPseq.csv,PTEN-VAPseq,score,Score,1D5R,"-.5, 1, 1.5"
Loading

0 comments on commit ff96533

Please sign in to comment.