Last updated: 2020-07-19

Checks: 7 0

Knit directory: psychencode/

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(20200622) 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 1e04578. 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:    analysis/.DS_Store
    Ignored:    output/.DS_Store

Untracked files:
    Untracked:  models/
    Untracked:  output/test_results/

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/calculate_covariances.Rmd) and HTML (docs/calculate_covariances.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 1e04578 sabrina-mi 2020-07-19 updated links
html 1e04578 sabrina-mi 2020-07-19 updated links
Rmd d0856a5 sabrina-mi 2020-07-19 added covariances job script links
Rmd 1487151 sabrina-mi 2020-07-19 add covariance scripts

Introduction

Linkage disequilibrium between snps should be considered when estimating their effects. An external reference panel with individual-level genotypic data is needed to infer LD among genetic variants, in this case, we used 1000 Genomes Project Europeans. The covariance matrix captures LD structure. Weights are computed for each variant to predict expression of a gene. Together, they can be used in S-PrediXcan to study association between predicted gene expression and a phenotype. Alvaro’s script for generating covariances takes in a predicted transciptome model and dosage information from the reference set.

Definitions

conda activate imlabtools
METAXCAN=/home/t.med.scmi/Github/MetaXcan/software
MODEL=/home/t.med.scmi/Github/psychencode
DATA=/scratch/t.med.scmi/1000G_hg37

Download Data

The data for each chromosome contains a VCF file with nucleotide variants, indexes, copy number variants and structural variants information, along with its tabix index file. To download from the command line, run the chunk below. Each file will take at least half an hour, so if possible, submit it as a job in CRI: https://github.com/hakyimlab/psychencode/blob/master/code/download_1000G_hg37.sh. (Run qsub download_1000G_hg37.sh)

cd $DATA
for I in {1..22}
do
    wget http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/release/20130502/ALL.chr$I.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz
    wget http://ftp.1000genomes.ebi.ac.uk/vol1/ftp/release/20130502/ALL.chr$I.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz.tbi
done

Convert Genotypes to PrediXcan Format

The VCFs need to be converted to simpler text files in “PrediXcan format”, with columns chromosome rsid position allele1 allele2 MAF id1 ….. idn. More info here: https://github.com/hakyimlab/PrediXcan/tree/master/Software#dosage-file-format. The output should be a gzipped text file for each chromosome. The conversion takes about 2 hours for each chromosome, so it’s best to submit the job in CRI: https://github.com/hakyimlab/psychencode/blob/master/code/1000G_hg37_to_predixcan.sh. However, if you run the chunk on a laptop, you may need to install bcftools beforehand. Run brew install bcftools or follow instructions here: https://samtools.github.io/bcftools/howtos/install.html

filter_and_convert ()
{
#echo -ne "varID\t" | gzip > $3
#bcftools view $1 -S $2 --force-samples -Ou |  bcftools query -l | tr '\n' '\t' | sed 's/\t$/\n/' | gzip >> $3

#The first python inline script will check if a variant is blacklisted
#[ -f $3 ] && rm $3
NOW=$(date +%Y-%m-%d/%H:%M:%S)
echo "Starting at $NOW"
bcftools +fill-tags $1 -Ou | bcftools query -f '%CHROM\t%ID\t%POS\t%REF\t%ALT\t%MAF[\t%GT]\n' | \
awk '
{
for (i = 1; i <=6; i ++) {
    printf("%s",$i)
    if (i < 6) {
        printf("\t")
    }

}
for (i = 7; i <= NF; i++) {
    if ( substr($i, 0, 1) == ".") {
        printf("\tNA")
    } else if ($i ~ "[0-9]|[0-9]") {
        n = split($i, array, "|")
        printf("\t%d",(array[1]>0)+(array[2]>0))
    } else {
        #printf("%s",$i)
        printf("Unexpected: %s",$i)
        exit 1
    }
}
printf("\n")
}
' | gzip > $2



NOW=$(date +%Y-%m-%d/%H:%M:%S)
echo "Ending at $NOW"
}

INPUT=$DATA/ALL.chr$I.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz
OUTPUT=/scratch/t.med.scmi/1000G_hg37_dosage/chr$I.txt.gz
[ -d /scratch/t.med.scmi/1000G_hg37_dosage ] || mkdir -p /scratch/t.med.scmi/1000G_hg37_dosage

for I in {1..22}
do
    filter_and_convert $INPUT $OUTPUT
done

Run Covariances Script

The script to generate covariances is here: https://github.com/hakyimlab/MetaXcan/blob/master/software/M01_covariances_correlations.py. More info: https://github.com/hakyimlab/MetaXcan/wiki/Command-Line-Reference#m01_covariances_correlationspy It takes the PrediXcan format dosages and a transcriptome prediction model, in this case, a database derived from a TWAS made available at: http://resource.psychencode.org. The output will be a gzipped text file with covariance between two snps. The script below can also be submitted as a job in CRI: https://github.com/hakyimlab/psychencode/blob/master/code/1000G_psychencode_cov.sh

python3 $METAXCAN/M01_covariances_correlations.py \
--weight_db $MODEL/psychencode_model/psychencode.db \
--input_folder /scratch/t.med.scmi/1000G_hg37_dosage \
--delimiter $'\t' \
--covariance_output $MODEL/psychencode_model/psychencode.txt.gz

sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/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     

loaded via a namespace (and not attached):
 [1] workflowr_1.6.2 Rcpp_1.0.3      rprojroot_1.3-2 digest_0.6.23  
 [5] later_1.0.0     R6_2.4.1        backports_1.1.5 git2r_0.27.1   
 [9] magrittr_1.5    evaluate_0.14   stringi_1.4.5   rlang_0.4.2    
[13] fs_1.3.1        promises_1.1.0  whisker_0.4     rmarkdown_2.1  
[17] tools_3.6.2     stringr_1.4.0   glue_1.3.1      httpuv_1.5.3.1 
[21] xfun_0.12       yaml_2.2.0      compiler_3.6.2  htmltools_0.4.0
[25] knitr_1.27