This notebook demonstrates how to analyze a batch of images associated to the paper 'Subdiffraction imaging of centrosomes reveals higher-order organizational features of pericentriolar material.' using the scripting facility available in Fiji
Fiji has been installed with few other plugins including the omero_ij plugin to allow to connect to an OMERO server.
The following section shows:
First we had Fiji and the plugins to the classpath.
//Add dependencies to the classpath
%classpath add jar /srv/conda/vnc/Fiji.app/jars/*
%classpath add jar /srv/conda/vnc/Fiji.app/plugins/*
//Connection information
HOST = "wss://idr.openmicroscopy.org/omero-ws"
USERNAME = "public"
PASSWORD = "public"
public
import omero.gateway.Gateway
import omero.gateway.LoginCredentials
import omero.log.SimpleLogger
// Method to connect to OMERO
def connect_to_omero(host, user, password) {
"Connect to OMERO"
credentials = new LoginCredentials()
credentials.getServer().setHostname(host)
credentials.getUser().setUsername(user.trim())
credentials.getUser().setPassword(password.trim())
simpleLogger = new SimpleLogger()
gateway = new Gateway(simpleLogger)
gateway.connect(credentials)
return gateway
}
// Connect to OMERO
println "connecting..."
gateway = connect_to_omero(HOST, USERNAME, PASSWORD)
println "connected..."
connecting... connected...
null
Select an image from the idr0021 study.
//Move to the next cell after entering a value
ga = new EasyForm("Select the Image to analyze")
ga.addTextField("ImageID").onInit({ga['ImageID'] = "1884807"})
ga
//Image to analyze
image_id = ga['ImageID'].toLong()
group_id = "-1"
-1
import ij.IJ
import ij.plugin.frame.RoiManager
//Function to Open an OMERO image using Bio-Formats
def open_image_plus(host, username, password, group_id, image_id) {
"Open the image using the Bio-Formats Importer"
StringBuilder options = new StringBuilder()
options.append("location=[OMERO] open=[omero:server=")
options.append(host)
options.append("\nuser=")
options.append(username)
options.append("\nport=")
options.append(443)
options.append("\npass=")
options.append(password)
options.append("\ngroupID=")
options.append(group_id)
options.append("\niid=")
options.append(image_id)
options.append("] ")
options.append("windowless=true view=Hyperstack ")
IJ.runPlugIn("loci.plugins.LociImporter", options.toString())
}
println "opening Image..."
// Open the Image using Bio-Formats
open_image_plus(HOST, USERNAME, PASSWORD, group_id, String.valueOf(image_id))
opening Image...
loci.plugins.LociImporter@5960cad2
We run fiji-macro-segment.ijm on the image.
The macro file will:
import ij.IJ
import ij.plugin.frame.RoiManager
imp = IJ.getImage()
RoiManager.getRoiManager()
IJ.runMacroFile("../scripts/fiji-macro-segment.ijm")
println "Analysis completed"
Area Mean Min Max 1 0.154 144.031 22 188 2 0.016 175.300 162 186 3 0.050 153.188 95 189 4 0.121 126.701 0 189 5 0.036 164.870 128 189 6 0.240 121.431 0 189 7 0.176 142.321 15 189 8 0.017 180.364 171 189 9 0.031 137.600 57 189 10 0.019 174.250 153 189 11 0.019 167.917 144 187 12 0.025 168.500 148 188 13 0.017 167.091 142 187 14 0.315 143.085 0 189 15 0.198 144.730 49 189 16 0.049 169.645 147 187 17 0.022 164.500 140 183 Analysis completed
null
We now run the macro on all the images in the study. This will take several minutes. This is mainly to show how to iterate over all the images in a study, you can also have a look at idr0021.groovy.
project_id = 51
51
import omero.gateway.SecurityContext
import omero.gateway.facility.BrowseFacility
import ij.IJ
//helper functions
//Function to Open an OMERO image using Bio-Formats
def open_image_plus(host, username, password, group_id, image_id) {
"Open the image using the Bio-Formats Importer"
StringBuilder options = new StringBuilder()
options.append("location=[OMERO] open=[omero:server=")
options.append(host)
options.append("\nuser=")
options.append(username)
options.append("\nport=")
options.append(443)
options.append("\npass=")
options.append(password)
options.append("\ngroupID=")
options.append(group_id)
options.append("\niid=")
options.append(image_id)
options.append("] ")
options.append("windowless=true view=Hyperstack ")
IJ.runPlugIn("loci.plugins.LociImporter", options.toString())
}
//Load the datasets
def get_datasets(gateway, ctx, project_id) {
"List all datasets contained in a Project"
browse = gateway.getFacility(BrowseFacility)
ids = new ArrayList(1)
ids.add(new Long(project_id))
projects = browse.getProjects(ctx, ids)
return projects[0].getDatasets()
}
//Load the images
def get_images(gateway, ctx, dataset_id) {
"List all images contained in a Dataset"
browse = gateway.getFacility(BrowseFacility)
ids = new ArrayList(1)
ids.add(new Long(dataset_id))
return browse.getImagesForDatasets(ctx, ids)
}
user = gateway.getLoggedInUser()
group_id = user.getGroupId()
ctx = new SecurityContext(group_id)
datasets = get_datasets(gateway, ctx, project_id)
//Close windows before starting
IJ.run("Close All")
datasets.each() { d ->
dataset_name = d.getName()
// for each dataset load the images
// get all images_ids in the dataset
images = get_images(gateway, ctx, d.getId())
images.each() { image ->
if (image.getName().endsWith(".tif")) {
return
}
id = image.getId()
println "Running macro on image: "+id
open_image_plus(HOST, USERNAME, PASSWORD, group_id, id)
imp = IJ.getImage()
IJ.runMacroFile("../scripts/fiji-macro-segment.ijm")
}
}
Running macro on image: 1884856 Area Mean Min Max 1 0.027 128.588 43 184 2 0.020 125.692 51 181 3 0.016 148.300 110 178 4 0.017 143.636 96 184 5 0.022 130.357 69 178 6 0.030 130.368 41 181 7 0.017 157.091 125 181 8 0.449 115.531 0 184 9 0.016 134.000 83 181 10 0.016 136.400 93 172 11 0.016 146.800 110 184 12 0.025 130.188 51 183 13 0.019 134.417 72 183 14 0.019 126.917 70 171 15 0.022 149.143 103 178 16 0.020 138.385 76 183 17 0.030 104.789 0 181 18 0.016 147.300 111 178 19 0.027 149.059 100 183 20 0.025 161.312 128 184 21 0.017 160.455 134 181 22 0.047 138.733 77 183 23 0.023 128.333 62 173 24 0.016 160.500 130 184 Running macro on image: 1884857 Area Mean Min Max 1 0.208 154.714 0 201 2 0.237 149.822 31 201 3 0.020 158.769 113 187 4 0.020 166.769 130 201 5 0.020 169.077 131 194 6 0.023 183.533 156 200 7 0.066 160.000 127 201 8 0.044 120.286 0 200 9 0.031 184.850 154 201 10 0.036 163.522 97 198 11 0.051 166.333 120 200 12 0.022 156.643 105 199 Running macro on image: 1884860 Area Mean Min Max 1 0.017 176.636 144 200 2 0.276 122.497 0 199 3 0.245 136.745 9 199 4 0.022 156.000 96 197 5 0.019 171.750 129 199 6 0.017 157.455 109 194 7 0.016 177.900 152 196 8 0.020 162.308 116 197 9 0.019 176.167 145 196 10 0.048 169.677 121 200 11 0.027 175.706 151 197 12 0.016 170.100 138 196 13 0.017 179.182 153 199 14 0.017 162.273 121 193 15 0.019 168.167 143 189 16 0.089 122.298 25 200 17 0.023 160.933 108 196 18 0.027 116.353 28 194 19 0.072 128.109 14 199 20 0.017 159.455 114 197 21 0.025 177.812 140 199 22 0.019 159.000 110 200 23 0.056 178.556 127 199 24 0.028 116.167 20 195 25 0.019 163.667 122 197 26 0.037 113.625 0 195 27 0.023 160.200 101 200 28 0.020 165.000 118 194 29 0.020 161.538 111 196 30 0.016 153.800 109 195 31 0.039 146.440 84 196 32 0.016 182.500 166 196 33 0.053 144.676 74 200 34 0.017 174.818 144 196 35 0.084 153.222 95 200 36 0.025 139.125 60 200 37 0.033 179.571 139 198 38 0.020 154.154 96 193 39 0.017 160.636 119 192 40 0.016 168.400 133 200 41 0.020 147.538 84 197 42 0.016 181.700 158 199 Running macro on image: 1884843 Area Mean Min Max 1 0.243 136.832 14 213 2 0.205 119.206 0 213 3 0.017 188.545 160 212 4 0.028 198.056 174 214 5 0.016 185.400 156 211 6 0.019 168.833 120 207 7 0.016 193.200 172 212 8 0.033 189.524 135 214 9 0.016 193.700 170 214 10 0.020 185.154 148 214 11 0.017 194.273 169 212 12 0.020 184.846 148 211 13 0.028 190.056 147 214 14 0.022 193.929 166 208 15 0.033 195.048 156 214 16 0.016 193.000 168 213 17 0.016 185.300 156 214 18 0.022 185.429 150 213 19 0.022 180.643 137 210 20 0.016 192.600 168 214 21 0.019 189.667 163 208 22 0.019 195.167 168 214 23 0.039 190.720 144 214 24 0.024 197.600 180 212 25 0.025 197.000 173 213 26 0.020 188.769 158 211 27 0.028 188.778 155 213 28 0.027 191.882 159 213 29 0.020 186.462 154 214 30 0.129 152.207 0 212 31 0.016 195.800 178 214 32 0.041 155.808 59 212 33 0.056 169.639 127 214 34 0.016 190.600 166 213 35 0.017 196.818 174 214 36 0.020 183.462 144 214 37 0.017 190.636 158 214 38 0.016 193.700 170 214 39 0.019 194.667 169 213 40 0.017 185.636 153 210 41 0.019 193.583 170 209 42 0.016 189.900 166 211 Running macro on image: 1884845 Area Mean Min Max 1 0.191 143.148 0 214 2 0.143 141.714 19 212 3 0.017 197.909 180 214 4 0.016 200.400 183 212 5 0.016 194.400 172 213 6 0.020 187.615 152 211 7 0.042 174.852 97 213 8 0.038 129.625 0 213 9 0.041 149.500 38 214 10 0.016 191.900 166 211 11 0.016 190.000 161 212 Running macro on image: 1884851 Area Mean Min Max 1 0.025 127.250 43 186 2 0.017 141.909 80 191 3 0.223 132.979 0 193 4 0.172 152.036 70 192 5 0.027 117.588 11 179 6 0.030 132.526 30 190 7 0.022 147.786 81 192 8 0.019 163.167 127 188 9 0.017 173.818 149 193 10 0.016 152.100 107 191 11 0.034 128.909 44 190 12 0.053 137.324 68 192 13 0.016 159.000 122 185 14 0.016 180.600 158 193 15 0.020 153.231 102 186 16 0.028 117.056 0 189 Running macro on image: 1884841 Area Mean Min Max 1 0.016 202 179 221 2 0.251 140.419 42 221 3 0.276 155.335 0 220 4 0.028 208.278 196 221 5 0.022 206.429 187 221 6 0.022 209.571 198 220 7 0.071 169.800 79 221 8 0.044 140.393 0 221 9 0.050 189.844 113 221 10 0.044 154.929 44 221 Running macro on image: 1884849
// Close the connection
gateway.disconnect()
println "Done"
Done
true
Copyright (c) 2021, University of Dundee All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.