Skip to content

Commit

Permalink
[FIX] hacky fix for FDRCorrector default (#663)
Browse files Browse the repository at this point in the history
* hacky fix for FDRCorrector default

* add constants file and reference from there

* add back in algorithm arguments as defaults as well
  • Loading branch information
jdkent authored Jan 17, 2024
1 parent 3422121 commit 674648e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,41 +1,17 @@
import metaAnalysisSpec from 'assets/config/meta_analysis_params.json';
import { Box, ListItem, ListItemText, Typography } from '@mui/material';
import {
IDynamicValueType,
IMetaAnalysisParamsSpecification,
} from 'components/MetaAnalysisConfigComponents';
import { IDynamicValueType } from 'components/MetaAnalysisConfigComponents';
import NeurosynthAccordion from 'components/NeurosynthAccordion/NeurosynthAccordion';
import NeurosynthAutocomplete, {
IAutocompleteObject,
} from 'components/NeurosynthAutocomplete/NeurosynthAutocomplete';
import { EAnalysisType } from 'hooks/metaAnalyses/useCreateAlgorithmSpecification';
import DynamicForm from 'components/MetaAnalysisConfigComponents/DynamicForm/DynamicForm';
import CreateMetaAnalysisSpecificationDialogBaseStyles from '../../CreateMetaAnalysisSpecificationDialogBase.styles';
import { useEffect, useMemo, useRef } from 'react';

const metaAnalysisSpecification: IMetaAnalysisParamsSpecification = metaAnalysisSpec;

const getDefaultValuesForTypeAndParameter = (
type: EAnalysisType | 'CORRECTOR',
parameterLabel: string | undefined
): IDynamicValueType => {
if (type && parameterLabel) {
const parameters = metaAnalysisSpecification[type][parameterLabel].parameters;
const defaultVals: IDynamicValueType = {};
for (const [key, value] of Object.entries(parameters)) {
if (parameters[key].type === null) {
// in the case of kwargs or any other input with no default value
defaultVals[key] = {};
} else {
defaultVals[key] = value.default;
}
}

return defaultVals;
}

return {};
};
import {
getDefaultValuesForTypeAndParameter,
metaAnalyticAlgorithms,
correctorOptions,
} from '../../CreateMetaAnalysisSpecificationDialogConstants';

const SelectSpecificationComponent: React.FC<{
onSelectSpecification: (algorithm: {
Expand All @@ -51,42 +27,6 @@ const SelectSpecificationComponent: React.FC<{
correctorArgs: IDynamicValueType;
};
}> = (props) => {
const initialized = useRef<boolean>(false);

const metaAnalyticAlgorithms: IAutocompleteObject[] = useMemo(
() =>
Object.keys(metaAnalysisSpecification[EAnalysisType.CBMA]).map((algoName) => ({
label: algoName,
description: metaAnalysisSpecification[EAnalysisType.CBMA][algoName]?.summary || '',
})),
[]
);

useEffect(() => {
if (props.algorithm?.estimator || initialized.current) return;

const algorithmOpt = metaAnalyticAlgorithms.find((algo) => algo.label === 'MKDADensity');
if (!algorithmOpt) return;
props.onSelectSpecification({
...props.algorithm,
estimator: algorithmOpt,
estimatorArgs: getDefaultValuesForTypeAndParameter(
EAnalysisType.CBMA,
algorithmOpt?.label
),
});
initialized.current = true;
}, [props.algorithm?.estimator, metaAnalyticAlgorithms, props]);

const correctorOptions: IAutocompleteObject[] = useMemo(
() =>
Object.keys(metaAnalysisSpecification.CORRECTOR).map((corrector) => ({
label: corrector,
description: metaAnalysisSpecification.CORRECTOR[corrector]?.summary,
})),
[]
);

return (
<Box>
<Typography sx={{ margin: '1rem 0' }} gutterBottom>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IAutocompleteObject } from 'components/NeurosynthAutocomplete/Neurosynt
import { useProjectName } from 'pages/Projects/ProjectPage/ProjectStore';
import { useEffect, useState } from 'react';
import BaseDialog, { IDialog } from '../BaseDialog';
import { EAnalysisType } from 'hooks/metaAnalyses/useCreateAlgorithmSpecification';
import CreateMetaAnalysisSpecificationAlgorithmStep from './CreateMetaAnalysisSpecificationAlgorithmStep/CreateMetaAnalysisSpecificationAlgorithmStep';
import CreateMetaAnalysisSpecificationDetailsStep from './CreateMetaAnalysisSpecificationDetailsStep/CreateMetaAnalysisSpecificationDetailsStep';
import {
Expand All @@ -13,6 +14,11 @@ import {
} from './CreateMetaAnalysisSpecificationDialogBase.types';
import CreateMetaAnalysisSpecificationReview from './CreateMetaAnalysisSpecificationReview/CreateMetaAnalysisSpecificationReview';
import CreateMetaAnalysisSpecificationSelectionStep from './CreateMetaAnalysisSpecificationSelectionStep/CreateMetaAnalysisSpecificationSelectionStep';
import {
getDefaultValuesForTypeAndParameter,
correctorOpt,
algorithmOpt,
} from './CreateMetaAnalysisSpecificationDialogConstants';

const CreateMetaAnalysisSpecificationDialogBase: React.FC<IDialog> = (props) => {
const projectName = useProjectName();
Expand All @@ -29,10 +35,10 @@ const CreateMetaAnalysisSpecificationDialogBase: React.FC<IDialog> = (props) =>
referenceDataset: undefined,
});
const [algorithm, setAlgorithm] = useState<IAlgorithmSelection>({
estimator: null,
estimatorArgs: {},
corrector: null,
correctorArgs: {},
estimator: algorithmOpt,
estimatorArgs: getDefaultValuesForTypeAndParameter(EAnalysisType.CBMA, algorithmOpt?.label),
corrector: correctorOpt,
correctorArgs: getDefaultValuesForTypeAndParameter('CORRECTOR', correctorOpt?.label),
});

useEffect(() => {
Expand All @@ -46,10 +52,13 @@ const CreateMetaAnalysisSpecificationDialogBase: React.FC<IDialog> = (props) =>
props.onCloseDialog();
setActiveStep(0);
setAlgorithm({
estimator: null,
estimatorArgs: {},
corrector: null,
correctorArgs: {},
estimator: algorithmOpt,
estimatorArgs: getDefaultValuesForTypeAndParameter(
EAnalysisType.CBMA,
algorithmOpt?.label
),
corrector: correctorOpt,
correctorArgs: getDefaultValuesForTypeAndParameter('CORRECTOR', correctorOpt?.label),
});
setSelection({
selectionKey: undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {
IMetaAnalysisParamsSpecification,
IDynamicValueType,
} from 'components/MetaAnalysisConfigComponents';
import { EAnalysisType } from 'hooks/metaAnalyses/useCreateAlgorithmSpecification';
import { IAutocompleteObject } from 'components/NeurosynthAutocomplete/NeurosynthAutocomplete';
import metaAnalysisSpec from 'assets/config/meta_analysis_params.json';

const getDefaultValuesForTypeAndParameter = (
type: EAnalysisType | 'CORRECTOR',
parameterLabel: string | undefined
): IDynamicValueType => {
if (type && parameterLabel) {
const parameters = metaAnalysisSpecification[type][parameterLabel].parameters;
const defaultVals: IDynamicValueType = {};
for (const [key, value] of Object.entries(parameters)) {
if (parameters[key].type === null) {
// in the case of kwargs or any other input with no default value
defaultVals[key] = {};
} else {
defaultVals[key] = value.default;
}
}

return defaultVals;
}

return {};
};

const metaAnalysisSpecification: IMetaAnalysisParamsSpecification = metaAnalysisSpec;

const metaAnalyticAlgorithms: IAutocompleteObject[] = Object.keys(
metaAnalysisSpecification[EAnalysisType.CBMA]
).map((algoName) => ({
label: algoName,
description: metaAnalysisSpecification[EAnalysisType.CBMA][algoName]?.summary || '',
}));

const correctorOptions: IAutocompleteObject[] = Object.keys(
metaAnalysisSpecification.CORRECTOR
).map((corrector) => ({
label: corrector,
description: metaAnalysisSpecification.CORRECTOR[corrector]?.summary,
}));

const correctorOpt =
correctorOptions.find((corrector) => corrector.label === 'FDRCorrector') || null;
const algorithmOpt = metaAnalyticAlgorithms.find((algo) => algo.label === 'MKDADensity') || null;

export {
getDefaultValuesForTypeAndParameter,
metaAnalysisSpecification,
metaAnalyticAlgorithms,
correctorOptions,
correctorOpt,
algorithmOpt,
};

0 comments on commit 674648e

Please sign in to comment.