Created
January 1, 2017 11:12
-
-
Save petebankhead/f7ceab6f23b89d61bf50767041f7c89c to your computer and use it in GitHub Desktop.
Set the classification of a subcellular detection according to whether it is inside or outside the nucleus
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
// Note: This sets the class according to spot/cluster location, | |
// but does not try to set meaningful colors at this point | |
// Get all spots/clusters | |
def clusters = getObjects({p -> p.class == qupath.imagej.detect.cells.SubcellularDetection.SubcellularObject.class}) | |
// Loop through all clusters | |
for (c in clusters) { | |
// Find the containing cell | |
def cell = c.getParent() | |
// Check the current classification - remove the last part if it | |
// was generated by a previous run of this command | |
def pathClass = c.getPathClass() | |
if (["Nuclear", "Cytoplasmic"].contains(c.getName())) { | |
pathClass = pathClass.getParentClass() | |
} | |
// Check the location of the cluster centroid relative to the nucleus, | |
// and classify accordingly | |
def nucleus = cell.getNucleusROI() | |
if (nucleus != null && nucleus.contains(c.getROI().getCentroidX(), c.getROI().getCentroidY())) { | |
c.setPathClass(getDerivedPathClass(c.getPathClass(), "Nuclear")) | |
} else | |
c.setPathClass(getDerivedPathClass(c.getPathClass(), "Cytoplasmic")) | |
} | |
fireHierarchyUpdate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ranadeyuq My guess is that in the script editor, the option Run → Include default bindings isn't selected.
In general, these gists are kind of 'throwaway' scripts to answer a specific question. This one would have been written for QuPath v0.1.2 but won't necessarily work in v0.2.0 because some pretty major changes are being made. The really important scripts should become built-in features of the software eventually, so that they can be kept up-to-date with changing versions.