-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat(web): add mutation badges #1446
Conversation
Add mutation badge React components for nuc and aa mutations. This is a simplified version of what's there in [Nextclade](https://github.com/nextstrain/nextclade/blob/c9d43865f7df492a3c2a6b2e1a9287c670155fd9/packages/nextclade-web/src/components/Common/MutationBadge.tsx) or [Covariants](https://github.com/hodcroftlab/covariants/blob/17884e1c0bf55602246f77aa31a70ee6a1c8d659/web/src/components/Common/MutationBadge.tsx). I had to port it from styled-components to tailwind. Badge segments are colored dynamically, depending on a character or gene name. I use `style` attr to handle that. Additionally, the text is being rendered of light or dark color depending on the contrast ratio relative to background color. I had to add `polished` NPM package to calculate contrast ratio. Notes: - There is no fixed list of genes/CDSes avaialble, so it's not immediately possible to render stable (recognizable) gene/CDS colors, which may increase readablity of aa badges significantly. In Nextclade the list is provided from "backend", and in Covariants the list is static, as it only deals with SC2. In Loclulus I decided to use color hash algorithm to generate colors from gene name strings for now. If backend could provide this data, then UX could be further improved. - It seems that `DataTable.astro` is only able to render values that are strings or numbers. I don't immediately see how the badges can be incorporated there without hacks. I need a bit more details of what's planned for this component. So for now I just temporarily added some hardcoded badges above the table as a showcase. - From a quick look, I found that backend currently provides mutations in string format, e.g. `A123G`. This means that these strings need to be parsed in order to extract gene, position, and ref and query characters. In Covariants this is done using regex [like that](https://github.com/hodcroftlab/covariants/blob/17884e1c0bf55602246f77aa31a70ee6a1c8d659/web/src/components/Common/parseAminoacidMutation.ts). It's a bit of a hairy adventure though. So if backend could precompute and supply structured data that'd be great. - I use exact values in tailwind classes, because these badge components don't fit well into the tailwind paradigm. These components should probably be extracted into some resusable NPM package with some configurable styling. And we'd share it across projects. Though the gene colors is an issue in this case.
The badges look nice! Here in higher resolution:
|
|
Re: tailwind. It's totally fine to mix tailwind classes and |
It should be possible to configure a data type so that we can render mutation badges, similar to how we show the "DataUseTermsHistoryModal" which is a react component loculus/website/src/components/SequenceDetailsPage/DataTable.astro Lines 37 to 46 in a996ba2
If you rebase on main, you'll get this version.
We'd set a loculus/website/src/components/SequenceDetailsPage/DataTable.astro Lines 18 to 19 in a996ba2
@theosanderson I think Ivan uses a browser extension, maybe this one even: |
The way I see it, conceptually, client has nothing to do with digesting mutations. This should be figured out not just in backend server, but very early during preprocessing stage.
Disadvantages:
|
Yep, that's Dark Reader :) |
Our backend in this context is LAPIS, so is quite constrained. If we do the regex-y stuff in the file that Cornelius points to, that will happen server-side within Astro (which is probably the only realistic option here in the short-term, other than client-side). Edit: or I may be wrong, LAPIS may already support this - who knows |
The string formatting happens here: loculus/website/src/components/SequenceDetailsPage/getTableData.ts Lines 154 to 160 in a996ba2
The input data comes from LAPIS: see OpenAPI docs Unfortunately it seems that LAPIS treats mutations as strings, not as an object. @chaoran-chen It doesn't look like LAPIS supports structured mutations, at least as far as I can tell from the docs. |
LAPIS indeed only returns mutations as strings. |
GenSpectrum/LAPIS-SILO#357 would be ready. Depending on the urgency you want to clean this up with |
Thanks Alex! That was fast! In LAPIS, I think that the default should remain as is but we can offer a parameter for requesting the mutations in the structured format. Let's discuss it next week. |
The PR to implement that in LAPIS is open: GenSpectrum/LAPIS#723 |
As GenSpectrum/LAPIS#723 is now merged I will modify loculus to use the processed mutation information instead of the mutation strings - afterwards we should be able to move forward with this feature :-) |
@anna-parker is it possible that this PR is now no longer relevant as you've already implemented mutation badges? |
@corneliusroemer true - I will close this then! Thanks @ivan-aksamentov for your work on this - I used it a lot in #1666 which has now been merged. |
preview URL: https://feat-mutation-badges.loculus.org/seq/LOC_000001Y.1
Summary
Add mutation badge React components for nuc and aa mutations.
This is a simplified version of what's there in Nextclade or Covariants. I had to port it from styled-components to tailwind.
Badge segments are colored dynamically, depending on a character or gene name. I use
style
attr to handle that.Additionally, the text is being rendered of light or dark color depending on the contrast ratio relative to background color. I had to add
polished
NPM package to calculate contrast ratio.Notes:
There is no fixed list of genes/CDSes avaialble, so it's not immediately possible to render stable (recognizable) gene/CDS colors, which may increase readablity of aa badges significantly. In Nextclade the list is provided from "backend" and then gene index in the list is used to select color from a fixed list of colors (with index wrap on overflow), and in Covariants the list is static, as it only deals with SC2. In both cases, color palette is taken from nextstrain.org "Nucleotide diversity of genome" panel, as something we are the most accustomed to in Nextstrain organization. In Loclulus I decided to use color hash algorithm to generate colors from gene name strings for now. If backend could provide this data, then UX could be further improved.
It seems that
DataTable.astro
is only able to render values that are strings or numbers. I don't immediately see how the badges can be incorporated there without hacks. I need a bit more details of what's planned for this component. So for now I just temporarily added some hardcoded badges above the table as a showcase.From a quick look, I found that backend currently provides mutations in string format, e.g.
A123G
. This means that these strings need to be parsed in order to extract gene, position, and ref and query characters. In Covariants this is done using regex like that. It's a bit of a hairy adventure though. So if backend could precompute and supply structured data that'd be great.I use exact values in tailwind classes, because these badge components don't fit well into the tailwind paradigm. These components should probably be extracted into some resusable NPM package with some configurable styling. And we'd share it across projects. Though the gene colors is an issue in this case.
Screenshot
With Dark Reader:
PR Checklist