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/*
g = new EasyForm("Enter credentials and continue to the next cell. Do not re-run this cell")
g.addTextField("Server").onInit({g['Server'] = "wss://workshop.openmicroscopy.org/omero-ws"})
g.addTextField("UserName")
g.addPasswordField("Password")
g
ga = new EasyForm("Select the Image to analyze")
ga.addTextField("ImageID")
ga
HOST = g['Server']
USERNAME = g['UserName'].trim()
PASSWORD = g['Password'].trim()
PORT = 443
image_id = ga['ImageID'].toLong()
group_id = -1
-1
import omero.gateway.Gateway
import omero.gateway.LoginCredentials
import omero.log.SimpleLogger
// Method to connect to OMERO
def connect_to_omero() {
"Connect to OMERO"
credentials = new LoginCredentials()
credentials.getServer().setHostname(HOST)
credentials.getUser().setUsername(USERNAME)
credentials.getUser().setPassword(PASSWORD)
simpleLogger = new SimpleLogger()
gateway = new Gateway(simpleLogger)
gateway.connect(credentials)
return gateway
}
// Connect to OMERO
println "connecting..."
gateway = connect_to_omero()
println "connected..."
connecting... connected...
null
import ij.IJ
def open_image_plus(host, username, port, 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.trim())
options.append("\nport=")
options.append(port)
options.append("\npass=")
options.append(password.trim())
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 "Image opening..."
open_image_plus(HOST, USERNAME, PORT, PASSWORD, String.valueOf(group_id), String.valueOf(image_id))
println "Image opened"
java.lang.NoSuchMethodError: ij.IJ.isJava18()Z at loci.plugins.util.LibraryChecker.checkJava(LibraryChecker.java:109) at loci.plugins.LociImporter.run(LociImporter.java:72) at ij.IJ.runUserPlugIn(IJ.java:199) at ij.IJ.runPlugIn(IJ.java:163) at ij.IJ.runPlugIn(IJ.java:152) at ij.IJ$runPlugIn.call(Unknown Source) at script1592252216124.open_image_plus(script1592252216124:20) at script1592252216124$open_image_plus.callCurrent(Unknown Source) at this cell line 23 at com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.runScript(GroovyCodeRunner.java:94) at com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.call(GroovyCodeRunner.java:59) at com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.call(GroovyCodeRunner.java:32)
import ij.IJ
import fiji.plugin.trackmate.Settings
import fiji.plugin.trackmate.Model
import fiji.plugin.trackmate.SelectionModel
import fiji.plugin.trackmate.TrackMate
import fiji.plugin.trackmate.detection.DetectorKeys
import fiji.plugin.trackmate.detection.LogDetectorFactory
import fiji.plugin.trackmate.tracking.sparselap.SparseLAPTrackerFactory
import fiji.plugin.trackmate.tracking.LAPUtils
import fiji.plugin.trackmate.visualization.hyperstack.HyperStackDisplayer
import fiji.plugin.trackmate.features.spot.SpotContrastAndSNRAnalyzerFactory
import fiji.plugin.trackmate.features.spot.SpotIntensityAnalyzerFactory
import fiji.plugin.trackmate.features.track.TrackSpeedStatisticsAnalyzer
def create_tracker(imp) {
"Create the trackmate model for the specified ImagePlus object"
// Instantiate model object
model = new Model()
// Prepare settings object
settings = new Settings()
settings.setFrom(imp)
// Configure detector
settings.detectorFactory = new LogDetectorFactory()
settings.detectorSettings.put(DetectorKeys.KEY_DO_SUBPIXEL_LOCALIZATION, true)
settings.detectorSettings.put(DetectorKeys.KEY_RADIUS, new Double(2.5))
settings.detectorSettings.put(DetectorKeys.KEY_TARGET_CHANNEL, 1)
settings.detectorSettings.put(DetectorKeys.KEY_THRESHOLD, new Double(5.0))
settings.detectorSettings.put(DetectorKeys.KEY_DO_MEDIAN_FILTERING, false)
// Configure tracker
settings.trackerFactory = new SparseLAPTrackerFactory()
settings.trackerSettings = LAPUtils.getDefaultLAPSettingsMap()
settings.trackerSettings['LINKING_MAX_DISTANCE'] = new Double(10.0)
settings.trackerSettings['GAP_CLOSING_MAX_DISTANCE'] = new Double(10.0)
settings.trackerSettings['MAX_FRAME_GAP'] = 3
// Add the analyzers for some spot features
settings.addSpotAnalyzerFactory(new SpotIntensityAnalyzerFactory())
settings.addSpotAnalyzerFactory(new SpotContrastAndSNRAnalyzerFactory())
// Add an analyzer for some track features, such as the track mean speed.
settings.addTrackAnalyzer(new TrackSpeedStatisticsAnalyzer())
settings.initialSpotFilterValue = 1
// Instantiate trackmate
trackmate = new TrackMate(model, settings)
ok = trackmate.checkInput()
if (!ok) {
print(str(trackmate.getErrorMessage()))
return null
}
ok = trackmate.process()
if (!ok) {
print(str(trackmate.getErrorMessage()))
return null
}
return model
}
imp = IJ.getImage()
trackmate_model = create_tracker(imp)
import java.util.ArrayList
import omero.gateway.model.EllipseData
import omero.gateway.model.PolylineData
import omero.gateway.model.ROIData
import omero.model.PolylineI
import static omero.rtypes.rstring
import fiji.plugin.trackmate.Spot
def convert_tracks(model, dx, dy) {
"Convert the tracks into OMERO objects"
rois = new ArrayList()
tracks = model.getTrackModel().trackIDs(true)
tracks.each() { track_id ->
track = model.getTrackModel().trackSpots(track_id)
roi = new ROIData()
rois.add(roi)
points = ""
track.each() { spot ->
sid = spot.ID()
// Fetch spot features directly from spot.
x = spot.getFeature('POSITION_X')/dx
y = spot.getFeature('POSITION_Y')/dy
r = spot.getFeature('RADIUS')
z = spot.getFeature('POSITION_Z')
t = spot.getFeature('FRAME')
// Save spot as Point in OMERO
ellipse = new EllipseData(x, y, r, r)
ellipse.setZ((int) z)
ellipse.setT((int) t)
// set trackmate track ID and spot ID for later
ellipse.setText(track_id+':'+sid)
// set a default color
settings = ellipse.getShapeSettings()
settings.setStroke(java.awt.Color.RED)
roi.addShapeData(ellipse)
points = points + x + ',' + y + ' '
}
// Convert the track
points = points.trim()
polyline = new PolylineI()
polyline.setPoints(rstring(points))
pl = new PolylineData(polyline)
// set a default color
settings = pl.getShapeSettings()
settings.setStroke(java.awt.Color.YELLOW)
roi.addShapeData(pl)
}
return rois
}
dx = imp.getCalibration().pixelWidth
dy = imp.getCalibration().pixelHeight
omero_rois = convert_tracks(trackmate_model, dx, dy)
import omero.gateway.facility.ROIFacility
import omero.gateway.SecurityContext
def save_rois(gateway, rois, image_id) {
roi_facility = gateway.getFacility(ROIFacility)
user = gateway.getLoggedInUser()
ctx = new SecurityContext(user.getGroupId())
results = roi_facility.saveROIs(ctx, image_id, user.getId(), rois)
}
save_rois(gateway, omero_rois, image_id)
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.