Last updated: 2020-11-24

Checks: 6 1

Knit directory: myproject/

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.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

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(20200813) 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 594a569. 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:    .DS_Store
    Ignored:    .RData
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/.DS_Store
    Ignored:    analysis/11.24.2020.2.png
    Ignored:    analysis/11.24.2020.3.png
    Ignored:    analysis/11.24.2020.4.png
    Ignored:    analysis/11.24.2020.5.png
    Ignored:    analysis/11.24.2020.6.png
    Ignored:    analysis/11.24.2020.7.png
    Ignored:    analysis/11.24.2020.8.png
    Ignored:    analysis/11.24.2020.9.png
    Ignored:    genotype/

Untracked files:
    Untracked:  ALL.chr1.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz
    Untracked:  ALL.chr2.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz
    Untracked:  getfastqtest2.csv

Unstaged changes:
    Modified:   analysis/prep.Rmd
    Modified:   analysis/susie.Rmd
    Modified:   analysis/varLD.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/susie.Rmd) and HTML (docs/susie.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
html fc30af3 mariesaitou 2020-09-06 Build site.
html f0b76bf mariesaitou 2020-08-31 Build site.
html dc5d623 mariesaitou 2020-08-31 Build site.
html 70f8755 mariesaitou 2020-08-31 Build site.
html 147ba3e mariesaitou 2020-08-31 Build site.
html b1b285d mariesaitou 2020-08-31 Build site.
html 2ba9baf mariesaitou 2020-08-31 Build site.
html 31bf3fa mariesaitou 2020-08-31 Build site.
Rmd bf3a8b6 mariesaitou 2020-08-31 wflow_publish(c(“analysis/index.Rmd”, “analysis/correl.Rmd”,

Cut the 100 up/downstream regions from the genotype file

module load vcftools
module load htslib 
csvfile=/project2/xuanyao/marie/E-GEUV-1/finemap/genelist.location1.csv
for line in `cat ${csvfile} | grep -v ^#`
do
  gene=`echo ${line} | cut -d ',' -f 1`
  chr=`echo ${line} | cut -d ',' -f 3`
  up=`echo ${line} | cut -d ',' -f 6`
  down=`echo ${line} | cut -d ',' -f 7`
  vcftools --gzvcf /project2/xuanyao/marie/E-GEUV-1/genotype/phase3/chr${chr}.1000gphase3.EUR.0.01.biallelic.recode.vcf.gz --chr ${chr} --from-bp ${up} --to-bp ${down} --recode --out ${gene}.EUR.genotype

done

run SuSiE

# 12419 genes are too many to run at once. Separate the gene list into small lists.

library(susieR)
library(data.table)
## read the gene list
#genelist=read.csv("genelist.test.csv", stringsAsFactors = F)
genelist=read.csv("gene.Yoruba.csv", stringsAsFactors = F)
#gene.expression.Africa = read.table("Yoruba.TPM.scaled.gene.bed")
gene.expression.Yoruba = fread("Yoruba.TPM.scaled.gene.bed.gz")

## read a gene from the list
filenameYoruba<-paste(genelist[,"gene"], ".Yoruba.genotype.recode.vcf", sep="")
genotype.Yoruba<- lapply(filenameYoruba, FUN=read.table, header = FALSE, stringsAsFactors = F)
names(genotype.Yoruba) <- genelist[,"gene"]
genotype.Yoruba.df <- rbindlist(genotype.Yoruba, fill=T, idcol = T)
genotype.Yoruba.df<-genotype.Yoruba.df[!duplicated(genotype.Yoruba.df[,c(".id","V3" )])&!duplicated(genotype.Yoruba.df[,c(".id","V3" )], fromLast = T),]


## convert vcf format as input dataset

genotype.Yoruba.data <- genotype.Yoruba.df[,11:length(genotype.Yoruba.df[1,])] 

genotype.Yoruba.data[genotype.Yoruba.data=="0|0"]<- 0L
genotype.Yoruba.data[genotype.Yoruba.data=="0|1"]<- 1L
genotype.Yoruba.data[genotype.Yoruba.data=="1|0"]<- 1L
genotype.Yoruba.data[genotype.Yoruba.data=="1|1"]<- 2L
genotype.Yoruba.data1<- as.matrix(genotype.Yoruba.data)
genotype.Yoruba.data<- matrix(as.numeric(genotype.Yoruba.data1), nrow = nrow(genotype.Yoruba.data))

## scale the genotypes
scale.gen.Yoruba <- scale(t(genotype.Yoruba.data))
#hist(scale.gen.Yoruba[,20])

## extract genes from the gene expression list
test.expression.Yoruba <- gene.expression.Yoruba[unlist(lapply(genelist$gene, grep, gene.expression.Yoruba$ID)),]
expression.Yoruba <- t(test.expression.Yoruba[,-(1:4)])

## susieR
fitted.test.Yoruba <- as.list(NULL)
for(i in 1:12419){
  fitted.test.Yoruba[[i]] <-   susie(scale.gen.Yoruba[,(genotype.Yoruba.df$.id==genelist$gene[i])], expression.Yoruba[,i],
                                     L = 10,
                                     estimate_residual_variance = TRUE, 
                                     estimate_prior_variance = FALSE,
                                     scaled_prior_variance = 0.95,
                                     verbose = TRUE)
}

fitted.test.Yoruba[[4]]$sets$cs
## attach gene names to the result
fitted.Yoruba <-  as.list(NULL)
for(i in 1:12419){
  if(length(fitted.test.Yoruba[[i]]$sets$cs)!=0){
    fitted.Yoruba[[i]] <- stack(fitted.test.Yoruba[[i]]$sets$cs)
  }
}
check.Yoruba <- rbindlist(fitted.Yoruba, idcol=T)
check.Yoruba$name <- genelist[check.Yoruba$.id,"gene"]
result.temp <- as.list(NULL)
for(i in 1:length(check.Yoruba$.id)){result.temp[i] <- lapply(genotype.Yoruba[check.Yoruba$name[i]], "[", check.Yoruba$values[i],1:3)}
result.Yoruba <- data.frame(check.Yoruba$name, check.Yoruba$ind, check.Yoruba$values, rbindlist(result.temp))

names(result.Yoruba)<-c("gene","L","SNP","chr","loc","rs")

library(dplyr)
result.Yoruba<-result.Yoruba %>% as.data.frame() %>% mutate(gene.SNP = paste(!!!rlang::syms(c("gene", "rs")), sep="."))
write.csv(result.Yoruba, file = "result.Yoruba.csv")

2 populations merged analysis

Cut the 100 up/downstream regions from the genotype file

module load vcftools
module load htslib 
csvfile=/project2/xuanyao/marie/E-GEUV-1/finemap/BHloc.bothpop.csv
for line in `cat ${csvfile} | grep -v ^#`
do
  gene=`echo ${line} | cut -d ',' -f 1`
  chr=`echo ${line} | cut -d ',' -f 2`
  up=`echo ${line} | cut -d ',' -f 10`
  down=`echo ${line} | cut -d ',' -f 11`
  vcftools --gzvcf /project2/xuanyao/marie/E-GEUV-1/genotype/phase3/chr${chr}.1000gphase3.455.0.01.biallelic.recode.vcf --chr ${chr} --from-bp ${up} --to-bp ${down} --recode --out ${gene}.455.genotype

done

run SuSiE

# 12419 genes are too many to run at once. Separate the gene list into small lists.

library(susieR)
library(data.table)
## read the gene list

genelist=read.csv("BHloc.bothpop.ex.csv", stringsAsFactors = F)
#gene.expression.Africa = read.table("Yoruba.TPM.scaled.gene.bed")
gene.expression = read.csv("scaled.bothpops.TPM.csv", stringsAsFactors = F)

## read a gene from the list
filename<-paste("both/",genelist[,"gene"], ".455.genotype.recode.vcf", sep="")
genotype<- lapply(both/filename, FUN=read.table, header = FALSE, stringsAsFactors = F)
names(genotype) <- genelist[,"gene"]
genotype.df <- rbindlist(genotype, fill=T, idcol = T)
genotype.df<-genotype.df[!duplicated(genotype.df[,c(".id","V3" )])&!duplicated(genotype.df[,c(".id","V3" )], fromLast = T),]


## convert vcf format as input dataset

genotype.data <- genotype.df[,11:length(genotype.df[1,])] 

genotype.data[genotype.data=="0|0"]<- 0L
genotype.data[genotype.data=="0|1"]<- 1L
genotype.data[genotype.data=="1|0"]<- 1L
genotype.data[genotype.data=="1|1"]<- 2L
genotype.data1<- as.matrix(genotype.data)
genotype.data<- matrix(as.numeric(genotype.data1), nrow = nrow(genotype.data))

## scale the genotypes
scale.gen <- scale(t(genotype.data))
#hist(scale.gen.Yoruba[,20])

## extract genes from the gene expression list
test.expression <- gene.expression[unlist(lapply(genelist$gene, grep, gene.expression$gene)),]
expression <- t(test.expression[,-(1:4)])

## susieR
fitted.test<- as.list(NULL)
for(i in 1:2998){
  fitted.test[[i]] <-   susie(scale.gen[,(genotype.df$.id==genelist$gene[i])], expression[,i],
                                     L = 10,
                                     estimate_residual_variance = TRUE, 
                                     estimate_prior_variance = FALSE,
                                     scaled_prior_variance = 0.95,
                                     verbose = TRUE)
}

fitted.test[[4]]$sets$cs
## attach gene names to the result
fitted <-  as.list(NULL)
for(i in 1:2998){
  if(length(fitted.test[[i]]$sets$cs)!=0){
    fitted[[i]] <- stack(fitted.test[[i]]$sets$cs)
  }
}
check <- rbindlist(fitted, idcol=T)
check$name <- genelist[check$.id,"gene"]
result.temp <- as.list(NULL)
for(i in 1:length(check$.id)){result.temp[i] <- lapply(genotype[check$name[i]], "[", check$values[i],1:3)}
result <- data.frame(check$name, check$ind, check$values, rbindlist(result.temp))

names(result)<-c("gene","L","SNP","chr","loc","rs")

library(dplyr)
result<-result %>% as.data.frame() %>% mutate(gene.SNP = paste(!!!rlang::syms(c("gene", "rs")), sep="."))
write.csv(result, file = "susieR.bothpops.csv")

fitted<- as.list(NULL) for(i in 1:1365){ if(length(fitted.test[[i]]\(sets\)cs)!=0){ fitted[[i]] <- cbind(stack(fitted.test[[i]]\(sets\)cs),fitted.test[[i]][[“pip”]][unlist(fitted.test[[i]]\(sets\)cs)]) } }

check<- rbindlist(fitted, idcol=T) check\(name <- genelist[check\).id,“gene”]

names(check) names(check)[4] <- “PIP” result.temp <- as.list(NULL) for(i in 1:length(check\(.id)){result.temp[i] <- lapply(genotype[check\)name[i]], “[”, check\(values[i],1:3,)} result<- data.frame(check\)name, check\(ind, check\)values,check$PIP, rbindlist(result.temp)) names(result)<-c(“gene”,“L”,“SNP”,“PIP”,“chr”,“loc”,“rs”)

library(dplyr) result<-result %>% as.data.frame() %>% mutate(gene.SNP = paste(!!!rlang::syms(c(“gene”, “rs”)), sep=“.”)) write.csv(result, file = “susieR.bothpopsPIP.csv”, append = T)

TARO

gene.expression = read.csv(“scaled.bothpops..csv”, stringsAsFactors = F)


sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS  10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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.5       rstudioapi_0.11  whisker_0.4      knitr_1.30      
 [5] magrittr_1.5     R6_2.4.1         rlang_0.4.8      stringr_1.4.0   
 [9] tools_4.0.2      xfun_0.18        git2r_0.27.1     htmltools_0.5.0 
[13] ellipsis_0.3.1   rprojroot_1.3-2  yaml_2.2.1       digest_0.6.27   
[17] tibble_3.0.4     lifecycle_0.2.0  crayon_1.3.4     later_1.1.0.1   
[21] vctrs_0.3.4      promises_1.1.1   fs_1.5.0         glue_1.4.2      
[25] evaluate_0.14    rmarkdown_2.5    stringi_1.5.3    compiler_4.0.2  
[29] pillar_1.4.6     backports_1.1.10 httpuv_1.5.4     pkgconfig_2.0.3