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)
}