Last active
December 18, 2020 06:28
-
-
Save romainGuiet/08e60992a286d7c3e44ad9f453ff0d0a to your computer and use it in GitHub Desktop.
An example script to show how to filter spots after the detection. #Fiji #EasyXT-Fiji #Imaris #BIOP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name_spots = "pinkySpots"; | |
name_filtered_spots = name_spots+"-filtered"; | |
rt = new ResultsTable() | |
rt.reset() | |
// Here teh script expect to find the demo.ims file in the folder Fiji>Plugins>BIOP | |
def plugins_dir = IJ.getDirectory("plugins") | |
def biop_dir = new File(plugins_dir , "BIOP") | |
ims_name = "HeLa_H2B-mcherry_Tubline-EGFP_mitochondria-MitoTracker_reduced.ims" | |
ims_path = new File( biop_dir, ims_name) | |
// get ImarisApp | |
def imaris_app = EasyXT.getImaris() | |
// make Imaris open an imaris file | |
EasyXT.openImage(ims_path) | |
//we detect the spots and add them to the Scene | |
detected_spots = SpotsDetector.Channel(2)// 3rd channel | |
.setName(name_spots) | |
.setDiameter(3) | |
.setFilter("\"Quality\" above 25") | |
.isSubtractBackground(true) | |
.build() | |
.detect() | |
EasyXT.addToScene(detected_spots) | |
// get the number of spots | |
detected_spots_Nbr = detected_spots.Get().mIds.size() | |
// prepare lists to store required infos to create spots | |
def xyzFiltered_spots = [] | |
def tFiltered_spots = [] | |
def rFiltered_spots = [] | |
for ( i in 0..detected_spots_Nbr-1){ | |
// with this silly example , we check if it belongs to an even (or odd) time-point ? | |
if (detected_spots.Get().mIndicesT[i]%2 == 0){ | |
// and add | |
xyzFiltered_spots.add(detected_spots.Get().mPositionsXYZ[i]) // alternatively : detected_spots.GetPositionsXYZ() | |
tFiltered_spots.add(detected_spots.Get().mIndicesT[i]) // alternatively : detected_spots.GetIndicesT() | |
rFiltered_spots.add(detected_spots.Get().mRadii[i]) // alternatively : detected_spots.GetRadii () | |
} | |
} | |
//make new spots, using the IFactory | |
filtered_spots = imaris_app.GetFactory().CreateSpots() | |
// assign the required information for the spots | |
filtered_spots.Set(xyzFiltered_spots as float[][] ,tFiltered_spots as int[] ,rFiltered_spots as float[] ) | |
// (optionnal set a name) | |
filtered_spots.SetName("Filtered Spots") | |
// add to the scene | |
EasyXT.addToScene(filtered_spots) | |
/* | |
* A more advanced filtering using results from Statistics | |
*/ | |
spots_id = detected_spots.GetIds() | |
rt = EasyXT.getStatistics(detected_spots, "Intensity Median") // get a table with value for all the channels | |
//rt = EasyXT.getStatistics(detected_spots, "Volume") // | |
//rt.show() | |
def xyzAdvFiltered_spots= [] | |
def tAdvFiltered_spots = [] | |
def rAdvFiltered_spots = [] | |
for ( i in 0..detected_spots_Nbr-1){ | |
// with this silly example , we check if it belongs to an even (or odd) time-point ? | |
id_row = getRowIdxOf ( rt , "ID" , spots_id[i] ) | |
median_int_C3 = rt.getValue("Intensity Median C3", id_row) | |
if ( median_int_C3 > 100){ | |
// and add | |
xyzAdvFiltered_spots.add(detected_spots.Get().mPositionsXYZ[i]) // alternatively : detected_spots.GetPositionsXYZ() | |
tAdvFiltered_spots.add(detected_spots.Get().mIndicesT[i]) // alternatively : detected_spots.GetIndicesT() | |
rAdvFiltered_spots.add(detected_spots.Get().mRadii[i]) // alternatively : detected_spots.GetRadii () | |
} | |
} | |
//make new spots, using the IFactory | |
advFiltered_spots = imaris_app.GetFactory().CreateSpots() | |
// assign the required information for the spots | |
advFiltered_spots.Set(xyzAdvFiltered_spots as float[][] ,tAdvFiltered_spots as int[] ,rAdvFiltered_spots as float[] ) | |
// (optionnal set a name) | |
advFiltered_spots.SetName("Adv. Filtered Spots") | |
// add to the scene | |
EasyXT.addToScene(advFiltered_spots) | |
/* | |
* Companion function to look for an ID in the result table | |
*/ | |
def getRowIdxOf ( ResultsTable , ColumnName , UniqueID ){ | |
row = 0 | |
while ( row < rt.size() ) { | |
if ( rt.getValue(ColumnName, row) == UniqueID) return row | |
else row++ | |
} | |
} | |
return | |
import Imaris.* | |
import ch.epfl.biop.imaris.* | |
import ij.*; | |
import ij.measure.ResultsTable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment