Last updated: 2023-03-18

Checks: 7 0

Knit directory: SMF/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). 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(20190719) 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 4f9a581. 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/

Untracked files:
    Untracked:  analysis/logistic_bound.Rmd
    Untracked:  data/count_files.RData
    Untracked:  data/lowgene/
    Untracked:  data/stmGTEx/
    Untracked:  output/luis/

Unstaged changes:
    Modified:   analysis/index.Rmd

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/tpm3_stm.Rmd) and HTML (docs/tpm3_stm.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 4f9a581 DongyueXie 2023-03-18 wflow_publish("analysis/tpm3_stm.Rmd")

Introduction

In this example, we illustrate running stm on TPM3 gene, per base pair reads from GTEX.

Model fitting

datax = read.csv('/project2/mstephens/gtex-stm/Counts/TPM3.Counts.csv.gz')
rownames(datax) = datax[,1]
datax = datax[,-1]
datax = as.matrix(datax)
datax = datax[,colSums(datax)!=0]
library(Matrix)
library(fastTopics)
X = Matrix(datax,sparse=T)

fit_fasttopics = fit_topic_model(X,k=7)

library(ebpmf)
tpm3_fit_fasttopics <- readRDS("~/Rpackages/gsmash/output/tpm3_fit_fasttopics.rds")
fit_stm = ebpmf_identity(datax,K=7,init = list(L_init = tpm3_fit_fasttopics$L,F_init = tpm3_fit_fasttopics$F))

Visualize factors

fit_fasttopics = readRDS("~/Rpackages/gsmash/output/tpm3_fit_fasttopics.rds")
fit_stm = readRDS("~/Rpackages/gsmash/output/tpm3_fit_stm.rds")
par(mfrow=c(2,1))
for(i in 1:7){
  plot(fit_fasttopics$F[,i],col='grey50',pch='.',cex=2,type='l',xlab='position',ylab='',main=paste('topic model, factor', i))
  plot(fit_stm$res$qf$Ef_smooth[,i],col='grey50',pch='.',cex=2,type='l',xlab='position',ylab='',main=paste('smoothed topic model, factor', i))
}

Visualize loadings Using structure plot

Post-processing factors

We see that there are spikes at the beginning/ending of exons. Large reads at the beginning/ending of exons may due to splitting reads.

To get a better visualization of smoothed factors, we can post-process them using robust runmed method.

The function runmed(x,k) returns the running median of x over window size k. We can tune \(k\) for each topic to achieve best visualization. Here I choose \(k=43\). Usually \(k\) between 11 to 111 should be good.

par(mfrow=c(1,1))
for(k in 1:7){
plot(fit_stm$EF[,k],col='grey80',pch='.',cex=3,xlab='position',ylab='')
lines(runmed(fit_stm$EF[,k],k=43),type='l',col=1)
legend('topright',c('smoothed factors', 'post-processed using runmed'),pch=c(20,NA),lty=c(NA,1),col=c('grey80',1))
}


sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS:   /software/R-4.1.0-no-openblas-el7-x86_64/lib64/R/lib/libRblas.so
LAPACK: /software/R-4.1.0-no-openblas-el7-x86_64/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C           
 [4] LC_COLLATE=C         LC_MONETARY=C        LC_MESSAGES=C       
 [7] LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C        
[10] LC_TELEPHONE=C       LC_MEASUREMENT=C     LC_IDENTIFICATION=C 

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10      rstudioapi_0.13  whisker_0.4      knitr_1.33      
 [5] magrittr_2.0.3   R6_2.5.1         rlang_1.0.6      fastmap_1.1.0   
 [9] fansi_1.0.4      highr_0.9        stringr_1.5.0    tools_4.1.0     
[13] xfun_0.24        utf8_1.2.3       cli_3.6.0        git2r_0.28.0    
[17] jquerylib_0.1.4  htmltools_0.5.4  rprojroot_2.0.2  yaml_2.3.7      
[21] digest_0.6.31    tibble_3.1.8     lifecycle_1.0.3  later_1.3.0     
[25] sass_0.4.0       vctrs_0.5.2      promises_1.2.0.1 fs_1.5.0        
[29] glue_1.6.2       evaluate_0.14    rmarkdown_2.9    stringi_1.6.2   
[33] bslib_0.2.5.1    compiler_4.1.0   pillar_1.8.1     jsonlite_1.8.4  
[37] httpuv_1.6.1     pkgconfig_2.0.3