Custom atlas error

196 views
Skip to first unread message

Caitlin Lloyd

unread,
Nov 5, 2020, 11:56:26 AM11/5/20
to brainGraph-help
Hi Chris,

Thank you for this wonderful resource!

I am hoping to use it with connectivity matrices generated by MRtrix, which used the Freesurfer DK atlas, but in a different order to usual (and to that specified in the preloaded atlas of brainGraph). I am have modified the dk atlas accordingly, to create 'custom.atlas', and am trying to create the brainGraph list object, however am getting the persistent error 

{ : task 1 failed - "object 'atlas.own' not found

when running

g <- vector('list', length(thresholds))
g.group <- vector('list', length(thresholds))
for (j in seq_along(thresholds)) {
g[[j]] <- make_brainGraphList(A.norm.sub[[j]], atlas='atlas.own', modality=modality,
                                weighting='sld', threshold=thresholds[j],
                                weighted=TRUE, gnames=covars.dti$C_ID, grpNames = covars.dti$Group)
  g.group[[j]] <- make_brainGraphList(A.norm.mean[[j]], 'atlas.own', modality=modality, weighting='sld', threshold=thresholds[j], weighted=TRUE, gnames=grps)
}

I have followed previous threads to make sure all variables are formatted as they should be, and that the array is set as a data.table as not data.frame. I don't think it is an issue with the connectivity matrices themselves, or not setting the grps variables etc, since if I specify a different atlas (e.g. 'dk') it works fine.

I wondered whether you might have some thoughts on what to try next?

Thank you very much!

Caitlin

Chris Watson

unread,
Nov 5, 2020, 12:04:17 PM11/5/20
to brainGr...@googlegroups.com
Do you have a variable called "atlas.own" in the workspace?

--
You received this message because you are subscribed to the Google Groups "brainGraph-help" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brainGraph-he...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brainGraph-help/f696426d-ec54-4dc8-9737-5de22ddd83ddn%40googlegroups.com.

Caitlin Lloyd

unread,
Nov 5, 2020, 12:11:55 PM11/5/20
to brainGraph-help
Initially I tried with atlas.own just being a dataframe in the workspace, when I then do:

atlas <- 'atlas.own'

and try running the same code like this:
g[[j]] <- make_brainGraphList(A.norm.sub[[j]], atlas, modality=modality,
                             weighting='sld', threshold=thresholds[j],
                                 weighted=TRUE, gnames=covars.dti$C_ID, grpNames = covars.dti$Group)

I then get a different error: serialize(data, node$con) : error writing to connection

Thank you!

Caitlin

Chris Watson

unread,
Nov 5, 2020, 12:27:01 PM11/5/20
to brainGr...@googlegroups.com
You should not need to specify another variable as you are doing; i.e., you do not need
atlas <- 'atlas.own'

I am asking if you have a variable named 'atlas.own'. Please tell me the output of this command:
str(atlas.own)

Caitlin Lloyd

unread,
Nov 5, 2020, 12:29:16 PM11/5/20
to brainGraph-help
Got it, thank you!

Here is output:
Classes ‘data.table’ and 'data.frame': 84 obs. of  8 variables:
 $ name     : chr  "lBSTS" "lcACC" "lcMFG" "lCUN" ...
 $ x.mni    : num  -56 -2 -45 -1 -16 -24 -47 -56 -1 -43 ...
 $ y.mni    : num  -44 21 18 -82 -10 -54 -70 -32 -48 -87 ...
 $ z.mni    : num  5 27 46 20 -29 -16 31 -24 25 1 ...
 $ lobe     : Factor w/ 7 levels "Frontal","Parietal",..: 3 6 1 4 3 3 2 3 6 4 ...
 $ hemi     : Factor w/ 2 levels "L","R": 1 1 1 1 1 1 1 1 1 1 ...
 $ index    : int  1 2 3 4 5 6 7 8 9 10 ...
 $ name.full: chr  "L bank of the superior temporal sulcus" "L caudal anterior cingulate" "L caudal middle frontal gyrus" "L cuneus" ...
 - attr(*, ".internal.selfref")=<externalptr>

Chris Watson

unread,
Nov 5, 2020, 12:39:21 PM11/5/20
to brainGr...@googlegroups.com
In that case, can you run the following command:

make_brainGraph(A.norm.sub[[1]][, , 1], atlas='atlas.own', modality=modality,
                                weighting='sld', threshold=thresholds[1],
                                weighted=TRUE, name=covars.dti$C_ID[1], Group=covars.dti$Group[1])

And then return the output of "traceback()".

If that doesn't seem to show anything new, you can try

g.tmp <- graph_from_adjacency_matrix(A.norm.sub[[1]][, , 1], mode='undirected', diag=FALSE, weighted=TRUE)
make_brainGraph(g.tmp, atlas='atlas.own', ...)

where the "..." above are the same function arguments as above. Then return the output of "traceback()" from that call.

If *that* doesn't show anything different, then please send me all the data I would need to replicate the problem. Please also let me know what version of brainGraph you're using.

Caitlin Lloyd

unread,
Nov 5, 2020, 12:57:02 PM11/5/20
to brainGraph-help
In response to the first command, I get the serialize error: Error in serialize(data, node$con) : error writing to connection. 

The output of traceback is:

14: serialize(data, node$con)
13: sendData.SOCKnode(con, list(type = type, data = value, tag = tag))
12: sendData(con, list(type = type, data = value, tag = tag))
11: postNode(con, "EXEC", list(fun = fun, args = args, return = return, 
        tag = tag))
10: sendCall(cl[[i]], fun, list(...))
9: clusterCall(cl, workerInit, c.expr, exportenv, pkgname, packages, 
       attachExportEnv)
8: e$fun(obj, substitute(ex), parent.frame(), e$data)
7: foreach(i = verts, .combine = "c") %d% {
       g.sub <- graph_from_adjacency_matrix(A[X[[i]], X[[i]]], mode = "undirected", 
           weighted = weighted)
       efficiency(g.sub, "global", weights = weights)
   }
6: efficiency(g, "local", use.parallel = use.parallel, A = Adist)
5: set_brainGraph_attr(x, type, ...)
4: make_brainGraph.igraph(g, atlas, type, level, set.attrs, modality, 
       weighting, threshold, name, Group, subnet, A = x, ...)
3: make_brainGraph(g, atlas, type, level, set.attrs, modality, weighting, 
       threshold, name, Group, subnet, A = x, ...)
2: make_brainGraph.matrix(A.norm.sub[[1]][, , 1], atlas = "atlas.own", 
       modality = modality, weighting = "sld", threshold = thresholds[1], 
       weighted = TRUE, name = covars.dti$C_ID[1], Group = covars.dti$Group[1])
1: make_brainGraph(A.norm.sub[[1]][, , 1], atlas = "atlas.own", 
       modality = modality, weighting = "sld", threshold = thresholds[1], 
       weighted = TRUE, name = covars.dti$C_ID[1], Group = covars.dti$Group[1])

The same error is thrown when I try the second command too.

Is it something to do with the atlas nodes?

Chris Watson

unread,
Nov 5, 2020, 1:00:28 PM11/5/20
to brainGr...@googlegroups.com
No, this looks like an issue with multicore processing. What OS are you using? What kind of CPU do you have (i.e., does it have multiple cores/threads)?
Do you set up your session for multicore processing, as described in the GitHub README.md and the User Guide?

Caitlin Lloyd

unread,
Nov 5, 2020, 1:16:00 PM11/5/20
to brainGraph-help
Hi Chris,

Thank you for this. You are correct in that it looks like something to do with the session set up - I had managed to miss the multicore lines; sorry about that.

Now when I run, I get this error: task 1 failed - "‘-’ only defined for equally-sized data frames"

The matrix I have is 84 by 84, though it is not symmetric - could that be the issue? It did work when using a different atlas so I am not sure that is the problem is the only thing.

Output of traceback is:
: stop(simpleError(msg, call = expr))
4: e$fun(obj, substitute(ex), parent.frame(), e$data)
3: foreach(i = seq_len(kNumGraphs)) %dopar% {
       res <- loopfun(x[, , i], atlas, type, level, set.attrs, modality, 
           weighting, threshold[i], name = gnames[i], Group = grpNames[i], 
           subnet = subnet, mode = mode, diag = diag, weighted = weighted, 
           use.parallel = FALSE, ...)
   }
2: make_brainGraphList.array(A.norm.sub[[j]], atlas, modality = modality, 
       weighting = "sld", threshold = thresholds[j], weighted = TRUE, 
       gnames = covars.dti$C_ID, grpNames = covars.dti$Group)
1: make_brainGraphList(A.norm.sub[[j]], atlas, modality = modality, 
       weighting = "sld", threshold = thresholds[j], weighted = TRUE, 
       gnames = covars.dti$C_ID, grpNames = covars.dti$Group)

Thank you so much for your help with this, and your patience!

Caitlin

Chris Watson

unread,
Nov 5, 2020, 1:20:56 PM11/5/20
to brainGr...@googlegroups.com
It should be symmetric, as "create_mats" symmetrizes them.
Please try again the commands from my previous email.


Caitlin Lloyd

unread,
Nov 5, 2020, 1:57:15 PM11/5/20
to brainGraph-help
Thank you. Error from both commands is: Error in Ops.data.frame(coords[es[, 2L], list(x.mni, y.mni, z.mni)], coords[es[,  : 
  ‘-’ only defined for equally-sized data frames

Then traceback shows:

This is the output: 11: stop(gettextf("%s only defined for equally-sized data frames", 
        sQuote(.Generic)), domain = NA)
10: Ops.data.frame(coords[es[, 2L], list(x.mni, y.mni, z.mni)], coords[es[, 
        1L], list(x.mni, y.mni, z.mni)])
9: NextMethod()
8: Ops.data.table(coords[es[, 2L], list(x.mni, y.mni, z.mni)], coords[es[, 
       1L], list(x.mni, y.mni, z.mni)])
7: rowSums((coords[es[, 2L], list(x.mni, y.mni, z.mni)] - coords[es[, 
       1L], list(x.mni, y.mni, z.mni)])^2)
6: edge_spatial_dist(g)
5: set_brainGraph_attr(x, type, ...)
4: make_brainGraph.igraph(g, atlas, type, level, set.attrs, modality, 
       weighting, threshold, name, Group, subnet, A = x, ...)
3: make_brainGraph(g, atlas, type, level, set.attrs, modality, weighting, 
       threshold, name, Group, subnet, A = x, ...)
2: make_brainGraph.matrix(A.norm.sub[[1]][, , 1], atlas = "atlas.own", 
       modality = modality, weighting = "sld", threshold = thresholds[1], 
       weighted = TRUE, name = covars.dti$C_ID[1], Group = covars.dti$Group[1])
1: make_brainGraph(A.norm.sub[[1]][, , 1], atlas = "atlas.own", 
       modality = modality, weighting = "sld", threshold = thresholds[1], 
       weighted = TRUE, name = covars.dti$C_ID[1], Group = covars.dti$Group[1])

Chris Watson

unread,
Nov 5, 2020, 2:07:31 PM11/5/20
to brainGr...@googlegroups.com
Ok, please send me all the data I need to replicate the error.

Caitlin Lloyd

unread,
Nov 5, 2020, 5:55:54 PM11/5/20
to brainGraph-help
Hi Chris,

 I can definitely send the data over, although I am actually wondering if part of the issue is that the matrix and subject names are not aligned?

Thank you again!

Caitlin

Chris Watson

unread,
Nov 5, 2020, 6:24:32 PM11/5/20
to brainGr...@googlegroups.com
I do not know what you are referring to. Subject names do not come into play based on the error you most recently posted. If I had to guess, I would say there is something wrong w/ the region names in your data and in your custom atlas, either a mismatch in the numbers of regions, or a mismatch in the names in both sources. But I would need to look at your data to be able to tell.

djaka

unread,
Nov 5, 2020, 9:18:22 PM11/5/20
to brainGraph-help
I'm following this with interest - I have the same data sources (freesurfer parcellations processed with labelconvert from mrtrix3 and  mrtrix3 connectomes) and encountered the same initial error.

Setup:
Windows: brainGraph 3.0.0, R 3.6.2, Windows 10 on multicore machine; doSNOW set up as per the User Guide
Linux: brainGraph 3.0.0, R 3.6.3, Ubuntu 18 via WSL, doMC as per the User Guide

Can confirm the on Windows, setting atlas<-'atlas.own' throws the error as above: "task 1 failed - "object ' atlas.own  ' not found
On Ubuntu, no such error. Note slightly different version of R which also may be the culprit?

Caitlin,
Using this code for the mrtrix3 version of the freesurfer LUT, hope this helps
dk.scgm.mrtrix<-rbind(dk.scgm[1:34],
                      list("lCER",-20,-70,-40,"Cerebellum","L",35,"L Cerebellum"),
                      dk.scgm[35:41,],
                      dk.scgm[76:82,],
                      dk.scgm[42:75,],
                      list("rCER",20,-70,40,"Cerebellum","R",35,"R Cerebellum")
)
dk.scgm.mrtrix[,7]<-seq(1:84) # fix the index variable
dk.scgm.mrtrix <- as_atlas(dk.scgm.mrtrix)

But getting errors further down with dt.G <- rbindlist(lapply(g, graph_attr_dt)), so not sure how realiable this is! :)

Chris Watson

unread,
Nov 5, 2020, 9:37:45 PM11/5/20
to brainGr...@googlegroups.com
Thanks for adding to the discussion. Is this a standard parcellation/ordering in mrtrix? If so, I could add it for a future version.

It is strange that you get that error on Windows but not Linux. I cannot easily debug issues on Windows (or Mac).

Note that when you are creating "dk.scgm.mrtrix", you are assigning the same index (35) for both L and R cerebellum. This could be the source of your error w/ "graph_attr_dt", but if not I would like to see what error message you get.

Caitlin Lloyd

unread,
Nov 5, 2020, 9:48:05 PM11/5/20
to brainGraph-help
Hi both!

Thank you very much for your help.

So, I can confirm that the source of the error was completely me - I had (as you had done above) added the Cerebellem into the LUT file, and managed to name the right Cer as lCer, so there was a duplicate, as Chris thought. My code is now running, and producing data tables for graph and vertices - as per Chris' point above, I think the error could be using the same index for the cerebellem. This is what I used:

atlas.own <- read.table("fs_default.txt", header=FALSE) #This is the FS file used by MRtrix 

atlas.own$V3 <- gsub("ctx-rh-", "R", atlas.own$V3)
atlas.own$V3 <- gsub("ctx-lh-", "L", atlas.own$V3)
atlas.own$V3 <- gsub("Right-", "R", atlas.own$V3)
atlas.own$V3 <- gsub("Left-", "L", atlas.own$V3)
atlas.own$V3 <- gsub("bankssts", "bank of the superior temporal sulcus", atlas.own$V3)
atlas.own$V3 <- gsub("Accumbens-area", "nucleus accumbens", atlas.own$V3)
atlas.own$V3 <- gsub("rostralanteriorcingulate", " rostral anterior cingulate cortex", atlas.own$V3)

atlas.own <- atlas.own[-1,]


ClosestMatch2 = function(string, stringVector){
  
  stringVector[amatch(string, stringVector, maxDist=Inf)]
  
}
atlas.own$name.full <- ClosestMatch2(atlas.own$V3, dk.scgm$name.full)
atlas.own <- plyr::join(atlas.own, dk.scgm)
atlas.own$index <- atlas.own$V1
atlas.own  <- atlas.own[,c(9:15,8)]
atlas.own[35,] <- cbind("lCer", 20, -70, -40, "SCGM", "L", 35, "L Cerebellum")
atlas.own[84,] <- c("rCer", 20, -70, -40, "SCGM", "R", 84, "R Cerebellum")
setDT(atlas.own)
atlas.own <- as_atlas(atlas.own)
atlas.own$x.mni <- as.numeric(atlas.own$x.mni)
atlas.own$y.mni <- as.numeric(atlas.own$y.mni)
atlas.own$z.mni <- as.numeric(atlas.own$z.mni)
atlas.own$index <- as.integer(atlas.own$index)


Then proceed with code as above:

g.group <- vector('list', length(thresholds))
for (j in seq_along(thresholds)) {
g[[j]] <- make_brainGraphList(A.norm.sub[[j]], atlas='atlas.own', modality=modality,
                                weighting='sld', threshold=thresholds[j],
                                weighted=TRUE, gnames=covars.dti$C_ID, grpNames = covars.dti$Group)
  g.group[[j]] <- make_brainGraphList(A.norm.mean[[j]], 'atlas.own', modality=modality, weighting='sld', threshold=thresholds[j], weighted=TRUE, gnames=grps)
}
saveRDS(g, file=file.path(savedir, 'g.rds'), compress='xz')
saveRDS(g.group, file=file.path(savedir, 'g.group.rds'), compress='xz')

Looking forward to continuing analyses!

Caitlin

djaka

unread,
Nov 7, 2020, 3:17:35 AM11/7/20
to brainGraph-help
Thanks all. Everything is working for me as well - albeit still only in Linux (via WSL). I suspect this is due to the known issue in Windows where if foreach is called within functions then it may not automatically pull items from the global environment. 

The mrtrix freesurfer parcellation/ordering is somewhat standard, in that it's the default that ships with mrtrix. Both mine and Caitlin's code above work to recreate it.

Incidentaly, my previous errors with graph_attr_dt I think was due to my covars.dti being a data.frame, not data.table.

NB: Caitlin, the MNI X coordinate for the left cerebellum should be negative (ie. -20) in case you run into display problems later.

Thanks again,
Dave

Chris Watson

unread,
Nov 7, 2020, 11:08:27 AM11/7/20
to brainGr...@googlegroups.com
Thanks for figuring that out. On Windows, you would probably have to export the variable "atlas.own" (or whatever the name is). I should probably add that to the README.

Chris

Reply all
Reply to author
Forward
0 new messages