Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 924 filter nodes #1083

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e70f7f1
draft Network and update stories
asizemore Apr 25, 2024
cbb5f30
Merge branch 'main' into feature-996-consolidate-networks
asizemore Apr 25, 2024
4d6ba37
have BipartiteNetwork call NetworkPlot
asizemore Apr 26, 2024
a4e08c4
rename so that networks in components follow Plot convention
asizemore Apr 26, 2024
16ec12d
consolidate network style props
asizemore Apr 29, 2024
c340fac
add back partition names as annotations
asizemore Apr 29, 2024
960af06
handle empty Network data
asizemore Apr 29, 2024
a57b70a
add default layout for network
asizemore Apr 29, 2024
b5833d8
Clean up Network stories
asizemore Apr 30, 2024
a39c3b8
cleanup
asizemore May 1, 2024
15ff8c3
Merge branch 'main' into feature-996-consolidate-networks
asizemore May 1, 2024
7e0158d
update imports for BipartiteNetworkPlot
asizemore May 2, 2024
2711c35
Merge branch 'main' into feature-996-consolidate-networks
asizemore May 2, 2024
02b9ec5
update NodeMenuActions imports
asizemore May 2, 2024
2a0d736
Merge branch 'main' into feature-996-consolidate-networks
asizemore May 7, 2024
dee9ffc
simplify coordinate logic in bpnet
asizemore May 8, 2024
7b9a57e
remove a loop over the nodes
asizemore May 8, 2024
ef1f2ad
Merge branch 'main' into feature-996-consolidate-networks
asizemore May 8, 2024
21babcc
update imports
asizemore May 8, 2024
c805b7f
Merge branch 'main' into feature-996-consolidate-networks
asizemore May 9, 2024
8e7f73e
Merge branch 'main' into feature-996-consolidate-networks
asizemore May 9, 2024
995aa38
setup input for node filter
asizemore May 14, 2024
429b2af
Merge branch 'main' into feature-924-filter-nodes
asizemore May 14, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ export function DifferentialAbundanceConfiguration(
showClearSelectionButton={false}
disableInput={disableGroupValueSelectors}
isLoading={continuousVariableBins.pending}
isSearchable={true}
/>
<FloatingButton
icon={SwapHorizOutlined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import {
CorrelationBipartiteNetworkResponse,
} from '../../../api/DataClient/types';
import { twoColorPalette } from '@veupathdb/components/lib/types/plots/addOns';
import { useCallback, useMemo } from 'react';
import { useCallback, useMemo, useState } from 'react';
import { scaleOrdinal } from 'd3-scale';
import { uniq } from 'lodash';
import { usePromise } from '../../../hooks/promise';
import {
useDataClient,
useFindEntityAndVariableCollection,
useStudyEntities,
useStudyMetadata,
} from '../../../hooks/workspace';
Expand All @@ -41,7 +42,7 @@ import { NumberInput } from '@veupathdb/components/lib/components/widgets/Number
import { NumberOrDate } from '@veupathdb/components/lib/types/general';
import { useVizConfig } from '../../../hooks/visualizations';
import { FacetedPlotLayout } from '../../layouts/FacetedPlotLayout';
import { H6 } from '@veupathdb/coreui';
import { H6, SearchBox, SelectList } from '@veupathdb/coreui';
import { CorrelationConfig } from '../../../types/apps';
import { StudyMetadata } from '../../..';
import { NodeMenuAction } from '@veupathdb/components/lib/types/plots/network';
Expand Down Expand Up @@ -122,6 +123,7 @@ function BipartiteNetworkViz(props: VisualizationProps<Options>) {
const { id: studyId } = studyMetadata;
const entities = useStudyEntities(filters);
const dataClient: DataClient = useDataClient();
const findEntityAndVariableCollection = useFindEntityAndVariableCollection();

const computationConfiguration: CorrelationConfig = computation.descriptor
.configuration as CorrelationConfig;
Expand Down Expand Up @@ -177,6 +179,14 @@ function BipartiteNetworkViz(props: VisualizationProps<Options>) {
])
);

const createNodeList = () =>
data.value
? data.value.bipartitenetwork.data.nodes.map((node) => node.id)
: [];
const [keepNodeIds, setKeepNodeIds] = useState<string[]>(createNodeList);
// console.log(data.value?.bipartitenetwork.data.nodes.map((node) => node.id));
console.log(keepNodeIds);

// Determine min and max stroke widths. For use in scaling the strokes (weightToStrokeWidthMap) and the legend.
const dataWeights =
data.value?.bipartitenetwork.data.links.map(
Expand Down Expand Up @@ -223,8 +233,9 @@ function BipartiteNetworkViz(props: VisualizationProps<Options>) {
.range(twoColorPalette); // the output palette may change if this visualization is reused in other contexts (ex. not a correlation app).

// Find display labels
const nodesWithLabels = data.value.bipartitenetwork.data.nodes.map(
(node) => {
const nodesWithLabels = data.value.bipartitenetwork.data.nodes
.filter((node) => keepNodeIds.includes(node.id))
.map((node) => {
// node.id is the entityId.variableId
const displayLabel = fixVarIdLabel(
node.id.split('.')[1],
Expand All @@ -236,8 +247,7 @@ function BipartiteNetworkViz(props: VisualizationProps<Options>) {
id: node.id,
label: displayLabel,
};
}
);
});

const nodesById = new Map(nodesWithLabels.map((n) => [n.id, n]));

Expand All @@ -264,16 +274,24 @@ function BipartiteNetworkViz(props: VisualizationProps<Options>) {
...data.value.bipartitenetwork.data,
partitions: orderedPartitions,
nodes: nodesWithLabels,
links: data.value.bipartitenetwork.data.links.map((link) => {
return {
source: link.source,
target: link.target,
strokeWidth: weightToStrokeWidthMap(Number(link.weight)),
color: link.color ? linkColorScale(link.color.toString()) : '#000000',
};
}),
links: data.value.bipartitenetwork.data.links
.filter(
(link) =>
keepNodeIds.includes(link.source.id) &&
keepNodeIds.includes(link.target.id)
)
.map((link) => {
return {
source: link.source,
target: link.target,
strokeWidth: weightToStrokeWidthMap(Number(link.weight)),
color: link.color
? linkColorScale(link.color.toString())
: '#000000',
};
}),
};
}, [data.value, entities, minDataWeight, maxDataWeight]);
}, [data.value, entities, minDataWeight, maxDataWeight, keepNodeIds]);

