Skip to content

no parcellation for GLM with Freesurfer. #343

Description

@knutj
  • What are you trying to do?
    I am trying to run GLM on Freesurfer mgh and get out parcellation for each p-values after FDR
  • If you've tried running this with BrainSpace code already, how did you do so and what went wrong?
    I used the example and use fsaverage ad template and used SurfStatReadSurf1 to read in mgh.
  • Please tell us about your computing environment:
    Matlab 2022b and Ubuntu 22.04
  • Other information
    The tutorial lack example that used matlab.

Activity

  1. knutj commented on Mar 17, 2023

    @knutj
    Author

    Can you also please add Desikan-Killiany Atlas from Freesurfer to fetch parcellation.

  2. zihuaihuai commented on May 4, 2026

    @zihuaihuai
    Collaborator

    Hi @knutj — a couple of things bundled here, let me address them separately.

    1. GLM on FreeSurfer .mgh data with parcellation output (MATLAB). You can use BrainStat's MATLAB stack directly; the input just needs to be an n_subjects × n_vertices matrix on fsaverage (or whichever template you used). Rough sketch:

    % Load thickness for each subject onto fsaverage
    Y = zeros(numel(subjects), 327684); % both hemispheres, fsaverage
    for i = 1:numel(subjects)
        [lh, ~] = SurfStatReadData1(fullfile(subjects{i}, 'surf', 'lh.thickness.fsaverage.mgh'));
        [rh, ~] = SurfStatReadData1(fullfile(subjects{i}, 'surf', 'rh.thickness.fsaverage.mgh'));
        Y(i, :) = [lh; rh]';
    end
    
    % Build the model
    age   = FixedEffect(tbl.age);
    sex   = FixedEffect(tbl.sex);
    group = FixedEffect(tbl.group);
    M     = 1 + age + sex + group;
    contrast = tbl.group == 'patient';
    
    % Fit, with FDR correction
    slm = SLM(M, contrast, 'surf', 'fsaverage', 'correction', {'fdr'});
    slm.fit(Y);
    
    % Per-vertex p-values are in slm.Q. To roll them up to a parcellation:
    parc = fetch_parcellation('fsaverage', 'schaefer', 400);  % or 'aparc' for DK
    roi_mean_p = accumarray(parc(parc>0), slm.Q(parc>0), [], @mean);

    The "parcellation for each p-value" part isn't a built-in helper — you aggregate the per-vertex slm.Q (FDR-corrected) over whichever parcellation you load.

    2. Adding the Desikan–Killiany (aparc) atlas to fetch_parcellation. Reasonable ask; today fetch_parcellation ships Schaefer / Glasser / Yeo / economo. DK is already on fsaverage as ?h.aparc.annot so it would be a small loader addition rather than a new download. PRs welcome — the relevant function is brainstat.datasets.parcellation.fetch_parcellation (Python) and fetch_parcellation.m in the MATLAB tree.

    3. MATLAB tutorial gap. Confirmed — the Sphinx tutorials are Python-only; MATLAB users currently have to translate by reading the function help. A short MATLAB walkthrough alongside the Python ones would be a useful addition; happy to take PRs.

  3. added
    DocumentationImprovements or additions to documentation
    MATLABOn the MATLAB implementation
    questionFurther information is requested
    on May 4, 2026
  4. zihuaihuai commented on May 4, 2026

    @zihuaihuai
    Collaborator

    Partially addressed in #380: fetch_parcellation(template, "destrieux", ...) now returns the FreeSurfer aparc.a2009s parcellation via nilearn (fsaverage5 native; other fsaverage templates resampled nearest-neighbour). The original ask also included aparc/Desikan-Killiany; that one needs a hosted .annot file, so it's left as a follow-up tracked here. The MATLAB-tutorial gap from your third point is still open and would be a useful contribution.

  5. added a commit that references this issue on May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationImprovements or additions to documentationMATLABOn the MATLAB implementationquestionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions