Skip to content

Instantly share code, notes, and snippets.

View tferr's full-sized avatar

Tiago Ferreira tferr

View GitHub Profile
@tferr
tferr / download_ML_soma_locations.py
Created June 14, 2023 20:42
SNT script for bulk export of soma coordinates of MouseLight Neurons to a CSV file
from sc.fiji.snt.analysis import SNTTable
from sc.fiji.snt.io import MouseLightQuerier, MouseLightLoader
"""
Jython script for bulk export of soma coordinates of MouseLight Neurons to a CSV file.
To Run this script:
- Download Fiji and install SNT (by subscribing to Fiji's Neuroanatomy update site)
- Edit the 'destination' variable and run this script from Fiji's Script Editor
(using Python as language)
- For instructions on how to run SNT from a native python environment have a look at
ImageJ 2.1.0/1.53j; Java 1.8.0_202 [x86_64]
-- Application: ImageJ --
Title = ImageJ
Version = 2.1.0/1.53j
groupId = net.imagej
artifactId = imagej
Automatic-Module-Name = net.imagej
Build-Jdk-Spec = 1.8
Class-Path = imagej-common-0.33.0.jar imglib2-5.10.0.jar imglib2-roi-0.10.3.jar scijava-table-0.5.0.jar udunits-4.3.18.jar imagej-launcher-5.0.3.jar imagej-notebook-0.7.1.jar commons-text-1.8.jar xchart-3.5.4.jar VectorGraphics2D-0.13.jar imagej-ops-0.45.5.jar imagej-mesh-0.8.0.jar imglib2-algorithm-0.11.2.jar imglib2-algorithm-fft-0.2.0.jar mines-jtk-20151125.jar imglib2-realtransform-3.0.0.jar jitk-tps-3.0.1.jar ejml-0.24.jar log4j-1.2.17.jar parsington-2.0.0.jar scijava-search-0.7.0.jar prettytime-4.0.1.Final.jar scripting-javascript-0.5.0.jar commons-math3-3.6.1.jar joml-1.9.25.jar ojalgo-45.1.1.jar jama-1.0.3.jar imagej-updater-0.10.5.jar commons-lang-2.6.jar scifio-0.41.0.jar scifio-jai-imageio-1.1.1.jar imglib2-cache-1.0.0-beta-13.jar caffeine-2.4.0.jar scijava-common-2.83.3.jar eventbus-1.4.jar image
@tferr
tferr / Test.java
Created March 31, 2021 22:38
Example to test Macro recordability of Scijava components
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import org.scijava.ItemVisibility;
import org.scijava.command.Command;
import org.scijava.command.DynamicCommand;
@tferr
tferr / BruteForceMLQuery.python
Created January 4, 2021 22:48
Jython script that uses SNT to perform a 'brute force' ML query
from sc.fiji.snt.io import MouseLightLoader, MouseLightQuerier
from sc.fiji.snt.analysis import NodeStatistics, TreeStatistics
from sc.fiji.snt.annotation import AllenUtils
soma_area = AllenUtils.getCompartment("MOs")
target_area = AllenUtils.getCompartment("ACA")
input_ids = MouseLightQuerier.getIDs(soma_area)
output_ids = []
for in_id in input_ids:
@tferr
tferr / H5_To_Tiff_Converter.groovy
Last active December 4, 2019 09:44
Fiji script for extracting image data from HDF5 files
#@File(style="directory", label="Input directory containing H5 files") inDir
#@File(style="directory", label="Output directory for saving converted TIFFs") outDir
import static groovy.io.FileType.FILES
import sc.fiji.hdf5.HDF5ImageJ
import ij.IJ
inDir.eachFileRecurse(FILES) { file ->
if (file.name.endsWith(".h5")) {
println("Converting "+ file)
@tferr
tferr / ExtractSomaPositions.groovy
Last active October 19, 2019 18:33
Extract soma positions from ML database
import sc.fiji.snt.io.MouseLightLoader
import sc.fiji.snt.annotation.AllenCompartment
import sc.fiji.snt.annotation.AllenUtils
import java.text.DecimalFormat
// The name of the compartment to extract somas from
compartmentOfInterest = AllenUtils.getCompartment("Cerebral cortex")
/*
If MouseLightQuerier is available one could simply do:
#@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
@tferr
tferr / MOpShowcase.groovy
Last active September 25, 2019 06:35
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
# @ImageJ ij
# @LUTService lut
import java.text.DecimalFormat
import net.imglib2.display.ColorTable
import org.scijava.util.Colors;
import sc.fiji.snt.*
import sc.fiji.snt.io.*
import sc.fiji.snt.analysis.*
import sc.fiji.snt.annotation.*
# @ImageJ ij
# @LUTService lut
import java.text.DecimalFormat
import net.imglib2.display.ColorTable
import sc.fiji.snt.*
import sc.fiji.snt.io.*
import sc.fiji.snt.analysis.*
import sc.fiji.snt.annotation.*
import sc.fiji.snt.viewer.*