Skip to content

Commit

Permalink
oncoprint color config for mutations testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Lai committed Aug 18, 2023
1 parent 378093e commit 958fadc
Show file tree
Hide file tree
Showing 6 changed files with 455 additions and 24 deletions.
56 changes: 56 additions & 0 deletions src/pages/resultsView/ResultsViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ import {
ONCOKB_DEFAULT_INFO,
USE_DEFAULT_PUBLIC_INSTANCE_FOR_ONCOKB,
} from 'react-mutation-mapper';
import { RGBAColor } from 'oncoprintjs';

type Optional<T> =
| { isApplicable: true; value: T }
Expand Down Expand Up @@ -573,6 +574,15 @@ export class ResultsViewPageStore extends AnalysisStore

@observable queryFormVisible: boolean = false;

@observable userAlterationColors: {
[alteration: string]: string | undefined;
} = {};

private _selectedComparisonGroupsWarningSigns = observable.map<
string,
boolean
>({}, { deep: false });

@computed get doNonSelectedDownloadableMolecularProfilesExist() {
return (
this.nonSelectedDownloadableMolecularProfilesGroupByName.result &&
Expand All @@ -586,6 +596,52 @@ export class ResultsViewPageStore extends AnalysisStore
| ModifyQueryParams
| undefined = undefined;

@action.bound
public onAlterationColorChange(
alteration: string,
color: string | undefined
) {
if (color == undefined && this.userAlterationColors[alteration]) {
delete this.userAlterationColors[alteration];
} else this.userAlterationColors[alteration] = color;
}

@action public showAlterationWarningSign(
alteration: string,
markedValue: boolean
) {
this._selectedComparisonGroupsWarningSigns.set(alteration, markedValue);
}

public flagDuplicateColorsForAlterations(
alteration: string,
color: string | undefined
) {
let colors: { [color: string]: number } = {};

Object.keys(this.userAlterationColors).forEach(
(a: string, i: number) => {
let alterationColor =
a === alteration ? color : this.userAlterationColors[a];
if (
alterationColor == undefined ||
colors[alterationColor] == undefined
) {
if (alterationColor != undefined)
colors[alterationColor] = 1;
this.showAlterationWarningSign(alteration, false);
} else {
colors[alterationColor] = colors[alterationColor] + 1;
this.showAlterationWarningSign(alteration, true);
}
}
);
}

public isAlterationMarkedWithWarningSign(alteration: string): boolean {
return !!this._selectedComparisonGroupsWarningSigns.get(alteration);
}

@action.bound
public setOncoprintAnalysisCaseType(e: OncoprintAnalysisCaseType) {
this.urlWrapper.updateURL({
Expand Down
59 changes: 39 additions & 20 deletions src/shared/components/oncoprint/DeltaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
SortConfig,
TrackId,
UserTrackSpec,
IGeneticAlterationRuleSetParams,
} from 'oncoprintjs';
import _ from 'lodash';
import {
Expand Down Expand Up @@ -55,7 +56,8 @@ export function transition(
getTrackSpecKeyToTrackId: () => { [key: string]: TrackId },
getMolecularProfileMap: () =>
| { [molecularProfileId: string]: MolecularProfile }
| undefined
| undefined,
customRule?: IGeneticAlterationRuleSetParams
) {
const notKeepingSorted = shouldNotKeepSortedForTransition(
nextProps,
Expand Down Expand Up @@ -85,7 +87,8 @@ export function transition(
prevProps,
oncoprint,
getTrackSpecKeyToTrackId,
getMolecularProfileMap
getMolecularProfileMap,
customRule
);
transitionSortConfig(nextProps, prevProps, oncoprint);
transitionTrackGroupSortPriority(nextProps, prevProps, oncoprint);
Expand Down Expand Up @@ -582,7 +585,8 @@ function hasGeneticTrackRuleSetChanged(
prevProps.distinguishMutationType ||
nextProps.distinguishDrivers !== prevProps.distinguishDrivers ||
nextProps.distinguishGermlineMutations !==
prevProps.distinguishGermlineMutations
prevProps.distinguishGermlineMutations ||
nextProps.test !== prevProps.test
);
}

Expand All @@ -593,7 +597,8 @@ function transitionTracks(
getTrackSpecKeyToTrackId: () => { [key: string]: TrackId },
getMolecularProfileMap: () =>
| { [molecularProfileId: string]: MolecularProfile }
| undefined
| undefined,
customRule?: IGeneticAlterationRuleSetParams
) {
// Initialize tracks for rule set sharing
const trackIdForRuleSetSharing = {
Expand Down Expand Up @@ -735,7 +740,9 @@ function transitionTracks(
oncoprint,
nextProps,
prevProps,
trackIdForRuleSetSharing
trackIdForRuleSetSharing,
undefined,
customRule
);
delete prevGeneticTracks[track.key];
}
Expand All @@ -750,7 +757,9 @@ function transitionTracks(
oncoprint,
nextProps,
prevProps,
trackIdForRuleSetSharing
trackIdForRuleSetSharing,
undefined,
customRule
);
}
}
Expand Down Expand Up @@ -1088,20 +1097,29 @@ function transitionGeneticTrack(
nextProps: IOncoprintProps,
prevProps: Partial<IOncoprintProps>,
trackIdForRuleSetSharing: { genetic?: TrackId },
expansionParentKey?: string
expansionParentKey?: string,
customRule?: IGeneticAlterationRuleSetParams
) {
const trackSpecKeyToTrackId = getTrackSpecKeyToTrackId();
if (tryRemoveTrack(nextSpec, prevSpec, trackSpecKeyToTrackId, oncoprint)) {
// Remove track
return;
} else if (nextSpec && !prevSpec) {
let rule = customRule
? customRule
: getGeneticTrackRuleSetParams(
nextProps.distinguishMutationType,
nextProps.distinguishDrivers,
nextProps.distinguishGermlineMutations
);
console.log(rule);
// if (rule.rule_params.conditional.disp_mut.inframe) {
// console.log('hi')
// rule.rule_params.conditional.disp_mut.inframe.shapes[0].fill = [153, 52, 4, 1]
// }
// Add track
const geneticTrackParams: UserTrackSpec<any> = {
rule_set_params: getGeneticTrackRuleSetParams(
nextProps.distinguishMutationType,
nextProps.distinguishDrivers,
nextProps.distinguishGermlineMutations
),
rule_set_params: rule,
label: nextSpec.label,
sublabel: nextSpec.sublabel,
track_label_color: nextSpec.labelColor || undefined,
Expand Down Expand Up @@ -1197,15 +1215,16 @@ function transitionGeneticTrack(
trackId
);
} else {
let rule = customRule
? customRule
: getGeneticTrackRuleSetParams(
nextProps.distinguishMutationType,
nextProps.distinguishDrivers,
nextProps.distinguishGermlineMutations
);
console.log(rule);
// otherwise, update ruleset
oncoprint.setRuleSet(
trackId,
getGeneticTrackRuleSetParams(
nextProps.distinguishMutationType,
nextProps.distinguishDrivers,
nextProps.distinguishGermlineMutations
)
);
oncoprint.setRuleSet(trackId, rule);
}
}
// either way, use this one now
Expand Down
6 changes: 5 additions & 1 deletion src/shared/components/oncoprint/Oncoprint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TrackSortDirection,
InitParams,
ColumnLabel,
IGeneticAlterationRuleSetParams,
} from 'oncoprintjs';
import { GenePanelData, MolecularProfile } from 'cbioportal-ts-api-client';
import { observer } from 'mobx-react';
Expand Down Expand Up @@ -275,6 +276,8 @@ export interface IOncoprintProps {
alterationTypesInQuery?: string[];

distinguishMutationType?: boolean;
test?: boolean;
rule?: IGeneticAlterationRuleSetParams;
distinguishDrivers?: boolean;
distinguishGermlineMutations?: boolean;

Expand Down Expand Up @@ -386,7 +389,8 @@ export default class Oncoprint extends React.Component<IOncoprintProps, {}> {
() => this.trackSpecKeyToTrackId,
() => {
return this.props.molecularProfileIdToMolecularProfile;
}
},
this.props.rule
);
this.lastTransitionProps = _.clone(props);
}
Expand Down
81 changes: 80 additions & 1 deletion src/shared/components/oncoprint/ResultsViewOncoprint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { AlterationTypeConstants } from 'shared/constants';
import { ResultsViewPageStore } from '../../../pages/resultsView/ResultsViewPageStore';
import {
getAlteredUids,
getGeneticTrackRuleSetParams,
getUnalteredUids,
makeClinicalTracksMobxPromise,
makeGenericAssayProfileCategoricalTracksMobxPromise,
Expand All @@ -54,7 +55,13 @@ import _ from 'lodash';
import { onMobxPromise, toPromise } from 'cbioportal-frontend-commons';
import { getServerConfig } from 'config/config';
import LoadingIndicator from 'shared/components/loadingIndicator/LoadingIndicator';
import { OncoprintJS, TrackGroupIndex, TrackId } from 'oncoprintjs';
import {
IGeneticAlterationRuleSetParams,
OncoprintJS,
RGBAColor,
TrackGroupIndex,
TrackId,
} from 'oncoprintjs';
import fileDownload from 'react-file-download';
import tabularDownload from './tabularDownload';
import classNames from 'classnames';
Expand Down Expand Up @@ -89,6 +96,7 @@ import '../../../globalStyles/oncoprintStyles.scss';
import { GenericAssayTrackInfo } from 'pages/studyView/addChartButton/genericAssaySelection/GenericAssaySelection';
import { toDirectionString } from './SortUtils';
import { RestoreClinicalTracksMenu } from 'pages/resultsView/oncoprint/RestoreClinicalTracksMenu';
import { hexToRGBA } from 'shared/lib/Colors';

interface IResultsViewOncoprintProps {
divId: string;
Expand Down Expand Up @@ -253,6 +261,15 @@ export default class ResultsViewOncoprint extends React.Component<

@observable renderingComplete = false;

@observable
rule: IGeneticAlterationRuleSetParams = getGeneticTrackRuleSetParams(
this.distinguishMutationType,
this.distinguishDrivers,
this.distinguishGermlineMutations
);

@observable test: boolean = false;

private heatmapGeneInputValueUpdater: IReactionDisposer;

private molecularProfileIdToTrackGroupIndex: {
Expand Down Expand Up @@ -485,9 +502,15 @@ export default class ResultsViewOncoprint extends React.Component<
get sortByCaseListDisabled() {
return !self.caseListSortPossible;
},
get rule() {
return self.rule;
},
get distinguishMutationType() {
return self.distinguishMutationType;
},
get test() {
return self.test;
},
get distinguishDrivers() {
return self.distinguishDrivers;
},
Expand Down Expand Up @@ -705,6 +728,12 @@ export default class ResultsViewOncoprint extends React.Component<
onSelectDistinguishMutationType: (s: boolean) => {
this.distinguishMutationType = s;
},
onSelectTest: (s: boolean) => {
this.test = s;
},
onSetRule: (rule: IGeneticAlterationRuleSetParams) => {
this.rule = rule;
},
onSelectDistinguishDrivers: action((s: boolean) => {
if (!s) {
this.props.store.driverAnnotationSettings.oncoKb = false;
Expand Down Expand Up @@ -1690,6 +1719,7 @@ export default class ResultsViewOncoprint extends React.Component<
this
.selectedGenericAssayEntitiesGroupedByGenericAssayTypeFromUrl
}
setRules={this.setRules}
/>
</FadeInteraction>
);
Expand Down Expand Up @@ -1792,6 +1822,53 @@ export default class ResultsViewOncoprint extends React.Component<
return WindowStore.size.width - 75;
}

@action.bound
public setRules(alteration: string, color: RGBAColor | undefined) {
if (color == undefined) {
this.rule = getGeneticTrackRuleSetParams(
this.distinguishMutationType,
this.distinguishDrivers,
this.distinguishGermlineMutations
);
for (alteration in this.props.store.userAlterationColors) {
if (
this.props.store.userAlterationColors[alteration] !==
undefined
) {
this.rule.rule_params.conditional.disp_mut[
alteration
].shapes[0].fill = hexToRGBA(
this.props.store.userAlterationColors[alteration]!
);
}
}
} else {
// const rules = getGeneticTrackRuleSetParams(this.distinguishMutationType,
// this.distinguishDrivers,
// this.distinguishGermlineMutations
// );
// if (rules.rule_params.conditional.disp_mut.missense && this.test) {
// rules.rule_params.conditional.disp_mut.missense.shapes[0].fill = [0, 128, 0, 1]
// }
// else if (rules.rule_params.conditional.disp_mut.missense && !this.test) {
// rules.rule_params.conditional.disp_mut.missense.shapes[0].fill = [83, 212, 0, 1]
// }
if (this.rule.rule_params.conditional.disp_mut[alteration]) {
this.rule.rule_params.conditional.disp_mut[
alteration
].shapes[0].fill = color;
}
// else if (rules.rule_params.conditional.disp_mut['splice,missense,inframe,trunc,promoter,other'] && this.test) {
// rules.rule_params.conditional.disp_mut['splice,missense,inframe,trunc,promoter,other'].shapes[0].fill = [0, 128, 0, 1]
// }
// else if (rules.rule_params.conditional.disp_mut['splice,missense,inframe,trunc,promoter,other'] && !this.test) {
// rules.rule_params.conditional.disp_mut['splice,missense,inframe,trunc,promoter,other'].shapes[0].fill = [83, 212, 0, 1]
// }
// this.rule = rules;
}
console.log(this.rule);
}

public render() {
return (
<div style={{ position: 'relative' }}>
Expand Down Expand Up @@ -1892,6 +1969,7 @@ export default class ResultsViewOncoprint extends React.Component<
distinguishMutationType={
this.distinguishMutationType
}
test={this.test}
distinguishDrivers={this.distinguishDrivers}
distinguishGermlineMutations={
this.distinguishGermlineMutations
Expand All @@ -1915,6 +1993,7 @@ export default class ResultsViewOncoprint extends React.Component<
initParams={{
max_height: Number.POSITIVE_INFINITY,
}}
rule={this.rule}
/>
</div>
</div>
Expand Down
Loading

0 comments on commit 958fadc

Please sign in to comment.