Counting the red cells is easy. The hard part is deciding what to divide them by.
Counting the red cells in a map takes one line.
til_px = (code == 2).sum()
But you cannot use that number as it stands. Slides come in different sizes —
one map is 250,000 cells, another is 20,000.
You need a rate before you can compare. And the problem is the denominator.
Candidate
Formula
Does it make sense?
the whole grid
red ÷ (width × height)
puts bare glass into the denominator
tissue tiles
red ÷ (blue + red)
counts only where a lymphocyte could be
tumour region only
red ÷ tumour tiles
the most correct thing to say — but there is no tumour boundary in this data
Same map, same red cells. And yet the numbers are 45.66% and 8.43%.
PythonRuns in your browser
"The value changes" you might shrug at.
What is serious is when the ranking changes.
Because slides differ in how much of the grid their tissue fills, switching the
denominator lifts some slides and lowers others.
Measure four slides both ways and the ranking really does flip — by tissue, 44-2668 (45.7%) sits far above BR-8483 (15.9%); by grid it is 8.43% against 8.74% and they swap places.
PythonRuns in your browser
Switch the denominator. A bar turns amber when that slide changed places.
Loading…
The third candidate — dividing by the tumour region only — is in fact the
most correct thing to do pathologically. A lymphocyte that got inside the tumour and
one that was always sitting in the normal tissue next door mean different things.
But this map does not say where the tumour is.
Producing that information would need another model that segments tumour regions,
and the public data does not have one.
So the infiltration rate we use is "relative to all tissue".
That is a limitation, and it follows every result from here on. Do not forget it.
🤔 Check yourself
Why use 'tissue tiles' as the denominator of the infiltration rate?
Answer A denominator should be the places that had the opportunity. There were never any cells on the glass, so including it unfairly penalises slides whose tissue is spread thin.
🤔 Check yourself
What is the worst thing about switching the denominator to 'the whole grid'?
Answer If every slide shrank by the same factor the ranking would survive and it would hardly matter. The problem is that how much of the grid the tissue fills differs per slide.