Last updated: 2024-09-16

Checks: 7 0

Knit directory: lung_lymph_scMultiomics/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). 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(20221229) 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 a2b320f. 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:    analysis/.RData
    Ignored:    analysis/.Rhistory

Untracked files:
    Untracked:  analysis/.ipynb_checkpoints/
    Untracked:  analysis/test.pdf
    Untracked:  analysis/test_GO_enrichment.ipynb
    Untracked:  analysis/u19_atac_fastTopics.Rmd
    Untracked:  analysis/u19_regulon_enrichment.Rmd
    Untracked:  analysis/ukb-a-446.log
    Untracked:  code/run_magma/
    Untracked:  data/DA_peaks_Tsub_vs_others.RDS
    Untracked:  data/DA_peaks_by_cell_type.RDS
    Untracked:  data/TF_target_sizes_GRN.txt
    Untracked:  data/U19_T_cell_peaks_metadata.RDS
    Untracked:  data/Wang_2020_T_cell_peaks_metadata.RDS
    Untracked:  data/lung_GRN_CD4_T_edges.txt
    Untracked:  data/lung_GRN_CD8_T_edges.txt
    Untracked:  data/lung_GRN_Th17_edges.txt
    Untracked:  data/lung_GRN_Treg_edges.txt
    Untracked:  output/annotation_reference.txt
    Untracked:  output/fastTopics
    Untracked:  output/homer/
    Untracked:  output/ldsc_enrichment
    Untracked:  output/lung_immune_atac_peaks_high_ePIPs.RDS
    Untracked:  output/positions.bed
    Untracked:  output/topic1/
    Untracked:  output/topic10/
    Untracked:  output/topic11/
    Untracked:  output/topic12/
    Untracked:  output/topic2/
    Untracked:  output/topic3/
    Untracked:  output/topic4/
    Untracked:  output/topic5/
    Untracked:  output/topic6/
    Untracked:  output/topic7/
    Untracked:  output/topic8/
    Untracked:  output/topic9/
    Untracked:  test.pdf

Unstaged changes:
    Modified:   analysis/cross_tissue_DE_u19_fastTopics.Rmd
    Modified:   analysis/identify_regulatory_programs_u19_GRN.Rmd
    Modified:   analysis/rank_TFs_from_pairwise_comparison.ipynb
    Modified:   analysis/u19_h2g_enrichment.Rmd
    Deleted:    code/run_fastTopic.R
    Deleted:    lung_immune_fine_mapping.Rproj

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/test_magma.Rmd) and HTML (docs/test_magma.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 a2b320f Jing Gu 2024-09-16 test topic enrichment for genetic risks

MAGMA

Gene analysis A linear principal component regression model that estimates whether there is genetic effect of gene g on the phenotype Y, conditional on all covariates. The model first projects genotype matrix for a gene g onto its PCs, pruning away PCs with very small eigenvalues. Then it performs F test in the regression of Y on SNP matrix and covariates to estimate genetic effect.

\[ Y = \alpha_{0g}\vec 1 + X_g^*\alpha_g + W\beta_g + \epsilon_g \] When inividual geneotype matrix not available, MAGMA performs gene test with mean \(X^2\) statistics and a gene p-value is then obtained by using a known approximation of the sampling distribution. Please refer to the following paper for details of approximation for the distribution of the weighted combination of p-values. This model requires summary statistics and reference LD panel.

Hou C (2005) A simple approximation for the distribution of the weighted combination of non-independent or independent probabilities. Stat Probabil Lett 73: 179–187.

Competitive gene-set analysis

One-sided Two-sample T test or linear regression in equivalence is applied to test whether the genes in a gene set are more strongly associated with Y or not.

Let Z denote the association z-score. Let \(\S_s\) be an indicator variable with element \(s_g = 1\) defined as for gene g in gene set s and 0 otherwise. The goal is to test whether \(\beta_s\) is greater than zero, which represents the difference in association between genes in the gene set and genes outside the gene set.

\[ Z = \beta_{0s}\vec 1 + S_s\beta_s + \epsilon \] This also be tested by unpaired two sample T-test, while two samples can have unequal variances and sample sizes.

Testrun

Procedure:

  1. annotate SNPs and genes
  2. gene-based analysis
  3. gene-set analysis

Results

When corrected for multiple testing, tests will be significant if p-value lower than ~0.005. Around half of the tests show significant p-values, which makes us wonder if p-values are inflated. Then we try using the input genes for topic modeling rather than all genes as background so that they are more comparable.

  • Total number of genes reduced from to 18K to ~16K
  • P values for the reduced background genes are very similar to the full ones.

Test enrichment using top 100 genes from each topic

The supplementary table from MAGMA paper shows the mean type 1 error rates are well controlled for a set of size 100. The MSigDB canonical pathways contains 1320 gene sets from a number of different databases. I can look into the average size of the gene sets. MAGMA controlling for type 1 error rates for gene-set analysis

Instead of all DE genes, I used top 100 up-regulated genes ranked by z scores to test the enrichment for each topic. Now we see only k3, k4, k5 and k12 (4/12) topics show significant enrichment after multiple testing correction.


R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /software/openblas-0.3.13-el7-x86_64/lib/libopenblas_haswellp-r0.3.13.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] data.table_1.15.4 workflowr_1.7.1  

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.12       highr_0.10        compiler_4.2.0    pillar_1.9.0     
 [5] bslib_0.7.0       later_1.3.2       git2r_0.33.0      jquerylib_0.1.4  
 [9] tools_4.2.0       getPass_0.2-2     digest_0.6.35     jsonlite_1.8.8   
[13] evaluate_0.23     lifecycle_1.0.4   tibble_3.2.1      pkgconfig_2.0.3  
[17] rlang_1.1.3       cli_3.6.2         rstudioapi_0.15.0 crosstalk_1.2.1  
[21] yaml_2.3.8        xfun_0.43         fastmap_1.1.1     httr_1.4.7       
[25] stringr_1.5.1     knitr_1.46        htmlwidgets_1.6.4 fs_1.6.4         
[29] vctrs_0.6.5       sass_0.4.9        DT_0.33           rprojroot_2.0.4  
[33] glue_1.7.0        R6_2.5.1          processx_3.8.3    fansi_1.0.6      
[37] rmarkdown_2.26    callr_3.7.3       magrittr_2.0.3    whisker_0.4.1    
[41] ps_1.7.6          promises_1.3.0    htmltools_0.5.8.1 httpuv_1.6.14    
[45] utf8_1.2.4        stringi_1.7.6     cachem_1.0.8