/CellDiversityRao

The application of Rao diversity metric to measure the environmental heterogeneity of specific immune cells.

Primary LanguageRMIT LicenseMIT

CellDiversityRao (v1)

R version

About The Project

The application of Rao diversity metric to measure the environmental heterogeneity of specific immune cells.

Main aspects of CellDiversityRaoce:

  • (describe here how the json files are generated).
  • Use of subtype of immune cells to extract spatial diversity features (use of Rao metric - Spectral Rao).
  • Use of raster to depict the spatial patterns of the diversity features.
  • Generate single feature descriptor per file to be used for further analysis.

(back to top)

Built With

List of major frameworks/libraries used to build the project.

  • RStudio
  • R

(back to top)

Getting Started

Cell Diversity Rao consists of three segments.

  1. The preparation of the json file data.
  2. The feature extraction of the Rao features.
  3. The plot or depiction in 2D of the spatial Rao features.

Data preparation

The R file wsi_rao_feat contains the dependencies and scripts for the upcoming work.

  1. We unzip a testing json file located in the /data/ folder. The file is testing_image.zip. Inside the file that is used for testing the scripts is testing_image.json.

  2. The file has information related to the position of different type of cells, in this case we identified necrotic, neoplastic, inflammatory, connective and non-neoplastic epithelial cells. Also other type of position of cells can be used (e.g. subtype of immune cells such as CD4+, CD8+ and CD4+) as long as they are saved in the json format. Minor adjustments are neded to be saved as a csv for processing.

  3. The cell position and identification (x and y position and label 'cell type') are taken to be converted as raster (rasterize), a graphical representation of 2D. The spectralrao function is used to do so. Previously, a empty raster is created with specific number of rows and columns (matrix) so the same canvas is used for every type of cell or representation, as it is needed to be compared across, to obtain a true diversity measurement.

  4. The spectralrao function generates a rao matrix. In this example, we use the option of 'multidimension' and euclidean distance. The multi-dimension stands for taking into account different type of popultions of cells, calculating the Rao index across the diversity of cells. From this rao matrix, we can either plot it, save it, calculate statistical moments (e.g. mean or median of the matrix, density distribution).

  5. To plot the example, we use the spplot function. First, the rao matrix is re-rasterize and rescale (0,1). The dimenions are the same as the canvas, if more details is needed, the canvas size can be increased.

Rao Feature extraction

The rao matrix can is adjusted to be a vector and transposed. Any NaN values found are removed. Then the statistical moments can be calculated. This values are then representing each image or file or case.

   # we transform the rao matrix as vector and transpose it.
raomatrix2_trans <- as.vector(t(raomatrix2[[1]]))
# we remove any nan values or are not taken into account
raomatrix2_trans <- raomatrix2_trans[!is.na(raomatrix2_trans)]
# sort the values for further processing
raomatrix2_trans <- sort(raomatrix2_trans, decreasing = TRUE)
# Calculate the basics statistics from the matrix
# mean, median, max, min or standard deviation
mean(raomatrix2_trans)

Plot of the Rao features and representation

To plot, simply use the spplot function or plot directly with the raster function raster::plot(raster(rao matrix)).

rao_mat1 <- c(r1,r2,r3,r4,r5)
raomatrix1<-spectralrao(input=rao_mat1,window=3,mode="multidimension",distance_m="euclidean",lambda=0.5,na.tolerance=0.85,rescale=FALSE, shannon=F)
spplot(rescale0to1(rast(raomatrix1[[1]])), col.regions = c(topo.colors(50),rev(heat.colors(50))), at=seq(0,1, by=0.01), xlab = "Rao (x-axis)", ylab = "Rao (y-axis)",main=list(label="All cells",cex=2))

Usage

Some screenshots and image generated can be observe below.

R output examples

The example plots generated by R. (left) The plot of the raster::plot and (right) the combination of multiple raster plots of the different cell types. Below is the example of using a raster canvas of higher value, of which the detail of the values can be seen.

Light         Dark         Dark         Dark

(back to top)

R output examples - EXTRA

The R file wsi_cell_plots, contains examples of how to plot in R the cell position and identifier from the json files. The cell were identified on a H&E image using the Hover-Net approach. The files then were saved in json files.

Light

Roadmap

  • Update the README
  • Add back running scrips
  • Add Additional Templates w/ Examples
  • Add "components" document to easily copy & paste sections of the readme
  • Multi-language Support
    • Spanish

Future uses will be added once are found or observed.

(back to top)

References

Please cite the paper below if you want to implement this approach:

Lopez de Rodas M, Nagineni V, Ravi A, Datar IJ, Mino-Kenudson M, Corredor G, Barrera C, Behlman L, Rimm DL, Herbst RS, Madabhushi A, Riess JW, Velcheti V, Hellmann MD, Gainor J, Schalper KA. Role of tumor infiltrating lymphocytes and spatial immune heterogeneity in sensitivity to PD-1 axis blockers in non-small cell lung cancer. J Immunother Cancer. 2022 Jun;10(6):e004440. doi: p10.1136/jitc-2021-004440. PMID: 35649657; PMCID: PMC9161072.

@ARTICLE{Lopez_de_Rodas2022-tc,
title    = "Role of tumor infiltrating lymphocytes and spatial immune
            heterogeneity in sensitivity to {PD-1} axis blockers in non-small
            cell lung cancer",
author   = "Lopez de Rodas, Miguel and Nagineni, Venkata and Ravi, Arvind and
            Datar, Ila J and Mino-Kenudson, Mari and Corredor, German and
            Barrera, Cristian and Behlman, Lindsey and Rimm, David L and
            Herbst, Roy S and Madabhushi, Anant and Riess, Jonathan W and
            Velcheti, Vamsidhar and Hellmann, Matthew D and Gainor, Justin
            and Schalper, Kurt A",
journal  = "J Immunother Cancer",
volume   =  10,
number   =  6,
month    =  jun,
year     =  2022,
address  = "England",
keywords = "immunotherapy; lung neoplasms; lymphocytes, tumor-infiltrating;
            programmed cell death 1 receptor; tumor biomarkers",
language = "en"
}

Rao approach in R was followed by the work done by Rocchini, Marcantonio and Ricotta.

Duccio Rocchini, Matteo Marcantonio, Carlo Ricotta, Measuring Rao's Q diversity index from remote sensing: An open source solution, Ecological Indicators, Volume 72, 2017, Pages 234-238, ISSN 1470-160X. doi.org/10.1016/j.ecolind.2016.07.039.

@article{ROCCHINI2017234,
title = {Measuring Rao's Q diversity index from remote sensing: An open source solution},
journal = {Ecological Indicators},
volume = {72},
pages = {234-238},
year = {2017},
issn = {1470-160X},
doi = {https://doi.org/10.1016/j.ecolind.2016.07.039},
url = {https://www.sciencedirect.com/science/article/pii/S1470160X16304319},
author = {Duccio Rocchini and Matteo Marcantonio and Carlo Ricotta}
}

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Cristian Barrera - cbarrera31@gatech.edu

Project Link: https://github.com/maberyick/CellDiversityRao

(back to top)