Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/pages/studyView/StudyViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ import StudyViewURLWrapper from './StudyViewURLWrapper';
import { isMixedReferenceGenome } from 'shared/lib/referenceGenomeUtils';
import { Datalabel } from 'shared/lib/DataUtils';
import PromisePlus from 'shared/lib/PromisePlus';
import { getSuffixOfMolecularProfile } from 'shared/lib/molecularProfileUtils';
import {
getSingleSelectableProfileSuffixIfUnique,
getSuffixOfMolecularProfile,
} from 'shared/lib/molecularProfileUtils';
import {
createAlteredGeneComparisonSession,
doesChartHaveComparisonGroupsLimit,
Expand Down Expand Up @@ -10403,6 +10406,20 @@ export class StudyViewPageStore
.value();
}

if (
this.filteredVirtualStudies.result.length === 0 &&
this.studyIds.length === 1 &&
molecularProfileFilters.length === 0 &&
this.molecularProfiles.isComplete
) {
const singleSuffix = getSingleSelectableProfileSuffixIfUnique(
this.molecularProfiles.result
);
if (singleSuffix) {
molecularProfileFilters.push(singleSuffix);
}
}

if (molecularProfileFilters.length > 0) {
formOps.profileFilter = molecularProfileFilters.join(',');
}
Expand Down
88 changes: 86 additions & 2 deletions src/shared/components/query/QueryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ import {
ResultsViewURLQueryEnum,
} from 'pages/resultsView/ResultsViewURLWrapper';
import { isMixedReferenceGenome } from 'shared/lib/referenceGenomeUtils';
import { getSuffixOfMolecularProfile } from 'shared/lib/molecularProfileUtils';
import {
getSingleSelectableProfileSuffixIfUnique,
getSuffixOfMolecularProfile,
} from 'shared/lib/molecularProfileUtils';
import { VirtualStudy } from 'shared/api/session-service/sessionServiceModels';
import { isQueriedStudyAuthorized } from 'pages/studyView/StudyViewUtils';
import { toQueryString } from 'shared/lib/query/textQueryUtils';
Expand Down Expand Up @@ -465,6 +468,23 @@ export class QueryStore {
selectedIdSet = _.fromPairs(this.profileFilterSet.toJSON());
}
}
// #11569: default-select the only molecular profile when nothing else
// matched (e.g. RNA-only studies). Only when selection is still empty so we
// do not override mutation/CNA/SV defaults in mixed cohorts (see PR #5462).
if (
this.validProfileIdSetForSelectedStudies.isComplete &&
_.isEmpty(selectedIdSet) &&
_.isEmpty(this.profileFilterSetFromUrl) &&
_.isEmpty(this.profileIdsFromUrl)
) {
const singleSuffix = getSingleSelectableProfileSuffixIfUnique(
this.molecularProfilesInSelectedStudies.result || [],
{ forDownloadTab: this.forDownloadTab }
);
if (singleSuffix) {
selectedIdSet[singleSuffix] = true;
}
}
return selectedIdSet;
}

Expand Down Expand Up @@ -1091,6 +1111,13 @@ export class QueryStore {
this.studiesHaveChangedSinceInitialization
) {
this.profileFilterSet = undefined;

// Keep default auto-selection in the load lifecycle so UI
// reflects the checked profile immediately after profiles load.
const defaultProfile = this.defaultProfileToSelect;
if (defaultProfile) {
this.selectMolecularProfile(defaultProfile, true);
}
}
},
});
Expand Down Expand Up @@ -1795,6 +1822,60 @@ export class QueryStore {
);
}

@computed get shouldSelectDefaultProfile() {
if (Object.keys(this.selectedProfileIdSet).length > 0) {
return false;
}
if (
!_.isEmpty(this.profileFilterSetFromUrl) ||
!_.isEmpty(this.profileIdsFromUrl)
) {
return false;
}

let profileTypeCount = 0;
Object.values(AlterationTypeConstants).forEach(profileType => {
if (
this.getFilteredProfiles(
profileType as MolecularProfile['molecularAlterationType']
).length > 0
) {
profileTypeCount++;
}
});

if (profileTypeCount === 1) {
return true;
}

const hasMutationProfile =
this.getFilteredProfiles(
AlterationTypeConstants.MUTATION_EXTENDED as MolecularProfile['molecularAlterationType']
).length > 0;
const hasMrnaProfile =
this.getFilteredProfiles(
AlterationTypeConstants.MRNA_EXPRESSION as MolecularProfile['molecularAlterationType']
).length > 0;

return !hasMutationProfile && hasMrnaProfile;
}

@computed get defaultProfileToSelect() {
if (!this.shouldSelectDefaultProfile) {
return undefined;
}

for (const profileType of Object.values(AlterationTypeConstants)) {
const profiles = this.getFilteredProfiles(
profileType as MolecularProfile['molecularAlterationType']
);
if (profiles.length > 0) {
return profiles[0];
}
}
return undefined;
}

// SAMPLE LIST

