Skip to content

Commit e0d965a

Browse files
committed
It works but review needed
1 parent 130c98c commit e0d965a

File tree

3 files changed

+160
-5
lines changed

3 files changed

+160
-5
lines changed

src/pages/studyView/StudyViewPageStore.ts

Lines changed: 131 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ import {
186186
transformSampleDataToSelectedSampleClinicalData,
187187
updateCustomIntervalFilter,
188188
invokeGenomicDataCount,
189+
invokeGenomicDataCountIncludeSampleid,
189190
invokeMutationDataCount,
190191
invokeNamespaceDataCount,
191192
invokeGenericAssayDataCount,
@@ -1635,6 +1636,128 @@ export class StudyViewPageStore
16351636
});
16361637
}
16371638

1639+
private createGeneSpecificComparisonSession(
1640+
chartMeta: ChartMeta,
1641+
clinicalAttributeValues: ClinicalDataCountSummary[],
1642+
statusCallback: (phase: LoadingPhase) => void
1643+
): Promise<string> {
1644+
statusCallback(LoadingPhase.DOWNLOADING_GROUPS);
1645+
1646+
// will come back to this
1647+
const promises: any = [this.selectedSamples];
1648+
1649+
return new Promise<string>(resolve => {
1650+
onMobxPromise<any>(
1651+
promises,
1652+
async (
1653+
selectedSamples: Sample[] // do we need to await this because the backend produces the sample set
1654+
) => {
1655+
const chartInfo = this._geneSpecificChartMap.get(
1656+
chartMeta.uniqueKey
1657+
);
1658+
// TODO: Replace `any` with GenomicDataCountItem[]
1659+
let data: any[] = [];
1660+
// take a look at this function invokeGenomicDataCount() inStudyViewUtils
1661+
1662+
if (!chartInfo || !this.hasFilteredSamples) {
1663+
return;
1664+
}
1665+
//TODO change the method name to something more generic
1666+
data = await invokeGenomicDataCountIncludeSampleid(
1667+
chartInfo,
1668+
this.filters,
1669+
true
1670+
);
1671+
1672+
const SKIP_VALUES = new Set(['NOT_PROFILED']);
1673+
const NON_MUTATION_VALUES = new Set(['NOT_MUTATED']);
1674+
1675+
// flat extrat all the counts
1676+
const allCounts = _.chain(data)
1677+
.flatMap(item => item.counts ?? [])
1678+
.value();
1679+
1680+
const grouped = new Map<string, Set<string>>();
1681+
const lcValueToColor = _.keyBy(clinicalAttributeValues, d =>
1682+
d.value.toLowerCase()
1683+
);
1684+
1685+
// group them into mutated, not_mutated, not_profiled
1686+
for (const count of allCounts) {
1687+
const sampleIds: string[] = count.sampleIds ?? [];
1688+
if (
1689+
sampleIds.length === 0 ||
1690+
SKIP_VALUES.has(count.value)
1691+
)
1692+
continue; // case of no samples
1693+
1694+
const key = NON_MUTATION_VALUES.has(count.value)
1695+
? count.value
1696+
: 'MUTATED';
1697+
1698+
if (!grouped.has(key)) {
1699+
grouped.set(key, new Set());
1700+
}
1701+
1702+
const sampleIdSet = grouped.get(key)!;
1703+
for (const rawId of sampleIds) {
1704+
const id = rawId.substring(
1705+
rawId.lastIndexOf('_') + 1
1706+
);
1707+
sampleIdSet.add(id);
1708+
}
1709+
}
1710+
1711+
const groups: SessionGroupData[] = _.chain(
1712+
clinicalAttributeValues
1713+
)
1714+
.map(attrVal => {
1715+
const groupName = attrVal.value;
1716+
const sampleIdSet = grouped.get(groupName);
1717+
1718+
if (!sampleIdSet || sampleIdSet.size === 0) {
1719+
return null;
1720+
}
1721+
1722+
const sampleIdentifiers: SampleIdentifier[] = Array.from(
1723+
sampleIdSet
1724+
).map(id => ({
1725+
sampleId: id,
1726+
studyId: this.studyIds[0],
1727+
}));
1728+
const lcValue = attrVal.value.toLowerCase();
1729+
1730+
return getGroupParameters(
1731+
groupName,
1732+
sampleIdentifiers,
1733+
this.studyIds,
1734+
lcValueToColor[lcValue].color
1735+
);
1736+
})
1737+
.filter((g): g is SessionGroupData => g !== null)
1738+
.slice(
1739+
// not sure if this slice works for all charts
1740+
0,
1741+
doesChartHaveComparisonGroupsLimit(chartMeta)
1742+
? MAX_GROUPS_IN_SESSION
1743+
: undefined
1744+
)
1745+
.value();
1746+
1747+
statusCallback(LoadingPhase.CREATING_SESSION);
1748+
1749+
// create session and get id
1750+
const { id } = await comparisonClient.addComparisonSession({
1751+
groups,
1752+
clinicalAttributeName: chartMeta.displayName, // NOT SURE WHAT TO PASS HERE
1753+
origin: this.studyIds,
1754+
});
1755+
return resolve(id);
1756+
}
1757+
);
1758+
});
1759+
}
1760+
16381761
private createCnaGeneComparisonSession(
16391762
chartMeta: ChartMeta,
16401763
hugoGeneSymbols: string[],
@@ -2072,12 +2195,17 @@ export class StudyViewPageStore
20722195
const chartInfo = this._geneSpecificChartMap.get(
20732196
chartMeta.uniqueKey
20742197
)!;
2075-
2076-
comparisonId = await this.createCnaGeneComparisonSession(
2198+
comparisonId = await this.createGeneSpecificComparisonSession(
20772199
chartMeta,
2078-
[chartInfo.hugoGeneSymbol],
2200+
params.clinicalAttributeValues!,
20792201
statusCallback
20802202
);
2203+
2204+
// comparisonId = await this.createCnaGeneComparisonSession(
2205+
// chartMeta,
2206+
// [chartInfo.hugoGeneSymbol],
2207+
// statusCallback
2208+
// );
20812209
} else {
20822210
comparisonId = await this.createCategoricalAttributeComparisonSession(
20832211
chartMeta,

src/pages/studyView/StudyViewUtils.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ import { MultiSelectionTableRow } from './table/MultiSelectionTable';
125125
import Survival from 'pages/groupComparison/Survival';
126126
import { StructVarMultiSelectionTableRow } from './table/StructuralVariantMultiSelectionTable';
127127
import { ObservableMap } from 'mobx';
128+
import { boolean } from 'yargs';
128129

129130
// Cannot use ClinicalDataTypeEnum here for the strong type. The model in the type is not strongly typed
130131
export enum ClinicalDataTypeEnum {
@@ -4252,6 +4253,33 @@ export async function invokeGenericAssayDataCount(
42524253
return undefined;
42534254
}
42544255

4256+
export async function invokeGenomicDataCountIncludeSampleid(
4257+
chartInfo: GenomicChart,
4258+
filters: StudyViewFilter,
4259+
includeSampleIds: boolean
4260+
) {
4261+
let result = [];
4262+
let params = {
4263+
genomicDataCountFilter: {
4264+
genomicDataFilters: [
4265+
{
4266+
hugoGeneSymbol: chartInfo.hugoGeneSymbol,
4267+
profileType: chartInfo.profileType,
4268+
} as GenomicDataFilter,
4269+
],
4270+
studyViewFilter: filters,
4271+
},
4272+
$queryParameters: {
4273+
projection: 'DETAILED',
4274+
includeSampleIds,
4275+
},
4276+
} as any;
4277+
4278+
result = await getInternalClient().fetchMutationDataCountsUsingPOST(params);
4279+
4280+
return result;
4281+
}
4282+
42554283
export async function invokeGenomicDataCount(
42564284
chartInfo: GenomicChart,
42574285
filters: StudyViewFilter

src/pages/studyView/charts/ChartContainer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,7 @@ export class ChartContainer extends React.Component<IChartContainerProps, {}> {
406406
(this.props.promise.result.treatments ??
407407
this.props.promise.result.patientTreatments ??
408408
this.props.promise.result)!.length > 1 &&
409-
COMPARISON_CHART_TYPES.indexOf(this.props.chartType) > -1 &&
410-
!this.props.chartMeta.mutationOptionType
409+
COMPARISON_CHART_TYPES.indexOf(this.props.chartType) > -1
411410
);
412411
}
413412

0 commit comments

Comments
 (0)