Negative NBLAST Score

20 views
Skip to first unread message

Morolake Okanlawon

unread,
May 6, 2025, 11:58:30 AMMay 6
to nat-user
Hello,
I am new to NBLAST, and I am trying to calculate the NBLAST scores of different neurons against each other. My results show negative scores except when comparing a neuron to itself (score is 1). Is this possible or is it an error in my code? Is there anything else I can do to change this? Please see my code below. I look forward to your response. Thank you.

Regards,
Morolake.

# Set default NBLAST score matrix to be used in flycircuit searches
options('flycircuit.scoremat' = "allbyallblastcv4.5")

# Define a function to install any CRAN packages that are missing
install_if_missing <- function(pkgs) {
  for (pkg in pkgs) {
    if (!requireNamespace(pkg, quietly = TRUE)) {
      install.packages(pkg)
    }
  }
}

# Install general-purpose CRAN packages used for plotting, clustering, etc.
install_if_missing(c('doMC', 'dendroextras', 'rgl', 'ggplot2', 'spam', 'knitr', 'apcluster', 'mixOmics'))

# Install Bioconductor packages if they're not already installed
if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager")
if (!requireNamespace("Heatplus", quietly = TRUE)) BiocManager::install("Heatplus")

# Ensure remotes is installed for downloading packages from GitHub
install_if_missing("remotes")

# Define GitHub packages (neuron morphology + brain data tools) and install if missing
github_packages <- list(
  "nat" = "jefferis/nat",                              # Main neuroanatomy toolkit
  "nat.nblast" = "jefferislab/nat.nblast",            # NBLAST algorithm for comparing neurons
  "nat.templatebrains" = "jefferislab/nat.templatebrains", # Brain template support
  "nat.flybrains" = "jefferislab/nat.flybrains",      # Fly brain-specific tools
  "flycircuit" = "jefferis/flycircuit"                # FlyCircuit neuron data access
)

# Loop through and install GitHub packages if not already available
for (pkg in names(github_packages)) {
  if (!requireNamespace(pkg, quietly = TRUE)) {
    remotes::install_github(github_packages[[pkg]])
  }
}

# Load libraries for neuron analysis and NBLAST
library(nat)
library(flycircuit)
library(nat.flybrains)
library(nat.nblast)

# Set up parallel processing for faster NBLAST on multiple cores
if (Sys.info()['sysname'] == "Windows") {
  # On Windows, use the doParallel backend
  install_if_missing("doParallel")
  library(doParallel)
  n_cores <- parallel::detectCores() - 1     # Use all but one core
  cl <- makeCluster(n_cores)
  registerDoParallel(cl)
  message(sprintf("Registered %d cores for parallel processing using doParallel.", n_cores))
} else {
  # On Mac/Linux, use doMC
  install_if_missing("doMC")
  library(doMC)
  registerDoMC()
  message(sprintf("Registered %d cores for parallel processing using doMC.", parallel::detectCores()))
}

# Load neurons from SWC files in a specified folder
my_neurons <- read.neurons("C:/Users/mrokanla/Desktop/JO skeleton files", format = "swc")

# Print the first few neurons to check if they loaded correctly
print(head(my_neurons))

# Run all-by-all NBLAST to compute similarity scores between neurons
nblast_scores <- nblast_allbyall(my_neurons, normalisation = c("mean"))

# Print a small portion of the NBLAST score matrix to preview results
print(nblast_scores[1:2, 1:2])

# Print the number of neurons loaded
print(length(my_neurons))

# Save the full NBLAST score matrix to a CSV file
write.csv(as.matrix(nblast_scores), "nblast_scores.csv", row.names = TRUE)

# Shut down the parallel processing cluster (only needed on Windows)
if (Sys.info()['sysname'] == "Windows") {
  stopCluster(cl)
}

Greg Jefferis

unread,
May 6, 2025, 12:03:25 PMMay 6
to Morolake Okanlawon, 'Morolake Okanlawon' via nat-user
Dear Morolake,

Thanks for your interest. A negative score indicates a mismatch. If it is closes to -0.8 then it essentially means the two neurons are nowhere near each other in space.

Most likely your neurons are not calibrated in microns – perhaps they are in nm – or they are not spatially co-registered.

To convert nm -> microns

my_neurons_um= my_neurons/1000

Also it is recommended to cover skeletons to dot props objects e.g.:

my_neurons_um.dps= dotprops(my_neurons_um, resample=1, k=5)

Best wishes,

Greg.


Gregory Jefferis
Division of Neurobiology
MRC Laboratory of Molecular Biology
Francis Crick Avenue
Cambridge Biomedical Campus
Cambridge, CB2 OQH, UK

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
http://jefferislab.org
https://www.zoo.cam.ac.uk/research/groups/connectomics


--
You received this message because you are subscribed to the Google Groups "nat-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nat-user+u...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/nat-user/4434271a-102f-4171-b716-23ad12452a40n%40googlegroups.com.

Morolake Okanlawon

unread,
May 6, 2025, 12:20:10 PMMay 6
to nat-user
Thank you for your help. Converting to microns and using dotprops did the trick! Everything’s working now.

Regards,
Morolake.
Reply all
Reply to author
Forward
0 new messages