Learn R Programming

tlsR (version 0.1.2)

detect_TLS: Detect Tertiary Lymphoid Structures using a KNN-density approach

Description

This function identifies TLS candidates germinated with B cells (BIC) by: 1. Finding regions of high local B-cell density (KNN-based). 2. Requiring a minimum number of neighbouring T cells (T-B cell co-localisation). 3. Applying sensible size and shape filters.

Value

The original data frame with two new columns:

tls_id_knn

0 = non-TLS, positive integer = TLS cluster ID

tls_center_x, tls_center_y

Coordinates of detected TLS centres (only for TLS cells)

Arguments

LSP

Character. Sample name in the global ldata list.

k

Integer. Number of nearest neighbours to consider (default 30 - works very well on 0.325 um/px imaging).

bcell_density_threshold

Numeric. Minimum average 1/k-distance for B cells to be considered "dense" (default 15 um).

min_B_cells

Integer. Minimum number of B cells in a candidate TLS (default 50).

min_T_cells_nearby

Integer. Minimum T cells within 50 um of the B-cell cluster centre (default 30).

max_distance_T

Numeric. Radius (um) to search for surrounding T cells (default 50).

ldata

Optional. Named list of data frames. If NULL, uses global ldata.

Examples

Run this code
data(toy_ldata)
ldata <- detect_TLS("ToySample", k = 30, ldata = toy_ldata)
table(ldata[["ToySample"]]$tls_id_knn)
plot(ldata[["ToySample"]]$x, ldata[["ToySample"]]$y,
     col = ifelse(ldata[["ToySample"]]$tls_id_knn > 0, "red", "gray"),
     pch = 19, cex = 0.5, main = "Detected TLS in toy data")

Run the code above in your browser using DataLab