@computed get defaultSelectedSampleListId() {
Expand Down Expand Up @@ -2255,14 +2336,17 @@ export class QueryStore {
);

this.profileIdsFromUrl = _.compact(profileIds);
this.profileFilterSetFromUrl = undefined;
this.zScoreThreshold = params.Z_SCORE_THRESHOLD || '2.0';
this.rppaScoreThreshold = params.RPPA_SCORE_THRESHOLD || '2.0';
if (params.data_priority) {
this.dataTypePriorityFromUrl = params.data_priority;
}
if (params.profileFilter) {
if (isNaN(parseInt(params.profileFilter, 10))) {
this.profileFilterSetFromUrl = params.profileFilter.split(',');
this.profileFilterSetFromUrl = _.compact(
params.profileFilter.split(',')
);
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/shared/lib/getDefaultMolecularProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ export function getFilteredMolecularProfiles(
);
}
}
// get rid of any undefined items
if (_.compact(defaultProfiles).length === 0) {
const selectable = profiles.filter(p => p.showProfileInAnalysisTab);
if (selectable.length === 1) {
defaultProfiles = [selectable[0]];
}
}
return _.compact(defaultProfiles);
}
82 changes: 81 additions & 1 deletion src/shared/lib/molecularProfileUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { assert } from 'chai';
import { MolecularProfile } from 'cbioportal-ts-api-client';
import { getSuffixOfMolecularProfile } from './molecularProfileUtils';
import {
getSingleSelectableProfileSuffixIfUnique,
getSuffixOfMolecularProfile,
} from './molecularProfileUtils';
import { getFilteredMolecularProfiles } from './getDefaultMolecularProfiles';
import { AlterationTypeConstants } from 'shared/constants';

describe('MolecularProfileUtils', () => {
describe('getSuffixOfMolecularProfile', () => {
Expand All @@ -14,4 +19,79 @@ describe('MolecularProfileUtils', () => {
assert.equal(result, suffix);
});
});

describe('getSingleSelectableProfileSuffixIfUnique', () => {
it('returns suffix when exactly one showProfileInAnalysisTab profile', () => {
const profiles = [
{
studyId: 's1',
molecularProfileId: 's1_rna_geo',
molecularAlterationType: 'MRNA_EXPRESSION',
showProfileInAnalysisTab: true,
},
] as MolecularProfile[];
assert.equal(
getSingleSelectableProfileSuffixIfUnique(profiles),
'rna_geo'
);
});

it('returns undefined when two distinct suffixes exist', () => {
const profiles = [
{
studyId: 's1',
molecularProfileId: 's1_mutations',
molecularAlterationType: 'MUTATION_EXTENDED',
showProfileInAnalysisTab: true,
},
{
studyId: 's1',
molecularProfileId: 's1_gistic',
molecularAlterationType: 'COPY_NUMBER_ALTERATION',
showProfileInAnalysisTab: true,
},
] as MolecularProfile[];
assert.isUndefined(
getSingleSelectableProfileSuffixIfUnique(profiles)
);
});

it('returns one suffix when two studies share the same suffix', () => {
const profiles = [
{
studyId: 'a',
molecularProfileId: 'a_mutations',
molecularAlterationType: 'MUTATION_EXTENDED',
showProfileInAnalysisTab: true,
},
{
studyId: 'b',
molecularProfileId: 'b_mutations',
molecularAlterationType: 'MUTATION_EXTENDED',
showProfileInAnalysisTab: true,
},
] as MolecularProfile[];
assert.equal(
getSingleSelectableProfileSuffixIfUnique(profiles),
'mutations'
);
});
});

describe('getFilteredMolecularProfiles single-profile fallback', () => {
it('selects the only RNA profile when mutation/CNA defaults are empty', () => {
const profiles = [
{
studyId: 'g',
molecularProfileId: 'g_geo_mx',
molecularAlterationType:
AlterationTypeConstants.MRNA_EXPRESSION,
showProfileInAnalysisTab: true,
},
] as MolecularProfile[];
const out = getFilteredMolecularProfiles(profiles, undefined, 0);
assert.equal(out.length, 1);
assert.equal(out[0]!.molecularProfileId, 'g_geo_mx');
});
});
});
26 changes: 26 additions & 0 deletions src/shared/lib/molecularProfileUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
import { MolecularProfile } from 'cbioportal-ts-api-client';
import _ from 'lodash';

export function getSuffixOfMolecularProfile(profile: MolecularProfile) {
return profile.molecularProfileId.replace(profile.studyId + '_', '');
}

/**
* When the cohort exposes exactly one selectable analysis profile (one suffix),
* return that suffix so the query UI can default-check it. Covers RNA-only and
* other single-profile studies (#11569). Multiple studies sharing the same
* suffix still count as one checkbox column — one suffix is returned.
*/
export function getSingleSelectableProfileSuffixIfUnique(
profiles: MolecularProfile[],
options?: { forDownloadTab?: boolean }
): string | undefined {
if (!profiles?.length) {
return undefined;
}
const forDownloadTab = options?.forDownloadTab ?? false;
const selectable = profiles.filter(
p => p.showProfileInAnalysisTab || forDownloadTab
);
if (!selectable.length) {
return undefined;
}
const bySuffix = _.groupBy(selectable, p => getSuffixOfMolecularProfile(p));
const suffixes = Object.keys(bySuffix);
return suffixes.length === 1 ? suffixes[0] : undefined;
}