Analysing exported .geojson annotations from Qupath in SpatStat in R

I am new to coding, with a background in life sciences/biology.

I am aiming to analyse the co-localisation of leukaemia cells to areas of blood vessels and adipocytes.

I have exported the cell locations as points with marks representing either CKIT positivity or DAPI-only positivity.

I have exported point patterns of the cells in Qupath and annotations of the locations of blood vessels/endomucin stained structures and adipocytes/perilipin stained structures as .geojson files from Qupath.

.geojson file of exported Qupath annotations

The window should be a square box from which I have sampled the tissue.

I have attached an image of the example of how I obtained the points and annotations from qupath. The endomucin and perilipin stained annotations are in white and green respectively, identified through qupath’s pixel classifier which I trained. The points are the cells.

Qupath cell points and annotations

I would like the window to be the square outter box, the points as a multitype point pattern and the annotations for perilipin and endomucin staining to act as spatial covariates for the point pattern analysis. However, how do I best model these latter annotations? After importing them as a .geojson into R, converting to sf format, some the edges are touching when checking with st_is_valid.

Should I convert this to a pixel image or binary mask? Can they remain as polygons and be converted to owin objects? (such as the Murchison gold data in Baddeley’s wonderful spatial point pattern analysis book). I have not had much luck converting these polygons to owin objects.

The other key part of this is the annotations need to retain their class as either perilipin or endomucin stained… Perhaps this would be easier as pixel images with factor levels?

I have attempted to import the .geojson files and convert them to spatstat based windows with the following code:

library(sf)
library(spatstat)
library(spatstat.geom)

setwd("~/RStudio/ImageAnalysis")

pt_geojson <- "Veh Tibia - Proximal Tibia.geojson"
annotations_sf <- st_read(pt_geojson)

# Check resulting sf object

head(annotations_sf)

annotations_transform <- st_transform(annotations_sf, crs = 26717)

annotations_owin <- as.owin(annotations_transform)

plot(annotations_owin)

Unfortunately this just generates the following error:

Error in if (!all(st_dimension(W) == 2)) stop("as.owin.sfc needs polygonal geometries") : 
  missing value where TRUE/FALSE needed

I added the following code:

# Check for invalid geometries
invalid_geometries <- st_is_valid(annotations_sf, reason = TRUE)
print(invalid_geometries)

# Fix invalid geometries
annotations_sf <- st_make_valid(annotations_sf)

# Verify geometries are now valid
valid_geometries <- st_is_valid(annotations_sf, reason = TRUE)
print(valid_geometries)

This resulted in the following:

> # Check for invalid geometries
> invalid_geometries <- st_is_valid(annotations_sf, reason = TRUE)
Warning messages:
1: In st_is_longlat(x) :
  bounding box has potentially an invalid value range for longlat data
2: In st_is_longlat(x) :
  bounding box has potentially an invalid value range for longlat data
> print(invalid_geometries)
 [1] "Valid Geometry"          "Edge 2 crosses edge 4"  
 [3] "Edge 16 crosses edge 20" "Valid Geometry"         
 [5] "Valid Geometry"          "Edge 14 crosses edge 20"
 [7] "Valid Geometry"          "Valid Geometry"         
 [9] "Edge 0 crosses edge 8"   "Edge 16 crosses edge 18"
[11] "Edge 6 crosses edge 8"   "Valid Geometry"         
[13] "Valid Geometry"          "Valid Geometry"         
[15] "Edge 0 crosses edge 26"  "Edge 4 crosses edge 10" 
[17] "Valid Geometry"          "Valid Geometry"         
[19] "Edge 12 crosses edge 18" "Valid Geometry"         
[21] "Edge 0 crosses edge 10"  "Valid Geometry"         
[23] "Valid Geometry"          "Valid Geometry"         
[25] "Edge 10 crosses edge 12" "Valid Geometry"         
[27] "Valid Geometry"          "Valid Geometry"         
[29] "Valid Geometry"          "Edge 4 crosses edge 24" 
> 
> # Fix invalid geometries
> annotations_sf <- st_make_valid(annotations_sf)
Warning message:
In st_is_longlat(x) :
  bounding box has potentially an invalid value range for longlat data
> 
> # Verify geometries are now valid
> valid_geometries <- st_is_valid(annotations_sf, reason = TRUE)
> print(valid_geometries)
 [1] "Valid Geometry"          "Edge 2 crosses edge 4"  
 [3] "Edge 16 crosses edge 20" "Valid Geometry"         
 [5] "Valid Geometry"          "Edge 14 crosses edge 20"
 [7] "Valid Geometry"          "Valid Geometry"         
 [9] "Edge 0 crosses edge 8"   "Edge 16 crosses edge 18"
[11] "Edge 6 crosses edge 8"   "Valid Geometry"         
[13] "Valid Geometry"          "Valid Geometry"         
[15] "Edge 0 crosses edge 26"  "Edge 4 crosses edge 10" 
[17] "Valid Geometry"          "Valid Geometry"         
[19] "Edge 12 crosses edge 18" "Valid Geometry"         
[21] "Edge 0 crosses edge 10"  "Valid Geometry"         
[23] "Valid Geometry"          "Valid Geometry"         
[25] "Edge 10 crosses edge 12" "Valid Geometry"         
[27] "Valid Geometry"          "Valid Geometry"         
[29] "Valid Geometry"          "Edge 4 crosses edge 24"

And rerunning the plot afterwards generated this horribly merged plot of all the annotations.

Failed polygonal window plot

New contributor

Callum Fernando is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật