Calculate the average value of each cell characteristic of the positive cell

In QUPATH, I want to calculate the average value of all the cell features classified as positive through the script, such as the average value of the nucleus area classified as positive and the average value of the nucleus circumference classified as positive. What should I do?I refer to some of the ones that calculate the area of positive cells, but how do you use scripts to calculate the average of a particular feature?Thank you very much!

Background

  • What is the image about? Provide some background and/or a description of the image. Try to avoid field-specific “jargon”.

Analysis goals

  • What information are you interested in getting from this image?

Challenges

  • What stops you from proceeding?
  • What have you tried already?
  • Have you found any related forum topics? If so, cross-link them.
  • What software packages and/or plugins have you tried?

If you already have scripts to calculate the sum of a particular measurement, all you need to do to calculate the average is divide by the number of cells, which can be obtained using
cellCount = getCellObjects().size()

That would get the total number of cells in the image, so you may want to use a subset of that with something like

positiveCells = getCellObjects().findAll{it.getPathClass() == getPathClass("Positive")}
positiveCellsCount = positiveCells.size()

Hard to say too much more without knowing more about the project and where you want to save the measurements. Per annotation? Are there different annotations? Different classes of annotation? Do you really want to cycle through all of the measurements?

Thank you very much for your reply. I now want to get the average value of all the features classified as positive or negative in the entire image. As shown in the table below, the first row represents the average value of each feature of the cell as negative, and the second row the average value of each feature that indicates that the cell is positive. I just think it is more useful to get the information of the entire image when I am currently researching. I found some scripts, and there was an error when running, please help me see how to change.


Hi all,

Just a short point here. We often recommend the users of our bioimaging and optics core facility to split the data gathering part from the data analysis part.

QuPath is meant to be a visualisation and quantification tool (and much more), not a statistics or data analysis tool. My suggestion is to export all results that QuPath produces and use something like Pivot tables in Excel or your favorite software to group your data and get the summary stats you want…

Usually makes things easier, especially as it’s usually not enough to just get averages but you need to run significance tests, test for sample variability and more…

Not very useful advice but a friendly recommendation

3 Likes

Just seconding what @oburri says – you can script all your measurements in QuPath, but it’s really easy to introduce a bug and so for this kind of thing I’d always recommend exporting the data and exploring it deeper elsewhere. Or doing both approaches and comparing.

Re. the error, not sure if it’s the reason but you’ve got ‘smart quotes’ – ‘’ – rather than 'straight quotes''' – around your text, which Groovy won’t like.

Anyhow, he’s a shorter script showing how you can calculate averages of a measurement for all positive cells (intended to be checked elsewhere, as per Oli’s advice :slight_smile: ):

def cells = getCellObjects()

def positive = cells.findAll { cell -> cell.getPathClass() == getPathClass('Positive')}
def areas = positive.collect { cell -> measurement(cell, 'Nucleus: Area') } as double[]
print areas.average()
1 Like

Edited after @Research_Associate spotted a typo in the original (which used all cells, not positive only)… and therefore inadvertently further supported @oburri’s point.

1 Like

Thank you very much for your reply, this is a very useful suggestion,I always struggled with how to use qupath to get a more concise and clear result, but other data processing software can also get the same result.