#$ -S /bin/bash
#$ -l h_rt=20:0:0
#$ -l h_vmem=20G,tmem=20G
#$ -cwd
#$ -j y
#$ -N Transferability

#####1. Create credible set based on Established SNP list with LD calculated based on EUR ref panel

genodir=/SAN/ugi/mdd/trans_ethnic_ma/data/1000G/EUR #Directory to the EUR LD reference panel from the 1000 Genomes project
WD=/SAN/ugi/mdd/trans_ethnic_ma # project working directory
LD_EUR=eur_autosomes_hwe_1e-6_rmdup_rmmissing # 1000 Genomes LD reference file name
GWAS_EUR=EUR_GWAS_SNPs_rsid.txt #File name of published GWAS in Europeans

plink command to generate the credible set for each loci based on LD from European population
plink --bfile $genodir/$LD_EUR --r2 --ld-snp-list $WD/data/$GWAS_EUR --ld-window-kb 50 --ld-window 99999 --ld-window-r2 0.8 --out $WD/results/eur.gwas.snps.eu 

##reformat the credible set result from plink

sed q eur.gwas.snps.eu.ld > head.txt

grep -v -f head.txt eur.gwas.snps.eu.ld > body.txt

sed 's/SNP_A/SNP.Lead/g' head.txt > temp.txt
sed 's/SNP_B/SNP.proxy/g' temp.txt > header.txt
sed 's/CHR_B/CHR/g' header.txt > temp.txt
sed 's/BP_B/BP/g' temp.txt > header.txt

cat header.txt body.txt > eur.gwas.snps.eu.ld.txt 
rm body.txt

## Subsequent steps implemented in R, please see Transferability.R for details.