cwatson / braingraph Goto Github PK
View Code? Open in Web Editor NEWGraph theory analysis of brain MRI data
Graph theory analysis of brain MRI data
Hi Chris,
Im following your user's guide to construct a structural covariance network. Very helpful, thanks.
Unfortunately I get stuck at the 'model residuals' part, specifically:
all.dat.resids <- get.resid(lhrh, covars=covars, exclude.cov='Group')
gives an error:
Error in setkeyv(x, cols, verbose = verbose, physical = physical) : x is not a data.table
I've looked into the function, running it step by step. And it seems that the issue arises when using the melt()
function:
DT.m <- melt(DT.cov, id.vars = names(covars), variable.name = "region")
which gives a warning message:
Warning message: In melt(DT.cov, id.vars = names(covars), variable.name = "region") : The melt generic in data.table has been passed a data.frame and will attempt to redirect to the relevant reshape2 method; please note that reshape2 is deprecated, and this redirection is now deprecated as well. To continue using melt methods from reshape2 while both libraries are attached, e.g. melt.list, you can prepend the namespace like reshape2::melt(DT.cov). In the next version, this warning will become an error.
And I think this leads to the problem that DT.m
is not a data.table. Hence, when submitting it to setkey(DT.m, region, Study.ID)
, an error message is given:
Error in setkeyv(x, cols, verbose = verbose, physical = physical) : x is not a data.table
I've looked this warning up online, and it seems indeed some things have changed in using the melt()
function. I guess this needs to be adjusted in your get.resid()
function as well.
Best,
Tessa
Greetings,
I'm hoping to understand if your tool is compatible, or could be made compatible with McGill's CIVET tool.
http://www.bic.mni.mcgill.ca/ServicesSoftware/CIVET-2-1-0-Table-of-Contents
Thank you!
Hi!
What an excellent package! I stumbled upon it when a user of my own package had issues which stem from my package also exporting a dk
dataset what was conflicting with yours.
Please consider submitting this work to the Neuroconductor project. Its a great way to get R users in Neuroimaging easy access to your package :)
Hope this finds you well.
I want to introduce my tutorial on building multiple networks and save the data table to excel csv file.
Since igraph has delete the function 'as_adjacency_matrix()' and some of you may come up with this problem in your new R (for example, I used R 4.4.0), I have updated my tutorial to overcome this issue and also showed how to build networks with brainGraph (https://github.com/Clancy-wu/brainGraph_tutorial)
The steps I used:
(1) use fmriprep+xcp_d to process functinal images, get MNI bold nii.gz
(2) use qsiprep to process difussion iamges, get tck file
(3) use pearsonr to construct functional network and use sift2_invnodevol_count to construct fiber network.
(4) split the functional and fiber networks to raw network, positive network, and negative network.
(5) use brainGraph to compute network properties and save results to csv file. Note that this netowrk files are .txt format.
The brainGraph is great, but not good enough. I think that most issues of it are actually from R software, not brainGraph itself.
Hi
Thank you for providing this nice R package. I really want to use it, but I ran into some problems:
robustness(g, type = "vertex", measure = c('random'))
Error in { : task 3 failed - "Invalid vertex names"
vulnerability(g, use.parallel=TRUE, weighted=FALSE)
Error in vuln[verts] <- foreach(i = verts, .combine = "c") %d% { :
replacement has length zero
I encountered the above error on both MacOS and Windows. I read the previous discussion and it seems that the brainGraph package is best to run on Linux?
This is my net file:
PS: My installation method is: devtools::install_github('cwatson/brainGraph')
Hi Watson,
I am using my own atlas(shen278) to create a brainGraph object, however, something is going wrong.
> test_brainGraph <- make_brainGraph(test, "shen278_atlas", group = shen278_yeo17$yeo17) Error in make_brainGraph(test, "shen278_atlas", group = shen278_yeo17$yeo17) : object 'group.cols' not found
I checked the source code, and it appears that the group.cols is not defined early in the make_brainGraph() function, and meanwhile it is also not included in the internal data of the package. Is it just a color vector?
Thanks,
Zikai
@cwatson You mentioned brainGraph
was mostly developed on CentOS 6/7. I'm having a hard time trying to get pass the cairoDevice
installation in RStudio Server. I have installed GTK 2.24
along with cairo-devel
and dependencies on my CentOS 7 but it's still giving me errors below. My Ubuntu 16 didn't have this issue. Any thoughts?
R session is headless; GTK+ not initialized.
(R:25763): Gtk-WARNING **: gtk_disable_setlocale() must be called before gtk_init()
Error: package or namespace load failed for ‘cairoDevice’:
.onLoad failed in loadNamespace() for 'cairoDevice', details:
call: fun(libname, pkgname)
error: GDK display not found - please make sure X11 is running
Error: loading failed
Execution halted
Hello!
I am new to using NBS in R but have used it before with success in MatLab. I am transitioning to R for cost reasons and would like to try to stay on that platform. When I am run NBS using this code:
NBS(control_reward_filtered, irr.parent_NBS_filtered, second.col)
I receive the following error:
Error in :=
(eval(sID), seq_len(dim(covars)[1L])) :
Check that is.data.table(DT) == TRUE. Otherw
irr.parent_NBS_filtered.csv
second.col.csv
control_reward_filtered.csv
ise, := and :=
(...) are defined for use in j, once only and in particular ways. See help(":=").
When I review the error using help and online it suggests there might be a corruption in the newest version of data.table and I need to revert to an old version. Is there a way to run the NBS package by calling an old version of data.table?
Attaching files called in this code as examples.
Hi. Thank you for this great package. I've successfully run "set_brainGraph_attr" and
"dt.G <- rbindlist(lapply(g, graph_attr_dt))".
But I have trouble getting the output from
"dt.V <- rbindlist(lapply(g, function(x)
rbindlist(lapply(x, vertex_attr_dt))))"
Error in get(g$atlas) : invalid first argument
g is a large list (7 elements), that is 7 groups I have.
I'd appreciate your help in this regard.
Thank you.
When I try to use either atlas including scgm (destrieux, dk, dkt) in import_scn, I get the following error:
Error in update_fs_names(asegfile, "aseg", exclude.subs) :
argument "exclude.subs" is missing, with no default
Even when I specifically include a subject in exclude.sub.
Hi everyone,
i have a question about structural covariance matrices analysis. Following the manual i built adjacency matrices and graphs for my structural data. At this point I would like performing statistical analysis between groups at graph and vertex level, but i have three groups (i.e 1st patient group, 2nd patient group, 3 control group). How could i perform Statistics analysis in this situation (ANOVA)? The permutation analysis I read in the manual does a comparison only between two groups. An other question is if it is possible choosing the groups to compare in the permutation analysis.
Thanks
Hi,
I am unsure if this is an appropriate ask of brainGraph.
Nevertheless, I have a list of coordinates I would like to parcellate across the DK atlas. Is this possible using brainGraph?
Best wishes,
Brandon
Thank you for providing this nice R package. I want to calculate my network (igraph) robustness and vulnerability. When I run the robustness function with degree and betweeness centrality measures, it does run fine. However, for the random argument, I always get the following error message:
Error in { : task 3 failed - "Invalid vertex names"
Any ideas on how to solve the problem? Why is it just a problem with "random" and not the other two arguments? Thank you!
This is an edge case, but where all subject IDs are numeric then those with leading zeros will be changed when imported with import_scn
.
For example "0506"
becomes "506"
because fread guesses whether columns are numeric or not based on their content. Character output is guaranteed because of as.character
, but if there are leading zeros then as.character(as.numeric(x)) != as.character(x)
.
I have a relatively simple fix, so simple I've not bothered with a PR - happy to do so if it helps.
If you add the argument colClasses=list(character = 1)
to the calls to fread (within update_fs_names
) then column 1 will always be read in as a character by data.table.
This should have no side effects as types for all other columns will be unaffected and column 1 is specified to be the freesurfer Study.ID
Hi,
I am new to the brainGraph. I've gotten stuck at "make_brainGraphList", and hope you could give me some suggestions. The error reads
"r in { :
task 1 failed - "Length of new attribute value must be 1 or 84, the number of target vertices, not 0"
The input matrices are symmetric with 0 in the diagonal, each one is 84 by 84, totally 210. I am using a custom atlas (modified from dk atlas).
Attached are the scripts, one of the the connectivity matrices, and the atlas rda file.
Thank you.
Ping
brainGraph_files.zip
Hi, thanks for the great package and detailed documents. I'm working with rs-fmri functional connectivity matrices. I've successfully make brainGraphList with 10 thresholds, and saved g/g.group.rds. But something wrong when creating vertex measures:
dt.V <- rbindlist(lapply(g, vertex_attr_dt))
Error in colnamesInt(x, neworder, check_dups = FALSE) :
argument specifying columns specify non existing column(s): cols[1]='density'
The graph measures rbindlist(lapply(g, graph_attr_dt))
worked fine:
I checked the documents, seems density
is the argument for structural covariance network? I guess the key of rbindlist should be threshold
. But I dont know how to fix that.
I'd appreciate your reply.
Thank you.
Hi Chris,
I am interested in using brainGraph package to access vertex roles in some igraph network I am working. My problem is I don't know what this {memb}{A numeric vector of membership indices of each vertex} means. Can I extract it from my igraph networks? Bear with me because I am a noobie at this. Thanks in advance.
Rodrigo
From my experience, I have to say that lot errors may occur at the parameter 'atlas' in make_brainGraphList.
I defined my self atlas, and I run it successfully in the Linux system. However, when I run the same code in Windows, I get error in make_brainGraphList saying "cannot find objective 'shaefer' " (I have named my atlas as shaefer). I am sure that I have load my atlas and I can see the atlas when I type it in the terminal. Also, my atlas meets your standards.
I have to say that the parameter 'atlas' really brings some difficulties to users. I suggest that in the future, maybe you can make 'atlas' as an optional parameter, so that it can be suitable for more types of data, rather than fMRI dataset. : )
Hi Chris,
If I understand the package right, brainGraph universally stores strength-type weights (i.e. larger value = stronger connections), then converts these with xfm.weights
when cost/distance type weights (larger value = weaker connection) are needed.
The efficiency
function needs the latter cost/distance type weights, but the documentation doesn't specify this.
First proposal - to clarify the documentation:
weights: Numeric vector of edge weights; if NULL (the default), and if the graph has edge attribute weight, then that will be used. To avoid using weights, this should be NA. Note: weights must be transformed such that the strongest connections have the lowest weights (see xfm.weights)
Beyond the documentation, if a user makes a weighted brainGraph and just wants to know the efficiency it's relatively natural to just run efficiency(myGraph)
. This gives the wrong answer because strength weights are used rather than distance weights. The package intended way to get efficiency measures is set_brainGraph_attr
which works fine because this function handles the conversion.
I wanted to see what you think about changing the efficiency function so expected results for a weighted brainGraph are obtained by default?
For example, have efficiency transform input weights by default, adding an argument with options from xfm.weights
, something like: weight.xfm = c("1/w", "-log(w)", "1-w", "none")
, with the "none"
option allowing a graph with pre-calculated distance weights to be passed. Then, when efficiency is called within set_brainGraph_attr
you could pass "none"
to avoid repeated transformations for the block of graph measures that use distance weights.
What do you think? Happy to help with a PR if this would be of any use.
Alternatively if it's just me that wants to do it this way I can just wrap the function :)
All the best,
Andrew
Is the any alternative link for the user link? Dropbox seems to no longer have the file.
I found all the existing atlas with .aseg (subcortical components) contains only structures can be allocated in left/right lobe.
Is there any required modification for use custom atlas with structure cannot be assign left or right? (i.e. brainstem, pons)
Should I just put 3rd value (like M for middle instead of L or R) in column? It seems empty column causes error.
Hi, thank you for developing this package! I want to create an array with all my ".mat" files but it appears this issue:
DCF_mats<- list(path= 'C:/Users/maval/OneDrive/Data_dsi/Primer_analisis_preliminar_dsi/DCF_todaslasmat')
DCF_array<- create_mats(DCF_mats, modality = "dti", algo = "deterministic")
Error in create_mats(DCF_mats, modality = "dti", algo = "deterministic") :
length(A.files) == nz is not TRUE
Hi,
When using rich_club_norm()
I get an error and a warning:
Error in seq_len(max.deg) :
argument must be coercible to non-negative integer
In addition: Warning message:
In max(V(g)$degree) : no non-missing arguments to max; returning -Inf
This is apparently due to the fact that the code calls V(g)$degree
, while it's not calculated beforehand.
Am I right? Does it have a quick fix, or I do it myself?
Hello, @cwatson. I'm trying to build several graphs of BOLD data using different atlases. The first two run with no issues (as they're both implemented in your latest version), but when I get to the third make_brainGraphList
stops and throws:
Error in { : task 1 failed - "object 'schaefer100x7' not found"
.
I found another similar issue [#4], but I still can't resolve my problem. I followed the User Guide in building the data.table atlas object (it has the required columns and then I ran it hrough as_atlas
). It is accessible in my environment and has the same name as the atlas
string object that is used as an argument for make_brainGraphList
. When I run get(atlas)
before running make_brainGraphList
, the data.table comes without any issue. I tried saving it as an .rda and then loading it again. Nothing seems to work.
When I ran the function after using debug()
, I could see that it crashes just as it reaches the foreach (%dopar%) loop; but it is so deep in the make_brainGraph
method, that I don't know how to fix it myself.
Any help would be greatly appreciated.
As discussed in this Stack Overflow question, brainGraph::efficiency()
uses igraph::distance
to calculate distance matrices.
When the number of vertices is large, this can easily eat up all of the memory of a local machine.
A solution that @cwatson proposed on SO is to run the calculation in parallel for sufficiently large graphs. I'm unsure of where to draw this line.
Moreover, since even parallel calculations can easily eat up memory and take hours to solve, I want to add that the best way to approach this might be to throw an error that prompts the user to either:
parallel_efficiency()
) orTRUE
evaluates the problem via {doParallel}, and uses 1/2 the cores by default, or by the number of cores specified in a cores
argumentHi, thanks for developing this great R package! I have an issue running the script "brainGraph_permute", in particular when running the script the output is:
error in { task 3 "atlas name "Gordon333dil" not found
I followed all the previous steps in the guide to build a custom atlas, successfully because all previous analysis and graph building were fine and correct. Also the bootstrapping was ok, but wen i run this command:
brainGraph_permute(densities, all.dat.resids, perms = myPerms, level = "graph", atlas=atlas)
the output is the error i mentioned above.
In my Global Env Var there are either ATLAS variable (character one "gordon333dil") and the gordon333dil (that is the data.table of my custom atlas).
Do you have any suggestion?
Thanks
@cwatson I've followed the User Guide Section 2.4 on generating my own atlas and saving it to a .rda
file.
However, when calling it from set_brainGraph_attr
, the atlas data table is loaded by eval(parse(text=atlas))
where only predefined atlases could be loaded but not user defined atlases. Setting up working directory to point to the user's atlas setwd()
didn't work as well. Seems like it needs to be in the NAMESPACE
or environment()
path.
Any suggestions on how to get around this? Thanks!
Dear Chris!!
when I ran the code below, I got this error.
I think the part of "graph_from_adjacency_matrix" was ok. I got the list of iGraph class object.
but "set_brainGraph_attr" was the problem where I got an error.
is there any thoughts or comments? what am I getting this error??
Please help me out!!!
atlas <- "aal116"
modality <- "fmri"
allg <- apply(allmats, 1, function(sub) {
g <- graph_from_adjacency_matrix(sub, mode="undirected", weighted=TRUE, diag=FALSE)
g <- set_brainGraph_attr(g, atlas = atlas, modality = modality)
return(g)
})
Error in { : task 1 failed - "argument is of length zero"
In addition: Warning message:
executing %dopar% sequentially: no parallel backend registered
Called from: e$fun(obj, substitute(ex), parent.frame(), e$data)
Browse[1]>
@cwatson
Appreciate your effort on this package and releasing it to others! Do you have any guidelines on how others can help contribute?
I followed the brainGraph user guide for version 3.0.0., but when I get to the make_brainGraphList command I get the following error:
Error in { : task 1 failed - "invalid 'length.out' value"
This is a sample of the adjacency matrices
adjmats.zip
Could you help fix this error?
HI Chris,
I am wondering whether plot function can help plot same group ROIs in same colour based on coordinates. Here is the example data. The first three are coordinate and the last column is the group.
Thanks~
`
x | y | z | group | |
---|---|---|---|---|
0 | -34.0239520958084 | -40.1017964071856 | -22.0059880239521 | 3 |
1 | -36.3230769230769 | -55.6 | -18.4307692307692 | 2 |
2 | -26.0408163265306 | -45.0612244897959 | -13.8163265306122 | 3 |
3 | -28.6739926739927 | -35.9267399267399 | -14.8791208791209 | 3 |
4 | -28.3012048192771 | -62.1927710843374 | -13.2289156626506 | 3 |
5 | -35.7305699481865 | -70.6113989637306 | -16.1554404145078 | 2 |
6 | -44.876404494382 | -69.8089887640449 | -13.7752808988764 | 3 |
7 | -24.3027888446215 | -58.2709163346614 | -8.95617529880478 | 1 |
8 | -22.3983050847458 | -74.8305084745763 | -9.33050847457627 | 3 |
9 | -40.9387755102041 | -78.9387755102041 | -13.8639455782313 | 2 |
10 | -18.75 | -36.2166666666667 | -12.55 | 3 |
11 | -24.23598820059 | -85.9233038348082 | -15.4749262536873 | 2 |
12 | -21.3461538461538 | -49.4487179487179 | -6.41025641025641 | 3 |
13 | -39.136 | -86.752 | -15.936 | 1 |
`
Hi,
I can not load the brainGraph sucessfully.
I had tried to reinstall R to 3.6.1, and all packages.
However, it can not solve the problem.
I guess the problem might because "mediation" package has deleted the "summary.mediate" object, while your packkage still use the name not available now.
-lzy
I've gotten some connectivity matrices from ExploreDTI using the AAL atlas. These were originally .mat files, I 've converted them into .csv files. I tried to do a create_mats, but I end up with the following error:
Error in scan(x, what = numeric(0), n = Nv * ncols, quiet = TRUE) :
scan() expected 'a real', got '"","CM.1","CM.2","CM.3","CM.4","CM.5","CM.6","CM.7","CM.8","CM.9","CM.10","CM.11","CM.12","CM.13","CM.14","CM.15","CM.16","CM.17","CM.18","CM.19","CM.20","CM.21","CM.22","CM.23","CM.24","CM.25","CM.26","CM.27","CM.28","CM.29","CM.30","CM.31","CM.32","CM.33","CM.34","CM.35","CM.36","CM.37","CM.38","CM.39","CM.40","CM.41","CM.42","CM.43","CM.44","CM.45","CM.46","CM.47","CM.48","CM.49","CM.50","CM.51","CM.52","CM.53","CM.54","CM.55","CM.56","CM.57","CM.58","CM.59","CM.60","CM.61","CM.62","CM.63","CM.64","CM.65","CM.66","CM.67","CM.68","CM.69","CM.70","CM.71","CM.72","CM.73","CM.74","CM.75","CM.76","CM.77","CM.78","CM.79","CM.80","CM.81","CM.82","CM.83","CM.84","CM.85","CM.86","CM.87","CM.88","CM.89","CM.90"'
Dear Watson,
I learned much from your package and this hepls me a lot, so I should say much thanks to you.
I used to choose GRETNA (a tool for graph theory analysis in matlab, born at year 2013) for my work, but it really out of date for lacking various analysis models.
When I knew about your BrainGraph, I realized that this is what I really want which would meet with all requirements of my work at present. However, I have some suggestions for this version of manual and package, and I hope these points could help you to develp a better future version.
Best wish,
Yours Sincerely,
Kang Wu
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.