Scripting for applying multiple classifications QuPath

Hi, I am pretty new to scripting and not familiar with the groovy language. I am trying to analyse multi-channel fluorescent images and determine double positive cells and having a few problems:

Firstly,

when editng this script Pete posted on his blog here (Multichannel fluorescence & multiple classifications | Pete’s blog) I keep getting a error for the line " println classifier.classifyObjects(cells)"

// Apply classifications
def cells = QPEx.getCellObjects()
cells.each {it.setPathClass(null)}
for (classifier in classifiers) {
    println classifier.classifyObjects(cells)
}
println 'None: \t' + cells.count {it.getPathClass() == null}
QPEx.fireHierarchyUpdate()

Error message:

ERROR: NullPointerException at line 33: null

ERROR: qupath.lib.objects.classes.PathClassFactory.getPathClass(PathClassFactory.java:229)

Secondly,

I would like to define the threshold of each fluorescent channel based off the fluorescent intensity mean and MAD using something similar to petes code here but I am unsure how to use this in conjunction with the code above

def measurementName = 'Cell: CK mean'
double k = 5

def cells = getCellObjects()

def allMeasurements = cells.stream()
        .mapToDouble({p -> p.getMeasurementList().getMeasurementValue(measurementName)})
        .filter({d -> !Double.isNaN(d)})
        .toArray()
double median = getMedian(allMeasurements)

// Subtract median & get absolute value
def absMedianSubtracted = Arrays.stream(allMeasurements).map({d -> Math.abs(d - median)}).toArray()

// Compute median absolute deviation & convert to standard deviation approximation
double medianAbsoluteDeviation = getMedian(absMedianSubtracted)
double sigma = medianAbsoluteDeviation / 0.6745

// Return threshold
double threshold = median + k * sigma

/**
 * Get median value from array (this will sort the array!)
 */
double getMedian(double[] vals) {
    if (vals.length == 0)
        return Double.NaN
    Arrays.sort(vals)
    if (vals.length % 2 == 1)
        return vals[(int)(vals.length / 2)]
    else
        return (vals[(int)(vals.length / 2)-1] + vals[(int)(vals.length / 2)]) / 2.0
}

Any help is wildly appreciated and thank you in advance!

1 Like

I haven’t dug through everything you posted, but is there any reason you have not tried the more current documentation: Multiplexed analysis — QuPath 0.2.3 documentation ?

That post seems to be from 2018, and I am fairly certain 0.2.0 was out mid 2020, making any code found there very likely a bit out of date.