Last updated: 2020-03-17

Checks: 6 0

Knit directory: m6AQTL_reproducibleDocument/

This reproducible R Markdown analysis was created with workflowr (version 1.3.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(20200317) 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! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.

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:


Untracked files:
    Untracked:  analysis/Re-analysis_of_Wang_2015_cell.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 R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view them.

File Version Author Date Message
Rmd bb81e9f scottzijiezhang 2020-03-17 wflow_publish(c(“WASP_mapping.Rmd”, “peak_calling.Rmd”, “m6AQTL_mapping.Rmd”, “Analysis_of_m6AQTL.Rmd”, “Annotating_m6AQTL_enrichment.Rmd”,

Peak calling

Count Reads from BAM files

library(MeRIPtools)
samplenames <- c("NA18486","NA18498","NA18499","NA18501","NA18502","NA18504","NA18505","NA18507","NA18508","NA18510","NA18511","NA18516","NA18517","NA18519","NA18522","NA18523","NA18852","NA18855","NA18856","NA18858","NA18861","NA18862","NA18870","NA18907","NA18909","NA18912","NA18913","NA18916","NA19092","NA19093","NA19098","NA19099","NA19101","NA19102","NA19108","NA19114","NA19116","NA19119","NA19127","NA19128","NA19130","NA19131","NA19137","NA19138","NA19140","NA19143","NA19144","NA19147","NA19152","NA19153","NA19159","NA19160","NA19192","NA19193","NA19200","NA19204","NA19209","NA19222","NA19239","NA19257")

LCLs <- countReads(samplenames = samplenames, 
                   gtf = "~/Database/genome/hg19/hg19_UCSC.gtf",
                   fragmentLength = 150,
                   bamFolder = "~/m6AQTL/WASP_OUT_201907/",
                   outputDir = "~/m6AQTL/m6A_QTL_results/",
                   modification = "m6A",
                   binSize = 50,
                   strandToKeep = "opposite",
                   threads = 30
                   )
save(LCLs, file = "~/m6AQTL/m6A_QTL_results/PoissonGamma_analysis/monster.RData" )

Peak calling

LCLs <- callPeakFisher(LCLs,threads = 40)
LCLs <- reportJointPeak(LCLs, joint_threshold = 5, threads = 30)
LCLs <- jointPeakCount(LCLs)

check IP efficiency

.noZero <- function(x){sapply(x,max,1)}
library(MeRIPtools)
#load("~/m6AQTL/peakcalling/MeRIPtools/m6ALCLs_MeRIP.Peak.RData")
LCLs <- readRDS("~/m6AQTL/peakcalling/MeRIPtools/jointPeak_threshold5_MeRIP.RDS")
newLCLs <- filter(LCLs, !apply(extractInput(LCLs), 1, function(x) any(x == 0 )) )
T0 <- colSums(counts(newLCLs)[,1:length(newLCLs@samplenames)] )
T1 <- colSums(counts(newLCLs)[,(length(newLCLs@samplenames)+1) : (2*length(newLCLs@samplenames)) ] )
##filter out peaks with OR < 1
enrichFlag <- apply( t( t(extractIP(newLCLs))/T1 )/ t( t( extractInput(newLCLs) )/T0 ),1,function(x){sum(x>1)> newLCLs@jointPeak_threshold})
newLCLs <-  MeRIPtools::filter(newLCLs, enrichFlag )
OR <- t( apply(extractIP(newLCLs),1,.noZero)/T1 )/ t( t( extractInput(newLCLs) )/T0 )
colnames(OR) <- newLCLs@samplenames
library(reshape2)
OR_melt <- melt(as.data.frame(OR))
ggplot(OR_melt,aes(x = variable, y = log(value) ))+geom_boxplot()+theme_classic()+theme(axis.text.x = element_text(face = "bold",angle = 90))

calculate the offset term for IP efficiency

K_IPe_ij <- apply(logOR[logOR.id,], 2, function(x){
  
  fit <- lm(y~m, data = data.frame(y = x, m=rowMeans(logOR)[logOR.id] ))
  y.est <- predict(fit, newdata =  data.frame(m = rowMeans(logOR)))
  return( y.est - rowMeans(logOR) )
  })

check GC content

## read peaks into GRanges list skipping introns
peaks.gr <- m6Amonster:::.peakToGRangesList(jointPeak(newLCLs))
library(BSgenome.Hsapiens.UCSC.hg19)
library(stringr)

registerDoParallel(30)
peakGC <- foreach( i = 1:length(peaks.gr), .combine = c)%dopar%{
  peakSeq <- paste( getSeq( BSgenome.Hsapiens.UCSC.hg19 , peaks.gr[[i]] ,as.character =T ) , collapse = "")
  sum( str_count(peakSeq, c("G","g","C","c"))  )/nchar(peakSeq)
}

Calculate the GC content offset term

peakGC_l <- round(peakGC,digits = 2)
peakGC_l[which(peakGC_l<0.2)] <-median(peakGC_l[which(peakGC_l<0.2)] ) # combine some bins at low GC due to low number of peaks
peakGC_l[which(peakGC_l>0.84)] <-median(peakGC_l[which(peakGC_l>0.84)] )# combine some bins at high GC due to low number of peaks
l <- sort(unique(peakGC_l))
y <- log( OR ) - K_IPe_ij
colnames(y) <- newLCLs@samplenames
b.l <- tapply(rowMeans( y ), peakGC_l ,  median) 
bil <- apply( y, 2, tapply, peakGC_l, median )
bi. <- apply(  y , 2, median )
b.. <- median(  y )
Fil <- as.data.frame( as.matrix(bil) - as.vector(b.l) ) - ( bi. - b.. )
Fil$GC <- l

Fij <- foreach( ii = 1:length(newLCLs@samplenames), .combine = cbind)%dopar%{
      GC_fit <- lm(Fil[,ii] ~ poly(l,4) )
      predict(GC_fit, newdata = data.frame(l = peakGC) )
}
colnames(Fij) <- newLCLs@samplenames

The final Log-OR corrected for IP efficency and GC bias is obtained by

Log.OR <- log(OR)- K_IPe_ij - Fij

Analysis of m6A peaks

Load m6AQTL and m6Apeaks

library(MeRIPtools)
library(BSgenome.Hsapiens.UCSC.hg19)

LCLs <- readRDS( "~/m6AQTL/peakcalling/MeRIPtools/jointPeak_threshold5_MeRIP.RDS")

m6AQTL <-  readRDS("~/m6AQTL/m6A_QTL_results/linear_model/m6AQTL.m6APeak_logOR_GC.IP.adjusted_qqnorm.15PCs.fastQTL.nominals.rds")
lead_m6AQTL <- readRDS( file = "~/m6AQTL/m6A_QTL_results/linear_model/lead.m6AQTL.m6APeak_logOR_GC.IP.adjusted_qqnorm.15PCs.fastQTL.nominals.rds")

permutation_m6AQTL <-  readRDS("~/m6AQTL/m6A_QTL_results/linear_model/m6AQTL.m6APeak_logOR_GC.IP.adjusted_qqnorm.15PCs.fastQTL.permutations.rds")

sig.m6AQTL <- lead_QTL <- lead_m6AQTL[lead_m6AQTL$PEAK %in% permutation_m6AQTL[permutation_m6AQTL$qvalue<0.1,"PEAK"], ]



m6Apeaks <- jointPeak(LCLs)

LCLs_tested <- filter(LCLs, paste0(m6Apeaks$chr,":",m6Apeaks$start,"-",m6Apeaks$end,"_",m6Apeaks$name,"_",m6Apeaks$strand ) %in% unique(m6AQTL$PEAK) ) 

LCLs_lead <- filter(LCLs, paste0(m6Apeaks$chr,":",m6Apeaks$start,"-",m6Apeaks$end,"_",m6Apeaks$name,"_",m6Apeaks$strand ) %in% unique(lead_QTL$PEAK) )

m6Apeaks <- m6Apeaks[which( paste0(m6Apeaks$chr,":",m6Apeaks$start,"-",m6Apeaks$end,"_",m6Apeaks$name,"_",m6Apeaks$strand ) %in% unique(m6AQTL$PEAK)),]
sig.QTL.peaks <- m6Apeaks[match(unique(lead_QTL$PEAK), paste0(m6Apeaks$chr,":",m6Apeaks$start,"-",m6Apeaks$end,"_",m6Apeaks$name,"_",m6Apeaks$strand) ),1:12]

Plot distribution of variant associated peaks on metagene.

plotMetaGeneMulti(list("All joint peaks" = m6Apeaks,"Variant associated peaks"=sig.QTL.peaks),"~/Database/genome/hg19/hg19_UCSC.gtf")

All peaks

peakDistribution( LCLs_tested )

variant associated peaks

peakDistribution( LCLs_lead )

De novo motif analysis by Homer2 for all Joint peaks and variant associated peaks

write.table(sig.QTL.peaks,
              file = paste0("~/m6AQTL/m6A_QTL_results/linear_model/variant_associated_peaks.bed"),sep = "\t",row.names = F,col.names = F,quote = F)
system2(command = "bedtools", args = paste0("getfasta -fi ~/Database/genome/hg19/hg19_UCSC.fa -bed ~/m6AQTL/m6A_QTL_results/linear_model/variant_associated_peaks.bed -s -split > ~/m6AQTL/m6A_QTL_results/linear_model/variant_associated_peaks.fa ") )

system2(command = "findMotifs.pl", args = paste0("~/m6AQTL/m6A_QTL_results/linear_model/variant_associated_peaks.fa fasta  ~/m6AQTL/m6A_QTL_results/linear_model/Homer2 -fasta ~/Database/transcriptome/backgroud_peaks/hg38_200bp_randomPeak.fa -len 5,6 -rna -p 20 -S 5 -noknown"),wait = F )

write.table(m6Apeaks,
              file = paste0("~/m6AQTL/m6A_QTL_results/linear_model/joint_peaks.bed"),sep = "\t",row.names = F,col.names = F,quote = F)
system2(command = "bedtools", args = paste0("getfasta -fi ~/Database/genome/hg19/hg19_UCSC.fa -bed ~/m6AQTL/m6A_QTL_results/linear_model/joint_peaks.bed -s -split > ~/m6AQTL/m6A_QTL_results/linear_model/joint_peaks_peaks.fa ") )
system2(command = "findMotifs.pl", args = paste0("~/m6AQTL/m6A_QTL_results/linear_model/joint_peaks_peaks.fa fasta  ~/m6AQTL/m6A_QTL_results/linear_model/JointPeaks/Homer2 -fasta ~/Database/transcriptome/backgroud_peaks/hg38_200bp_randomPeak.fa -len 5,6,7 -rna -p 20 -S 5 -noknown"),wait = F )

Plot motif

library(Logolas)
color_motif <- c( "orange", "blue", "red","green")
for(i in 1:3){
  pwm.m <- t( read.table(paste0("~/m6AQTL/m6A_QTL_results/linear_model/JointPeaks/Homer2/homerResults/motif",i,".motif"), header = F, comment.char = ">",col.names = c("A","C","G","U")) )
  motif_p <- sapply(1:3, function(x){
   strsplit( as.character( read.table(paste0("~/m6AQTL/m6A_QTL_results/linear_model/JointPeaks/Homer2/homerResults/motif",x,".motif"),comment.char = "", nrows = 1)[,12]  ), split= ":")[[1]][4] 
})
  colnames(pwm.m) <- 1:ncol(pwm.m)

  try(logomaker(pwm.m ,type = "EDLogo",colors = color_motif,color_type = "per_row" ,logo_control =  list(pop_name = paste0("m6A motif",i,"  p-value:",motif_p[i])))
  )

}
for(i in 1:3){
  pwm.m <- t( read.table(paste0("~/m6AQTL/m6A_QTL_results/linear_model/Homer2/homerResults/motif",i,".motif"), header = F, comment.char = ">",col.names = c("A","C","G","U")) )
  motif_p <- sapply(1:3, function(x){
   strsplit( as.character( read.table(paste0("~/m6AQTL/m6A_QTL_results/linear_model/Homer2/homerResults/motif",x,".motif"),comment.char = "", nrows = 1)[,12]  ), split= ":")[[1]][4] 
})
  colnames(pwm.m) <- 1:ncol(pwm.m)

  logomaker(pwm.m ,type = "EDLogo",colors = color_motif,color_type = "per_row" ,logo_control =  list(pop_name = paste0("m6A motif",i,"  p-value:",motif_p[i])))
}

sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 17.10

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

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

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

loaded via a namespace (and not attached):
 [1] workflowr_1.3.0 Rcpp_1.0.1      digest_0.6.18   rprojroot_1.3-2
 [5] backports_1.1.4 git2r_0.25.2    magrittr_1.5    evaluate_0.13  
 [9] stringi_1.4.3   fs_1.3.0        whisker_0.3-2   rmarkdown_1.12 
[13] tools_3.5.3     stringr_1.4.0   glue_1.3.1      xfun_0.6       
[17] yaml_2.2.0      compiler_3.5.3  htmltools_0.3.6 knitr_1.22