Skip to content

Commit

Permalink
fixed filters, plots crash, mutations, selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Lai committed Oct 13, 2022
1 parent c2c5fe2 commit daf9f10
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 158 deletions.
8 changes: 0 additions & 8 deletions src/pages/groupComparison/GroupComparisonMutationMapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from 'shared/components/mutationMapper/MutationMapper';

interface IGroupComparisonMutationMapperProps extends IMutationMapperProps {
mutationData?: Mutation[] | undefined;
onInit?: (mutationMapper: GroupComparisonMutationMapper) => void;
}

Expand All @@ -21,18 +20,11 @@ class GroupComparisonMutationMapper extends MutationMapper<
> {
constructor(props: IGroupComparisonMutationMapperProps) {
super(props);

// makeObservable<GroupComparisonMutationMapper, 'geneWidth'>(this);
// makeObservable(this)
}

protected get mutationTableComponent() {
return null;
}

// protected get mutationPlot() {

// }
}

export default GroupComparisonMutationMapper;
49 changes: 42 additions & 7 deletions src/pages/groupComparison/GroupComparisonPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import {
} from 'shared/lib/customTabs/customTabHelpers';
import { getSortedGenericAssayTabSpecs } from 'shared/lib/GenericAssayUtils/GenericAssayCommonUtils';
import { HelpWidget } from 'shared/components/HelpWidget/HelpWidget';
import GroupComparisonMutationMapper from './GroupComparisonMutationMapper';
import Mutations from './Mutations';

export interface IGroupComparisonPageProps {
Expand Down Expand Up @@ -134,6 +133,7 @@ export default class GroupComparisonPage extends React.Component<
this.store.genericAssayEnrichmentProfilesGroupedByGenericAssayType,
this.store.mutations,
this.store.mutationsByGroup,
this.store.genes,
],
render: () => {
return (
Expand Down Expand Up @@ -227,6 +227,33 @@ export default class GroupComparisonPage extends React.Component<
: ''
}
>
<div style={{ width: 100, paddingBottom: 10 }}>
<ReactSelect
name="Select gene"
onChange={(option: any | null) => {
if (option) {
this.store.setSelectedMutationMapperGene(
option.value
);
}
}}
options={this.store.genes.result!.map(
gene => ({
label: gene.hugoGeneSymbol,
value: gene,
})
)}
value={{
label: this.store
.selectedMutationMapperGene
.hugoGeneSymbol,
value: this.store
.selectedMutationMapperGene,
}}
clearable={false}
searchable={true}
/>
</div>
<div>
<h3>
{_(this.store.mutationsByGroup.result!)
Expand All @@ -243,21 +270,25 @@ export default class GroupComparisonPage extends React.Component<
.flatten()
.value()}
filters={{
groupFilters: this.store.groupedSamples.map(
group => ({
group: group.name,
groupFilters: _(
this.store.mutationsByGroup.result!
)
.keys()
.value()
.map(group => ({
group: group,
filter: {
type:
'GroupComparisonFilter',
values: [group.name],
values: [group],
},
})
),
})),
filterAppliersOverride: {
['GroupComparisonFilter']: this
.store.applySampleIdFilter,
},
}}
gene={this.store.selectedMutationMapperGene}
/>
</div>

Expand All @@ -271,6 +302,10 @@ export default class GroupComparisonPage extends React.Component<
this.store.mutationsByGroup
.result![g.uid]
}
gene={
this.store
.selectedMutationMapperGene
}
/>
</div>
);
Expand Down
111 changes: 46 additions & 65 deletions src/pages/groupComparison/GroupComparisonStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
SampleMolecularIdentifier,
GenePanelDataMultipleStudyFilter,
Mutation,
Gene,
} from 'cbioportal-ts-api-client';
import { action, observable, makeObservable, computed } from 'mobx';
import client from '../../shared/api/cbioportalClientInstance';
Expand All @@ -37,11 +38,11 @@ import {
} from 'shared/api/session-service/sessionServiceModels';
import ComplexKeySet from 'shared/lib/complexKeyDataStructures/ComplexKeySet';
import { REQUEST_ARG_ENUM } from 'shared/constants';
import { Sample } from 'cbioportal-ts-api-client/src/generated/CBioPortalAPIInternal';
import { DataFilter } from 'react-mutation-mapper';

