Skip to content

Commit

Permalink
create new session for updated custom survival plots
Browse files Browse the repository at this point in the history
  • Loading branch information
qlu-cls committed May 17, 2024
1 parent 727f897 commit ca3c51d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 116 deletions.
74 changes: 32 additions & 42 deletions src/pages/groupComparison/Survival.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ export default class Survival extends React.Component<ISurvivalProps, {}> {
private differentDescriptionExistMessage =
'Different descriptions of survival data were used for different studies.';

// @observable
// private selectedSurvivalPlotPrefix: string | undefined = undefined;

@observable
private startEventPosition: 'FIRST' | 'LAST' = 'FIRST';

Expand Down Expand Up @@ -355,6 +352,37 @@ export default class Survival extends React.Component<ISurvivalProps, {}> {
this.selectedCensoredClinicalEventAttributes = [];
}

@action.bound
private onAddSurvivalPlot() {
this.props.store.addSurvivalRequest(
this._selectedStartClinicalEventType!,
this.startEventPosition,
this.selectedStartClinicalEventAttributes,
this._selectedEndClinicalEventType!,
this.endEventPosition,
this.selectedEndClinicalEventAttributes,
this._selectedCensoredClinicalEventType!,
this.censoredEventPosition,
this.selectedCensoredClinicalEventAttributes
);
this.setSurvivalPlotPrefix(
getSurvivalPlotPrefixText(
this._selectedStartClinicalEventType!,
this.startEventPosition,
this.selectedStartClinicalEventAttributes,
this._selectedEndClinicalEventType!,
this.endEventPosition,
this.selectedEndClinicalEventAttributes,
this._selectedCensoredClinicalEventType!,
this.censoredEventPosition,
this.selectedCensoredClinicalEventAttributes
)
);
this.props.store.updateCustomSurvivalPlots(
this.props.store.customSurvivalPlots
);
}

@computed get selectedCensoredClinicalEventType() {
if (this._selectedCensoredClinicalEventType !== undefined) {
if (this._selectedCensoredClinicalEventType === 'any') {
Expand Down Expand Up @@ -699,45 +727,7 @@ export default class Survival extends React.Component<ISurvivalProps, {}> {
disabled={
this.isAddSurvivalPlotDisabled
}
onClick={e => {
this.props.store.addSurvivalRequest(
this
._selectedStartClinicalEventType!,
this.startEventPosition,
this
.selectedStartClinicalEventAttributes,
this
._selectedEndClinicalEventType!,
this.endEventPosition,
this
.selectedEndClinicalEventAttributes,
this
._selectedCensoredClinicalEventType!,
this.censoredEventPosition,
this
.selectedCensoredClinicalEventAttributes
);
this.setSurvivalPlotPrefix(
getSurvivalPlotPrefixText(
this
._selectedStartClinicalEventType!,
this.startEventPosition,
this
.selectedStartClinicalEventAttributes,
this
._selectedEndClinicalEventType!,
this.endEventPosition,
this
.selectedEndClinicalEventAttributes,
this
._selectedCensoredClinicalEventType!,
this
.censoredEventPosition,
this
.selectedCensoredClinicalEventAttributes
)
);
}}
onClick={this.onAddSurvivalPlot}
>
Add survival plot
</button>
Expand Down
8 changes: 2 additions & 6 deletions src/shared/api/session-service/sessionServiceModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ClinicalTrackConfig,
GeneticTrackConfig,
} from 'shared/components/oncoprint/Oncoprint';
import { CustomSurvivalPlots } from 'shared/lib/comparison/ComparisonStoreUtils';
import { PageSettingsIdentifier } from 'shared/userSession/PageSettingsIdentifier';

export interface Session {
Expand Down Expand Up @@ -62,6 +63,7 @@ export type ComparisonSession = {
origin: string[];
clinicalAttributeName?: string;
groupNameOrder?: string[];
customSurvivalPlots?: CustomSurvivalPlots;
};

export type SessionGroupData = GroupData & {
Expand Down Expand Up @@ -109,12 +111,6 @@ export type ResultPageSettings = {
geneticlist?: GeneticTrackConfig[];
};

export type ComparisonPageSettings = {
[sessionId: string]: {
[prefix: string]: Partial<SurvivalRequest>;
};
};

export type PageSettingsData = StudyPageSettings | ResultPageSettings;

export type PageSettingsUpdateRequest = PageSettingsIdentifier &
Expand Down
91 changes: 24 additions & 67 deletions src/shared/lib/comparison/ComparisonStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import { getSurvivalStatusBoolean } from 'pages/resultsView/survival/SurvivalUti
import {
cnaEventTypeSelectInit,
CopyNumberEnrichmentEventType,
CustomSurvivalPlots,
EnrichmentEventType,
getCopyNumberEventTypesAPIParameter,
getMutationEventTypesAPIParameter,
Expand All @@ -109,7 +110,6 @@ import {
import { getServerConfig } from 'config/config';
import IComparisonURLWrapper from 'pages/groupComparison/IComparisonURLWrapper';
import {
ComparisonPageSettings,
ComparisonSession,
SessionGroupData,
} from 'shared/api/session-service/sessionServiceModels';
Expand Down Expand Up @@ -221,28 +221,10 @@ export default abstract class ComparisonStore extends AnalysisStore

this.reactionDisposers.push(
reaction(
() => toJS(this.customSurvivalPlots),
() => {
if (this.isSavingSessionPossible) {
this.updateChartSettings();
}
}
)
);

this.reactionDisposers.push(
reaction(
() => this.pageSettings.isComplete,
() => this.isSessionLoaded,
isComplete => {
//execute if user log in from study page
if (isComplete && this.isSavingSessionPossible) {
console.log(
'userSettings updated',
this.pageSettings.result
);
this.loadChartSettings();
// this.previousSettings = this.currentChartSettingsMap;
// this.loadChartSettings();
if (isComplete) {
this.loadCustomSurvivalCharts();
}
}
)
Expand Down Expand Up @@ -347,11 +329,6 @@ export default abstract class ComparisonStore extends AnalysisStore
return this._session.isComplete;
}

@computed get isSavingSessionPossible() {
return this.isSessionLoaded;
// return this.isLoggedIn && this.sessionServiceIsEnabled;
}

public async addGroup(group: SessionGroupData, saveToUser: boolean) {
this.newSessionPending = true;
if (saveToUser && this.isLoggedIn) {
Expand All @@ -371,6 +348,19 @@ export default abstract class ComparisonStore extends AnalysisStore
this.saveAndGoToSession(newSession);
}

public async updateCustomSurvivalPlots(
customSurvivalPlots: CustomSurvivalPlots
) {
const newSession = toJS(this._session.result!);
newSession.customSurvivalPlots = toJS(customSurvivalPlots);

if (this.isSessionLoaded) {
await comparisonClient.addComparisonSession(newSession);
}

this.saveAndGoToSession(newSession);
}

readonly origin = remoteData({
// the studies that the comparison groups come from
await: () => [this._session],
Expand Down Expand Up @@ -583,24 +573,6 @@ export default abstract class ComparisonStore extends AnalysisStore
},
});

readonly pageSettings = remoteData<ComparisonPageSettings | undefined>({
invoke: async () => {
if (this.isSavingSessionPossible) {
return JSON.parse(
localStorage.getItem('comparisonPageSettings') ?? '{}'
);
// return sessionServiceClient.fetchStudyPageSettings(
// toJS(this.studyIds)
// );
}
return undefined;
},
default: undefined,
onError: () => {
// fail silently when an error occurs
},
});

public readonly alterationEnrichmentProfiles = remoteData({
await: () => [this.molecularProfilesInActiveStudies],
invoke: () => {
Expand Down Expand Up @@ -789,9 +761,7 @@ export default abstract class ComparisonStore extends AnalysisStore
};
} = {};

@observable customSurvivalPlots: {
[prefix: string]: Partial<SurvivalRequest>;
} = {};
@observable customSurvivalPlots: CustomSurvivalPlots = {};

@observable customClinicalAttributes: ClinicalAttribute[] = [];

Expand Down Expand Up @@ -1206,12 +1176,14 @@ export default abstract class ComparisonStore extends AnalysisStore
this.customSurvivalPlots = _.omitBy(
toJS(this.customSurvivalPlots),
(value, key) => key === prefix
) as { [prefix: string]: Partial<SurvivalRequest> };
) as CustomSurvivalPlots;

this.customSurvivalDataPromises = _.omitBy(
toJS(this.customSurvivalDataPromises),
(value, key) => key === prefix
) as { [prefix: string]: MobxPromise<ClinicalData[]> };

this.updateCustomSurvivalPlots(toJS(this.customSurvivalPlots));
}
}

Expand Down Expand Up @@ -3403,10 +3375,9 @@ export default abstract class ComparisonStore extends AnalysisStore
}

@action.bound
private loadChartSettings(): void {
this.customSurvivalPlots = (this.pageSettings.result ?? {})[
this._session.result!.id
];
private loadCustomSurvivalCharts(): void {
this.customSurvivalPlots =
this._session.result!.customSurvivalPlots ?? {};

_.forEach(this.customSurvivalPlots, plot => {
this.addSurvivalRequest(
Expand All @@ -3428,18 +3399,4 @@ export default abstract class ComparisonStore extends AnalysisStore
);
});
}

@action.bound
private updateChartSettings(): void {
let pageSettings: ComparisonPageSettings =
this.pageSettings.result || {};
pageSettings[this._session.result!.id] = toJS(this.customSurvivalPlots);

localStorage.setItem(
'comparisonPageSettings',
JSON.stringify(pageSettings)
);

console.log('saving user settings', pageSettings);
}
}
6 changes: 5 additions & 1 deletion src/shared/lib/comparison/ComparisonStoreUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ComparisonStore, {
ClinicalEventDataWithKey,
} from 'shared/lib/comparison/ComparisonStore';
import { MolecularProfile } from 'cbioportal-ts-api-client';
import { MolecularProfile, SurvivalRequest } from 'cbioportal-ts-api-client';
import { stringListToMap } from 'cbioportal-frontend-commons';
import _ from 'lodash';

Expand Down Expand Up @@ -166,6 +166,10 @@ export const amplificationGroup = [CopyNumberEnrichmentEventType.AMP];
export const deletionGroup = [CopyNumberEnrichmentEventType.HOMDEL];
export const cnaGroup = [...amplificationGroup, ...deletionGroup];

export type CustomSurvivalPlots = {
[prefix: string]: Partial<SurvivalRequest>;
};

export function cnaEventTypeSelectInit(
profiles: MolecularProfile[]
): {
Expand Down

0 comments on commit ca3c51d

Please sign in to comment.