@yibeichan/claude-skills 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +98 -0
  3. package/cli.js +272 -0
  4. package/install.py +240 -0
  5. package/package.json +44 -0
  6. package/skills/bidsapp-nidm-standards/SKILL.md +202 -0
  7. package/skills/bidsapp-nidm-standards/references/babs_config.md +20 -0
  8. package/skills/bidsapp-nidm-standards/references/cli_arguments.md +76 -0
  9. package/skills/bidsapp-nidm-standards/references/container_patterns.md +53 -0
  10. package/skills/bidsapp-nidm-standards/references/nidm_integration.md +403 -0
  11. package/skills/bidsapp-nidm-standards/references/repo_structure.md +121 -0
  12. package/skills/bidsapp-nidm-standards/references/testing_patterns.md +82 -0
  13. package/skills/dicom2fmriprep/SKILL.md +377 -0
  14. package/skills/dicom2fmriprep/evals/evals.json +26 -0
  15. package/skills/dicom2fmriprep/references/babs-details.md +407 -0
  16. package/skills/dicom2fmriprep/references/fmriprep-details.md +250 -0
  17. package/skills/dicom2fmriprep/references/heudiconv-details.md +243 -0
  18. package/skills/fmri-ssm/SKILL.md +317 -0
  19. package/skills/fmri-ssm/references/code_templates.md +1570 -0
  20. package/skills/fmri-ssm/references/downstream_analysis.md +680 -0
  21. package/skills/fmri-ssm/references/group_inference.md +608 -0
  22. package/skills/fmri-ssm/references/hrf_modeling.md +447 -0
  23. package/skills/fmri-ssm/references/model_catalog.md +436 -0
  24. package/skills/fmri-ssm/references/paradigm_guide.md +406 -0
  25. package/skills/fmri-ssm/references/preprocessing.md +614 -0
  26. package/skills/fmri-ssm.zip +0 -0
  27. package/skills/neuroimaging-qc/SKILL.md +203 -0
  28. package/skills/neuroimaging-qc/references/eeg_qc.md +400 -0
  29. package/skills/neuroimaging-qc/references/fmri_qc.md +343 -0
  30. package/skills/neuroimaging-qc/references/fnirs_qc.md +430 -0
  31. package/skills/neuroimaging-qc/references/structural_qc.md +454 -0
  32. package/skills/neuroimaging-qc/scripts/parse_fmriprep_confounds.py +153 -0
  33. package/skills/neuroimaging-qc/scripts/parse_mriqc.py +114 -0
  34. package/skills/neuroimaging-qc/scripts/qc_report.py +295 -0
  35. package/skills/scientific-writer/SKILL.md +202 -0
  36. package/skills/scientific-writer/references/citation_styles.md +163 -0
  37. package/skills/scientific-writer/references/field_conventions.md +245 -0
  38. package/skills/scientific-writer/references/figures_tables.md +225 -0
  39. package/skills/scientific-writer/references/reporting_guidelines.md +225 -0
  40. package/skills.json +54 -0
