The Problem

Researchers working on the Janelia FlyEM male‑cns connectome need a convenient R interface that exposes the full set of metadata, mesh data, and neuprint queries without repeatedly writing boilerplate code. The raw neuprint API and malevnc package expose a fragmented set of functions, making it difficult to pull together meshes, transform coordinates, and retrieve neuron IDs in a single workflow.

What This Does

malecns packages the male‑cns dataset into a single R package that wraps the malevnc and neuprintr libraries.

  • dr_malecns() (in R/neuprint.R) discovers the default dataset snapshot.
  • mcns_neuprint_meta() (in R/neuprint.R) pulls all metadata columns, including flywireType, mancType, and itoleeHl.
  • read_mcns_meshes() (in R/mesh.R) loads pre‑computed meshes from the bundled data/ directory.
  • xform_brain() (in R/xform.R) converts coordinates between FlyWire and malecns voxel spaces.

The package ships pre‑processed .rda files (data/malecns.surf.rda, data/malecns_shell.surf.rda, etc.) that avoid on‑the‑fly conversions.

How It Is Wired

Entry point – dr_malecns() in R/neuprint.R.

  1. dr_malecns() calls mcns_neuprint_meta() to fetch the neuprint cursor for the default snapshot.
  2. mcns_neuprint_meta() uses neuprintr functions to query the neuprint API and returns a data.frame of all columns.
  3. read_mcns_meshes() loads the relevant .rda file from data/ and returns an rgl mesh list; it internally calls xyz() from R/xyz.R to convert voxel indices to world coordinates.
  4. xform_brain() (in R/xform.R) performs affine transformations by delegating to malevnc::xform_brain() and normalises the output for downstream use.

External touchpoints – the package reads from data/, writes to the user’s R workspace, and performs HTTP requests via neuprintr. Critical hubs – R/neuprint.R is the widest blast radius; changing it propagates to all metadata‑dependent functions. R/xform.R is a secondary hub for coordinate conversions.

How To Use It

# clone
git clone https://github.com/moses-y/malecns
cd malecns

# install dependencies
R -e "install.packages('natmanager'); natmanager::install(pkgs='natverse/malecns')"

# set neuprint token
usethis::edit_r_environ()
# add: NEUPRINT_TOKEN=<your token>
library(malecns)

# verify dataset
dr_malecns()

# fetch metadata
pnmeta <- mcns_neuprint_meta('/.+_[adl]+PN')
table(pnmeta$type)

# load meshes
vm6 <- read_mcns_meshes('VM6_adPN')
plot3d(vm6, alpha = .1)

# transform a point
xform_brain(cbind(109953, 50450, 1660) * c(4,4,40), reference = 'malecns', sample = 'FlyWire')

Real‑World Use

A common workflow is to annotate a set of neurons, transform their coordinates into a shared reference, and push the results into Neuroglancer.

ml <- read_mcns_meshes('/type:(DA1|DL3)_lPN')
ml_meta <- mcns_neuprint_meta(names(ml))
plot3d(ml, col = ml_meta$type)
# clipboard ready for Neuroglancer
clipr::write_clip(xform_brain(cbind(109953, 50450, 1660) * c(4,4,40), 'malecns', 'FlyWire')/8)

Code Health & Issues

  • Tests: 13 testthat files under tests/testthat/ cover all public functions.
  • CI: GitHub Actions (.github/workflows/R-CMD-check.yaml) run unit tests, linting, and package checks on every push.
  • License: LICENSE.md (MIT).
  • Measured findings: static analysis reports no critical bugs; all exported functions are documented in man/*.Rd.
  • Missing: No example CLI script; the package is intended to be used via R code only.

The Bottom Line

malecns provides a lightweight, well‑tested R wrapper that consolidates male‑cns metadata, meshes, and coordinate transforms. It is ideal for researchers who already use neuprintr and malevnc and need a single entry point for data retrieval. The codebase is small, documented, and CI‑protected, making it a low‑risk addition to a neuroinformatics pipeline.