brainGraph
(RRID: SCR_017260) is an
R package for performing graph theory
analyses of brain MRI data. It is most useful in atlas-based analyses (e.g., using an atlas such as
AAL,
or one from Freesurfer); however, many of
the computations (e.g., the GLM-based
functions and the network-based statistic) will work with any graph that
is compatible with igraph. The package will
perform analyses for structural covariance networks (SCN), DTI tractography
(I use probtrackx2 from FSL), and
resting-state fMRI covariance (I have used the Matlab-based DPABI
toolbox).
The package should work "out-of-the-box" on Linux systems (at least on Red Hat-based systems; i.e., CentOS, RHEL, Scientific Linux, etc.) since almost all development (and use, by me) has been on computers running CentOS 6 and (currently) CentOS 7. I have also had success running it (and did some development) on Windows 7, and have heard from users that it works on some versions of Mac OS and on Ubuntu. Please see the User Guide (mentioned below) for more details.
Many brainGraph
functions utilize multiple CPU cores. This is primarily done
via the foreach
package. Depending on your OS, you will need to install
doMC (macOS and Linux)
or doSNOW
(Windows).
I mostly use Freesurfer and FSL, but the following software packages should be suitable. Note that this is an incomplete list; any software that can output a connectivity matrix will work. Freesurfer FSL DPARSF PANDA * TrackVis
There are several brain atlases for which the data are present in brainGraph
.
Atlases containing .scgm
in the name contain both cortical and SubCortical Gray Matter (SCGM) regions.
1. dk
and dk.scgm
: Desikan-Killiany
2. dkt
and dkt.scgm
: Desikan-Killiany-Tourville
3. destrieux
and destrieux.scgm
: Destrieux
4. aal90
and aal116
: Automated Anatomical Labeling atlas
5. aal2.94
and aal2.120
: AAL-2
6. brainsuite
: Brainsuite
7. craddock200
: Craddock-200
8. dosenbach160
: Dosenbach-160
9. hoa112
: Harvard-Oxford atlas
10. lpba40
: LONI Probabilistic Brain Atlas
11. hcp_mmp1.0
: HCP-1mm
12. power264
: Power-264
13. gordon333
: Gordon-333
14. brainnetome
: Brainnetome
Some functions accept a custom.atlas
argument, so that you can analyze data that is from an atlas not present in brainGraph
.
Other atlases to be added in the future include the following (I would need specific coordinate, region name, and lobe and hemisphere information):
Shen-268
Von Economo-Koskinas
Willard-499 (see Richiardi et al., 2015)
Schaefer-400
(see Schaefer et al., 2018)
There are (primarily) two ways to install this package:
install.packages('brainGraph')
install.packages('brainGraph', dependencies=TRUE)
devtools::install_github('cwatson/brainGraph')
This should install all of the dependencies needed along with the package itself. For more details, see the User Guide (PDF link).
To set up your R session for parallel processing, you can use the following code. Note that it is different for Windows. This code should be run before any data processing. If you will always use a single OS, you can remove the unnecessary lines.
OS <- .Platform$OS.type
if (OS == 'windows') {
library(snow)
library(doSNOW)
num.cores <- as.numeric(Sys.getenv('NUMBER_OF_PROCESSORS'))
cl <- makeCluster(num.cores, type='SOCK')
clusterExport(cl, 'sim.rand.graph.par') # Or whatever functions you will use
registerDoSNOW(cl)
} else {
library(doMC)
registerDoMC(detectCores() - 1L) # Keep 1 core free
}
For example, I source the following simple script before I do any parallel processing with brainGraph
:
pacman::p_load(brainGraph, doMC)
registerDoMC(detectCores())
On some systems (e.g., macOS and Windows) it might be difficult to
install the necessary packages/dependencies for the GUI functions. Since v2.2.0
(released 2018-05-28),
the R packages RGtk2
and cairoDevice
have been changed to Suggests (i.e., they are no longer required),
so it can be installed on a "headless" server.
If you are on macOS or Windows and would like GUI functionality, please see this GitHub Gist. The comments contain more recent information. You may also need to install a few additional packages, shown here:
install.packages('gWidgets', dependencies=TRUE)
install.packages('gWidgetsRGtk2', dependencies=TRUE)
install.packages('RGtk2Extras', dependencies=TRUE)
There are a few suggested packages that may be required for certain functions:
RGtk2
and cairoDevice
: as mentioned above, these are required to use the GUIboot
: required for brainGraph_boot
Hmisc
: required for corr.matrix
ade4
: required for loo
and aop
expm
: required for communicability
and centr_betw_comm
I have a User Guide that contains extensive code examples for analyses common to brain MRI studies. I also include some code for getting your data into R from Freesurfer, FSL, and DPABI, and some suggestions for workflow organization.
The User Guide is the most complete documentation of this package. If you are a beginner using R, I encourage you to read it thoroughly. You may start with the Preface or at whichever chapter is suitable for your analyses.
There are several major changes in v3.0.0
. See the User Guide for more extensive details.
brainGraphList
objectNBS
and mtpc
To access the User Guide, a PDF is available at this link.
In addition to the extensive list of measures available in igraph, I have functions for calculating/performing:
There are several analyses based on the General Linear Model (GLM), and others that have different purposes.
There is a plotting GUI for fast and easy data exploration that will not work without data from a standard atlas (ideally to be extended some time in the future). You may use a custom atlas if you follow the same format as the other atlases in the package (see Chapter 4 of the User Guide for instructions).
For bug reports, feature requests, help with usage/code/etc., please join the Google Group brainGraph-help. You may also consult the User Guide, and you can open an issue here on GitHub.
An incomplete list of features/functionality I plan on adding to future versions:
- Longitudinal modeling (with linear mixed effects (LME) models)
- Thresholding and graph creation using the minimum spanning tree as a base
- Thresholding and graph creation for resting-state fMRI using a technique such as the graphical lasso
- Write functions to print group analysis results in xtable format for LaTeX
documents
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.