Skip to content

Commit

Permalink
Merge pull request #2093 from broadinstitute/jb-subsample-cell-fillte…
Browse files Browse the repository at this point in the history
…r-bugfix

Omit subsample parameter if cluster is not subsampled (SCP-5438)
  • Loading branch information
jlchang authored Aug 1, 2024
2 parents 37681a6 + 1a8bae1 commit edc1854
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/javascript/components/explore/ExploreDisplayTabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ export function handleClusterSwitchForFiltering(cellFilteringSelection, newCellF
}
}

/** get the appropriate subsampling value, accounting for number of points & subsampling status **/
export function getSubsampleThreshold(exploreParams, exploreInfo) {
if (exploreInfo?.cluster && !exploreInfo.cluster.isSubsampled) {
return null
}
return exploreParams?.subsample || (exploreInfo?.cluster?.numPoints > 100_000 ? 100_000 : null)
}

/** wrapper function with error handling/state setting for retrieving cell facet data */
function getCellFacetingData(cluster, annotation, setterFunctions, context, prevCellFaceting) {
const [
Expand All @@ -122,7 +130,7 @@ function getCellFacetingData(cluster, annotation, setterFunctions, context, prev
const allAnnots = exploreInfo?.annotationList.annotations
if (allAnnots && allAnnots.length > 0) {
if (!prevCellFaceting?.isFullyLoaded) {
const subsample = exploreParams?.subsample || (exploreInfo?.cluster?.numPoints > 100_000 ? 100_000 : null)
const subsample = getSubsampleThreshold(exploreParams, exploreInfo)
initCellFaceting(
cluster, annotation, studyAccession, allAnnots, prevCellFaceting, subsample
).then(newCellFaceting => {
Expand Down
31 changes: 30 additions & 1 deletion test/js/explore/explore-display-tabs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import React from 'react'
import { render, screen, waitFor } from '@testing-library/react'
import * as UserProvider from '~/providers/UserProvider'
import ExploreDisplayTabs, {
getEnabledTabs, handleClusterSwitchForFiltering
getEnabledTabs, handleClusterSwitchForFiltering, getSubsampleThreshold
} from 'components/explore/ExploreDisplayTabs'
import ExploreDisplayPanelManager from '~/components/explore/ExploreDisplayPanelManager'
import PlotTabs from 'components/explore/PlotTabs'
Expand Down Expand Up @@ -499,4 +499,33 @@ describe('explore tabs are activated based on study info and parameters', () =>
})
)
})

it('Loads correct subsampling threshold', async () => {
const subsampleExploreInfo = {
cluster: {
isSubsampled: true,
numPoints: 212345
}
}
const exploreInfo = {
cluster: {
isSubsampled: false,
numPoints: 212345
}
}
const exploreWithSubsample = {
cluster: 'foo',
subsample: 100000
}
const exploreWithoutSubsample = { cluster: 'foo'}

let subsampleThreshold = getSubsampleThreshold(exploreWithSubsample, subsampleExploreInfo)
expect(subsampleThreshold).toEqual(exploreWithSubsample.subsample)
subsampleThreshold = getSubsampleThreshold(exploreWithoutSubsample, subsampleExploreInfo)
expect(subsampleThreshold).toEqual(100000)
subsampleThreshold = getSubsampleThreshold(exploreWithSubsample, exploreInfo)
expect(subsampleThreshold).toBeNull()
subsampleThreshold = getSubsampleThreshold(exploreWithoutSubsample, exploreInfo)
expect(subsampleThreshold).toBeNull()
})
})

0 comments on commit edc1854

Please sign in to comment.