akoyabio / phenoptrReports

Create analysis reports from inForm data.
https://akoyabio.github.io/phenoptrReports
zlib License
15 stars 7 forks source link

Spatial map viewer fails with older inForm data #16

Closed AB-Kent closed 5 years ago

AB-Kent commented 5 years ago

The spatial map viewer may fail to show cells when using older inForm cell seg data.

The problem occurs with inForm data which was created in pixel coordinates and converted to microns using the default setting of two pixels per micron. In this case, the data for each field will have the origin at the top-left of the field, rather than an origin in slide coordinates.

The spatial map viewer tries to recognize data in this form and convert to slide coordinates, to match the image coordinates. To do so, it compares the maximum X and Y coordinates within a field to the actual size of the field. If the coordinates fit within the field, the origin is offset to match slide coordinates.

Because the default conversion factor is slightly too small, cells at the edge of the image may appear to exceed the field bounds, defeating the test for field origin. As a result, the origin is not shifted and the cells don't appear on the plot.

A workaround is to read in the cell seg table, multiply the Cell X Position and Cell Y Position values by 2, and divide them by the correct value.

A possible fix would be to detect this situation by looking for a large majority of cells, but not all cells, within the field boundary, and then to apply the same fix.

AB-Kent commented 5 years ago

inForm 2.4.4 is the first version that supported exporting cell seg data in microns, so files created with older versions will have this problem. So will more recent files which were written with pixels selected as the output unit.

The units are encoded into some of the headers in the cell seg data, so opening a file in Notepad and scanning the first line should show either pixels or microns as the unit.

The conversion to microns happens in the consolidate addin and may be controlled by the setting of the phenoptr.pixels.per.micron option.