Skip to content

Commit

Permalink
Add support for MALP-EM
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Mar 1, 2024
1 parent 35d517f commit 9ed0b1b
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 8 deletions.
150 changes: 150 additions & 0 deletions scripts/data/nmm_info.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
0,Background,Background,NA
1,3rdVentricle,3rdVentricle,NA
2,4thVentricle,4thVentricle,NA
3,RightAccumbensArea,RightAccumbensArea,right
4,LeftAccumbensArea,LeftAccumbensArea,left
5,RightAmygdala,RightAmygdala,right
6,LeftAmygdala,LeftAmygdala,left
7,BrainStem,BrainStem,NA
8,RightCaudate,RightCaudate,right
9,LeftCaudate,LeftCaudate,left
10,RightCerebellumExterior,RightCerebellumExterior,right
11,LeftCerebellumExterior,LeftCerebellumExterior,left
12,RightCerebellumWhiteMatter,RightCerebellumWhiteMatter,right
13,LeftCerebellumWhiteMatter,LeftCerebellumWhiteMatter,left
14,RightCerebralExterior,RightCerebralExterior,right
15,LeftCerebralExterior,LeftCerebralExterior,left
16,RightCerebralWhiteMatter,RightCerebralWhiteMatter,right
17,LeftCerebralWhiteMatter,LeftCerebralWhiteMatter,left
18,CSF,CSF,NA
19,RightHippocampus,RightHippocampus,right
20,LeftHippocampus,LeftHippocampus,left
21,RightInfLatVent,RightInfLatVent,right
22,LeftInfLatVent,LeftInfLatVent,left
23,RightLateralVentricle,RightLateralVentricle,right
24,LeftLateralVentricle,LeftLateralVentricle,left
25,RightPallidum,RightPallidum,right
26,LeftPallidum,LeftPallidum,left
27,RightPutamen,RightPutamen,right
28,LeftPutamen,LeftPutamen,left
29,RightThalamusProper,RightThalamusProper,right
30,LeftThalamusProper,LeftThalamusProper,left
31,RightVentralDC,RightVentralDC,right
32,LeftVentralDC,LeftVentralDC,left
33,Rightvessel,Rightvessel,right
34,Leftvessel,Leftvessel,left
35,OpticChiasm,OpticChiasm,NA
36,CerebellarVermalLobulesI-V,CerebellarVermalLobulesI-V,NA
37,CerebellarVermalLobulesVI-VII,CerebellarVermalLobulesVI-VII,NA
38,CerebellarVermalLobulesVIII-X,CerebellarVermalLobulesVIII-X,NA
39,LeftBasalForebrain,Leftbasalforebrain,left
40,RightBasalForebrain,Rightbasalforebrain,right
41,RightACg,Ganteriorcingulategyrus Right,right
42,LeftACg,Ganteriorcingulategyrus Left,left
43,RightAIns,Anteriorinsula Right,right
44,LeftAIns,Anteriorinsula Left,left
45,RightAOrG,Anteriororbitalgyrus Right,right
46,LeftAOrG,Anteriororbitalgyrus Left,left
47,RightAnG,Angulargyrus Right,right
48,LeftAnG,Angulargyrus Left,left
49,RightCalc,Calcarinecortex Right,right
50,LeftCalc,Calcarinecortex Left,left
51,RightCO,Centraloperculum Right,right
52,LeftCO,Centraloperculum Left,left
53,RightCun,Cuneus Right,right
54,LeftCun,Cuneus Left,left
55,RightEntA,Ententorhinalarea Right,right
56,LeftEntA,Ententorhinalarea Left,left
57,RightFO,Frontaloperculum Right,right
58,LeftFO,Frontaloperculum Left,left
59,RightFRP,Frontalpole Right,right
60,LeftFRP,Frontalpole Left,left
61,RightFuG,Fusiformgyrus Right,right
62,LeftFuG,Fusiformgyrus Left,left
63,RightGRe,Gyrusrectus Right,right
64,LeftGRe,Gyrusrectus Left,left
65,RightIOG,Inferioroccipitalgyrus Right,right
66,LeftIOG,Inferioroccipitalgyrus Left,left
67,RightITG,Inferiortemporalgyrus Right,right
68,LeftITG,Inferiortemporalgyrus Left,left
69,RightLiG,Lingualgyrus Right,right
70,LeftLiG,Lingualgyrus Left,left
71,RightLOrG,Lateralorbitalgyrus Right,right
72,LeftLOrG,Lateralorbitalgyrus Left,left
73,RightMCgG,Middlecingulategyrus Right,right
74,LeftMCgG,Middlecingulategyrus Left,left
75,RightMFC,Medialfrontalcortex Right,right
76,LeftMFC,Medialfrontalcortex Left,left
77,RightMFG,Middlefrontalgyrus Right,right
78,LeftMFG,Middlefrontalgyrus Left,left
79,RightMOG,Middleoccipitalgyrus Right,right
80,LeftMOG,Middleoccipitalgyrus Left,left
81,RightMOrG,Medialorbitalgyrus Right,right
82,LeftMOrG,Medialorbitalgyrus Left,left
83,RightMPoG,Postcentralgyrusmedialsegment Right,right
84,LeftMPoG,Postcentralgyrusmedialsegment Left,left
85,RightMPrG,Precentralgyrusmedialsegment Right,right
86,LeftMPrG,Precentralgyrusmedialsegment Left,left
87,RightMSFG,Superiorfrontalgyrusmedialsegment Right,right
88,LeftMSFG,Superiorfrontalgyrusmedialsegment Left,left
89,RightMTG,Middletemporalgyrus Right,right
90,LeftMTG,Middletemporalgyrus Left,left
91,RightOCP,Occipitalpole Right,right
92,LeftOCP,Occipitalpole Left,left
93,RightOFuG,Occipitalfusiformgyrus Right,right
94,LeftOFuG,Occipitalfusiformgyrus Left,left
95,RightOpIFG,Opercularpartoftheinferiorfrontalgyrus Right,right
96,LeftOpIFG,Opercularpartoftheinferiorfrontalgyrus Left,left
97,RightOrIFG,Orbitalpartoftheinferiorfrontalgyrus Right,right
98,LeftOrIFG,Orbitalpartoftheinferiorfrontalgyrus Left,left
99,RightPCgG,Posteriorcingulategyrus Right,right
100,LeftPCgG,Posteriorcingulategyrus Left,left
101,RightPCu,Precuneus Right,right
102,LeftPCu,Precuneus Left,left
103,RightPHG,Parahippocampalgyrus Right,right
104,LeftPHG,Parahippocampalgyrus Left,left
105,RightPIns,Posteriorinsula Right,right
106,LeftPIns,Posteriorinsula Left,left
107,RightPO,Parietaloperculum Right,right
108,LeftPO,Parietaloperculum Left,left
109,RightPoG,Postcentralgyrus Right,right
110,LeftPoG,Postcentralgyrus Left,left
111,RightPOrG,Posteriororbitalgyrus Right,right
112,LeftPOrG,Posteriororbitalgyrus Left,left
113,RightPP,Planumpolare Right,right
114,LeftPP,Planumpolare Left,left
115,RightPrG,Precentralgyrus Right,right
116,LeftPrG,Precentralgyrus Left,left
117,RightPT,Planumtemporale Right,right
118,LeftPT,Planumtemporale Left,left
119,RightSCA,Subcallosalarea Right,right
120,LeftSCA,Subcallosalarea Left,left
121,RightSFG,Superiorfrontalgyrus Right,right
122,LeftSFG,Superiorfrontalgyrus Left,left
123,RightSMC,Supplementarymotorcortex Right,right
124,LeftSMC,Supplementarymotorcortex Left,left
125,RightSMG,Supramarginalgyrus Right,right
126,LeftSMG,Supramarginalgyrus Left,left
127,RightSOG,Superioroccipitalgyrus Right,right
128,LeftSOG,Superioroccipitalgyrus Left,left
129,RightSPL,Superiorparietallobule Right,right
130,LeftSPL,Superiorparietallobule Left,left
131,RightSTG,Superiortemporalgyrus Right,right
132,LeftSTG,Superiortemporalgyrus Left,left
133,RightTMP,Temporalpole Right,right
134,LeftTMP,Temporalpole Left,left
135,RightTrIFG,Triangularpartoftheinferiorfrontalgyrus Right,right
136,LeftTrIFG,Triangularpartoftheinferiorfrontalgyrus Left,left
137,RightTTG,Transversetemporalgyrus Right,right
138,LeftTTG,Transversetemporalgyrus Left,left
139,NA,Not Used,NA
140,NA,Not Used,NA
141,NA,Not Used,NA
142,NA,Not Used,NA
143,NA,Not Used,NA
144,NA,Not Used,NA
145,NA,Not Used,NA
146,NA,Not Used,NA
147,NA,Not Used,NA
148,NA,Not Used,NA
149,NA,Not Used,NA
92 changes: 92 additions & 0 deletions scripts/data/roi_i256.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"min": 0,
"max": 0,
"R": [
65, 10, 223, 120, 216, 207, 251, 93, 252, 217, 21, 253, 131, 165, 173, 143,
144, 217, 86, 89, 63, 254, 172, 1, 142, 107, 42, 78, 221, 8, 222, 71, 127,
126, 167, 33, 104, 2, 208, 216, 0, 251, 7, 105, 2, 101, 248, 190, 253, 62,
255, 224, 166, 37, 110, 138, 45, 34, 6, 37, 69, 201, 43, 122, 199, 37, 173,
194, 103, 211, 75, 159, 96, 4, 239, 98, 110, 193, 253, 166, 40, 255, 48,
130, 140, 243, 101, 9, 177, 220, 133, 32, 4, 81, 48, 48, 210, 109, 60, 132,
1, 119, 1, 159, 247, 33, 212, 187, 253, 144, 196, 254, 168, 79, 64, 196, 39,
97, 73, 173, 104, 216, 217, 43, 101, 119, 254, 5, 237, 103, 203, 122, 57,
87, 251, 164, 19, 75, 200, 2, 252, 150, 66, 0, 255, 157, 23, 254, 55, 16,
240, 161, 69, 253, 207, 195, 5, 60, 255, 251, 200, 217, 134, 123, 253, 180,
27, 246, 130, 136, 250, 232, 4, 125, 140, 22, 253, 255, 13, 180, 123, 61,
254, 111, 10, 185, 76, 192, 255, 223, 186, 61, 198, 5, 172, 13, 83, 172,
171, 6, 23, 73, 134, 133, 109, 61, 213, 55, 57, 132, 36, 209, 2, 144, 1,
253, 68, 155, 3, 160, 2, 77, 121, 70, 67, 176, 223, 131, 4, 162, 232, 255,
150, 94, 235, 191, 207, 10, 246, 0, 225, 4, 209, 116, 57, 112, 172, 253, 1,
6, 92, 227, 73, 62, 135, 223
],
"G": [
162, 50, 112, 245, 4, 124, 176, 243, 56, 125, 183, 139, 182, 68, 189, 4,
225, 10, 20, 223, 7, 46, 31, 193, 225, 250, 219, 41, 2, 100, 83, 181, 34,
150, 72, 223, 168, 248, 80, 253, 7, 117, 214, 2, 248, 10, 3, 59, 179, 160,
90, 244, 146, 4, 207, 4, 125, 255, 96, 100, 1, 208, 130, 51, 116, 181, 236,
53, 244, 5, 165, 28, 181, 86, 96, 42, 254, 1, 134, 194, 214, 92, 41, 204,
137, 86, 207, 3, 143, 3, 100, 239, 164, 94, 65, 251, 131, 244, 173, 57, 143,
107, 217, 53, 210, 0, 148, 250, 45, 198, 81, 40, 61, 218, 252, 88, 171, 0,
248, 24, 248, 4, 41, 100, 187, 46, 208, 145, 43, 168, 121, 46, 175, 250,
125, 107, 233, 112, 207, 231, 174, 215, 53, 9, 43, 153, 52, 124, 128, 65,
210, 147, 255, 147, 63, 200, 148, 254, 0, 179, 241, 42, 239, 2, 230, 8, 82,
135, 87, 16, 3, 87, 86, 151, 254, 8, 255, 86, 53, 19, 7, 192, 171, 201, 253,
247, 197, 103, 251, 126, 0, 149, 54, 183, 61, 126, 79, 113, 10, 103, 184,
75, 11, 195, 222, 136, 149, 131, 8, 99, 240, 177, 252, 255, 198, 16, 7, 68,
178, 66, 191, 150, 73, 26, 211, 109, 78, 209, 240, 254, 1, 166, 247, 131, 2,
0, 167, 127, 133, 10, 43, 99, 235, 3, 214, 142, 176, 82, 132, 38, 10, 249,
255, 215, 44, 81
],
"B": [
176, 182, 248, 37, 117, 35, 96, 69, 32, 152, 108, 20, 237, 250, 2, 89, 141,
216, 111, 251, 211, 149, 10, 44, 214, 103, 31, 251, 3, 32, 252, 246, 97, 1,
219, 167, 197, 4, 36, 116, 206, 118, 106, 43, 205, 204, 114, 69, 127, 205,
87, 80, 41, 251, 145, 204, 253, 161, 247, 1, 149, 9, 43, 253, 97, 72, 136,
161, 171, 181, 26, 255, 108, 80, 218, 214, 231, 255, 84, 31, 109, 4, 218, 3,
217, 36, 68, 85, 241, 39, 221, 2, 240, 2, 173, 42, 206, 5, 110, 46, 103, 27,
212, 184, 2, 207, 246, 45, 116, 72, 110, 253, 38, 105, 248, 159, 243, 81,
192, 93, 141, 145, 24, 157, 234, 131, 57, 178, 62, 75, 65, 176, 148, 40,
253, 66, 76, 240, 51, 154, 17, 251, 139, 253, 207, 9, 114, 49, 200, 254, 96,
73, 138, 118, 204, 102, 137, 89, 145, 161, 4, 112, 66, 234, 147, 178, 212,
205, 185, 11, 203, 131, 2, 250, 118, 169, 1, 185, 154, 53, 171, 197, 61,
175, 249, 96, 15, 254, 95, 5, 222, 75, 246, 194, 2, 61, 180, 25, 133, 165,
15, 233, 59, 35, 221, 140, 109, 7, 114, 255, 198, 0, 115, 168, 252, 23, 242,
80, 75, 142, 137, 255, 12, 182, 68, 201, 4, 111, 37, 228, 83, 248, 24, 192,
249, 5, 54, 223, 160, 122, 160, 114, 145, 119, 252, 31, 253, 250, 10, 214,
8, 47, 0, 142, 222, 70
],
"A": [
0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64
],
"I": [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172,
173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187,
188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202,
203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
248, 249, 250, 251, 252, 253, 254, 255
]
}
31 changes: 31 additions & 0 deletions scripts/malpem2niivue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import itertools
import json
from pathlib import Path
from typing import Iterator


def main():
here = Path(__file__).parent
nmm_info = here / 'data' / 'nmm_info.csv'
roi_i256 = here / 'data' / 'roi_i256.json'
output = here.parent / 'visualdataset' / 'colormaps' / 'MALP-EM.v1.3.json'

with roi_i256.open('r') as f:
cmap = json.load(f)

labels = itertools.chain(iter_nmm_labels(nmm_info), itertools.repeat('NA'))
cmap['labels'] = [label for _i, label in zip(cmap['I'], labels)]

with output.open('w') as f:
json.dump(cmap, f)


def iter_nmm_labels(p: Path) -> Iterator[str]:
with p.open('r') as f:
for line in f:
_i, _abbreviation, name, _side = line.split(',')
yield name


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion visualdataset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
|_|
"""

__version__ = '0.2.0'
__version__ = '0.2.1'
22 changes: 17 additions & 5 deletions visualdataset/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
import os.path
from argparse import ArgumentParser, Namespace, ArgumentDefaultsHelpFormatter
from pathlib import Path
from typing import Optional

from chris_plugin import chris_plugin
from pydantic import TypeAdapter

from visualdataset import DISPLAY_TITLE
from visualdataset.json_arg_parser import parse_args
from visualdataset.brain_dataset import brain_dataset
from visualdataset.options import ChrisViewerFileOptions

parser = ArgumentParser(description='Prepares a dataset for use with the ChRIS_ui '
'"Visual Datasets" feature.',
formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('--mode', type=str, default='file', choices=['file', 'string', 'freesurfer-7.3.3'],
parser.add_argument('--mode', type=str, default='file', choices=['file', 'string', 'freesurfer-7.3.3', 'malpem-1.3'],
help='File matching and option selection mode. file=accept JSON files from '
'--matchers and --options. string=accept JSON strings from --matchers and --options. '
'freesurfer=built-in support for the FreeSurfer output files.')
Expand Down Expand Up @@ -46,13 +46,25 @@ def main(options: Namespace, inputdir: Path, outputdir: Path):
first_run_files = _LIST_ADAPTER.validate_json(options.first_run_files)
first_run_tags = _DICT_ADAPTER.validate_json(options.first_run_tags)

if not first_run_files and options.mode.lower().startswith('freesurfer'):
if t1 := next(filter(os.path.isfile, inputdir.rglob('T1.mgz')), None):
first_run_files.append(str(t1.relative_to(inputdir)))
if not first_run_files:
if options.mode.lower().startswith('freesurfer'):
first_run_files.extend(find_first_matching(inputdir, 'T1.mgz'))
elif options.mode.lower().startswith('malpem'):
first_run_files.extend(find_first_matching(inputdir, '*_N4_masked.nii.gz'))
first_run_files.extend(find_first_matching(inputdir, '*_MALPEM.nii.gz'))

print(DISPLAY_TITLE, flush=True)
brain_dataset(inputdir, outputdir, matchers, tag_options, first_run_files, first_run_tags, options.readme)


def find_first_matching(input_dir: Path, glob: str) -> list[str]:
matches = filter(os.path.isfile, input_dir.rglob(glob))
rel = map(lambda p: p.relative_to(input_dir), matches)
rel_as_str = map(str, rel)
if some := next(rel_as_str, None):
return [some]
return []


if __name__ == '__main__':
main()
Loading

0 comments on commit 9ed0b1b

Please sign in to comment.