@@ -0,0 +1,406 @@
1
+ # Paradigm-Specific Guidance for SSMs in fMRI
2
+
3
+ ## Table of Contents
4
+ 1. [Resting State](#resting-state)
5
+ 2. [Task-Based: General Principles](#task-general)
6
+ 3. [Task-Based: MID (Monetary Incentive Delay)](#mid)
7
+ 4. [Task-Based: SST (Stop-Signal Task)](#sst)
8
+ 5. [Task-Based: N-back (Working Memory)](#nback)
9
+ 6. [Task-Based: Other Common Tasks](#other-tasks)
10
+ 7. [Naturalistic: Movie/TV Watching](#movie)
11
+ 8. [Naturalistic: Video Gaming](#gaming)
12
+ 9. [Cross-Paradigm Considerations](#cross-paradigm)
13
+
14
+ ---
15
+
16
+ ## 1. Resting State {#resting-state}
17
+
18
+ ### What SSMs reveal
19
+ Resting-state SSMs identify recurring patterns of brain activity (states) and their temporal
20
+ dynamics (transitions, dwell times, sequencing). The dominant finding across the literature is
21
+ that resting-state BOLD data visits a small number of recurring functional connectivity patterns,
22
+ with dwell times on the order of seconds to tens of seconds.
23
+
24
+ ### Recommended models
25
+ **First choice: Gaussian HMM** — The workhorse of resting-state SSM analysis. States are
26
+ defined by mean activation and/or functional connectivity patterns.
27
+
28
+ **When dynamics matter: HMM-MAR** — If you care about how temporal dynamics (spectral content,
29
+ directed connectivity) differ between states, not just spatial patterns.
30
+
31
+ **When K is uncertain: Sticky HDP-HMM** — Learns the number of states from data.
32
+
33
+ **For continuous dynamics: SLDS** — When you want smooth latent trajectories rather than
34
+ discrete state assignments.
35
+
36
+ ### Key considerations
37
+
38
+ **Number of states:** Most resting-state HMM studies use K=4-12. The "right" K depends on
39
+ data quality, scan length, and the granularity of states you care about. Low K (3-5) gives
40
+ broad network states (e.g., visual, default mode, frontoparietal). Higher K (8-12) gives
41
+ finer sub-states within networks. Above K=12, states often become unstable or very brief.
42
+
43
+ **Scan length matters:** For a K-state HMM with full covariance on p ROIs, you need roughly
44
+ K × p × (p+1)/2 data points for stable covariance estimation. A 10-minute scan at TR=0.8s
45
+ gives ~750 TRs. With 100 ROIs and K=6, that's tight. Solutions: use diagonal covariance,
46
+ reduce dimensionality (ICA to 15-25 components), or pool across runs/sessions.
47
+
48
+ **Stationarity within runs:** Most resting-state HMMs assume the transition matrix is
49
+ stationary within a run. If you expect non-stationary dynamics (e.g., drowsiness increasing
50
+ over the scan), consider time-varying transition probabilities or splitting long runs.
51
+
52
+ **Eyes-open vs. eyes-closed:** This affects state definitions substantially. Document and
53
+ control for it. If mixing, include it as a covariate or analyze separately.
54
+
55
+ **Drowsiness/arousal:** Participants often become drowsy during long resting scans. This
56
+ creates drift in brain state dynamics that is not intrinsic resting-state dynamics. Consider
57
+ monitoring arousal (eye tracking, EEG alpha power if available) or using concurrent
58
+ physiological recordings. Drowsiness-related states can dominate the HMM if not accounted for.
59
+
60
+ ### Typical pipeline
61
+ 1. Preprocess with fMRIPrep + XCP-D (see `preprocessing.md`)
62
+ 2. Parcellate (Schaefer 100-400) or ICA (15-50 components)
63
+ 3. Z-score each region/component within each run
64
+ 4. Concatenate runs (respecting run boundaries — reset forward algorithm)
65
+ 5. Fit Gaussian HMM with K=4-12, full or diagonal covariance
66
+ 6. Run 50+ random restarts with K-means initialization
67
+ 7. Model selection via BIC or cross-validated log-likelihood
68
+ 8. Validate: check state spatial maps, dwell time distributions, test-retest reliability
69
+
70
+ ---
71
+
72
+ ## 2. Task-Based: General Principles {#task-general}
73
+
74
+ ### What SSMs add beyond GLM
75
+ Standard GLM analysis asks: "Which regions activate during condition X?" SSMs ask: "What
76
+ latent states does the brain traverse during this task, and how do task events influence
77
+ state dynamics?" SSMs can reveal: states that don't correspond 1:1 to task conditions
78
+ (e.g., preparation, error monitoring, mind-wandering during task), individual differences
79
+ in state transition dynamics, and how brain states predict behavior on a trial-by-trial basis.
80
+
81
+ ### Unique considerations for task data
82
+
83
+ **HRF alignment is critical.** Task events happen at known times. If your SSM should recover
84
+ these events, you must account for the HRF delay. See `hrf_modeling.md` for approaches.
85
+
86
+ **Task structure provides validation.** Unlike resting state, you can check whether inferred
87
+ states align with known task conditions. If your 3-state HMM on an N-back task doesn't show
88
+ states that correlate with 0-back vs. 2-back blocks, something may be wrong.
89
+
90
+ **Event-related vs. block design:**
91
+ - Block designs: long, sustained states (~15-30s). HRF has time to reach steady state within
92
+ blocks. SSMs are straightforward — states should roughly correspond to blocks.
93
+ - Event-related designs: brief events (~1-5s) with variable ISI. Much more challenging for
94
+ SSMs because HRF smears rapid transitions. Deconvolution or HRF-aware modeling is often needed.
95
+
96
+ **Covariates to consider:**
97
+ - Task timing (onsets, durations) — enter into transition model or use for initialization
98
+ - Behavioral measures (RT, accuracy) — can be modeled as emissions or used for validation
99
+ - Condition type — for IO-HMM, enter as input to transition model
100
+ - Block number or run number — for fatigue/learning effects
101
+
102
+ ### Model choice for task data
103
+ - **Gaussian HMM**: States = different activation patterns for different task conditions
104
+ - **IO-HMM**: Task events drive state transitions (most principled for task data)
105
+ - **SLDS with inputs**: Task events influence continuous latent dynamics
106
+ - **HMM-MAR**: If you care about how directed connectivity changes with task conditions
107
+
108
+ ---
109
+
110
+ ## 3. MID — Monetary Incentive Delay Task {#mid}
111
+
112
+ ### Task structure
113
+ - Cue phase (~2s): signals upcoming reward/loss/neutral trial
114
+ - Anticipation phase (variable delay, ~2-4s): waiting for target
115
+ - Target phase (~0.5s): button press required
116
+ - Feedback phase (~1.5s): outcome displayed
117
+ - ITI: variable (~2-8s)
118
+
119
+ ### SSM considerations
120
+
121
+ **Expected states:** A well-fitting SSM might recover:
122
+ - Baseline/rest state (ITI)
123
+ - Reward anticipation state (after reward cue, during delay)
124
+ - Loss anticipation state (after loss cue)
125
+ - Motor preparation/execution state (around target)
126
+ - Reward feedback state
127
+ - Loss feedback state
128
+
129
+ **HRF challenge:** MID has rapid phase transitions (cue → anticipation → target → feedback)
130
+ within a single trial (~6-10s total). The HRF from the cue is still evolving when feedback
131
+ occurs. This overlap makes it very difficult to resolve individual phases with SSMs on BOLD.
132
+
133
+ **Recommended approaches:**
134
+ 1. **Phase-level analysis:** Model each trial phase as a separate condition. Use IO-HMM with
135
+ phase onsets (HRF-convolved) as inputs to the transition model.
136
+ 2. **Condition-level analysis (simpler):** Collapse across trial phases, model reward vs. loss
137
+ vs. neutral as states. Better SNR but loses within-trial dynamics.
138
+ 3. **Deconvolve first:** If within-trial dynamics are the focus, deconvolve BOLD using known
139
+ trial timing, then fit SSM on deconvolved signal.
140
+
141
+ **Key covariates:**
142
+ - Cue type (reward magnitude: $0, $1, $5 / loss magnitude)
143
+ - Anticipation duration (variable delay)
144
+ - Behavioral performance (hit/miss)
145
+ - Reward prediction error (outcome - expected)
146
+
147
+ **Regions of interest:** Nucleus accumbens, ventral striatum, vmPFC, anterior insula, VTA.
148
+ For parcellated analyses, ensure subcortical regions are included (Schaefer + subcortical,
149
+ or Glasser parcellation with subcortex).
150
+
151
+ ---
152
+
153
+ ## 4. SST — Stop-Signal Task {#sst}
154
+
155
+ ### Task structure
156
+ - Go trials (~75%): arrow appears, press button matching direction
157
+ - Stop trials (~25%): arrow appears, followed by stop signal (auditory/visual) after
158
+ variable stop-signal delay (SSD)
159
+ - Successful stop: inhibited response
160
+ - Failed stop: button press despite stop signal
161
+
162
+ ### SSM considerations
163
+
164
+ **Expected states:**
165
+ - Baseline/fixation state
166
+ - Go processing state (stimulus encoding → response preparation → execution)
167
+ - Stop processing state (stop signal detection → response inhibition)
168
+ - Error monitoring state (after failed stops)
169
+
170
+ **Critical issue — SSRT and state timing:** The stop-signal reaction time (SSRT, typically
171
+ ~200-250ms) is much faster than fMRI resolution. You cannot resolve the go-vs-stop
172
+ "race" at the BOLD level. SSMs on SST fMRI data will capture sustained states
173
+ (blocks of mostly-go vs. blocks with more stops) rather than trial-level go/stop dynamics.
174
+
175
+ **Recommended approaches:**
176
+ 1. **Block-level analysis:** If using a blocked SST design, SSMs can capture different
177
+ states for go-blocks vs. stop-blocks.
178
+ 2. **Trial-type modeling:** Use IO-HMM where trial type (go, successful stop, failed stop)
179
+ enters as input. States reflect different cognitive modes across trial types.
180
+ 3. **Post-error dynamics:** Model how the brain state after failed stops differs from
181
+ successful stops — error monitoring and strategic adjustment.
182
+
183
+ **Key covariates:**
184
+ - Trial type (go, successful stop, failed stop)
185
+ - SSD (stop-signal delay — varies adaptively)
186
+ - RT on go trials (proxy for response caution)
187
+ - Previous trial type (post-error slowing context)
188
+
189
+ **Regions of interest:** Right inferior frontal gyrus, pre-SMA, STN (subthalamic nucleus),
190
+ caudate, anterior insula.
191
+
192
+ ---
193
+
194
+ ## 5. N-back — Working Memory Task {#nback}
195
+
196
+ ### Task structure
197
+ - Variants: 0-back (control), 1-back, 2-back, sometimes 3-back
198
+ - Stimuli: letters, faces, shapes, or other items presented sequentially
199
+ - Blocks of same n-back level (~20-30s) alternating, or mixed designs
200
+ - Button press for targets (matches) and non-targets
201
+
202
+ ### SSM considerations
203
+
204
+ **Expected states:**
205
+ - Load-dependent states: distinct states for 0-back (vigilance/perceptual matching),
206
+ 1-back (simple maintenance), 2-back (active maintenance + updating)
207
+ - Within-block states: encoding, maintenance, comparison, response
208
+ - Off-task states: mind-wandering, especially during easier conditions
209
+
210
+ **Advantages for SSMs:** N-back has clear load-dependent effects widely studied with GLM.
211
+ SSMs can reveal: how quickly subjects transition into the task state after block onset,
212
+ whether subjects maintain the task state throughout the block, and individual differences
213
+ in state stability (linked to working memory capacity).
214
+
215
+ **Recommended approaches:**
216
+ 1. **Block-level HMM:** Fit Gaussian HMM expecting states to correspond to n-back levels.
217
+ HRF-informed initialization using block onsets + ~5s delay.
218
+ 2. **IO-HMM with load as input:** Load level enters the transition model. The model
219
+ learns how load affects the probability of being in each state.
220
+ 3. **Continuous performance monitoring:** Fit HMM and examine when subjects "fall out" of
221
+ the task state — correlate with behavioral accuracy.
222
+
223
+ **Key covariates:**
224
+ - N-back level (0, 1, 2)
225
+ - Stimulus type (target vs. non-target)
226
+ - Accuracy (correct, error, miss)
227
+ - RT
228
+ - Block position (first block vs. later blocks — fatigue effects)
229
+
230
+ **Regions of interest:** DLPFC, posterior parietal cortex (IPS), ACC/pre-SMA, basal ganglia.
231
+
232
+ ---
233
+
234
+ ## 6. Other Common Tasks {#other-tasks}
235
+
236
+ ### Flanker / Stroop / Go-NoGo
237
+ Similar considerations to SST. Key SSM interest: how conflict monitoring states emerge
238
+ and how post-conflict adjustment unfolds over time. Use IO-HMM with congruency as input.
239
+
240
+ ### Gambling / Decision-Making Tasks
241
+ State inference can capture deliberation vs. impulsive choice states, risk assessment states,
242
+ and outcome processing states. Key covariate: expected value, risk level, choice RT.
243
+
244
+ ### Social Cognition (Theory of Mind, Empathy)
245
+ Tasks often use narratives or videos. Consider naturalistic approaches (Section 7-8)
246
+ if stimuli are extended. For brief vignettes, standard task approaches apply.
247
+
248
+ ### Motor Tasks (Finger Tapping, Sequence Learning)
249
+ Clean paradigm for SSM validation — motor states have well-characterized neural correlates.
250
+ Good test case for new SSM methods. HRF is relatively fast in motor cortex.
251
+
252
+ ---
253
+
254
+ ## 7. Naturalistic: Movie/TV Watching {#movie}
255
+
256
+ ### What makes naturalistic paradigms special for SSMs
257
+
258
+ 1. **Continuous, rich stimulation** — No discrete trials or blocks. Brain states emerge from
259
+ ongoing stimulus processing. SSMs are particularly well-suited because they naturally model
260
+ continuous state evolution.
261
+
262
+ 2. **Shared stimulus across subjects** — All subjects see the same movie. This enables
263
+ inter-subject state alignment: if subjects enter similar states at similar times, the
264
+ states are likely stimulus-driven rather than idiosyncratic.
265
+
266
+ 3. **Ecological validity** — Brain dynamics during movie watching may better reflect
267
+ real-world cognition than artificial tasks.
268
+
269
+ 4. **Long runs** — Movies/shows typically last 10+ minutes, providing more data per run
270
+ than many task designs. This helps estimation, especially for complex models.
271
+
272
+ ### Recommended models
273
+
274
+ **Gaussian HMM** — Standard first pass. States capture spatial patterns of activation/FC
275
+ during different types of content (dialogue, action, emotional scenes).
276
+
277
+ **HMM-MAR** — Captures changes in temporal dynamics. Useful for distinguishing states with
278
+ similar spatial patterns but different spectral content (e.g., sustained attention during
279
+ slow dialogue vs. rapid processing during action sequences).
280
+
281
+ **Hierarchical HMM** — Natural fit for movie paradigms where dynamics operate at multiple
282
+ timescales: fast states (seconds, within-scene dynamics) nested within slow states
283
+ (minutes, narrative segments).
284
+
285
+ **IO-HMM with stimulus features** — Use extracted movie features (optical flow, audio energy,
286
+ face presence, semantic content) as inputs to model stimulus-driven state transitions.
287
+
288
+ ### Stimulus annotation
289
+
290
+ For IO-HMM or supervised validation, annotate the stimulus:
291
+
292
+ | Feature | How to extract | Temporal resolution |
293
+ |---------|---------------|-------------------|
294
+ | Scene cuts | Shot boundary detection (e.g., PySceneDetect) | Event-level |
295
+ | Optical flow | OpenCV/DeepFlow | Frame-level → TR-average |
296
+ | Audio energy (RMS) | librosa | Frame-level → TR-average |
297
+ | Speech presence | Voice activity detection | Frame-level → TR-average |
298
+ | Facial presence | Face detection (MTCNN, RetinaFace) | Frame-level → TR-average |
299
+ | Emotional valence | Manual annotation or sentiment models | Scene-level |
300
+ | Semantic content | Manual annotation, word embeddings | Varies |
301
+
302
+ Downsample all features to TR resolution before entering as SSM covariates.
303
+
304
+ ### Key considerations
305
+
306
+ **Inter-subject consistency:** A hallmark analysis for movie-watching SSMs is inter-subject
307
+ state synchrony. If many subjects are in the same state at the same time, those states are
308
+ stimulus-driven. Low synchrony may indicate idiosyncratic processing or mind-wandering.
309
+
310
+ ```python
311
+ def state_synchrony(all_subjects_states, n_states):
312
+ """Compute inter-subject state synchrony at each time point.
313
+
314
+ Parameters
315
+ ----------
316
+ all_subjects_states : array, shape (n_subjects, T)
317
+ State assignments per subject
318
+ n_states : int
319
+
320
+ Returns
321
+ -------
322
+ synchrony : array, shape (T,)
323
+ Proportion of subjects in the modal state at each time point
324
+ """
325
+ T = all_subjects_states.shape[1]
326
+ synchrony = np.zeros(T)
327
+ for t in range(T):
328
+ state_counts = np.bincount(all_subjects_states[:, t], minlength=n_states)
329
+ synchrony[t] = state_counts.max() / all_subjects_states.shape[0]
330
+ return synchrony
331
+ ```
332
+
333
+ **HRF for naturalistic:** Generally fit on BOLD directly (Approach 1). Naturalistic stimuli
334
+ are continuous, so there is no clear event onset to deconvolve against. States at the BOLD
335
+ timescale (5-30 seconds) are the natural unit of analysis and correspond to cognitively
336
+ meaningful epochs (scene segments, emotional beats).
337
+
338
+ **Specific movies/shows with existing benchmarks:**
339
+ - Forrest Gump (studyforrest.org): extensive annotations, multi-modal neuroimaging
340
+ - The Grand Budapest Hotel: used in multiple HMM studies
341
+ - Sherlock (Chen et al., 2017): recall paradigm with event segmentation data
342
+ - Friends (sitcom): used in Courtois NeuroMod and other datasets
343
+ - Raiders of the Lost Ark: classic for ISC analyses
344
+
345
+ ---
346
+
347
+ ## 8. Naturalistic: Video Gaming {#gaming}
348
+
349
+ ### Unique aspects of gaming for SSMs
350
+
351
+ 1. **Active participation** — Unlike movies, the subject is making decisions and acting.
352
+ Brain states are not purely stimulus-driven but reflect the subject's strategy, attention,
353
+ and motor planning.
354
+
355
+ 2. **Dynamic environments** — Game state changes based on player actions, creating a
356
+ closed-loop system. The SSM ideally models the brain-game feedback loop.
357
+
358
+ 3. **High temporal variability** — Action games have rapid state transitions. Strategy
359
+ games may have sustained deliberation states. The temporal structure depends on genre.
360
+
361
+ 4. **Rich behavioral data** — Button presses, game state, performance metrics are available
362
+ at high temporal resolution, providing excellent covariates and validation targets.
363
+
364
+ ### Recommended approaches
365
+
366
+ **IO-HMM with game-state features:** Use game telemetry (player position, health, enemies
367
+ visible, score changes, difficulty) as inputs to the transition model.
368
+
369
+ **Behavioral prediction from states:** Fit HMM on brain data, then predict upcoming
370
+ button presses or game performance from inferred states. If brain states predict behavior
371
+ above chance, they're capturing something meaningful.
372
+
373
+ **State-action mapping:** For each brain state, characterize the distribution of player
374
+ actions. This reveals the cognitive strategies associated with each state.
375
+
376
+ ### Challenges
377
+
378
+ - **Motion artifacts:** Active gaming involves more head motion than passive viewing.
379
+ Aggressive motion correction is essential. See `preprocessing.md`.
380
+ - **Non-stationarity:** Player behavior changes as they learn the game. Consider
381
+ time-varying models or segmenting by game phase (early, mid, late).
382
+ - **Controller artifacts:** Button presses and controller movements can cause small head
383
+ movements. Include button-press regressors in confound regression.
384
+ - **Variable trial structure:** Unlike traditional tasks, gaming has no fixed trial structure.
385
+ This is both a feature (ecological validity) and a challenge (no ground truth for validation).
386
+
387
+ ---
388
+
389
+ ## 9. Cross-Paradigm Considerations {#cross-paradigm}
390
+
391
+ ### Comparing states across paradigms
392
+ If the same subjects do both resting-state and task fMRI, you can ask: do resting-state
393
+ brain states recur during task performance? Approach: fit a group HMM on resting data, then
394
+ apply it to task data (forward algorithm only, no re-estimation) to see how task-evoked
395
+ dynamics map onto the resting-state repertoire.
396
+
397
+ ### Mixed designs (task + rest blocks)
398
+ Some designs alternate task blocks with rest blocks (e.g., N-back with interleaved rest).
399
+ SSMs naturally capture both the task states and the rest states. This is a powerful design
400
+ for validation: the SSM should recover task/rest alternation.
401
+
402
+ ### Transfer learning across paradigms
403
+ If you have limited task data but abundant resting data, consider: fit a rich model on
404
+ resting data (learning the state repertoire), then apply to task data with task-specific
405
+ transition probabilities. This leverages the resting data to define states while allowing
406
+ task data to define how states are traversed.