Intro

Occasionally CATMAID users add the soma tag multiple times in error. We can find such neurons and generate CATMAID URLs to inspect them.

Setup

First load main packages

library(elmr)
cl=try(catmaid_login())
catmaid_available=inherits(cl, "catmaid_connection")
library(knitr)
# only run if catmaid available
# and cache so only run once per day
opts_chunk$set(eval=inherits(cl, "catmaid_connection"),cache.extra=Sys.Date())
library(dplyr)
rgl::setupKnitr()

Finding neurons with multiple somata

First let’s fetch information about all the labels (aka tags) applied to nodes in the current project.

Now let’s restrict to cases where there are multiple soma tags per skeleton

XYZ position of the nodes we picked

Now let’s calculate the distance from the neuropil surface

labelID labelName skeletonID treenodeID X Y Z radius login d rank
2773 soma 1298891 7525237 395633 95574.1 177520 2855 batesa -9679.3672 1
2773 soma 1298891 59494856 404914 96547.4 161000 51 serratosal 5889.5078 2
2773 soma 2015619 56565186 322684 154162.0 201600 1985 serratosal -13418.3672 1
2773 soma 2015619 18010667 371782 128203.0 176640 -1 batesa 14364.7969 2
2773 soma 3106997 13589617 513563 144817.0 165880 1597 masoodpanahn -1645.4375 1
2773 soma 3106997 13588952 519345 161710.0 160000 1745 masoodpanahn 1982.2188 2
2773 soma 3658067 12345094 618824 218757.0 60680 2440 alghailanis 2672.0000 1
2773 soma 3658067 30290984 413013 240218.0 145680 -1 polskyj 13872.9307 2
2773 soma 3721315 12460766 434532 254146.0 84880 3918 calles -1958.2266 1
2773 soma 3721315 12459557 433766 253732.0 84320 -1 dacksa -1411.4219 2
2773 soma 3726283 35469519 322772 155344.0 181680 2093 tenshawe -4882.7500 1
2773 soma 3726283 35469478 323028 155599.0 181200 -1 tenshawe -4637.3281 2
2773 soma 3788293 19104385 370375 152519.0 215520 1904 batesa -7053.4844 1
2773 soma 3788293 19104384 370363 152491.0 215400 1889 batesa -6953.6719 2
2773 soma 6645033 6781342 617127 261972.0 67160 3076 calles 226.7500 1
2773 soma 6645033 41219199 495505 264349.0 62520 -1 coatesk 11138.4375 2
2773 soma 6645033 43899462 484171 264798.0 77240 -1 dacksa 19888.5879 3
2773 soma 7937976 57573136 320075 162848.0 185360 1702 serratosal -8638.3906 1
2773 soma 7937976 13380406 377685 210574.0 176800 -1 batesa 4119.5508 2
2773 soma 8758601 49116764 440102 203967.0 56360 2454 helmickl 988.2188 1
2773 soma 8758601 52299679 476735 214771.0 39800 -1 helmickl 11180.5352 2
2773 soma 9623317 32110234 428951 298439.0 209400 1781 eichlerk -8578.3516 1
2773 soma 9623317 59058312 497414 339922.0 164720 42 eichlerk 19744.7969 2
2773 soma 10108062 33531079 419915 224525.0 51080 -1 coatesk -3335.2869 1
2773 soma 10108062 40684585 513639 219860.0 46640 -1 sweetn 700.5312 2
2773 soma 10110812 44656714 657952 265904.0 156680 -1 marquism -6115.3125 1
2773 soma 10110812 44656784 667914 256180.0 145520 -1 marquism 3447.3750 2
2773 soma 10234277 34371718 493445 360456.0 122800 2392 eichlerk -4578.3750 1
2773 soma 10234277 36336623 493429 360356.0 122560 2197 jefferis -4491.7812 2
2773 soma 12173355 44728863 649485 226483.0 181440 -1 marquism -4930.6875 1
2773 soma 12173355 44728872 648709 227851.0 181120 -1 marquism -3965.1250 2
2773 soma 12529405 51019292 432457 146688.0 62800 1948 lia -2623.7188 1
2773 soma 12529405 51021568 462561 275852.0 192680 -1 lia 17362.4688 2
2773 soma 13082053 52561173 632767 284886.0 29440 2426 toj -13823.0625 1
2773 soma 13082053 52561151 632533 284312.0 30280 -1 toj -13010.6250 2
2773 soma 14019704 44310666 411763 163520.0 79080 2336 tenshawe 979.7429 1
2773 soma 14019704 44310655 411512 163639.0 79320 -1 tenshawe 984.1561 2
2773 soma 14462790 56638440 392006 167674.0 87520 1750 ludwigh 681.5938 1
2773 soma 14462790 57473239 372964 161629.0 106960 -1 ludwigh 4346.0000 2
2773 soma 14933802 59013131 293731 147387.0 207680 2541 kinde -8970.4141 1
2773 soma 14933802 56163931 272602 161879.0 235200 -1 sancerg -7160.1328 2

This lets us see that in some cases there are two soma tags outside the neuropil (negative d) and close together - these are probably duplicates - whereas in other cases it is likely that points were added in error. We can also plot the points colouring them by their rank order (most external first).

Now we can use this information to construct an url for each node.

It might be useful to know who ‘owns’ each neuron. I think the simplest way to assign this is by the user who has traced most nodes for each skeleton (since there may be different users responsible for each soma).

Google sheet

Let’s make a google sheet with all those urls that we can then review manually:

As an alternative we can divide that up with one worksheet per user.

library(googlesheets)
gs <- googlesheets::gs_new("multi_soma_neurons_by_user")
gs_add_sheet <- function(x, gs, ...) {
  gs_ws_new(row_extent = nrow(x)+1, col_extent = ncol(x), ss = gs, ..., input=x, col_names=T)
}
multiple_soma_info %>% 
  arrange(skeletonID, d) %>% 
  mutate(user=factor(get_top_user(skeletonID))) -> msi2

for(u in levels(msi2$user)) {
  gs_add_sheet(subset(msi2, user==u), gs, ws_title=u)
  cat(".")
}