Skip to content

Instantly share code, notes, and snippets.

@tferr
Created October 1, 2019 18:08
Show Gist options
  • Save tferr/17de61fc1b12f6e07e09bc9ca2050f3f to your computer and use it in GitHub Desktop.
Save tferr/17de61fc1b12f6e07e09bc9ca2050f3f to your computer and use it in GitHub Desktop.
#@File(style="directory", label="Output directory") destinationDirectory
#@String(label="CCF Compartment (acronym, id, or label)", value="Isocortex") compartmentName
#@String(label="What to save?", choices={"dendrites", "axons", "all"}) subTreeName
import sc.fiji.snt.io.MouseLightLoader
import sc.fiji.snt.annotation.AllenCompartment
import sc.fiji.snt.annotation.AllenUtils
import sc.fiji.snt.Tree
import java.text.DecimalFormat
compartmentOfInterest = AllenUtils.getCompartment(compartmentName)
if (!MouseLightLoader.isDatabaseAvailable() || !compartmentOfInterest) {
println("""Aborting: Can only proceed with valid compartment and
successful connection to database""")
return
}
println("ML Database is online")
for (neuron in 1..MouseLightLoader.getNeuronCount()) {
// Define a valid cell ID
id = "AA" + new DecimalFormat("0000").format(neuron)
loader = loader = new MouseLightLoader(id)
print("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 (compartmentOfInterest.contains(somaCompartment)) {
print(" Downloading dendrites...")
dendroTree = loader.getTree(subTreeName)
println("\tSWC saved: " + dendroTree.saveAsSWC(""+destinationDirectory+"/"+id+".swc"))
} else {
println(" Soma not associated with " + compartmentOfInterest + ". Skipping...")
}
}
println("Finished parsing of all " + MouseLightLoader.getNeuronCount() + " available neurons")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment