Last updated: 2022-08-19

Checks: 7 0

Knit directory: analysis_pipelines/

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(20200524) 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 6e9c89d. 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/test_sldsc_splicingAnnot.Rmd
    Untracked:  code/sldsc_annot_generic_baselineLD_separate.sbatch
    Untracked:  scripts/tmp.R

Unstaged changes:
    Modified:   analysis/mapgen_torus_susie_AF.Rmd
    Modified:   analysis/sldsc_example_GTEx_QTLs.Rmd
    Modified:   code/mapgen_trackplots.R
    Modified:   scripts/run_finemapping.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/make_mapgen_trackplots.Rmd) and HTML (docs/make_mapgen_trackplots.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 6e9c89d kevinlkx 2022-08-19 added a note about counts data format
html ca16d13 kevinlkx 2022-08-18 Build site.
Rmd f05e951 kevinlkx 2022-08-18 added a tutorial for making track plots
Rmd 5295f53 kevinlkx 2022-08-18 added trackplot tutorials

Track plot tutorial

Required input data:

  • Genetic fine-mapping summary statistics.
  • Gene annotations (exons, introns, UTRs, etc.).
  • Functional annotation data, e.g.: ATAC-seq data, histone ChIP-seq peaks, PC-HiC loops, etc.

To make the trackplots, you will need to have the following packages installed: AnnotationDbi, org.Hs.eg.db, GenomicInteractions, Gviz, rtracklayer from Bioconductor.

Load R packages

suppressMessages(library(data.table))
suppressMessages(library(tidyverse))
suppressMessages(library(GenomicRanges))
suppressMessages(library(AnnotationDbi)) # match gene ID to gene symbol
suppressMessages(library(org.Hs.eg.db)) # match gene ID to gene symbol
suppressMessages(library(GenomicInteractions)) # visualize HiC plots
suppressMessages(library(rtracklayer)) # loading bigwigs/bed files
suppressMessages(library(bigsnpr)) # loading genotype data from 1000Genomes for LD calculation
suppressMessages(library(Gviz)) # make track plots
library(mapgen)
source("../code/mapgen_trackplots.R")
setwd("/project2/xinhe/kevinluo/gene-level-finemapping/trackplot_tutorial")

Load fine-mapping results.

finemapstats <- readRDS(system.file("extdata", "aFib_Finemapped.tble.rds", package = "mapgen"))
finemapstats.gr <- process_finemapping_sumstats(finemapstats, 
                                                snp = 'snp', chr = 'chr', 
                                                pos = 'pos', pip = 'susie_pip', 
                                                pval = 'pval', zscore = 'zscore', 
                                                cs = 'CS', locus = 'locus',  
                                                pip.thresh = 0)

Load genomic annotations and gene information

genomic.annots <- readRDS(system.file("extdata", "genomic.annots.hg19.gr.rds", package = "mapgen"))
gene.annots <- genomic.annots$genes

Load Promoter-capture HiC (PCHi-C) data from iPSC derived cardiomyocytes (CMs).

pcHiC.gr <- readRDS(system.file("extdata", "pcHiC.CM.gr.rds", package = "mapgen"))

Load H3K27ac and DHS bed files

H3K27ac_peaks <- rtracklayer::import("data/H3K27ac_heart_concat.bed")
DHS_peaks <- rtracklayer::import("data/FetalHeart_E083-DNase_hg19_cleaned_narrowPeak.bed.gz")

Load ATAC data files. These data need to be in wig, bigWig/bw, bedGraph, or bam format.

atac_data_files <- c("data/Hg19_Cardiomyocyte-TileSize-500-normMethod-ReadsInTSS-ArchR.bw.bedGraph",
                     "data/Hg19_Endothelial-TileSize-500-normMethod-ReadsInTSS-ArchR.bw.bedGraph")

atac_data <- lapply(atac_data_files, function(x){rtracklayer::import(x)})
names(atac_data) <- c("Cardiomyocyte", "Endothelial")

Make a track plot to visualize a locus

Load gene mapping result

gene.mapping.res <- readRDS("data/aFib_Finemapped_GeneMapped_ActivePromoter_07242021.gr.rds")

Get the genomic region for gene of interest

gene.of.interest <- "FGF9"
region <- get_gene_region(gene.mapping.res, gene.of.interest, ext = 10000)

Make track plot

pdf(paste0(gene.of.interest,'_trackplot.pdf'), width=12, height=8)
finemapping_annot_trackplot(finemapstats.gr, 
                            region, 
                            gene.annots, 
                            genome = "hg19", 
                            countsdata = atac_data, 
                            data_colors = c("red", "green"), 
                            data_ylim = c(0,0.8),
                            peaks = list("H3K27ac" = H3K27ac_peaks, "DHS" = DHS_peaks), 
                            HiC_loops = list("PC-HiC" = pcHiC.gr),
                            highlight_snps = "topSNP")
dev.off()

sessionInfo()