Skip to content

Commit

Permalink
Merge pull request #4432 from gblaih/group-comparison-lollipop-plot-f…
Browse files Browse the repository at this point in the history
…requency

Fix incorrect mutation frequency in group comparison lollipop plot
  • Loading branch information
alisman authored Dec 1, 2022
2 parents c22a1c9 + feb28f4 commit c6a9550
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ class DefaultMutationMapperStore<T extends Mutation>
return this.groupedMutationsByPosition.map(groupedMutations => ({
group: groupedMutations.group,
counts: this.countUniqueMutationsByPosition(
groupedMutations.mutations
groupedMutations.mutations,
groupedMutations.group
),
}));
}
Expand All @@ -393,24 +394,27 @@ class DefaultMutationMapperStore<T extends Mutation>
);
}

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 => {
const position = parseInt(pos, 10);
// 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
Expand Down
12 changes: 8 additions & 4 deletions src/pages/groupComparison/GroupComparisonMutationsTabPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 (
Expand Down
61 changes: 41 additions & 20 deletions src/pages/groupComparison/GroupComparisonStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down
9 changes: 6 additions & 3 deletions src/shared/components/mutationMapper/MutationMapperStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface IMutationMapperStoreConfig {
group: string;
filter: DataFilter<any>;
}[];
countUniqueMutations?: (mutations: Mutation[]) => number;
countUniqueMutations?: (mutations: Mutation[], group?: string) => number;
}

export default class MutationMapperStore extends DefaultMutationMapperStore<
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit c6a9550

Please sign in to comment.