-
Notifications
You must be signed in to change notification settings - Fork 0
feat(website): resistance mutation sets as collections #1181
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
Open
fhennig
wants to merge
17
commits into
main
Choose a base branch
from
resistance-collections
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+182
−374
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e4c5318
feat(backend): add script to seed resistance mutation collections
fhennig 88f9d5a
initial implementation
fhennig e0de78c
feat(backend): support session token auth in resistance collections s…
fhennig 9a95528
feat(website): source resistance mutations from backend collections
fhennig a5115a6
refactor(website): simplify resistance mutation types and hook
fhennig 7ec3e98
chore(backend): remove resistance mutation collection seeding script
fhennig 1a13ad1
feat(website): resolve wasap config server-side to support staging ov…
fhennig 6f56af5
chore(website): remove resolved TODOs and set 1h stale time for resis…
fhennig c59d24f
fix(website): set correct prod resistance collection IDs (1, 2, 3)
fhennig 831288a
chore(website): update test fixture collection IDs to match prod (1, …
fhennig 45caf50
chore(website): remove parallel fetching TODO from WasapPage
fhennig 8ad8ec2
format
fhennig 2b50741
refactor(website): fetch resistance data server-side in Wasap.astro
fhennig a7d8212
fix typo
fhennig c396696
Potential fix for pull request finding
fhennig 98c8df8
fix log
fhennig 3ca2a5c
foo
fhennig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,34 @@ | ||
| --- | ||
| import { WasapPage } from './WasapPage'; | ||
| import { fetchResistanceData, type ResistanceData } from './resistanceData'; | ||
| import { BackendService } from '../../../backendApi/backendService.ts'; | ||
| import { isStaging, getBackendHost } from '../../../config.ts'; | ||
| import BaseLayout from '../../../layouts/base/BaseLayout.astro'; | ||
| import { wastewaterOrganismConfigs, type WastewaterOrganismName } from '../../../types/wastewaterConfig'; | ||
| import { getInstanceLogger } from '../../../logger.ts'; | ||
| import { | ||
| wastewaterOrganismConfigs, | ||
| wastewaterOrganismStagingConfigs, | ||
| type WastewaterOrganismName, | ||
| } from '../../../types/wastewaterConfig'; | ||
|
|
||
| type Props = { | ||
| wastewaterOrganism: WastewaterOrganismName; | ||
| }; | ||
|
|
||
| const { wastewaterOrganism } = Astro.props; | ||
| const { name } = wastewaterOrganismConfigs[wastewaterOrganism]; | ||
| const config = (isStaging() ? wastewaterOrganismStagingConfigs : wastewaterOrganismConfigs)[wastewaterOrganism]; | ||
| const backendService = new BackendService(getBackendHost()); | ||
| let resistanceData: ResistanceData = { mutationAnnotations: [], displayMutationsBySet: {} }; | ||
|
|
||
| try { | ||
| resistanceData = await fetchResistanceData(config, backendService); | ||
| } catch (error) { | ||
| getInstanceLogger('WasapPage').error( | ||
| `Failed to fetch resistance data for WASAP page (organism: ${wastewaterOrganism}): ${error}`, | ||
| ); | ||
|
Comment on lines
+25
to
+28
|
||
| } | ||
| --- | ||
|
|
||
| <BaseLayout title={`Swiss wastewater - ${name}`}> | ||
| <WasapPage wastewaterOrganism={wastewaterOrganism} client:only='react' /> | ||
| <BaseLayout title={`Swiss wastewater - ${config.name}`}> | ||
| <WasapPage config={config} resistanceData={resistanceData} client:only='react' /> | ||
| </BaseLayout> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's maybe add a simple unit test to test the mapping here? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import type { MutationAnnotations } from '@genspectrum/dashboard-components/util'; | ||
|
|
||
| import type { ResistanceMutationCollectionConfig, WasapPageConfig } from './wasapPageConfig'; | ||
| import type { BackendService } from '../../../backendApi/backendService'; | ||
| import type { Collection } from '../../../types/Collection'; | ||
|
|
||
| export type ResistanceData = { | ||
| /** Flat list of mutation annotations for the genome viewer. */ | ||
| mutationAnnotations: MutationAnnotations; | ||
| /** Map from set name (e.g. "3CLpro") to the genomic amino acid mutations to display. */ | ||
| displayMutationsBySet: Record<string, string[]>; | ||
| }; | ||
|
|
||
| export async function fetchResistanceData( | ||
| config: WasapPageConfig, | ||
| backendService: BackendService, | ||
| ): Promise<ResistanceData> { | ||
| if (!config.resistanceAnalysisModeEnabled) { | ||
| return { mutationAnnotations: [], displayMutationsBySet: {} }; | ||
| } | ||
| const collections = await Promise.all( | ||
| config.resistanceMutationCollections.map((setConfig) => | ||
| backendService.getCollection({ id: String(setConfig.collectionId) }), | ||
| ), | ||
| ); | ||
| return buildResistanceData(config.resistanceMutationCollections, collections); | ||
| } | ||
|
|
||
| function buildResistanceData( | ||
| setConfigs: ResistanceMutationCollectionConfig[], | ||
| collections: Collection[], | ||
| ): ResistanceData { | ||
| const mutationAnnotations: MutationAnnotations = []; | ||
| const displayMutationsBySet: Record<string, string[]> = {}; | ||
|
|
||
| setConfigs.forEach((setConfig, i) => { | ||
| const entries = collections[i].variants.flatMap((variant) => { | ||
| if (variant.type !== 'filterObject') return []; | ||
| return (variant.filterObject.aminoAcidMutations ?? []).map((aminoAcidMutation) => ({ | ||
| displayName: variant.name, | ||
| aminoAcidMutation, | ||
| })); | ||
| }); | ||
|
|
||
| displayMutationsBySet[setConfig.name] = entries.map((e) => e.aminoAcidMutation); | ||
|
|
||
| mutationAnnotations.push( | ||
| ...entries.map(({ displayName, aminoAcidMutation }) => ({ | ||
| name: displayName, | ||
| symbol: setConfig.annotationSymbol, | ||
| description: setConfig.description, | ||
| aminoAcidMutations: [aminoAcidMutation], | ||
| })), | ||
| ); | ||
| }); | ||
|
|
||
| return { mutationAnnotations, displayMutationsBySet }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI: If
fetchResistanceDatafails, the page renders with empty resistance data — the resistance mode dropdown will show zero options, but the user can still select the "resistance" tab and see an empty dropdown. Should we show some kind of user-facing warning in this case, or hide the resistance mode tab entirely when the data is unavailable?