-
-
Save vjcitn/d31651ad7e978e19f2e60f3f555f9c94 to your computer and use it in GitHub Desktop.
sample for generating a simple csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(GBCC.mcm) | |
library(SummarizedExperiment) | |
library(SpatialFeatureExperiment) # includes localResults method | |
x = GBCC.mcm::process_mcmicro("input.h5ad") | |
expr_matrix <- assay(x, "X") | |
expr_df <- as.data.frame(t(expr_matrix)) # Transpose so cells are rows | |
# Get cell metadata | |
metadata <- as.data.frame(colData(x)) | |
# Get spatial coordinates | |
coords <- as.data.frame(spatialCoords(x)) | |
# Combine everything into one comprehensive table | |
combined_data <- cbind( | |
cell_id = rownames(metadata), | |
coords, | |
metadata, | |
expr_df | |
) | |
# extract the "hot/coldspot statistics (Getis-Ord G*) as Z-score for each protein" | |
locg = localResults(x)$localG | |
dlocg = as.data.frame(locg) # undo the 'nesting' | |
kp = grep("Z.G", colnames(dlocg)) # keep only the Z-scores | |
dl = dlocg[,kp] | |
colnames(dl) = gsub("\\.i\\.", "", colnames(dl)) # trim the names | |
combined_data = cbind(combined_data, dl) # the trailing 27 columns have names [protein].Z.G | |
# Write to CSV | |
write.csv(combined_data, "spatial_expression_data.csv", row.names = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment