6
6
Using NIMADS with NiMARE
7
7
========================
8
8
9
- How to use the NeuroImaging Meta-Analysis Data Structure
10
- ` (NIMADS) <https://neurostuff.github.io/NIMADS/>`_ with NiMARE.
9
+ This example demonstrates the key functionality of the NeuroImaging Meta-Analysis Data Structure
10
+ (NIMADS) with NiMARE, including working with StudySets, annotations, coordinates, and metadata .
11
11
"""
12
+
13
+ from pprint import pprint
12
14
from requests import request
13
15
14
- from nimare .io import convert_nimads_to_dataset
15
16
from nimare .nimads import Studyset
16
17
18
+
17
19
###############################################################################
18
20
# Download Data from NeuroStore
19
21
# -----------------------------------------------------------------------------
@@ -25,32 +27,103 @@ def download_file(url):
25
27
return response .json ()
26
28
27
29
30
+ # Download a studyset and its annotation
28
31
nimads_studyset = download_file ("https://neurostore.org/api/studysets/Cv2LLUqG76W9?nested=true" )
29
32
nimads_annotation = download_file ("https://neurostore.org/api/annotations/76PyNqoTNEsE" )
30
33
31
34
32
35
###############################################################################
33
- # Load Data
36
+ # Create and Explore StudySet
34
37
# -----------------------------------------------------------------------------
35
- # Load the json files into a NiMADS Studyset object.
38
+ # Load the data into a NiMADS Studyset object and explore its contents
36
39
37
40
studyset = Studyset (nimads_studyset , annotations = nimads_annotation )
38
41
42
+ # Display basic information about the studyset
43
+ print ("\n StudySet Information:" )
44
+ print ("-" * 50 )
45
+ print (f"ID: { studyset .id } " )
46
+ print (f"Name: { studyset .name } " )
47
+ print (f"Number of studies: { len (studyset .studies )} " )
48
+ print (f"Number of annotations: { len (studyset .annotations )} " )
49
+
39
50
40
51
###############################################################################
41
- # Convert to NiMARE Dataset
52
+ # Explore Studies and Analyses
42
53
# -----------------------------------------------------------------------------
43
- # Convert the NiMADS Studyset object to a NiMARE Dataset object.
44
- # Then you can run NiMARE analyses on the Dataset object.
54
+ # Look at the first study and its analyses in detail
55
+
56
+ first_study = studyset .studies [0 ]
57
+ print ("\n First Study Details:" )
58
+ print ("-" * 50 )
59
+ print (f"Study ID: { first_study .id } " )
60
+ print (f"Title: { first_study .name } " )
61
+ print (f"Authors: { first_study .authors } " )
62
+ print (f"Publication: { first_study .publication } " )
63
+ print (f"Number of analyses: { len (first_study .analyses )} " )
64
+
65
+ # Show details of the first analysis
66
+ first_analysis = first_study .analyses [0 ]
67
+ print ("\n First Analysis Details:" )
68
+ print ("-" * 50 )
69
+ print (f"Analysis ID: { first_analysis .id } " )
70
+ print (f"Analysis Name: { first_analysis .name } " )
71
+ print (f"Number of coordinates: { len (first_analysis .points )} " )
72
+ print (f"Number of conditions: { len (first_analysis .conditions )} " )
73
+
74
+
75
+ ###############################################################################
76
+ # Working with Coordinates
77
+ # -----------------------------------------------------------------------------
78
+ # Demonstrate coordinate-based queries
79
+
80
+ # Example coordinate in MNI space
81
+ example_coord = [- 42 , - 58 , - 15 ] # MNI coordinates
82
+ print ("\n Coordinate Search Results:" )
83
+ print ("-" * 50 )
84
+ print (f"Searching near coordinate: { example_coord } " )
85
+
86
+ # Find analyses with coordinates within 10mm
87
+ nearby_analyses = studyset .get_analyses_by_coordinates (example_coord , r = 10 )
88
+ print (f"\n Found { len (nearby_analyses )} analyses within 10mm" )
89
+
90
+ # Find 5 closest analyses
91
+ closest_analyses = studyset .get_analyses_by_coordinates (example_coord , n = 5 )
92
+ print (f"\n Closest 5 analyses: { closest_analyses } " )
45
93
46
- nimare_dset = studyset .to_dataset ()
47
- nimare_dset .coordinates .head ()
48
94
49
95
###############################################################################
50
- # Directly to NiMARE Dataset
96
+ # Working with Annotations
51
97
# -----------------------------------------------------------------------------
52
- # Alternatively, you can convert the NiMADS json files directly to a NiMARE Dataset object
53
- # if you wish to skip using the nimads studyset object directly.
98
+ # Demonstrate how to work with study annotations
54
99
55
- nimare_dset_2 = convert_nimads_to_dataset (nimads_studyset , nimads_annotation )
56
- nimare_dset_2 .coordinates .head ()
100
+ print ("\n Annotation Information:" )
101
+ print ("-" * 50 )
102
+ for annotation in studyset .annotations :
103
+ print (f"\n Annotation ID: { annotation .id } " )
104
+ print (f"Annotation Name: { annotation .name } " )
105
+ print (f"Number of notes: { len (annotation .notes )} " )
106
+
107
+
108
+ ###############################################################################
109
+ # Query Metadata
110
+ # -----------------------------------------------------------------------------
111
+ # Show how to query analyses based on metadata
112
+
113
+ # Get all analyses that have a specific metadata field
114
+ metadata_results = studyset .get_analyses_by_metadata ("contrast_type" )
115
+ print ("\n Analyses with contrast_type metadata:" )
116
+ print ("-" * 50 )
117
+ pprint (metadata_results )
118
+
119
+
120
+ ###############################################################################
121
+ # Convert to NiMARE Dataset
122
+ # -----------------------------------------------------------------------------
123
+ # Convert the NiMADS Studyset to a NiMARE Dataset for further analysis
124
+
125
+ nimare_dset = studyset .to_dataset ()
126
+ print ("\n NiMARE Dataset Information:" )
127
+ print ("-" * 50 )
128
+ print ("Coordinates DataFrame Preview:" )
129
+ print (nimare_dset .coordinates .head ())
0 commit comments