Finding coexpressed genes in specific cell types

Shamoun was interested in finding coexpressed genes in specific cell types. Here is some code to do that. You have to enter in each cell type of interest individually.

# Create a variable called 'sce' that contains our Large SingleCellExperiment object from a file using R function readRDS()
sce <- readRDS(file = "~/workspace/Storage/C_MOOR/c_moor_ccc_su22/gastrulation_sce.RDS")

# Find top variable genes
sce <- logNormCounts(sce)
colLabels(sce) <- factor(sce$celltype)
dec <- modelGeneVar(sce)
top.hvgs <- getTopHVGs(dec, n=2000)

# Create a variable with your favorite gene
my_favorite_genes <- c("ENSMUSG00000038192","ENSMUSG00000047139")

# Create a variable with your favorite genes included together with the top HVGs 
of.interest <- c(top.hvgs[1:200], my_favorite_genes)

# Subset dataset to just the celltypes you are interested in
sce_subset <- sce[,sce$celltype %in% c("Def. endoderm")]

cor.pairs <- correlatePairs(x = sce_subset, subset.row = of.interest)
cor.pairs

Hi, when I try to run this code, I get an error:
Error: object ‘top.hvgs’ not found
Do you think you could let me know how to fix it? Thanks so much!

I get this error when trying to run the code and I dont know how to fix it

I edited my answer to include the code to generate the top.hvgs object. This was in the R notebook I shared previously (062322_mouse_gastrulation_part3.Rmd).

R is telling you the problem: logcounts not in names(assays()).

This means that the SingleCellExperiment object you are working with (we named it sce), doesn’t have logcounts information. The code to calculate logcounts was provided in 062322_mouse_gastrulation_part3.Rmd. I edited my code above to include this code. It should have everything you need now except to input your favorite genes and your cell type of interest. Good luck!