You can select synapses within a spatial region and then carrying out a random sub-sampling. This might be useful as part of a strategy for defining connectivity without reconstructing all connections.


First load main packages


In order to run some of the examples we need to ensure that we:

We will most our examples run conditionally based on this.

catmaid_available=inherits(cl, "catmaid_connection")

# set up for 3d plots based on rgl package
# frontal view
view3d(userMatrix=rgl::rotationMatrix(angle = pi, 1,0,0), zoom=0.6)

Selecting synapses

We're going to look at synapses downstream of DA1 PNs

cda1=catmaid_get_connectors_between('name:PN Glomerulus DA1')

If we wanted to get the upstream synapses, we could do that as follows: = 'name:PN Glomerulus DA1')

We then want to select synapses within a neuropil region, the lateral horn. The elmr package now has a neuropil surface object that we can use for this purpose. To look for points inside the right LH, we can extract just that region from the surface object containing all neuropils as follows:

# convert subset of regions to rgl::mesh3d object
lhr=as.mesh3d(, 'LH_R')

Now we can select just those synapses within the LH volume, by piping the XYZ positions of the presynaptic connector node to the pointsinside function.

# make a new logical column indicating if connector is inside LH
cda1$inlh=select(cda1, connector_x:connector_z) %>% 
  pointsinside(surf = lhr)
cda1 %>%
  filter(inlh) ->

Now let's take a random 10% sample of the post-synaptic connector nodes for just one PN:

cda1.lh %>%
  filter(pre_skid==61221) %>%
  sample_frac(size=0.1) ->

We can then construct CATMAID URLs for all those synapses:

       function(i) open_fafb(random_syn[i, c("post_node_x", "post_node_y", "post_node_z")],
            active_skeleton_id = random_syn$post_skid[i],
            active_node_id = random_syn$post_node_id[i], open = F)

That was a little bit clunky but we basically feed the open_fafb function the data one row at a time centering the URL on the postsynaptic node and selecting that node in the CATMAID viewer.

So here are the results


Using the results

Let's make a plot to get an idea of where those synapses are: First fetch the full structure of the seed PN


Now plot the selected and unselected synapses

# find bounding box containing selected synapses
synapse_bounds=apply(random_syn[,c("post_node_x", "post_node_y", "post_node_z")],2,range)
plot(seedpn, WithNodes=F, boundingbox=synapse_bounds)
# plot the synapses we didn't select
cda1.lh %>%
  filter(!post_node_id %in% random_syn$post_node_id & pre_skid %in% random_syn$pre_skid) %>%
  select(post_node_x:post_node_y) %>%
# and then the ones we did
points(random_syn$post_node_x, random_syn$post_node_y, col='red', pch=19)

Then you can open those urls directly in CATMAID:

for (u in synapse_urls) {
  readline("Press a key to move to open the next synapse (or Esc to cancel).")

or write them to a text file

writeLines(synapse_urls, con = 'PN61221_rand_synapse_urls.txt')

or upload them to a google doc

tf=tempfile(fileext = '.tsv')
write.table(random_syn, file=tf, sep="\t")
gs_upload(tf, sheet_title = 'PN61221_rand_synapse_urls')

jefferis/elmr documentation built on Feb. 23, 2020, 7:50 p.m.