Creating area from number of cell detections in QuPath

Is there a code to use to get the total area of cell detections for each class in QuPath? Also QuPath 0.2.0 m4 freezes when drawing polygons for classifications and i lose the key features for each cell detection.

There are many options for creating your own measurements here.

More options here on the old forum, though you might need to edit to sort by class.

Pete also has a script somewhere in his Gist that deals with some of the problems mentioned in the previous link, such as the total cell area being heavily influenced by the cell expansion, and therefor not usually a very accurate quantity as a measure of anything. It defines all areas within the annotation by the nearest cell class.

Also, if you have a bug where the hierarchy breaks, you might be unable to see the measurements until you restart QuPath, but I haven’t seen any consistent problems with selecting cells even with slides with around a million cells, so you would need to provide some additional details on how you are generating the freezes. There is some lag when attempting to draw a new annotation over many cells, maybe that is what you are referring to? If you wait though, it is not the program freezing.

I’m using this code but i cannot get it to give me the area per TMA. What and where do i need to add in the code to complete this?

def tumorCells = getCellObjects().findAll{it.getPathClass() == getPathClass("Tumor")}
def totalArea = 0
for (cell in tumorCells){
    totalArea = totalArea + cell.getMeasurementList().getMeasurementValue("Cell: Area")
println("Total area of your class of cells in square micrometers is: " + totalArea)

You will need to cycle through each core and use getChildObjects() (easy if you have no annotations) or getDescendantObjects() (more difficult, but necessary to pick out cells if you have annotations). The code for many of parts of QuPath scripting is rapidly changing, so no guarantee anything you find will work currently, but in the Making Measurements Gist there should be at least one example of cycling through cores and accessing cells that you can use as a basis for other scripts with TMAs. There are at least scripts for renaming all cells within a TMA core, and for generating percent by class within TMA cores.

Note also that the script above assumes the cells are classified precisely as ‘Tumor’ (and nothing else… and without intensity sub-classification). So… if your cells aren’t classified as tumor the area would also be 0.

1 Like

True, and as I mentioned, I’m generally not a fan of summing cell areas anyway due to the blindness of cell expansion. Stroma, for instance, is frequently massively underestimated. You might also consider Positive Pixel Detection if you have a DAB marker, or something like that.

Yes, i understand the problem with using cell area measurements as it ended up giving me a greater area than staining area detected in some cases.
For my analysis im trying to look at the infiltration of T cells into the tumour. As these are TMAs i cant really do the outer and inner invasive borders as the tumour islands are not big enough. So i tried to look at t cells in the tumour and stroma by positive cell classification and then normalise this to tumour and stroma area. Stroma area i calculated by taking the tumour area from the overall stained area (using a low threshold with pixel detection).
Is there a better way of doing this?
Thank you for your advice.

It would depend on what your stains actually are, and how you are determining the tumor cells. Sample pictures would help. Overall that sounds like a decent approach, assuming you can find a way to accurately determine the tumor area.