sidchop / brainconn Goto Github PK
View Code? Open in Web Editor NEWBrainconn - an R package for visualising brain connectivity data in 2D and interactive 3D
Home Page: https://sidchop.github.io/brainconn/articles/brainconn.html
License: Other
Brainconn - an R package for visualising brain connectivity data in 2D and interactive 3D
Home Page: https://sidchop.github.io/brainconn/articles/brainconn.html
License: Other
T
and F
can be overwritten with T<-FALSE
to be nefarious.
Hey folks--I've just installed brainconn from Github on MacOS 13.6.1 with R 4.3.1. However, it seems like the vignettes directory is absent from the installed directory, and 'vignettes("brainconn")' yields a warning that the vignette was not found.
Not sure if related or not, but running an example command from the vignette produces the error "No layout function defined for objects of class ". Please see below for input and backtrace.
I have just upgraded from Catalina to Ventura, with new R and RStudio installations. I believe all dependencies are present and freshly installed, but I mention it in case it's helpful context.
Thanks,
Jeff
Run `rlang::last_trace()` to see where the error occurred. > rlang::last_trace() Error in `handlers[[1L]]()`: ! No layout function defined for objects of class --- Backtrace: ▆ 1. ├─brainconn::brainconn(...) 2. │ └─brainconn:::build_plot(...) 3. │ ├─ggraph::create_layout(graph = conmat, layout = "stress", circular = TRUE) 4. │ └─ggraph:::create_layout.default(...) 5. │ ├─rlang::try_fetch(...) 6. │ │ ├─base::tryCatch(...) 7. │ │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers) 8. │ │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]]) 9. │ │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler) 10. │ │ └─base::withCallingHandlers(...) 11. │ ├─tidygraph::as_tbl_graph(graph) 12. │ └─tidygraph:::as_tbl_graph.matrix(graph) 13. │ └─tidygraph:::guess_matrix_type(x) 14. └─base::.handleSimpleError(...) 15. └─rlang (local) h(simpleError(msg, call)) 16. └─handlers[[1L]](cnd)library(brainconn)
Loading required package: ggraph
Loading required package: ggplot2
x <- example_unweighted_undirected
brainconn(atlas ="schaefer300_n7", conmat=x, node.size = 3, view="ortho")
Error inhandlers[[1L]]()
:
! No layout function defined for objects of class
Hello,
I am excited to try your package for a figure I want to create. I've created files for a custom atlas reflecting my ROIs and a file for my connectivity matrix (both are .csv), I believe in the styles of the sample data provided in the package. I've saved the attached atlas as a data frame variable called "AllROIs", and the connectivity matrix as a data frame variable called "conns". (Both files are attached) Using these files, the 2 dimensional brainconn will work, but the 3D version will not.
Here is the version of brainconn (2D) that works:
brainconn(atlas ="AllROIs", conmat=conns, view="left", node.size = 3, node.color = "hotpink", edge.width = 2, edge.color="darkblue", edge.alpha = 0.8, all.nodes = T, show.legend = F)
And here is what I have tried entering for brainconn3D:
brainconn3D(atlas ="AllROIs", conmat=conns, edge.width = 3, edge.color = "brown", node.size = 3, d.factor = 1.3, all.nodes = T, opacity = 0.3, show.legend = F)
The 2D code works but the 3D doesn't. check_atlas() says that my atlas file should work with both brainconn and brainconn3D, and as far as I can tell both files are in the same style as the sample data.
Do you have any ideas of what could be the problem?
List_of_all_ROIs_one_analysis_2.csv
contmat_2.csv
Allow node.size
argument to be some input which does this for the user.
ggconn
implies that the tools extend the grammar of graphics, rather than use them. Further, conn
is too general for any sort of connection, something more specific to brains would help.
brainconn
?
Email from Tajwar Sultana (PhD student):
"Using "brainconn" for pictorial representation of effective connectivity between brain regions.
In our project, we are finding effective connectivity between 11 brain regions. The ROI names and their MNI coordinates are:
PCC [0 -46 23]
mPFC [3 50 -7]
Left Hippocampus (lHC) [-28 -23 -11]
Right Hippocampus (rHC) [28 -17 -14]
Left Amygdala (lAMG) [-24 -4 -19]
Right Amygdala (rAMG) [20 -5 -17]
dACC [-6 32 26]
Left Insular (lINS) [-36 14 5]
Right Insular (rINS) [36 14 5]
lDLPFC [-45 44 -1]
rDLPFC [45 44 -1]
I want to know which atlas to use in brainconn function for our 11 x 11 matrix? For example, in schaefer300_n7, there are 300 ROIs and it will accept matrix with 300 rows only. So if we use this atlas then where its ROIs information can be found and will we provide sparse matrix with our respective region's data in it?"
Response:
Thanks for reaching out. To use brainconn with a custom 11x11 atlas, you have to create a custom atlas. (see the end of this vignette: https://sidchop.github.io/brainconn/articles/brainconn.html)
Here is some code that will do this for you in r:
#load brainconn
library(brainconn)
#create custom atlas
ROI.Name <- c("PCC", "mPFC", "lHC", "rHC", "lAMG", "rAMG", "dACC", "lINS", "rINS", "lDLPFC", "rDLPFC")
x.mni <- as.integer(c(0, 3, -28, 28, -24, 20, -6, -36, 36, -45, 45))
y.mni <- as.integer(c(-46, 50, -23,-17, -4,-5,32,14,14,44,44))
z.mni <- as.integer(c(23,-7,-11,-14,-19,-17,26,5,5,-1,-1))
network <- c("PCC", "mPFC", "lHC", "rHC", "lAMG", "rAMG", "dACC", "lINS", "rINS", "lDLPFC", "rDLPFC")
custom_atlas <- data.frame(ROI.Name, x.mni, y.mni,z.mni, network)
#check atlas meets brainconn specifications
check_atlas(custom_atlas)
#create a random 11 by 11 bimary matrix (you would enter your own dcm weights here)
r <- c <- 11
random_matrix <- matrix(rbinom(r*c,1,0.5),r,c)
#plot brain
brainconn(custom_atlas, conmat = random_matrix)
Vignette is a great start, but function docs are needed too.
Add examples, params, and descriptions
Hi,
Currently, i am working with brain metabolic networks in rat and i would like to know if it's possible apply the brainncon to plot the brain connectivity data in rat atlas.
Thanks,
Hello,
I installed the package yesterday. I am trying to plot the connectivity matrix using a custom atlas, but the plot does not display the correct connection.
Here is my custom atlas
custom_atlas.csv
And here is a sample conn matrix I am trying to use
sample_exp.csv
When I run the code
brainconn(atlas = custom_atlas, conmat = con_mat, edge.color = "black",
node.color = "steelblue", labels = TRUE, label.size = 3,
all.nodes = TRUE)
I get the following result which shows a connectivity between 2 nodes which aren't even connected.
Also using any value other than 1 for weights gives me the following error
"Error in $<-.data.frame
(*tmp*
, "x", value = c(-32L, 32L, 0L, -35L, :
replacement has 19 rows, data has 1"
Even when trying to plot the same example provided on the README page, it gives me different results compared to the plot shown in the image. Here is what I get.
I am using the package for the first time, so I am not sure what am I doing wring. Any help would be appreciated.
Thank you.
maybe something like what ggseg3d is doing.
Hi, thanks for the (hopefully :-) ) great tool.
I'm trying to plot coherence adjacency matrices, generated in fieldtrip/MATLAB, and exported as .csv on a custom atlas generated as per issue #16 . Sadly it plots all the edges independently of the value of thr (tried setting it to 50%, 90%, 99% of the max).
For instance
> brainconn(bna_atlas, conmat = testcoh, view = "front", thr=0.0604)
(0.0604 being 99% of the max 0.0610, but I tried also with 100%) produces the following figure, still containing the smaller edges of values 0.02 and 0.04, see the legend:
Any hint? Thanks ...
Hello Sid,
Greetings - thanks for your great package!
Everything was working fine till today - I updated my R version (to 4.3.0) and all packages.
I now keep getting this error message, for all examples/vignettes that you've provided.
brainconn(atlas ="schaefer300_n7", conmat=example_unweighted_undirected, view="ortho")
Error inhandlers[[1L]]()
:
! No layout function defined for objects of class
Runrlang::last_trace()
to see where the error occurred.
I think there's an issue with create_layout from ggraph, which for some reason takes data.frame objects but not matrices.
I tried modifying your build_plot function, in the lines with the create_layout function, I added as.data.frame(conmat) - things worked fine after that.
Hope this is helpful!
Best regards,
Srinivas B
I was curious to know if anyone has ever tried to use this package to create a montage figure which is typically published alongside fNIRS/EEG articles.
I was hoping to import a file with a list of labeled 10-20 locations which could get mapped and labelled onto the figure. Resulting to something similar to the figure below.
This is useful for visualizations purposes, esp since some centroids in asymmetric atlas are very non-sym
use usedata() to allow users to input their own atlas and background
Use usethis::use_data_raw()
to write the script for making the package datasets, which will run usethis::use_data()
to create correct package data files.
If you want to use the CSVs themselves in examples, store it online (say on GitHub) OR include the csv in the inst folder, and access it with system.file("path", package = "ggconn")
Instead of matching text for atlas
, directly accept any user object, and then test if the column names match your expected format. Provide instructions or tools for users to learn/create their own atlases.
Hi,
since the changes one month ago, it is not possible to visualize weighted matrices. Values above 1 are not accepted.
all the best
When edge.color.weighted set to TRUE, the edge color would always be the default "blue" no matter what other colours are set.
Email request:
"Can we label arrows (connections) with their weights? In this figure, it will be cluttered but if we have less number of connections then it will look good."
I would suggest to a high reg svg for the brain background
Run devtools::check()
and resolve outstanding errors, warnings, and notes.
TODO:
usethis::use_package("pkgname")
Use testthat
via usethis::use_test()
to test your package.
Bonus points, check code coverage using covr::codecov
.
Extra bonus points, set up continuous integration using github actions - examples of automatic testing can be seen here: https://github.com/r-lib/actions/tree/master/examples
Trying to use the Brainnetome as a custom atlas. It seems to work fine except when using brainconn() with view = "ortho" (it works with the other views), and brainconn3d(), as those produce the following error: "Error in conmat[i, ] : subscript out of bounds".
load_all()
is nice for development, but not suitable for end users.
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.