Skip to content

Instantly share code, notes, and snippets.

@tferr
Last active September 25, 2019 06:35
Show Gist options
  • Save tferr/dab8097ba612b1d36c787ef9969c6d81 to your computer and use it in GitHub Desktop.
Save tferr/dab8097ba612b1d36c787ef9969c6d81 to your computer and use it in GitHub Desktop.
This Script demonstrates how to visualize MouseLight Data in a programmatic manner. It assumes you have an up-to-date Fiji.app installation subscribed to the NeuroAnatomy & SciView update sites. Run it from Fiji's Script Editor
#@ImageJ ij
import sc.fiji.snt.analysis.MultiTreeColorMapper
import sc.fiji.snt.annotation.AllenCompartment
import sc.fiji.snt.annotation.AllenUtils
import sc.fiji.snt.io.MouseLightLoader
import sc.fiji.snt.viewer.Viewer3D
import sc.fiji.snt.util.SNTColor
import net.imagej.display.ColorTables
import java.text.DecimalFormat
compartmentMOp = AllenUtils.getCompartment("MOp")
if (!MouseLightLoader.isDatabaseAvailable() || !compartmentMOp) {
println("""Aborting: Can only proceed with valid compartment and
successful connection to database. Check your internet
connection""")
return
}
println("ML Database is online")
mopAxons = []
mopDendrites = []
for (neuron in 1..MouseLightLoader.getNeuronCount()) {
// We could use MouseLightQuerier to define a coDefine a valid cell ID
id = "AA" + new DecimalFormat("0000").format(neuron)
loader = loader = new MouseLightLoader(id)
println("Parsing " + id + "...")
if (!loader.idExists()) {
println(" id not found. Skipping...")
continue
}
// Retrieve the 1st node of the soma and its annotated compartment
soma = loader.getNodes("soma")[0]
somaCompartment = (AllenCompartment) soma.getAnnotation()
if (compartmentMOp.contains(somaCompartment)) {
print(" Retrieving data:")
mopAxons << loader.getTree("axon");
mopDendrites << loader.getTree("dendrite")
} else {
print(" Soma not associated with " + compartmentMOp + ". Skipping...")
}
}
println("Finished parsing of all " + MouseLightLoader.getNeuronCount() + " available neurons")
println("Retrieved " + mopAxons.size() + " cells")
// Now let's prepare the visualization
recViewer = new Viewer3D(ij.context())
// Dendrites: We'll use random colors
println("Mapping dendrites...")
colors = SNTColor.getDistinctColors(mopAxons.size())
counter = 0;
for (dendroTree in mopDendrites) {
dendroTree.setColor(colors[counter++])
}
// Axons: Color code by length
println("Mapping axons...")
axonMapper = new MultiTreeColorMapper(mopAxons)
axonMapper.map("length", ColorTables.ICE)
axonLimits = axonMapper.getMinMax()
// Add scale bar and meshes
recViewer.addColorBarLegend(ColorTables.ICE, axonLimits[0], axonLimits[1])
recViewer.add(compartmentMOp.getMesh())
brainMesh = AllenUtils.getCompartment("Whole Brain").getMesh()
recViewer.add(brainMesh)
recViewer.show();
recViewer.setViewPoint(1.0471976, 0.0)
mopAxons.eachWithIndex { axon, index ->
recViewer.add(axon)
recViewer.add(mopDendrites.get(index))
for (i in 1..6) {
sleep(500)
recViewer.rotate(1f);
}
recViewer.removeAllTrees();
}
return // Suppress Scijava Unsupported output warning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment