Last updated: 2022-07-15
Checks: 7 0
Knit directory: GSFA_analysis/
This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it's best to always run the code in an empty environment.
The command set.seed(20220524)
was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version d9e9144. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish
or wflow_git_commit
). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: analysis/figure/
Untracked files:
Untracked: analysis/music_LUHMES_data.Rmd
Untracked: analysis/spca_LUHMES_data.Rmd
Untracked: code/music_LUHMES_Yifan.R
Untracked: code/run_sceptre_LUHMES_data.sbatch
Untracked: code/run_sceptre_Tcells_stimulated_data.sbatch
Untracked: code/run_sceptre_Tcells_unstimulated_data.sbatch
Untracked: code/run_spca_LUHMES.R
Untracked: code/run_spca_TCells.R
Untracked: code/sceptre_LUHMES_data.R
Untracked: code/sceptre_Tcells_stimulated_data.R
Untracked: code/sceptre_Tcells_unstimulated_data.R
Unstaged changes:
Modified: analysis/sceptre_LUHMES_data.Rmd
Modified: code/run_sceptre_cropseq_data.sbatch
Modified: code/sceptre_analysis.R
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were made to the R Markdown (analysis/music_example_data.Rmd
) and HTML (docs/music_example_data.html
) files. If you've configured a remote Git repository (see ?wflow_git_remote
), click on the hyperlinks in the table below to view the files as they were in that past version.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | d9e9144 | kevinlkx | 2022-07-15 | test music package on example data |
CROP-seq datasets: /project2/xinhe/yifan/Factor_analysis/shared_data/
The data are Seurat objects, with raw gene counts stored in obj@assays$RNA@counts, and cell meta data stored in obj@meta.data. Normalized and scaled data used for GSFA are stored in obj@assays$RNA@scale.data , the rownames of which are the 6k genes used for GSFA.
MUSIC website: https://github.com/bm2-lab/MUSIC
setting
srun --mem=40G --time=10:0:0 --cpus-per-task=15
Load packages
library(data.table)
library(Seurat)
library(MUSIC)
library(ggplot2)
theme_set(theme_bw() + theme(plot.title = element_text(size = 14, hjust = 0.5),
axis.title = element_text(size = 14),
axis.text = element_text(size = 13),
legend.title = element_text(size = 13),
legend.text = element_text(size = 12),
panel.grid.minor = element_blank())
)
library(ComplexHeatmap)
setwd("/project2/xinhe/kevinluo/GSFA/music_analysis/example")
dir.create("./output", recursive = TRUE, showWarnings = FALSE)
expression_profile <- read.table("./crop_stimulated/expression_profile.txt",head=T,row.names=1,sep="\t")
perturb_information_df <- read.table("./crop_stimulated/perturb_information.txt",head=T,row.names=1,sep="\t")
perturb_information <- as.character(perturb_information_df[,1])
names(perturb_information) <- row.names(perturb_information_df)
# If you don't consider off-target effect, this file is not needed.
#sgRNA_information_df<-read.table("./crop_stimulated/sgRNA_information.txt",head=T,row.names=1,sep="\t")
#sgRNA_information<-as.character(sgRNA_information_df[,1])
#names(sgRNA_information)<-row.names(sgRNA_information_df)
# Have a look at expression_profile
dim(expression_profile)
expression_profile[1:3,1:3]
# perturb_information.
length(perturb_information)
setwd("/project2/xinhe/kevinluo/GSFA/music_analysis/example/output")
# For "data_format_example/crop_unstimulated.RData", this function integrates the input data and filters mitochondrial ribosomal protein(^MRP) and ribosomal protein(^RP).
crop_seq_list <- Input_preprocess(expression_profile, perturb_information)
# For data format like "perturb_GSM2396857" generated by 10X genomics, function "Input_preprocess_10X()" will be suitable. Users can also change this data format to the standard format like "data_format_example/crop_unstimulated.RData", then use function "Input_preprocess()" to process it.
#crop_seq_list<-Input_preprocess_10X("./perturb_GSM2396857")
# cell quality control
crop_seq_qc <- Cell_qc(crop_seq_list$expression_profile, crop_seq_list$perturb_information, species="Hs", plot=F)
# data imputation, it may take a little long time without parallel computation.
crop_seq_imputation <- Data_imputation(crop_seq_qc$expression_profile, crop_seq_qc$perturb_information, cpu_num=15)
saveRDS(crop_seq_imputation, "output/crop_seq_imputation.rds")
# cell filtering, it may take a little long time without parallel computation.
crop_seq_imputation <- readRDS("output/crop_seq_imputation.rds")
crop_seq_filtered <- Cell_filtering(crop_seq_imputation$expression_profile, crop_seq_imputation$perturb_information, cpu_num=10)
saveRDS(crop_seq_filtered, "output/crop_seq_filtered.rds")
# obtain highly dispersion differentially expressed genes.
crop_seq_filtered <- readRDS("output/crop_seq_filtered.rds")
crop_seq_vargene <- Get_high_varGenes(crop_seq_filtered$expression_profile, crop_seq_filtered$perturb_information, plot=T)
saveRDS(crop_seq_vargene, "output/crop_seq_vargene.rds")
# get topics.
crop_seq_vargene <- readRDS("output/crop_seq_vargene.rds")
system.time(
topic_model_list <- Get_topics(crop_seq_vargene$expression_profile,crop_seq_vargene$perturb_information,topic_number=c(4:6)))
saveRDS(topic_model_list, "output/topic_model_list.rds")
# This step may take a long time if you choosed a large scope of topic number. You can run each topic number seperately, then combine them to save time.
system.time(
topic_1 <- Get_topics(crop_seq_vargene$expression_profile,crop_seq_vargene$perturb_information,topic_number=4))
saveRDS(topic_1, "output/topic_4.rds")
system.time(
topic_2 <- Get_topics(crop_seq_vargene$expression_profile,crop_seq_vargene$perturb_information,topic_number=5))
saveRDS(topic_2, "output/topic_5.rds")
system.time(
topic_3 <- Get_topics(crop_seq_vargene$expression_profile,crop_seq_vargene$perturb_information,topic_number=6))
saveRDS(topic_3, "output/topic_6.rds")
topic_model_list<-list()
topic_model_list$models<-list()
topic_model_list$perturb_information<-topic_1$perturb_information
topic_model_list$models[[1]]<-topic_1$models[[1]]
topic_model_list$models[[2]]<-topic_2$models[[1]]
topic_model_list$models[[3]]<-topic_3$models[[1]]
saveRDS(topic_model_list, "output/topic_model_list.rds")
topic_model_list <- readRDS("output/topic_model_list.rds")
# select the optimal topic number.
optimalModel <- Select_topic_number(topic_model_list$models,plot=T)
# #If you just calculated one topic number, you can skip this step, just run the following:
# optimalModel <- topic_model_list$models[[1]]
# annotate each topic's functions. For parameter "species", Hs(homo sapiens) or Mm(mus musculus) are available.
topic_func <- Topic_func_anno(optimalModel, species="Hs", plot=T)
saveRDS(topic_func, "output/topic_func.rds")
# calculate topic distribution for each cell.
distri_diff <- Diff_topic_distri(optimalModel, topic_model_list$perturb_information, plot=T)
saveRDS(distri_diff, "output/distri_diff.rds")
# calculate the overall perturbation effect ranking list without "offTarget_Info".
rank_overall_result <- Rank_overall(distri_diff)
saveRDS(rank_overall_result, "output/rank_overall_result.rds")
#rank_overall_result<-Rank_overall(distri_diff,offTarget_hash=offTarget_Info) (when "offTarget_Info" is available).
# calculate the topic-specific ranking list.
rank_topic_specific_result <- Rank_specific(distri_diff)
saveRDS(rank_topic_specific_result, "output/rank_topic_specific_result.rds")
# calculate the perturbation correlation.
perturb_cor <- Correlation_perturbation(distri_diff,plot=T)
saveRDS(perturb_cor, "output/perturb_cor.rds")
sessionInfo()