export default class GroupComparisonStore extends ComparisonStore {
@observable.ref private sessionId: string;
@observable private sessionId: string;
@observable private _selectedMutationMapperGene: string;

constructor(
sessionId: string,
Expand Down Expand Up @@ -337,11 +338,6 @@ export default class GroupComparisonStore extends ComparisonStore {
) {
return Promise.resolve([]);
}
// const genes = await client.fetchGenesUsingPOST({
// geneIdType: 'HUGO_GENE_SYMBOL',
// // geneIds: this.activeGroups.result!.map(g => g.name)
// geneIds: this.genes.result!
// });
const sampleMolecularIdentifiers = getSampleMolecularIdentifiers(
this.samples.result!,
this.mutationEnrichmentProfiles.result!
Expand All @@ -350,9 +346,10 @@ export default class GroupComparisonStore extends ComparisonStore {
{
projection: REQUEST_ARG_ENUM.PROJECTION_DETAILED,
mutationMultipleStudyFilter: {
entrezGeneIds: [7157],
entrezGeneIds: [
this.selectedMutationMapperGene.entrezGeneId,
],
sampleMolecularIdentifiers,
// molecularProfileIds: this.mutationEnrichmentProfiles.result?.map(p => p.molecularProfileId)
} as MutationMultipleStudyFilter,
}
);
Expand All @@ -361,20 +358,16 @@ export default class GroupComparisonStore extends ComparisonStore {
},
});

// {sampleId: group}
@computed get groupedSamples(): { name: string; samples: string[] }[] {
// const map = new Map<string, string[]>();
const samplesByGroup = [];
for (const groupData of this._session.result!.groups) {
// map.set(groupData.name, groupData.studies[0].samples)
samplesByGroup.push({
name: groupData.name,
samples: groupData.studies[0].samples,
});
}
// console.log(map)
return samplesByGroup;
}
// @computed get groupedSamples(): { name: string; samples: string[] }[] {
// const samplesByGroup = [];
// for (const groupData of this._session.result!.groups) {
// samplesByGroup.push({
// name: groupData.name,
// samples: groupData.studies[0].samples,
// });
// }
// return samplesByGroup;
// }

// @computed get mutationsByGene(): { [hugoGeneSymbol: string]: Mutation[] } | undefined {
// if (this.mutations.isComplete) {
Expand All @@ -389,57 +382,45 @@ export default class GroupComparisonStore extends ComparisonStore {
// }
// }

// public get genes() {
// return this._genes;
// }
// private readonly _genes = remoteData({
// await: () => [this.samples, this.mutationEnrichmentProfiles],
// invoke: async () => {
// const genes = await client.fetchGenesUsingPOST({
// geneIdType: 'HUGO_GENE_SYMBOL',
// geneIds: this.activeGroups.result!.map(g => g.name)
// });
// return genes.map(g => g.hugoGeneSymbol)
// // return genes
// }
// })
readonly genes = remoteData({
invoke: async () => {
const genes = await client.fetchGenesUsingPOST({
geneIdType: 'HUGO_GENE_SYMBOL',
geneIds: ['TP53', 'KRAS', 'NRAS'],
});
return genes;
},
});

// @computed get genes () {
// const genes = []
// genes.push(this.mutationsByGene!['KRAS'][0].gene)
// genes.push(this.mutationsByGene!['TP53'][0].gene)
// return genes;
// }
// @computed get hugoGeneSymbols() {
// return (
// _.keys(this.mutationsByGene)
// )
// // return (
// // _.keys(this.mutationsByGene)
// // )
// }
@computed get selectedMutationMapperGene() {
const gene =
this.genes.result!.find(
g => g.hugoGeneSymbol === this._selectedMutationMapperGene
) || this.genes.result![0];
if (!gene) {
debugger;
}
return gene;
}

// @computed get groupedMutationsByGene() {
// // return _.groupBy(
// // this.mutations.result,
// // (mutation: Mutation) => mutation.gene.hugoGeneSymbol
// // );
// return _.filter(
// this.mutations.result,
// (mutation: Mutation) => mutation.gene.hugoGeneSymbol in this.hugoGeneSymbols
// )
// }
@action.bound
public setSelectedMutationMapperGene(gene: Gene) {
this._selectedMutationMapperGene = gene.hugoGeneSymbol;
}

@autobind
public applySampleIdFilter(
filter: DataFilter<string>,
mutation: Mutation
): boolean {
const group = this.groupedSamples.find(
g => g.name === filter.values[0]
);
const group = _(this.mutationsByGroup.result!)
.keys()
.value()
.find(g => g === filter.values[0]);
if (group) {
return group.samples.includes(mutation.sampleId);
return this.mutationsByGroup.result![group].some(
m => m.sampleId === mutation.sampleId
);
} else {
return false;
}
Expand Down
Loading

0 comments on commit daf9f10

Please sign in to comment.