diff --git a/packages/react-mutation-mapper/src/store/DefaultMutationMapperStore.ts b/packages/react-mutation-mapper/src/store/DefaultMutationMapperStore.ts index c28417c091d..9bed7b745dd 100644 --- a/packages/react-mutation-mapper/src/store/DefaultMutationMapperStore.ts +++ b/packages/react-mutation-mapper/src/store/DefaultMutationMapperStore.ts @@ -378,7 +378,8 @@ class DefaultMutationMapperStore return this.groupedMutationsByPosition.map(groupedMutations => ({ group: groupedMutations.group, counts: this.countUniqueMutationsByPosition( - groupedMutations.mutations + groupedMutations.mutations, + groupedMutations.group ), })); } @@ -393,9 +394,12 @@ class DefaultMutationMapperStore ); } - public countUniqueMutationsByPosition(mutationsByPosition: { - [pos: number]: T[]; - }): { [pos: number]: number } { + public countUniqueMutationsByPosition( + mutationsByPosition: { + [pos: number]: T[]; + }, + group?: string + ): { [pos: number]: number } { const map: { [pos: number]: number } = {}; Object.keys(mutationsByPosition).forEach(pos => { @@ -403,14 +407,14 @@ class DefaultMutationMapperStore // for each position multiple mutations for the same patient is counted only once const mutations = mutationsByPosition[position]; if (mutations) { - map[position] = this.countUniqueMutations(mutations); + map[position] = this.countUniqueMutations(mutations, group); } }); return map; } - public countUniqueMutations(mutations: T[]): number { + public countUniqueMutations(mutations: T[], group?: string): number { // assume by default all mutations are unique // child classes need to override this method to have a custom way of counting unique mutations return this.config.getMutationCount diff --git a/src/pages/groupComparison/GroupComparisonMutationsTabPlot.tsx b/src/pages/groupComparison/GroupComparisonMutationsTabPlot.tsx index a37aa5ab560..5bd84effa90 100644 --- a/src/pages/groupComparison/GroupComparisonMutationsTabPlot.tsx +++ b/src/pages/groupComparison/GroupComparisonMutationsTabPlot.tsx @@ -68,16 +68,20 @@ export default class GroupComparisonMutationsTabPlot extends React.Component< @computed get mutationMapperToolStore() { const store = new MutationMapperToolStore(this.props.mutations, { ...this.props.filters, - countUniqueMutations: this.countUniqueMutations, + countUniqueMutations: this.countUniqueMutationsInGroup, }); return store; } @autobind - protected countUniqueMutations(mutations: Mutation[]) { + protected countUniqueMutationsInGroup( + mutations: Mutation[], + group: string + ) { return this.axisMode === AxisScale.PERCENT ? (countUniqueMutations(mutations) / - this.props.store.profiledSamplesCount.result!) * + this.props.store.groupToProfiledSamples.result![group] + .length) * 100 : countUniqueMutations(mutations); } @@ -91,9 +95,9 @@ export default class GroupComparisonMutationsTabPlot extends React.Component< await: () => [ this.props.store.mutations, this.props.store.mutationsByGroup, - this.props.store.profiledSamplesCount, this.mutationMapperToolStore.mutationMapperStores, this.props.store.coverageInformation, + this.props.store.groupToProfiledSamples, ], render: () => { if ( diff --git a/src/pages/groupComparison/GroupComparisonStore.ts b/src/pages/groupComparison/GroupComparisonStore.ts index aa2ff61995f..cbfa0acc2fc 100644 --- a/src/pages/groupComparison/GroupComparisonStore.ts +++ b/src/pages/groupComparison/GroupComparisonStore.ts @@ -15,6 +15,7 @@ import { Mutation, Gene, GenePanelData, + Sample, } from 'cbioportal-ts-api-client'; import { action, observable, makeObservable, computed } from 'mobx'; import client from '../../shared/api/cbioportalClientInstance'; @@ -321,6 +322,46 @@ export default class GroupComparisonStore extends ComparisonStore { }, }); + public readonly groupToProfiledSamples = remoteData({ + await: () => [ + this._originalGroups, + this.sampleMap, + this.mutationEnrichmentProfiles, + this.coverageInformation, + ], + invoke: () => { + const sampleSet = this.sampleMap.result!; + const groups = this._originalGroups.result!; + const ret: { + [groupUid: string]: Sample[]; + } = {}; + for (const group of groups) { + for (const studyObject of group.studies) { + const studyId = studyObject.id; + for (const sampleId of studyObject.samples) { + const sample = sampleSet.get({ sampleId, studyId }); + if ( + sample && + this.mutationEnrichmentProfiles.result!.some(p => + isSampleProfiled( + sample.uniqueSampleKey, + p.molecularProfileId, + this.activeMutationMapperGene! + .hugoGeneSymbol, + this.coverageInformation.result! + ) + ) + ) { + ret[group.name] = ret[group.name] || []; + ret[group.name].push(sample); + } + } + } + } + return Promise.resolve(ret); + }, + }); + readonly mutations = remoteData({ await: () => [this.samples, this.mutationEnrichmentProfiles], invoke: async () => { @@ -343,26 +384,6 @@ export default class GroupComparisonStore extends ComparisonStore { }, }); - readonly profiledSamplesCount = remoteData({ - await: () => [ - this.samples, - this.coverageInformation, - this.mutationEnrichmentProfiles, - ], - invoke: async () => { - return this.samples.result!.filter(s => - this.mutationEnrichmentProfiles.result!.some(p => - isSampleProfiled( - s.uniqueSampleKey, - p.molecularProfileId, - this.activeMutationMapperGene!.hugoGeneSymbol, - this.coverageInformation.result! - ) - ) - ).length; - }, - }); - readonly allSamples = remoteData({ await: () => [this._session], invoke: async () => { diff --git a/src/shared/components/mutationMapper/MutationMapperStore.ts b/src/shared/components/mutationMapper/MutationMapperStore.ts index deeed0a44ac..542e08a02a7 100644 --- a/src/shared/components/mutationMapper/MutationMapperStore.ts +++ b/src/shared/components/mutationMapper/MutationMapperStore.ts @@ -64,7 +64,7 @@ export interface IMutationMapperStoreConfig { group: string; filter: DataFilter; }[]; - countUniqueMutations?: (mutations: Mutation[]) => number; + countUniqueMutations?: (mutations: Mutation[], group?: string) => number; } export default class MutationMapperStore extends DefaultMutationMapperStore< @@ -207,9 +207,12 @@ export default class MutationMapperStore extends DefaultMutationMapperStore< return buildNamespaceColumnConfig(this.mutationData.result); } - public countUniqueMutations(mutations: Mutation[]): number { + public countUniqueMutations(mutations: Mutation[], group?: string): number { return this.mutationMapperStoreConfig.countUniqueMutations - ? this.mutationMapperStoreConfig.countUniqueMutations(mutations) + ? this.mutationMapperStoreConfig.countUniqueMutations( + mutations, + group + ) : countUniqueMutations(mutations); }