Prepare data for gemma
# Generate Kinship Matrix
Rscript -e 'library(cegwas); kinship <- generate_kinship("WI.'${DATE}'.impute.vcf.gz"); write(kinship, "~/Desktop/kinship.20160408.tsv", sep = "\t", ncolumns = ncol(kinship));'
VCF=~/Dropbox/Andersenlab/Reagents/WormReagents/Variation/Andersen_VCF/WI.20160408.impute.vcf.gz
tag_snps=~/Dropbox/Andersenlab/Reagents/WormReagents/Variation/Andersen_VCF/41188.WS245.txt.gz
VERSION=20160408
bcftools view -O v -T ${tag_snps} -m2 -M2 ${VCF} | \
sed 's/0\|1/.\|./g' | \
sed 's/1\|0/.\|./g' | \
bcftools view -O z > mapping/mapping_snps.vcf.gz
vcftools --gzvcf mapping/mapping_snps.vcf.gz --plink --out mapping/mapping_snps
# Fix ped file
cat mapping/mapping_snps.ped | awk '{ $5 = "other"; print }' > mapping/mapping_snps.tmp.ped
mv mapping/mapping_snps.tmp.ped mapping/mapping_snps.ped
# Fix contigs in map file
cat mapping/mapping_snps.map | \
awk ' \
$2 ~ /^I:/ { $1 = "I"; print $0} \
$2 ~ /^II:/ { $1 = "II"; print $0} \
$2 ~ /^III:/ { $1 = "III"; print $0} \
$2 ~ /^IV:/ { $1 = "IV"; print $0} \
$2 ~ /^V:/ { $1 = "V"; print $0} \
$2 ~ /^X:/ { $1 = "X"; print $0} \
$2 ~ /^MtDNA:/ { $1 = "MtDNA"; print $0}' > mapping/mapping_snps.tmp.map
mv mapping/mapping_snps.tmp.map mapping/mapping_snps.map
# Must replace -9 with phenotype; Paste not working...python?
plink --file mapping/mapping_snps --make-bed --out mapping/mapping_snps.${VERSION}
# Fix BIM File
cat mapping/mapping_snps.${VERSION}.bim | \
awk ' \
$2 ~ /^I:/ { $1 = "I"; print $0} \
$2 ~ /^II:/ { $1 = "II"; print $0} \
$2 ~ /^III:/ { $1 = "III"; print $0} \
$2 ~ /^IV:/ { $1 = "IV"; print $0} \
$2 ~ /^V:/ { $1 = "V"; print $0} \
$2 ~ /^X:/ { $1 = "X"; print $0} \
$2 ~ /^MtDNA:/ { $1 = "MtDNA"; print $0}' | tr ' ' '\t' > mapping/mapping_snps.tmp.bim
mv mapping/mapping_snps.tmp.bim mapping/mapping_snps.${VERSION}.bim
# Fix Fam File
paste -d ' ' <(cut -f 1,2,3,4,5 -d ' ' mapping/mapping_snps.20160408.fam) mapping/telomere_phenotype.txt > mapping/mapping_snps.20160408.tmp.fam
mv mapping/mapping_snps.20160408.tmp.fam mapping/mapping_snps.20160408.fam
# Run command (locally)
docker run -it -v $(pwd):/home/linuxbrew sjackman/linuxbrew ./gemma \
-bfile mapping/mapping_snps.20160408 \
-k mapping/kinship.20160408.tsv \
-lmm 4 \
-o test2
docker run -it -v $(pwd):/home/linuxbrew sjackman/linuxbrew ./gemma \
-bfile mapping/mapping_snps.20160408 \
-gk 1 \
-o kmatrix
docker run -it -v $(pwd):/home/linuxbrew sjackman/linuxbrew ./gemma \
-bfile mapping/mapping_snps.20160408 \
-k mapping/kmatrix.cXX.txt \
-lmm 4 \
-o test_kmatrix
# Generate relatedness matrix
docker run -it -v $(pwd):/home/linuxbrew sjackman/linuxbrew ./gemma -bfile mapping/mapping_snps.20160408 -gk 2 -o relatedness_matrix.test.txt