const getNodeMenuActions = options?.makeGetNodeMenuActions?.(studyMetadata);

Expand Down Expand Up @@ -313,6 +331,11 @@ function BipartiteNetworkViz(props: VisualizationProps<Options>) {
[cleanedData]
);

const data1DisplayName =
findEntityAndVariableCollection(
computationConfiguration.data1?.collectionSpec
)?.variableCollection.displayName ?? 'Column 1';

// Have the bpnet component say "No nodes" or whatev and have an extra
// prop called errorMessage or something that displays when there are no nodes.
// that error message can say "your thresholds of blah and blah are too high, change them"
Expand Down Expand Up @@ -450,37 +473,87 @@ function BipartiteNetworkViz(props: VisualizationProps<Options>) {
return (
<div style={{ display: 'flex', flexDirection: 'column' }}>
{!hideInputsAndControls && (
<LabelledGroup label="Link thresholds" alignChildrenHorizontally={true}>
<NumberInput
onValueChange={(newValue?: NumberOrDate) =>
updateVizConfig({ correlationCoefThreshold: Number(newValue) })
}
label={'Absolute correlation coefficient'}
minValue={0}
maxValue={1}
value={
vizConfig.correlationCoefThreshold ??
DEFAULT_CORRELATION_COEF_THRESHOLD
}
step={0.05}
applyWarningStyles={cleanedData && cleanedData.nodes.length === 0}
/>

<NumberInput
label="P-Value"
onValueChange={(newValue?: NumberOrDate) =>
updateVizConfig({ significanceThreshold: Number(newValue) })
}
minValue={0}
maxValue={1}
value={
vizConfig.significanceThreshold ?? DEFAULT_SIGNIFICANCE_THRESHOLD
}
containerStyles={{ marginLeft: 10 }}
step={0.001}
applyWarningStyles={cleanedData && cleanedData.nodes.length === 0}
/>
</LabelledGroup>
<>
<LabelledGroup
label="Link thresholds"
alignChildrenHorizontally={true}
>
<NumberInput
onValueChange={(newValue?: NumberOrDate) =>
updateVizConfig({ correlationCoefThreshold: Number(newValue) })
}
label={'Absolute correlation coefficient'}
minValue={0}
maxValue={1}
value={
vizConfig.correlationCoefThreshold ??
DEFAULT_CORRELATION_COEF_THRESHOLD
}
step={0.05}
applyWarningStyles={cleanedData && cleanedData.nodes.length === 0}
/>

<NumberInput
label="P-Value"
onValueChange={(newValue?: NumberOrDate) =>
updateVizConfig({ significanceThreshold: Number(newValue) })
}
minValue={0}
maxValue={1}
value={
vizConfig.significanceThreshold ??
DEFAULT_SIGNIFICANCE_THRESHOLD
}
containerStyles={{ marginLeft: 10 }}
step={0.001}
applyWarningStyles={cleanedData && cleanedData.nodes.length === 0}
/>
</LabelledGroup>
<LabelledGroup label="Node filters" alignChildrenHorizontally={true}>
{/* <SearchBox
// autoFocus={autoFocusSearchBox}
searchTerm={searchTerm}
onSearchTermChange={onSearchTermChange}
placeholderText={searchBoxPlaceholder}
// iconName={searchIconName}
// iconPosition={searchIconPosition}
// helpText={searchBoxHelp}
// styleOverrides={styleSpec.searchBox}
/> */}
<span>{data1DisplayName}</span>
<SelectList
defaultButtonDisplayContent={'Select value(s)'}
items={
data.value
? data.value.bipartitenetwork.data.nodes.map((node) => ({
display: <span>{node.id}</span>,
value: node.id,
}))
: []
}
onChange={setKeepNodeIds}
value={keepNodeIds}
isDisabled={false}
isLoading={false}
/>
<span>Metadata</span>
<SelectList
defaultButtonDisplayContent={'Select value(s)'}
items={
data.value
? data.value.bipartitenetwork.data.nodes.map((node) => ({
display: <span>{node.id}</span>,
value: node.id,
}))
: []
}
onChange={setKeepNodeIds}
value={keepNodeIds}
isDisabled={false}
isLoading={false}
/>
</LabelledGroup>
</>
)}
<OutputEntityTitle subtitle={plotSubtitle} />
<LayoutComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import SelectList from '@veupathdb/coreui/lib/components/inputs/SelectList';
import { ReactNode } from 'react';
import { ClearSelectionButton } from '../../variableSelectors/VariableTreeDropdown';
import { SearchBox } from '@veupathdb/coreui';

export type ValuePickerProps = {
allowedValues?: string[];
Expand All @@ -13,6 +14,8 @@ export type ValuePickerProps = {
showClearSelectionButton?: boolean;
/** Show loading spinner */
isLoading?: boolean;
/** Show a searchbox? */
isSearchable?: boolean;
};

const EMPTY_ALLOWED_VALUES_ARRAY: string[] = [];
Expand All @@ -28,6 +31,7 @@ export function ValuePicker({
disableInput = false,
showClearSelectionButton = true,
isLoading = false,
isSearchable = false,
}: ValuePickerProps) {
const items = allowedValues.map((value) => ({
display: <span>{value}</span>,
Expand All @@ -37,6 +41,7 @@ export function ValuePicker({

return (
<>
{isSearchable && <SearchBox />}
<SelectList
defaultButtonDisplayContent={'Select value(s)'}
items={items}
Expand Down
Loading