Skip to content

Commit

Permalink
update scFeartures script
Browse files Browse the repository at this point in the history
  • Loading branch information
littlecabiria committed Nov 22, 2024
1 parent 208a246 commit 1997c3d
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/metrics/ks_statistic_sc_features/script.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,28 @@ requireNamespace("CARD", quietly = TRUE)
requireNamespace("SingleCellExperiment", quietly = TRUE)
requireNamespace("SummarizedExperiment", quietly = TRUE)

<<<<<<< Updated upstream
## VIASH START
par <- list(
input_spatial_dataset = "resources_test/spatialsimbench_mobnew/dataset_sp.h5ad",
input_singlecell_dataset = "resources_test/spatialsimbench_mobnew/dataset_sc.h5ad",
input_simulated_dataset = "resources_test/spatialsimbench_mobnew/simulated_dataset.h5ad",
=======
packages <- c("SingleCellExperiment", "SummarizedExperiment", "concaveman", "sp",
"Matrix", "methods", "ggplot2", "ggcorrplot", "MuSiC", "fields",
"MCMCpack", "dplyr", "sf", "RANN", "stats", "reshape2", "RColorBrewer",
"scatterpie", "grDevices", "nnls", "pbmcapply", "spatstat", "gtools",
"RcppML", "NMF")

# Load each package
lapply(packages, library, character.only = TRUE)

## VIASH START
par <- list(
input_spatial_dataset = "temp_pdac.positive.ks_statistic_sc_features/_viash_par/input_spatial_dataset_1/output_sp.h5ad",
input_singlecell_dataset = "temp_pdac.positive.ks_statistic_sc_features/_viash_par/input_singlecell_dataset_1/output_sc.h5ad",
input_simulated_dataset = "temp_pdac.positive.ks_statistic_sc_features/_viash_par/input_simulated_dataset_1/pdac.positive.generate_sim_spatialcluster.output_sp.h5ad",
>>>>>>> Stashed changes
output = "output.h5ad"
)
meta <- list(
Expand All @@ -31,11 +48,26 @@ real_log_count <- t(input_real_sp$layers[["logcounts"]])
real_prob_matrix <- input_real_sp$obsm[["celltype_proportions"]]
colnames(real_prob_matrix) <- paste0("ct", seq_len(ncol(real_prob_matrix)))

<<<<<<< Updated upstream
sim_log_count <- scuttle::normalizeCounts(t(input_simulated_sp$layers[["counts"]]))
=======
real_log_count <- real_log_count[ , colnames(real_log_count) %in% rownames(real_prob_matrix) ]

# build cell type deconvolution in simulated data

sim_sce <- scater::logNormCounts(SingleCellExperiment::SingleCellExperiment(
list(counts = Matrix::t(input_simulated_sp$layers[["counts"]])),
colData = input_simulated_sp$obs,
metadata = input_simulated_sp$obsm
))

sim_log_count <- SummarizedExperiment::assay(sim_sce, "logcounts")
>>>>>>> Stashed changes

# build cell type deconvolution in simulated data ## error
sim_prob_matrix <- CARD_processing(input_real_sp, input_sc)

sim_log_count <- sim_log_count[ , colnames(sim_log_count) %in% rownames(sim_prob_matrix) ]

feat_types <- c("L_stats", "celltype_interaction", "nn_correlation", "morans_I")

real_scfeatures_result <- scFeatures::scFeatures(real_log_count,
Expand All @@ -48,13 +80,23 @@ real_scfeatures_result <- scFeatures::scFeatures(real_log_count,
)

sim_scfeatures_result <- scFeatures::scFeatures(sim_log_count,
<<<<<<< Updated upstream
sample = rep("sample1", ncol(sim_log_count)),
spatialCoords = input_simulated_sp$obs[c("row", "col")],
feature_types = feat_types,
type = "spatial_t",
species = sc_species,
spotProbability = t(sim_prob_matrix)
)
=======
sample = rep("sample1", ncol(sim_log_count)),
spatialCoords = list( as.numeric( unlist( lapply( strsplit( colnames(sim_log_count) , "x"), `[`, 1) ) ) ,
as.numeric( unlist( lapply( strsplit( colnames(sim_log_count) , "x"), `[`, 2) ) ) ) ,
feature_types = feat_types,
type = "spatial_t",
species = sc_species,
spotProbability = t(sim_prob_matrix) )
>>>>>>> Stashed changes

ks_statistic_L_stats <- ks::kde.test(x1 = as.numeric(real_scfeatures_result$L_stats), x2 = as.numeric(sim_scfeatures_result$L_stats))
ks_statistic_celltype_interaction <- ks::kde.test(x1 = as.numeric(real_scfeatures_result$celltype_interaction), x2 = as.numeric(sim_scfeatures_result$celltype_interaction))
Expand Down

0 comments on commit 1997c3d

Please sign in to comment.