Tutorial to install natverse, including neuprint (original code included in link): http://natverse.org/neuprintr/articles/hemibrain_opns.html

Tutorial to install hemibrainr: https://github.com/natverse/hemibrainr

Startup

library(natverse)
library(hemibrainr)
library(dendroextras)
library(ggnetwork)
library(network)

Generating Skeletonizations

#setup
mypath = "images/skeletons/DN1pB"
DN1pB.info = neuprint_search(".*DN1pB.*")
lacroix = c("#C70E7B", "#FC6882", "#007BC3", "#54BCD1", "#EF7C12", "#F4B95A", 
            "#009F3F", "#8FDA04", "#AF6125", "#F4E3C7", "#B25D91", "#EFC7E6", 
            "#EF7C12", "#F4B95A", "#C23A4B", "#FBBB48", "#EFEF46", "#31D64D", 
            "#132157","#EE4244", "#D72000", "#1BB6AF")
names(lacroix) = c("purple", "pink",
                   "blue", "cyan",
                   "darkorange", "paleorange",
                   "darkgreen", "green",
                   "brown", "palebrown",
                   "mauve", "lightpink",
                   "orange", "midorange",
                   "darkred", "darkyellow",
                   "yellow", "palegreen", 
                   "navy","cerise",
                   "red", "marine")

#execute
hemibrain_view()
b = hemibrain_neuron_meshes(DN1pB.info$bodyid)
plot3d(b, WithConnectors = FALSE, col = lacroix["mauve"], lwd = 2)
nview3d('ventral')
rgl.snapshot(filename = "DN1pB.png", fmt ="png")

Generating Node Networks

#setup
shortest.paths = data.frame()
ER2.info = neuprint_search(".*ER2.*")
TuBu01.info = neuprint_search(".*TuBu01.*")

#execute
for(b in DN1pB.info$bodyid){
  for(c in ER2.info$bodyid){ 
    sp = neuprint_get_shortest_paths(body_pre = b, body_post = c, weightT = 10)
        dupe = ifelse(is.na(which(duplicated(sp$to))[1]),nrow(sp),which(duplicated(sp$to))[1])
        shortest = sp[1:dupe,]
        shortest.paths = rbind(shortest.paths, shortest)
        shortest.paths = unique(shortest.paths)
  } 
}


#Make network
set.seed(42)
paths = aggregate(list(weight = shortest.paths$weight), list(type.from = shortest.paths$type.from,
                                                            type.to = shortest.paths$type.to),
                 sum)
n = network(paths,
            matrix.type = "edgelist",
            ignore.eval = FALSE,
            layout = "fruchtermanreingold",
            names.eval = "weight",
            directed = TRUE)
n = ggnetwork(n, cell.jitter = 0.75, arrow.gap = 0.01)

#Set colors
types = unique(c(paths$type.to,paths$type.from))
type.cols = rep("grey30",length(types))
names(type.cols) = types
input_subtypes = unique(DN1pB.info$type)
input.cols = rep(lacroix[["orange"]],length(input_subtypes))
names(input.cols) = input_subtypes
int1_subtypes = unique(TuBu01.info$type)
int1.cols = rep(lacroix[["pink"]],length(int1_subtypes))
names(int1.cols) = int1_subtypes
output_subtypes = unique(ER2.info$type)
output.cols = rep(lacroix[["purple"]],length(output_subtypes))
names(output.cols) = output_subtypes
all.cols = c(input.cols,int1.cols,output.cols,type.cols[!names(type.cols)%in%c(names(output.cols),names(int1.cols),names(input.cols))])

#Plot
set.seed(1)
pdf(file = "DN1pB_to_ER2.pdf", height = 5, width = 5)
ggplot(n, aes(x = x, y = y, xend = xend, yend = yend)) +
  geom_edges(aes(color = vertex.names),
             curvature = 0.05,
             arrow = arrow(length = unit(6, "pt"), 
                           type = "closed")) +
  geom_nodes(aes(color = vertex.names, size = 6)) +
  geom_edgetext(aes(label = weight, color = vertex.names), fill = NA) +
  geom_nodelabel_repel(aes(color = vertex.names, label = vertex.names),
                       fontface = "bold", box.padding = unit(1, "lines")) +
  scale_color_manual(values = all.cols) +
  scale_fill_manual(values = all.cols) +
  theme_blank() +  
  guides(color = FALSE, shape = FALSE, fill = FALSE, size = FALSE, linetype = FALSE) + ylab("") + xlab("")
dev.off()
## png 
##   2