### Transform BigBrain to ICBM using local installation Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/scripts.rst Example of transforming a BigBrain volume to ICBM space using a local BigBrainWarp installation. Specifies input data, spaces, interpolation, output resolution, descriptor, and working directory. ```bash # for example, transformation of a bigbrain to icbm can take the form with a local installation bigbrainwarp --in_vol data.nii --in_space bigbrain --interp trilinear --out_space icbm --out_res 0.5 --desc data --wd /project/ ``` -------------------------------- ### Install ENIGMA Pygments Style Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/enigma-pygments-style-2020.7.8.2/README.md Install the enigma-pygments-style package using pip. ```bash python -m pip install enigma-pygments-style ``` -------------------------------- ### Load Data and Initialize Paths Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/tutorial_confluence.rst Sets up the environment by defining the main directory, adding necessary scripts to the path, and loading surface coordinate and confluence data. This is the initial setup for processing the BigBrain histological axis. ```matlab micaopen = '/path/to/parent/directory/'; mainDir = [micaopen '/CorticalConfluence/']; % scripts addpath(genpath([GH '/surfstat'])) addpath(genpath([mainDir '/scripts/']) ) % load data load([mainDir 'output/hipp_right_coord.mat']); load([mainDir 'output/confluent_surface_right.mat']); ``` -------------------------------- ### Verify ENIGMA Pygments Style Installation Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/enigma-pygments-style-2020.7.8.2/README.md Verify that the 'enigmalexer' style is available in Pygments by listing all available styles. ```python >>> from pygments.styles import get_all_styles >>> list(get_all_styles()) ``` -------------------------------- ### Check mincresample version Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/FAQs.rst Verify which mincresample executable is being used to avoid errors related to minc1 vs minc2 compatibility. Ensure it points to the minc2 installation. ```bash which mincresample ``` -------------------------------- ### Transform BigBrain to ICBM using Docker Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/scripts.rst Example of transforming a BigBrain volume to ICBM space using Docker. Mounts the project directory and specifies input/output details. Note the 'mount/' prefix for input volumes and the working directory set to 'mount'. ```bash # or with the docker version - note how the working input volume is preprended with the "mount/" and the working directory is set to "mount" docker run -it --rm -v /project/:/BigBrainWarp/mount caseypaquola/bigbrainwarp \ ``` -------------------------------- ### Run BigBrainWarp without Docker Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/scripts.rst Execute BigBrainWarp directly from a local installation. ```bash # without docker bigbrainwarp ``` -------------------------------- ### Generate Staining Intensity Profiles Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/FAQs.rst Use this script to generate equivolumetric surfaces and sample staining intensities from a volume. It requires input volume, upper and lower surfaces, and the desired number of surfaces. Ensure surface_tools is installed. ```bash bash sample_intensity_profiles.sh -in_vol full8_100um_optbal.mnc -upper_surf pial_left_327680.obj -lower_surf white_left_327680.obj -wd tests -num_surf 50 ``` -------------------------------- ### Evaluate Volume-Based Transformation using evaluate_warp Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/tutorial_evaluation.rst Use the evaluate_warp function to assess the accuracy of a specified transformation. This example evaluates the Xiao et al. transformation by comparing BigBrainSym to the ICBM2009sym template. ```bash # for example, we’ll evaluate the Xiao et al., cd $bbwDir sh scripts/evaluate_warp.sh --in_space bigbrainsym --out_space icbm –warp $bbwDir/xfms/BigBrain-to-ICBM2009sym-nonlin.xfm --wd /project/ ``` -------------------------------- ### Initialize and Download Scripts Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/installation.rst Source the init.sh script to set up environment variables and then run the downloads.sh script to fetch necessary files. Ensure you are within the BigBrainWarp GitHub repository directory. ```bash # run within BigBrainWarp github repo source scripts/init.sh bash scripts/downloads.sh ``` -------------------------------- ### Restructuring Initialization Script and Docker Image Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/updates.rst This update signifies a restructuring of the initialization scripts into downloads and init, and the creation of a new stable Docker image. ```text ↪ split installation scripts into downloads and init | @caseypaquola ``` -------------------------------- ### Load and Visualize Surface Data with SurfStat Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/visualisation.rst This Matlab script demonstrates loading .obj, Freesurfer, and Gifti surface formats, along with associated data (.txt, .curv, .shape.gii). It then visualizes the loaded data using SurfStatViewData. Ensure all necessary toolboxes and directories are added to the Matlab path. ```matlab % set directories GH = '/path/to/your/github/directories/ '; bbwdDir = [GH '/BigBrainWarp/']; % add directories to path addpath(genpath([GH '/micaopen/surfstat'])); addpath([bbwdDir '/scripts/']); addpath(genpath('/path/to/gifti-1.6/')); % download from https://www.artefact.tk/software/matlab/gifti/ % 1. Load the surface % .obj BB = SurfStatAvSurf({[bbwdDir '/tpl-bigbrain/tpl-bigbrain_hemi-L_desc-pial.obj'], \ [bbwdDir '/tpl-bigbrain/tpl-bigbrain_hemi-R_desc-pial.obj']}); % Binary Freesurfer surfaces (ie: .pial, .white, .sphere etc) FS = SurfStatAvSurf({[bbwdDir '/tpl-fsaverage/tpl-fsaverage_hemi-L_desc.pial'], \ [bbwdDir '/tpl-fsaverage/tpl-fsaverage_hemi-R_desc.pial']}); % Gifti surfaces tmp_lh = gifti([bbwdDir '/spaces/tpl-fs_LR/tpl-fs_LR_hemi-L_den-32k_desc-inflated.surf.gii']); tmp_rh = gifti([bbwdDir '/spaces/tpl-fs_LR/tpl-fs_LR_hemi-R_den-32k_desc-inflated.surf.gii']); FSLR32.coord = [tmp_lh.vertices' tmp_rh.vertices']; % coord and tri are the two expected components of a SurfStat surface structure FSLR32.tri = [tmp_lh.faces; tmp_rh.faces+length(tmp_lh.vertices)]; % 2. Load the data % .txt data tmp_lh = readmatrix([bbwdDir '/spaces/tpl-bigbrain/tpl-bigbrain_hemi-L_desc-Hist_G1.txt']); tmp_rh = readmatrix([bbwdDir '/spaces/tpl-bigbrain/tpl-bigbrain_hemi-R_desc-Hist_G1.txt']); BB_G1 = [tmp_lh; tmp_rh]; % Freesurfer-style curv data tmp_lh = read_curv([bbwdDir '/spaces/tpl-fsaverage/tpl-fsaverage_hemi-L_den-164k_desc-Micro_G1.curv']); tmp_rh = read_curv([bbwdDir '/spaces/tpl-fsaverage/tpl-fsaverage_hemi-R_den-164k_desc-Micro_G1.curv']); FS_G1 = [tmp_lh; tmp_rh]; % gifti data tmp_lh = gifti([bbwdDir '/spaces/tpl-fs_LR/tpl-fs_LR_hemi-L_den-32k_desc-Hist_G1.shape.gii']); tmp_rh = gifti([bbwdDir '/spaces/tpl-fs_LR/tpl-fs_LR_hemi-R_den-32k_desc-Hist_G1.shape.gii']); FSLR32_G1 = [tmp_lh.cdata; tmp_rh.cdata]; % 3. Visualise data figure; SurfStatViewData(BB, BB_G1) figure; SurfStatViewData(FSLR32, FSLR32_G1) ``` -------------------------------- ### Run BigBrainWarp with Docker Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/scripts.rst Execute BigBrainWarp using Docker by mounting a local directory for input and output data. ```bash # with docker (change the path to the local location of the mount accordingly) docker run -it --rm -v /local/directory/with/data/:/BigBrainWarp/mount \ caseypaquola/bigbrainwarp bigbrainwarp ``` -------------------------------- ### Sample Intensity Profiles Script Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/bigbrain_background.rst This script can be used to generate your own staining intensity profiles for the BigBrain dataset. Ensure you have the necessary BigBrain volume and surface data. ```bash sample_intensity_profiles.sh ``` -------------------------------- ### Added Documentation on Variance Explained Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/updates.rst This entry notes the update to the 'Toolbox contents' page to include documentation on the approximate variance explained by each eigenvector. ```text ↪ updated "Toolbox contents" page | @caseypaquola ``` -------------------------------- ### Display MINC Volume and Overlay Surface Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/visualisation.rst This bash command opens a MINC volume file using the Display tool. Subsequent steps involve loading a surface file via the terminal and saving the combined view. ```bash Display volume_file.mnc # Click "File" then "Load File" # in the terminal /full/path/to/surface_file.obj # Return to Main Menu, Click "Objects" then "Write Object to File" ``` -------------------------------- ### Overhauled Naming Conventions and Removed Dependencies Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/updates.rst This update reflects overhauled naming conventions, changes to bigbrainwarp arguments, the addition of options for mesh density, removal of Freesurfer dependencies, and creation of a new tutorial. ```text ↪ implemented BIDS-style naming of files | @caseypaquola ↪ changed bigbrainwarp arguments, requires "desc" | @caseypaquola ↪ added option for 32k or 164k mesh for fs_LR | @caseypaquola ↪ removed Freesurfer dependencies | @caseypaquola ↪ created tutorial on evaluating transformations | @caseypaquola ``` -------------------------------- ### Overhaul of Surface Transformation Scripts Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/updates.rst This entry notes an overhaul of surface transformation scripts and documentation, utilizing multi-modal surface matching. ```text ↪ Overhaul of surface transformation scripts and documentation | @caseypaquola ``` -------------------------------- ### Added ICBM Surface and Wrapper Script Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/updates.rst This update includes the addition of the ICBM surface template, an 'out_type' option in bigbrainwarp, and a wrapper script for generating staining intensity profiles. ```text ↪ added icbm surface template from civet | @caseypaquola ↪ added out_type option in bigbrainwarp | @caseypaquola ↪ created sample_intensity_profiles.sh | @caseypaquola ``` -------------------------------- ### Configure Sphinx to Use ENIGMA Pygments Style Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/enigma-pygments-style-2020.7.8.2/README.md Configure your Sphinx project's conf.py file to use the 'enigmalexer' style for syntax highlighting. ```python # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'enigmalexer' ``` -------------------------------- ### New Method for Microstructure Profile Moments Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/updates.rst This snippet indicates the addition of a new script for calculating moments from microstructure profiles and an amendment to the communities tutorial. ```text ↪ added scripts/calculate_moments.m | @caseypaquola ↪ amended communities tutorial | @caseypaquola ``` -------------------------------- ### Volume Transformation with BigBrainWarp Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/scripts.rst Perform volume-based transformations using BigBrainWarp. Specify input/output volumes, spaces, interpolation, and resolution. ```bash bigbrainwarp --in_vol mount/data.nii --in_space bigbrain --interp trilinear --out_space icbm --out_res 0.5 --desc data --wd mount ``` ```bash bigbrainwarp --in_vol data.mnc --in_space icbm --interp sinc --out_space bigbrainsym --desc data --wd /project/ ``` -------------------------------- ### Load BigBrain Profiles and Calculate Moments Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/tutorial_communities.rst This MATLAB code loads BigBrain microstructure profiles and calculates their central moments. It requires adding MICAopen and gifti to the MATLAB path and assumes specific file paths for the BigBrain surface and profiles. The calculation can take a significant amount of time. ```matlab % add paths addpath(genpath(micaopen)) # https://github.com/MICA-MNI/micaopen/ addpath(gifti-master) # https://www.artefact.tk/software/matlab/gifti/ % load surface BB = SurfStatAvSurf({[bbwDir '/spaces/bigbrain/gray_left_327680.obj'], \ [bbwDir '/spaces/bigbrain/gray_right_327680.obj']}); lh = gifti([bbwDir '/spaces/bigbrain/' parc_name '_lh_bigbrain.label.gii']); rh = gifti([bbwDir '/spaces/bigbrain/' parc_name '_rh_bigbrain.label.gii']); parc_bb = [lh.cdata; rh.cdata]; names = [lh.labels.name rh.labels.name]; % load BigBrain profiles and calculate moments MP = 65536 - reshape(dlmread([bbwDir '/spaces/tpl-bigbrain/tpl-bigbrain_desc-profiles.txt']),[], 50)'; MPmoments = calculate_moments(MP); % caution will take ~60 minutes to run with 10 parallel workers writetable(table(MPmoments', parc_bb, 'VariableNames', {'mo', 'yeo'}), \ [projDir '/output/yeo17_moments.csv']) ``` -------------------------------- ### Pre-computed Layer Thicknesses Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/updates.rst This update includes pre-computed BigBrain layer thicknesses in '/spaces/bigbrain/' and transformed layer thicknesses in fsaverage and fs_LR. ```text ↪ Pre-computed BigBrain layer thicknesses in /spaces/bigbrain/ ↪ Transformed layer thicknesses in fsaverage and /fs_LR ``` -------------------------------- ### Run BigBrainWarp Docker Container Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/installation.rst Execute the BigBrainWarp Docker container in interactive mode. The --rm flag ensures the container is removed upon exit. ```bash docker run --rm -it caseypaquola/bigbrainwarp bash ``` -------------------------------- ### Transform BigBrain Gradients to fsaverage using BigBrainWarp Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/tutorial_gradients.rst This bash script iterates through the first two BigBrain-derived gradients and transforms them from the 'bigbrain' space to the 'fsaverage' space using BigBrainWarp. It specifies input and output paths, the output description, and the interpolation method. ```bash # run from within BigBrainWarp github repo for ii in 1 2 : do bigbrainwarp --in_space bigbrain --out_space fsaverage --wd /local/directory/for/output/ \ --in_lh spaces/bigbrain/Hist_G${i}_lh.txt \ --in_rh spaces/bigbrain/Hist_G${i}_rh.txt \ --desc Hist_G${i} \ --interp linear done ``` -------------------------------- ### Surface Transformation with BigBrainWarp Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/scripts.rst Transform surface-based data using BigBrainWarp. Supports various input/output spaces like bigbrain, fsaverage, and fs_LR. Use 'sinc' or 'linear' interpolation. ```bash bigbrainwarp --in_lh lh.data.label.gii --in_rh rh.data.label.gii --in_space bigbrain --out_space fsaverage --desc data --wd /project/ ``` ```bash docker run -it --rm -v /project/:/BigBrainWarp/mount caseypaquola/bigbrainwarp \ bigbrainwarp --in_lh mount/lh.data.label.gii --in_rh mount/rh.data.label.gii --in_space bigbrain --out_space fsaverage --desc data --wd mount ``` ```bash bigbrainwarp --in_lh lh.data.label.txt --in_rh rh.data.label.txt --in_space fs_LR --interp linear --out_space bigbrain --out_dens 32 --desc data --wd /project/ ``` -------------------------------- ### New Option for Output Resolution Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/updates.rst This entry indicates the addition of an optional 'out_res' input parameter to the bigbrainwarp function for defining output resolution for volumes. ```text ↪ added optional "out_res" input parameter to bigbrainwarp | @caseypaquola ``` -------------------------------- ### Transform Atlas to BigBrain Surface Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/tutorial_communities.rst Use the bigbrainwarp command-line tool to transform an atlas from the fsaverage space to the BigBrain surface. Ensure you provide the correct paths for input annotations and specify the output description. ```bash bigbrainwarp --in_space fsaverage --out_space bigbrain --wd /local/directory/for/output/ \ --in_lh /full/path/to/lh.Yeo2011_17Networks_N1000.annot --in_rh /full/path/to/rh.Yeo2011_17Networks_N1000.annot \ --desc Yeo2011_17Networks_N1000 ``` -------------------------------- ### Simplified BigBrainWarp Functionality Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/updates.rst This update simplifies transforming data with BigBrainWarp by introducing a base function and expanding volume-based interpolation options. ```text ↪ created bigbrainwarp base function | @caseypaquola ↪ expanded volume-based interpolation options | @caseypaquola ``` -------------------------------- ### Build MPC and Diffusion Map Embedding for BigBrain Gradients Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/tutorial_gradients.rst This MATLAB snippet demonstrates how to load BigBrain profile data, create the Microstructure Profile Covariance (MPC) matrix, calculate normalized angle similarity, and perform diffusion map embedding to generate cortical gradients. It also shows how to re-expand the gradients to the whole cortex and save them as separate left and right hemisphere files. ```matlab % BigBrain profiles MP = reshape(dlmread([bbwDir '/spaces/bigbrain/profiles.txt']),[], 50)'; % load downsampling indexing load([bbwDir '/scripts/nn_surface_indexing.mat'], 'nn_bb'); % create MPC and gradient, using functions from the micaopen github MPC = build_mpc(MP,nn_bb); normangle = connectivity2normangle(MPC, 0); [eigenvectors, results] = mica_diffusionEmbedding(normangle, 'ncomponents', 10); eigenvalues = results.lambdas/sum(results.lambdas); for ii = 1:2 Gmpc = BoSurfStatMakeParcelData(eigenvectors(:,ii), S, nn_bb); # re-expands to whole cortex using a SurfStat function (https://github.com/MICA-MNI/micaopen/) lhOut = [bbwDir '/spaces/bigbrain/Hist-G' num2str(ii) '_lh.txt']; rhOut = [bbwDir 'spaces/bigbrain/Hist-G' num2str(ii) '_rh.txt']; writematrix(Gmpc(1:end/2)', lhOut) writematrix(Gmpc((end/2)+1:end)', rhOut) end ``` -------------------------------- ### Expanded Surface Transformation Functionality Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/updates.rst This update expands surface transformation functionality to include multi-modal surface registration, parcel-based transformation, and fs_LR for vertex-based nearest neighbour interpolation. ```text ↪ Added approach option for surface based transformations | @caseypaquola ↪ Added surface option for fs_LR and fsaverage compatibility | @caseypaquola ↪ Updated documention for surface transformations | @caseypaquola ``` -------------------------------- ### Transform BigBrain Volume to ICBM152 Space Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/tutorial_confluence.rst Use this command to nonlinearly transform a BigBrain volume to ICBM152 space using specified transformation matrices. Ensure the output directory exists. ```bash bigbrainwarp --in_space bigbrain --out_space icbm --wd /local_directory/for/output/ \ --in /full/path/to/histological_axis_vox.nii \ --desc confluence \ --interp trilinear ``` -------------------------------- ### Transformed Staining Intensity Profiles Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/updates.rst This snippet indicates the addition of transformed staining intensity profiles for fs_LR and fsaverage, including files for both spaces. ```text ↪ added spaces/fs_LR/profiles_fs_LR.txt | @caseypaquola ↪ added spaces/fsaverage/profiles_fsaverage.txt | @caseypaquola ``` -------------------------------- ### Pull BigBrainWarp Docker Image Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/installation.rst Pull the latest Docker image for BigBrainWarp. This image is updated with each new release of the software. ```bash docker pull caseypaquola/bigbrainwarp:latest ``` -------------------------------- ### Cortical Gradients in Volume Space Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/updates.rst This snippet indicates the addition of Hist, Micro, and Func gradients to the '/spaces/icbm/' directory, making cortical gradients available in volume space. ```text ↪ Hist, Micro and Func gradients added to /spaces/icbm/ | @caseypaquola ``` -------------------------------- ### Load Data and Train SVM Classifier Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/tutorial_communities.rst Loads pre-processed brain network data and trains a One-vs-Rest Support Vector Classifier. This snippet is used for predicting network communities based on extracted moments. ```python # import libraries import scipy.io as io from sklearn.svm import SVC from sklearn.multiclass import OneVsRestClassifier # load data mat = io.loadmat(projDir + "output/yeo17_moments_bb.mat") X = mat["Xcv_eq"] ycv = mat["ycv_eq"] n_classes = ycv.shape[1] folds = int(X.shape[2]) obs = ycv.shape[0] # predict in each fold train_folds = 5 y_pred = np.zeros([obs,train_folds]) for i in range(0,train_folds): classifier = OneVsRestClassifier(SVC(kernel='linear')) classifier.fit(X[:,:,i], ycv[:,i]) y_pred[:,i] = classifier.predict(X[:,:,i+train_folds]) io.savemat(projDir + "output/yeo17_moments_pred_ovr.mat", {"y_pred": y_pred}) ``` -------------------------------- ### Added bigbrain-transformed Desikan-Killany Parcellation Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/updates.rst This snippet indicates the addition of the 'aparc.label.gii' file for the bigbrain-transformed Desikan-Killany parcellation and updates to tutorials. ```text ↪ added *aparc.label.gii to space/tpl-bigbrain | @caseypaquola ↪ updated tutorials in readthedocs and code examples | @caseypaquola ``` -------------------------------- ### Create Confusion Matrix in MATLAB Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/tutorial_communities.rst Loads prediction results and calculates a confusion matrix for each fold. This is used to evaluate the accuracy of the predicted brain network communities. ```matlab # back to matlab to create the confusion matrix load([projDir '/output/yeo17_moments_pred.mat']) folds = size(y_pred,2); confusion_matrix = zeros(7,7,folds); for cv = 1:folds for ii = 1:17 for jj = 1:17 confusion_matrix(ii,jj,cv) = sum(ycv_eq(:,cv+5)==ii & y_pred(:,cv)==jj)/sum(ycv_eq(:,cv+5)==ii); end end end ``` -------------------------------- ### Nearest Neighbor Assignment on Mesh Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/tutorial_gradients.rst Assigns each vertex on the original BigBrain surface to the nearest vertex on the decimated surface (BB10) using shortest path on the mesh. Ties are broken by Euclidean distance. This process ensures all original vertices are accounted for within the new parcels. ```matlab nn_bb = zeros(1,length(BB.coord)); edg = SurfStatEdg(BB); parfor ii = 1:length(BB.coord) nei = unique(edg(sum(edg==ii,2)==1,:)); if isempty(nei) && ismember(ii, bb_downsample) nn_bb(ii) = ii; else while sum(ismember(nei, bb_downsample))==0 nei = [unique(edg(sum(ismember(edg,nei),2)==1,:)); nei]; end matched_vert = nei(ismember(nei, bb_downsample)); if length(matched_vert)>1 % choose the mesh neighbour that is closest in Euclidean space n1 = length(matched_vert); d = sqrt(sum((repmat(BB.coord(1:3,ii),1,n1) - BB.coord(:,matched_vert)).^2)); [~, idx] = min(d); nn_bb(ii) = matched_vert(idx); else nn_bb(ii) = matched_vert; end end ``` -------------------------------- ### Mesh Decimation of BigBrain Surface Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/tutorial_gradients.rst Performs mesh decimation on the BigBrain surface to reduce the number of vertices while preserving the overall shape. Requires the SurfStat toolbox and BigBrainWarp directory. ```matlab addpath(genpath(bbwDir)) BB = SurfStatAvSurf({[bbwDir '/spaces/bigbrainsym/gray_left_327680_2009b_sym.obj'], \ [bbwDir '/spaces/bigbrainsym/gray_right_327680_2009b_sym.obj']}); numFaces= 20484; patchNormal = patch('Faces', BB.tri, 'Vertices', BB.coord.','Visible','off'); Sds = reducepatch(patchNormal,numFaces); [~, bb_downsample] = intersect(patchNormal.Vertices,Sds.vertices,'rows'); BB10.tri = double(Sds.faces); BB10.coord = Sds.vertices'; ``` -------------------------------- ### Create Cross-Validation Folds for Classification Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/tutorial_communities.rst This MATLAB code prepares data for a machine learning classification task by creating cross-validation folds. It aims to balance the number of samples per network for training and testing. ```matlab % create 10 folds folds = 10; n = floor(6558/folds); % set based vertices in smallest network (DMN-A: 1100) Xcv_eq = zeros(n*17,size(MPmoments,1),folds); ycv_eq = zeros(n*17,folds); for ii = 1:17 idx = randperm(sum(parc==ii),sum(parc==ii)); % random list of number the length of the network idx_net = find(parc==ii); % where is the network in the feature vector for cv = 1:folds ``` -------------------------------- ### Process Surface Coordinates and Map to Volume Source: https://github.com/caseypaquola/bigbrainwarp/blob/master/docs/pages/tutorial_confluence.rst Reshapes surface coordinates, calculates geodesic distances, converts coordinates to voxel indices based on image information, and fills a BigBrain volume with average gradient values. This process maps the histological axis from surface to volume space. ```matlab % geodesic distance from the bridgeheads, and sorting coord_mat = reshape(AllEvSurf,3,[],1); index_local = [coord_mat; reshape(repmat(bridge_dist, 16, 1),1,[])]; % convert from mm to vox % establish world coordinates based on the start, step and length from the % mincinfo full8_100um_optbal.mnc index_local = [coord_mat; reshape(repmat(bridge_dist, 16, 1),1,[])]; index_global = []; index_global(1,:) = round((index_local(1,:) + 71.66)); index_global(2,:) = round((index_local(2,:) + 72.97)); index_global(3,:) = round((index_local(3,:) + 59.7777)); % remove coordinates outside the confluence index_global(4,:) = index_local(4,:); index_global(:,index_local(4,:)==0) = []; % find unique and fill [uc, ~, ic] = unique(index_global(1:3,:)', 'rows'); data = nan(140, 154, 121); for ii = 1:length(uc) data(uc(ii,1)-1:uc(ii,1)+1,uc(ii,2)-1:uc(ii,2)+1,uc(ii,3)-1:uc(ii,3)+1) = mean(index_global(4,ic==ii)); end info = niftiinfo([mainDir '/full8_1000um_optbal.nii']); info.Datatype = 'double'; niftiwrite(data,[mainDir '/bigbrain_axis_vox.nii'],info); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.