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

fix missing values from nexus #100

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 16 additions & 3 deletions src/components/Filter/CheckList/Description.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@ import { useAtomValue } from 'jotai';
import { useMemo } from 'react';
import { unwrap } from 'jotai/utils';
import { Spin } from 'antd';
import findKey from 'lodash/findKey';
import replace from 'lodash/replace';
import get from 'lodash/get';

import EXPLORE_FIELDS_CONFIG from '@/constants/explore-section/fields-config';
import { cellTypesByLabelAtom } from '@/state/build-section/cell-types';
import { FieldType } from '@/constants/explore-section/fields-config/types';
import EXPLORE_FIELDS_CONFIG from '@/constants/explore-section/fields-config';
import { ClassNexus } from '@/api/ontologies/types';

// NOTE: this due nexus es aggregation and the resource it self are having different keys name
// one with underscore, and the other with hyphen
const getClassByLabel = (label: string, classes: Record<string, ClassNexus>) => {
const normalizedLabel = replace(label, /[_-]/g, '');
const matchedKey = findKey(classes, (_, key) => replace(key, /[_-]/g, '') === normalizedLabel);
return get(classes, matchedKey ?? '', null);
};

export function CheckListDescription({
label,
Expand All @@ -26,6 +39,6 @@ function ClassDescription({ label }: { label: string }) {
if (!classes) {
return <Spin />;
}

return <span className="text-primary-1">{classes[label]?.definition}</span>;
const classObj = getClassByLabel(label, classes);
return <span className="text-primary-1">{classObj?.definition}</span>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type Props = {
removeGroup: (index: number | number[]) => void;
};

const label = (text: string) => (
<span className={classNames('text-base font-bold capitalize text-gray-500')}>{text}</span>
const label = (text: string, cls?: string) => (
<span className={classNames('text-base font-bold capitalize text-gray-500', cls)}>{text}</span>
);

export default function SynapseSet({
Expand Down Expand Up @@ -75,9 +75,14 @@ export default function SynapseSet({
})
);

const hasApic = groupedSections.includes('apic');

const targetOptions = groupedSections.map((value) => ({
value,
label: sectionTargetMapping[value as keyof typeof sectionTargetMapping],
label:
value === 'dend' && !hasApic
? 'Dendrites'
: sectionTargetMapping[value as keyof typeof sectionTargetMapping],
}));

const isAlreadyVisualized = useMemo(
Expand Down Expand Up @@ -370,7 +375,7 @@ export default function SynapseSet({
displayFormulaHelp && 'justify-between'
)}
>
{label('Formula')}
{label('Synapse distribution formula', 'normal-case')}
{displayFormulaHelp ? (
<CloseOutlined className="text-gray-300" onClick={toggleFormulaHelp} />
) : (
Expand All @@ -383,7 +388,7 @@ export default function SynapseSet({
displayFormulaHelp ? 'mb-4 h-full opacity-100' : 'mb-0 h-0 opacity-0'
)}
>
More information on formulas here: <br />
Supports advanced math functions (e.g., sin(x), log(x), ...). <br />
<a
target="_blank"
rel="noopener noreferrer"
Expand All @@ -397,10 +402,11 @@ export default function SynapseSet({
<input hidden readOnly name="distribution" value="formula" />
<Form.Item
name={[field.name, 'formula']}
extra={<small>x: distance from soma (µm)</small>}
rules={[
{
required: true,
message: 'Please provide a valid formula!',
message: 'Please provide a valid distribution formula!',
async validator(_, value) {
if (synapses?.[index].distribution !== 'formula') {
return Promise.resolve();
Expand All @@ -424,7 +430,7 @@ export default function SynapseSet({
)}
>
<Input
placeholder="00.3*x*x + 0.004"
placeholder="0.03*x*x + 0.004"
size="large"
className={classNames(
'text-base font-bold italic [&_.ant-input]:text-primary-8',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export const DEFAULT_SYNAPSE_VALUE: SingleSynaptomeConfig = {
};

export const sectionTargetMapping = {
dend: 'Dendrite',
dend: 'Basal Dendrites',
soma: 'Soma',
apic: 'Apical dendrite',
basal: 'Basal dendrite',
apic: 'Apical dendrites',
basal: 'Basal dendrites',
axon: 'Axon',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export default function WithControlPanel({
);

const data = useUnwrappedValue(dataAtom({ dataType, dataScope, virtualLabInfo, key: dataKey }));

const aggregations = data?.aggs;

return (
Expand Down
52 changes: 51 additions & 1 deletion src/state/build-section/cell-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { selectAtom } from 'jotai/utils';
import esb from 'elastic-builder';
import { Session } from 'next-auth';
import esb from 'elastic-builder';
import toLower from 'lodash/toLower';
import findKey from 'lodash/findKey';
import get from 'lodash/get';

import sessionAtom from '@/state/session';
import { createHeaders } from '@/util/utils';
import { ClassNexus } from '@/api/ontologies/types';
Expand Down Expand Up @@ -61,8 +65,54 @@ export const cellTypesByLabelAtom = selectAtom<
return cellTypes.hits.hits.reduce(
(acc: Record<string, ClassNexus>, classObj: ClassESResponse) => {
acc[classObj._source.label] = classObj._source;
// TODO: this is temporary until a fix applied to nexus/entitycore
const matchedKey = findKey(
TEMPORARY_TYPE_DEFINITION,
(_, k) => toLower(k) === toLower(classObj._source.label)
);
const matchedValue = get(
TEMPORARY_TYPE_DEFINITION,
matchedKey ?? '',
classObj._source?.definition
);

acc[classObj._source.label] = {
...classObj._source,
definition: matchedValue,
};
return acc;
},
{}
);
});

// TODO: this should be fixed in nexus/entitycore level
const TEMPORARY_TYPE_DEFINITION = {
cNAC: 'Continuous non-accommodating electrical type',
cADpyr: 'Continuous adapting pyramidal cell electrical type',
cACpyr: 'Continuous accommodating pyramidal cell electrical type',
bAC: 'Burst accommodating electrical type',
cAC: 'Continuous accommodating electrical type',
cNAD_lts_dSTR:
"Low-threshold spiking, tonically active, slow and regular firing, characteristic 'notch' in the membrane potential during the depolarizing phase of the action potential, depolarizing sag, high input resistance",
dAD_htp_dSTR:
'delayed spike, adapting or accelerating, input rectification, irregular spiking, high-threshold spike, pacemaker-like firing',
dAD_ltb_dSTR:
'Delayed spike, adapting or accelerating, input rectification, low resting potential, regular spiking, low-threshold spike, burst firing',
bSTUT: 'Burst stuttering electrical type',
dNAC: 'Delayed non-accommodating electrical type',
GEN_etype: 'Generic excitatory neuron electrical type',
GIN_etype: 'Generic inhibitory neuron electrical type',
bIR: 'Burst irregular electrical type',
bNAC: 'Burst non-accommodating electrical type',
cAD_noscltb: 'Continuous adapting non-oscillatory low-threshold bursting electrical type',
cIR: 'Continuous irregular electrical type',
cNAD_ltb_dSTR:
"Low-threshold spiking, tonically active, slow and regular firing, characteristic 'notch' in the membrane potential during the depolarizing phase of the action potential, depolarizing sag, high input resistance",
cNAD_noscltb: 'Continuous non-adapting non-oscillatory low-threshold bursting electrical type',
cSTUT: 'Continuous stuttering electrical type',
dAD_ltb: 'Delayed adapting low-threshold bursting electrical type',
dNAD_ltb: 'Delayed non-adapting low-threshold bursting electrical type',
dSTUT: 'Delayed stuttering electrical type',
bIR_dSTR: 'Tonically active neurons, irregular spiking, burst firing electrical type',
};