Skip to content

Commit

Permalink
complement option uses filtered ids now
Browse files Browse the repository at this point in the history
Signed-off-by: stefanbabukov <[email protected]>
  • Loading branch information
StefanBabukov committed Sep 19, 2023
1 parent 6ddc3e7 commit 6167241
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const CellSetsTool = (props) => {
<CellSetOperation
icon={<SplitCellsOutlined />}
onCreate={(name, color) => {
dispatch(createCellSet(experimentId, name, color, complement(selectedCellSetKeys, properties)));
dispatch(createCellSet(experimentId, name, color, complement(selectedCellSetKeys, cellSets)));
}}
ariaLabel='Complement of selected'
helpTitle='Create new cell set from the complement of the selected sets in the current tab.'
Expand Down
26 changes: 11 additions & 15 deletions src/utils/cellSetOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ const union = (listOfSets, properties) => {

const sets = listOfSets.map((key) => properties[key]?.cellIds || []);
const unionSet = new Set(
[].concat(
...sets.map(
(set) => [...set],
),
),
sets.flatMap(set => [...set]),
);

return unionSet;
Expand Down Expand Up @@ -54,29 +50,29 @@ const intersection = (listOfSets, properties) => {
return intersectionSet;
};

const complement = (listOfSets, properties) => {
const complement = (listOfSets, cellSets) => {
if (!listOfSets) {
return new Set();
}

const { properties, hierarchy } = cellSets;
// get the ids of all selected cells
const selectedCells = listOfSets.map(
(key) => properties[key]?.cellIds || null,
).filter(
(set) => set && set.size > 0,
).reduce(
(acc, curr) => new Set([...acc, ...curr]),
);
).flatMap((set) => [...set]);

const filteredCellIds = hierarchy.filter((rootCluster) => rootCluster.key === 'louvain')[0]
.children
.map((child) => child.key);

// get the ids of all cells in the dataset
// All cells are assumed to be included in at least 1 cluster
const complementSet = Object.values(properties).map(
(cluster) => cluster.cellIds,
const complementSet = filteredCellIds.map(
(cluster) => properties[cluster].cellIds,
).filter(
(set) => set && set.size > 0,
).reduce(
(acc, curr) => new Set([...acc, ...curr]),
);
).flatMap((set) => [...set]);

// remove all cells that are selected
if (selectedCells.size > 0) {
Expand Down

0 comments on commit 6167241

Please sign in to comment.