Skip to content

Commit

Permalink
add color config for all alterations
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Lai committed Aug 18, 2023
1 parent 958fadc commit c3551be
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 170 deletions.
85 changes: 53 additions & 32 deletions src/pages/resultsView/ResultsViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ import {
ONCOKB_DEFAULT_INFO,
USE_DEFAULT_PUBLIC_INSTANCE_FOR_ONCOKB,
} from 'react-mutation-mapper';
import { RGBAColor } from 'oncoprintjs';
import { IGeneticAlterationRuleSetParams, RGBAColor } from 'oncoprintjs';

type Optional<T> =
| { isApplicable: true; value: T }
Expand Down Expand Up @@ -575,7 +575,9 @@ export class ResultsViewPageStore extends AnalysisStore
@observable queryFormVisible: boolean = false;

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

private _selectedComparisonGroupsWarningSigns = observable.map<
Expand All @@ -599,45 +601,64 @@ export class ResultsViewPageStore extends AnalysisStore
@action.bound
public onAlterationColorChange(
alteration: string,
color: string | undefined
type: string,
color: RGBAColor
) {
if (color == undefined && this.userAlterationColors[alteration]) {
delete this.userAlterationColors[alteration];
} else this.userAlterationColors[alteration] = color;
this.userAlterationColors[alteration][type] = color;
}

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

public flagDuplicateColorsForAlterations(
alteration: string,
color: string | undefined
@action.bound
public setDefaultUserAlterationColors(
rule: IGeneticAlterationRuleSetParams
) {
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);
for (let alteration in rule.rule_params.conditional) {
this.userAlterationColors[alteration] = {};
for (let type in rule.rule_params.conditional[alteration]) {
if (alteration === 'disp_mrna') {
this.userAlterationColors[alteration][type] = rule
.rule_params.conditional[alteration][type].shapes[0]
.stroke as RGBAColor;
} else {
colors[alterationColor] = colors[alterationColor] + 1;
this.showAlterationWarningSign(alteration, true);
this.userAlterationColors[alteration][type] = rule
.rule_params.conditional[alteration][type].shapes[0]
.fill as RGBAColor;
}
}
);
}
}

// @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);
}
Expand Down
81 changes: 48 additions & 33 deletions src/shared/components/oncoprint/ResultsViewOncoprint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ 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 @@ -423,6 +422,7 @@ export default class ResultsViewOncoprint extends React.Component<
super(props);

makeObservable(this);
this.props.store.setDefaultUserAlterationColors(this.rule);
this.showOqlInLabels = props.store.queryContainsOql;
(window as any).resultsViewOncoprint = this;

Expand Down Expand Up @@ -1823,50 +1823,65 @@ export default class ResultsViewOncoprint extends React.Component<
}

@action.bound
public setRules(alteration: string, color: RGBAColor | undefined) {
public setRules(
alteration: string,
type: 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]!
);
for (let a in this.props.store.userAlterationColors) {
for (let t in this.props.store.userAlterationColors[a]) {
if (a === 'disp_mrna') {
if (a !== alteration && t !== type) {
this.rule.rule_params.conditional[a][
t
].shapes[0].stroke = this.props.store.userAlterationColors[
a
][t];
} else {
this.props.store.onAlterationColorChange(
alteration,
type,
this.rule.rule_params.conditional[a][t]
.shapes[0].stroke as RGBAColor
);
}
} else {
if (a !== alteration || t !== type) {
this.rule.rule_params.conditional[a][
t
].shapes[0].fill = this.props.store.userAlterationColors[
a
][t];
} else {
this.props.store.onAlterationColorChange(
alteration,
type,
this.rule.rule_params.conditional[a][t]
.shapes[0].fill as RGBAColor
);
}
}
}
}
} 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
if (alteration === 'disp_mrna') {
this.rule.rule_params.conditional[alteration][
type
].shapes[0].stroke = color;
} else {
this.rule.rule_params.conditional[alteration][
type
].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;
this.props.store.onAlterationColorChange(alteration, type, color);
}
console.log(this.rule);
// console.log(this.rule);
}

public render() {
Expand Down
Loading

0 comments on commit c3551be

Please sign in to comment.