@@ -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 ,
0 commit comments