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 5714 33700955 589956 204332.0 13000 2354 morrisw -9264.1611 1
2773 soma 5714 33614047 570552 242540.0 60840 -1 morrisw -1587.8125 2
2773 soma 856254 42752681 425431 211815.0 41800 -1 salmanf 556.9375 1
2773 soma 856254 19156039 528639 362285.0 160480 3100 schlegelp 2123.0000 2
2773 soma 861352 32450161 305410 253275.0 277760 1856 flynnm -16501.6250 1
2773 soma 861352 3628236 305999 253240.0 277160 -1 reiserm -16098.1562 2
2773 soma 929147 43802642 316003 144834.0 181480 2119 batesa -8953.3125 1
2773 soma 929147 41898953 338245 158245.0 165120 32 batesa 6298.5156 2
2773 soma 1277563 32595025 493176 130138.0 194240 3052 liangk -18194.5312 1
2773 soma 1277563 31821189 406528 112291.0 111400 -1 liangk 13397.7500 2
2773 soma 1363077 14837366 413621 234503.0 71280 1754 elbahnasawim -6167.0312 1
2773 soma 1363077 32130748 416874 258416.0 154440 -1 robertsr 12032.3301 2
2773 soma 2052519 32491695 346011 162977.0 114800 1896 liangk -18326.4062 1
2773 soma 2052519 31439008 427341 107547.0 128760 -1 liangk 28985.4023 2
2773 soma 2851242 6906660 320104 156382.0 176400 1436 robertsr -6780.7656 1
2773 soma 2851242 40430928 348144 139189.0 156640 -1 batesa 10451.1250 2
2773 soma 2891306 3516046 416504 218172.0 60400 3843 dbock -9733.9375 1
2773 soma 2891306 51630922 507616 271688.0 62280 -1 helmickl -2176.1875 2
2773 soma 2981229 32772105 388611 278461.0 94640 -1 tenshawe -1777.1562 1
2773 soma 2981229 32773150 385850 279970.0 97120 3298 tenshawe -1602.5625 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 3769648 43138238 380167 96744.8 167520 1709 edmondsona -5663.3672 1
2773 soma 3769648 12626305 375951 184757.0 176800 -1 batesa 18822.1250 2
2773 soma 3770805 5351518 492982 205520.0 208080 2002 taiszi -3426.4688 1
2773 soma 3770805 35194209 498927 213740.0 126920 -1 yangt 8333.3467 2
2773 soma 5322252 17825737 309447 274776.0 263160 1580 moranc -8763.7500 1
2773 soma 5322252 17820926 305023 264242.0 228600 -1 moranc 7897.3750 2
2773 soma 5675915 23536527 339774 151320.0 133080 2093 batesa -13098.6406 1
2773 soma 5675915 32131690 434674 135654.0 117920 -1 schlegelp 33361.9062 2
2773 soma 6543698 21717689 493385 366906.0 147440 1751 polskyj -8782.2188 1
2773 soma 6543698 33347169 428034 269639.0 130320 -1 popvicip 20277.0898 2
2773 soma 7739698 25182877 407164 203029.0 77320 2090 polskyj -3244.8906 1
2773 soma 7739698 31895604 420504 213379.0 110760 -1 yangt 24896.4688 2
2773 soma 8818720 29105950 366934 185972.0 212200 1947 polskyj -5813.6694 1
2773 soma 8818720 34480826 440158 218183.0 182160 -1 tenshawe 27790.7148 2
2773 soma 9416924 35178955 311637 139496.0 195040 1915 ludwigh -16750.4785 1
2773 soma 9416924 13377290 391244 211268.0 170600 -1 batesa 14531.7012 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 10322846 43410883 350348 303432.0 143560 1681 laughlandc -11376.0244 1
2773 soma 10322846 43343960 249322 285724.0 206400 -1 laughlandc 35623.9922 2
2773 soma 11545702 7265260 432417 217672.0 215400 2332 masoodpanahn -4067.2500 1
2773 soma 11545702 42403476 357440 151964.0 172200 -1 batesa 23012.2148 2
2773 soma 11666155 42801223 344090 327097.0 155560 2140 laughlandc -192.5469 1
2773 soma 11666155 42557407 239435 258372.0 211640 -1 ludwigh 25299.2500 2
2773 soma 12076836 44310666 411763 163520.0 79080 2336 tenshawe 979.7429 1
2773 soma 12076836 44310655 411512 163639.0 79320 -1 tenshawe 984.1561 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 12526387 49140372 409520 171312.0 76840 2305 rayshubskiys -6610.2212 1
2773 soma 12526387 49148380 470400 259489.0 156520 -1 rayshubskiys 14854.1436 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

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(".")
}