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

add toggle to normalize frequencies #1158

Merged
merged 8 commits into from
Jun 8, 2020

Conversation

rneher
Copy link
Member

@rneher rneher commented Jun 5, 2020

Description of proposed changes

Frequencies are currently normalized such that they sum up to 100% when all tips are visible. Sometimes it is useful to normalize them to the currently visible tips (say you filter to Europe an want to see frequencies of clades in Europe -- you'd like to see what fraction 20A has in Europe rather than what fraction European 20A has of all sequences).

This PR implements a toggle switch that allows to flip between these two normalizations.

The implementation is modeled on the showTransmissionLine toogle PR #1147

Related issue(s)

Fixes #784
related to #838

Testing

What steps should be taken to test the changes you've proposed?
If you added or changed behavior in the codebase, did you update the tests, or do you need help with this?

Thank you for contributing to Nextstrain!

@jameshadfield jameshadfield temporarily deployed to auspice-feat-frequencyn-jvexjj June 5, 2020 14:11 Inactive
@rneher rneher changed the title add toggle to normalize frequencies [DRAFT] add toggle to normalize frequencies Jun 5, 2020
@rneher rneher requested review from jameshadfield and eharkins and removed request for jameshadfield June 5, 2020 14:12
@rneher
Copy link
Member Author

rneher commented Jun 5, 2020

@jameshadfield @eharkins this isn't done yet... the transmission line toggle updates state but doesn't trigger a rerender of the frequencies. Once you update colorBy etc it works as intended. I got stuck on where this needs to be triggered.

But the basic behavior is in place. Without this normalization, clade frequencies in Europe look like this:
image

with the toggle true they look like:
image

but to get there I have to change the colorBy... would be great if you could point me to where this goes wrong.

@rneher rneher requested a review from jameshadfield June 5, 2020 16:44
@rneher
Copy link
Member Author

rneher commented Jun 5, 2020

@rneher rneher temporarily deployed to auspice-feat-frequencyn-jvexjj June 6, 2020 21:55 Inactive
@rneher
Copy link
Member Author

rneher commented Jun 6, 2020

I hooked up the recalculation of frequencies to the toggle. this now seems to work.

I also added a note to the title of the frequency panel.

@rneher rneher changed the title [DRAFT] add toggle to normalize frequencies add toggle to normalize frequencies Jun 6, 2020
@rneher rneher temporarily deployed to auspice-feat-frequencyn-jvexjj June 6, 2020 21:59 Inactive
@rneher rneher temporarily deployed to auspice-feat-frequencyn-jvexjj June 6, 2020 22:13 Inactive
@rneher
Copy link
Member Author

rneher commented Jun 6, 2020

this seem to work for me now. to test, look at a filtered dataset like

https://auspice-feat-frequencyn-jvexjj.herokuapp.com/flu/seasonal/h3n2/ha/3y?f_submitting_lab=Centers%20For%20Disease%20Control%20And%20Prevention

and toggle the frequency normalizer.

@rneher rneher temporarily deployed to auspice-feat-frequencyn-jvexjj June 7, 2020 12:12 Inactive
@rneher rneher temporarily deployed to auspice-feat-frequencyn-jvexjj June 7, 2020 12:30 Inactive
@rneher
Copy link
Member Author

rneher commented Jun 7, 2020

I made a couple of additions in response to suggestions by @huddlej including a check to avoid undefined results when there is no data and a message in the title of the card on how much data the result is based.

Toggling "normalize frequencies" now results in only a single dispatch call. This reduces the chances of state becoming out-of-sync in future work, and will allow narratives to function better (if we ever use frequencies in narratives).

The "TOGGLE_X" actions work best if the react component will update appropriately when that state changes (or some middleware listens for it and updates redux state accordingly). As the frequencies are currently designed, however, the underlying matrix is updated independent of the frequencies panel, and the panel component is more of a plain-renderer.
@jameshadfield jameshadfield temporarily deployed to auspice-feat-frequencyn-jvexjj June 8, 2020 00:29 Inactive
Copy link
Member

@jameshadfield jameshadfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! The dynamic title text is very helpful.

As you've found out, the frequencies behave slightly differently to the tree: For frequencies the underlying matrix is recalculated by actions such as filtering, tree-zooming etc, and the react component is more of a plain renderer of the pre-computed data. So a "toggle" action must recompute the appropriate redux state.

For the map, the react component does a lot of the data recompute itself, and so a "toggle" action would be a very simple action, and the <Map> component would do the appropriate recompute when it noticed that state change.

I added a commit which reduced the number of actions needed (more details in commit message).

@jameshadfield jameshadfield merged commit 0a998d8 into master Jun 8, 2020
@jameshadfield jameshadfield deleted the feat/frequencyNormalizationToggle branch June 8, 2020 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Frequencies behave unexpectedly after filtering
2 participants