Skip to content

Instantly share code, notes, and snippets.

@FloWuenne
Last active April 26, 2018 14:31
Show Gist options
  • Save FloWuenne/4f2074d791f7912119a8bfc285ce724c to your computer and use it in GitHub Desktop.
Save FloWuenne/4f2074d791f7912119a8bfc285ce724c to your computer and use it in GitHub Desktop.
Create an Rds file for the full heart maturation dataset
library(dplyr)
library(tidyr)
## Define S4 object with required components
Clustering_info <- setClass("clustering_module",slots=c(tsne="data.frame",
metadata="data.frame",
norm_exprs="data.frame",
marker_list="data.frame"))
## Load Seurat object
seurat_object <- readRDS("../Objects/Heart_maturation.joined_data.10pcs.Rds")
## Read marker list
marker_list <- read.table("../Marker/Seurat_all_cluster_markers.10pcs.tsv",
header=TRUE,
sep="\t")
## Only retain top 20 Marker based on avg_logFC
marker_list_subset <- marker_list %>%
group_by(cluster) %>%
top_n(n=50, wt=avg_logFC)
marker_list_subset <- as.data.frame(marker_list_subset)
## Normalized expression data
norm_exprs_sparse <- seurat_object@data
norm_exprs_matrix <- as.matrix(seurat_object@data)
norm_exprs_df <- as.data.frame(norm_exprs_matrix)
## Create a new data frame that contains tSNE embeddings and cluster identities
tsne_mappings <- seurat_object@dr$tsne@cell.embeddings
cell_identities <- data.frame(seurat_object@ident)
rownames(cell_identities) <- names(seurat_object@ident)
tsne_mappings <- merge(tsne_mappings,cell_identities,by=0,all=TRUE)
rownames(tsne_mappings) <- tsne_mappings$Row.names
tsne_mappings <- tsne_mappings %>%
select(-Row.names)
## Metadata information
metadata <- seurat_object@meta.data
clustering_object <- Clustering_info(tsne=tsne_mappings,
norm_exprs=norm_exprs_df,
metadata = metadata,
marker_list=marker_list_subset)
saveRDS(clustering_object,file=paste("../Shiny_server_data/Heart_maturation.FullDataset.clustering_module.Rds",sep=""))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment