Giter Site home page Giter Site logo

sidchop / brainconn Goto Github PK

View Code? Open in Web Editor NEW
38.0 3.0 6.0 98 MB

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

R 99.83% Rez 0.17%
neuroimaging networks mri eeg meg connectivity connectivity-matrix connectomics

brainconn's People

Contributors

psychelzh avatar sidchop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

brainconn's Issues

Vignettes not installed, No layout function defined for objects of class <matrix>

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

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 in handlers[[1L]]():
! No layout function defined for objects of class

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)

brainconn3D Error: Error in edge.list[e, 1] : subscript out of bounds

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

Positive and negative scales for edges

Hey Sid!

I wanted to see if it would be possible to add in a second scale for positive and negative edges. I'm trying to replicate the scales in the figure attached.

Thanks!
Hannah

brain

Consider renaming the package

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?

Making a 11 by 11 custom atlas

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)

The output of this code:
unnamed

Rat atlas

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,

Not able to plot the connectivity

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)
image2
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.
image

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.

brainconn ignores the 'thr' optional value

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:
image
Any hint? Thanks ...

Error message: "No layout function defined for objects of class <matrix>"

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 in handlers[[1L]]():
! No layout function defined for objects of class
Run rlang::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

Compatibility with EEG/fNIRS Montage

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.
1020-wiki - merged

Convert data csv to serialised R data

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")

Label edges with weight

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."

: matrix array

I would suggest to a high reg svg for the brain background

Brainnetome Atlas

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".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.