This is going to be a short vignette for the use of the functions used to derive spatial metrics.
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
devtools::load_all()
#> ℹ Loading spatialTIME
#> spatialTIME version:
#> 1.3.4.2
#> If using for publication, please cite our manuscript:
#> https://doi.org/10.1093/bioinformatics/btab757
mif = create_mif(clinical_data = example_clinical %>%
mutate(deidentified_id = as.character(deidentified_id)),
sample_data = example_summary %>%
mutate(deidentified_id = as.character(deidentified_id)),
spatial_list = example_spatial,
patient_id = "deidentified_id",
sample_id = "deidentified_sample")
markers = colnames(mif$spatial[[1]]) %>%
grep("CD3|Pos", ., value = T) %>%
grep("Cyto|Nucle", ., value = T, invert = T)
markers = markers[c(1,2,4,5,8)]
mif = ripleys_k(mif = mif,
mnames = markers[1:2],
r_range = 0:100,
num_permutations = 25,
edge_correction = 'translation',
permute = TRUE,
keep_permutation_distribution = FALSE,
workers = 1,
overwrite = TRUE,
xloc = NULL,
yloc = NULL)
mif$derived$univariate_Count %>%
ggplot() +
geom_line(aes(x = r, y = `Degree of Clustering Permutation`, color = deidentified_sample)) +
facet_grid(~Marker)
mif = bi_ripleys_k(mif = mif,
mnames = markers[1:2],
r_range = 0:100,
num_permutations = 25,
edge_correction = "translation",
permute = TRUE,
keep_permutation_distribution = FALSE,
workers = 1,
overwrite = TRUE,
xloc = NULL,
yloc = NULL)
mif$derived$bivariate_Count %>%
ggplot() +
geom_line(aes(x = r, y = `Degree of Clustering Permutation`, color = deidentified_sample)) +
facet_grid(~Anchor)
mif = NN_G(mif = mif,
mnames = markers[1:2],
r_range = 0:100,
num_permutations = 25,
edge_correction = "rs",
keep_perm_dis = FALSE,
workers = 1,
overwrite = TRUE,
xloc = NULL,
yloc = NULL)
mif$derived$univariate_NN %>%
ggplot() +
geom_line(aes(x = r, y = `Degree of Clustering Permutation`, color = deidentified_sample)) +
facet_grid(~Marker)
mif = bi_NN_G(mif = mif,
mnames = markers[1:2],
r_range = 0:100,
num_permutations = 25,
edge_correction = "rs",
keep_perm_dis = FALSE,
workers = 1,
overwrite = TRUE,
xloc = NULL,
yloc = NULL)
mif$derived$bivariate_NN %>%
ggplot() +
geom_line(aes(x = r, y = `Degree of Clustering Permutation`, color = deidentified_sample)) +
facet_grid(~Anchor)
mif = pair_correlation(mif = mif,
mnames = markers[1:2],
r_range = 0:100,
num_permutations = 25,
edge_correction = "translation",
keep_permutation_distribution = FALSE,
workers = 1,
overwrite = TRUE,
xloc = NULL,
yloc = NULL)
mif$derived$univariate_pair_correlation %>%
ggplot() +
geom_line(aes(x = r, y = `Degree of Correlation Permuted`, color = deidentified_sample)) +
facet_grid(~Marker)
#> Warning: Removed 5 rows containing missing values (`geom_line()`).
mif = bi_pair_correlation(mif = mif,
mnames = markers[1:2],
r_range = 0:100,
num_permutations = 25,
edge_correction = "translation",
keep_permutation_distribution = FALSE,
workers = 1,
overwrite = TRUE,
xloc = NULL,
yloc = NULL)
mif$derived$bivariate_pair_correlation %>%
ggplot() +
geom_line(aes(x = r, y = `Degree of Correlation Permuted`, color = deidentified_sample)) +
facet_grid(~From)
#> Warning: Removed 5 rows containing missing values (`geom_line()`).
mif = interaction_variable(mif = mif,
mnames = markers[1:2],
r_range = 0:100,
num_permutations = 25,
keep_permutation_distribution = FALSE,
workers = 1,
overwrite = TRUE,
xloc = NULL,
yloc = NULL)
mif$derived$interaction_variable %>%
ggplot() +
geom_line(aes(x = r, y = `Degree of Interaction Permuted`, color = deidentified_sample)) +
facet_grid(~From)
mif = dixons_s(mif = mif,
mnames = markers[1:2],
num_permutations = 25,
type = "Z",
workers = 1,
overwrite = TRUE,
xloc = NULL,
yloc = NULL)
#> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
#> 21, 22, 23, 24,
#> 25.
#> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
#> 21, 22, 23, 24,
#> 25.
#> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
#> 21, 22, 23, 24,
#> 25.
#> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
#> 21, 22, 23, 24,
#> 25.
#> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
#> 21, 22, 23, 24,
#> 25.
mif$derived$Dixon_Z %>%
filter(From != To) %>%
ggplot() +
geom_point(aes(x = Z, y = S, color = deidentified_sample)) +
facet_grid(~From)