# Filter and mask 1000 genomes data
nohup julia ./filter.jl > chr20.filter.out &
nohup julia ./filter.jl > chr10.filter.out &

# To compress to JLSO
nohup julia ./compress.jl > mendel.compress.chr20.out &
nohup julia ./compress.jl > mendel.compress.chr10.out &

# compress reference file to m3vcf/bref3
nohup /usr/bin/time Minimac3 --refHaps ref.chr20.excludeTarget.vcf.gz --processReference --prefix ref.chr20.excludeTarget > minimac3.chr20.m3vcf.out & 
nohup /usr/bin/time Minimac3 --refHaps ref.chr10.excludeTarget.vcf.gz --processReference --prefix ref.chr10.excludeTarget > minimac3.chr10.m3vcf.out &
java -jar bref3.18May20.d20.jar ref.chr10.excludeTarget.vcf.gz > ref.chr10.excludeTarget.bref3
java -jar bref3.18May20.d20.jar ref.chr20.excludeTarget.vcf.gz > ref.chr20.excludeTarget.bref3

# Prephase with Beagle 5.1 (minimac4 and impute5 requires prephased data)
nohup /usr/bin/time java -Xmx60g -jar beagle.18May20.d20.jar gt=target.chr20.typedOnly.masked.vcf.gz ref=ref.chr20.excludeTarget.bref3 out=target.chr20.prephased impute=false nthreads=10 > prephase.chr20.beagle.log &
nohup /usr/bin/time java -Xmx60g -jar beagle.18May20.d20.jar gt=target.chr10.typedOnly.masked.vcf.gz ref=ref.chr10.excludeTarget.bref3 out=target.chr10.prephased impute=false nthreads=10 > prephase.chr10.beagle.log &

# generate imp5 reffile and BGZF compress target to satisfy impute5 (first BGZF compress, index with tabix)
gunzip ref.chr20.excludeTarget.vcf.gz
gunzip ref.chr10.excludeTarget.vcf.gz
bgzip -c ref.chr20.excludeTarget.vcf > ref.chr20.excludeTarget.vcf.gz
bgzip -c ref.chr10.excludeTarget.vcf > ref.chr10.excludeTarget.vcf.gz
rm ref.chr20.excludeTarget.vcf
rm ref.chr10.excludeTarget.vcf
tabix -fp vcf ref.chr20.excludeTarget.vcf.gz
tabix -fp vcf ref.chr10.excludeTarget.vcf.gz
tabix -fp vcf target.chr20.prephased.vcf.gz
tabix -fp vcf target.chr10.prephased.vcf.gz
imp5 --h ref.chr20.excludeTarget.vcf.gz --r 20 --o ref.chr20.excludeTarget.imp5 --threads 10
imp5 --h ref.chr10.excludeTarget.vcf.gz --r 10 --o ref.chr10.excludeTarget.imp5 --threads 10

# Run MendelImpute
nohup /usr/bin/time julia ./impute.jl > mendel.impute.chr10.out &
nohup /usr/bin/time julia ./impute.jl > mendel.impute.chr20.out &

# Run Minimac4
nohup /usr/bin/time minimac4 --refHaps ref.chr20.excludeTarget.m3vcf.gz --haps target.chr20.prephased.vcf.gz --prefix minimac4.chr20.result --cpus 10 > minimac4.chr20.imputed.log & 
nohup /usr/bin/time minimac4 --refHaps ref.chr10.excludeTarget.m3vcf.gz --haps target.chr10.prephased.vcf.gz --prefix minimac4.chr10.result --cpus 10 > minimac4.chr10.imputed.log &

# Run Beagle 5.1
nohup /usr/bin/time java -Xmx60g -jar beagle.18May20.d20.jar gt=target.chr20.typedOnly.masked.vcf.gz ref=ref.chr20.excludeTarget.bref3 out=beagle.imputed.chr20 nthreads=10 > beagle.chr20.imputed.log &
nohup /usr/bin/time java -Xmx60g -jar beagle.18May20.d20.jar gt=target.chr10.typedOnly.masked.vcf.gz ref=ref.chr10.excludeTarget.bref3 out=beagle.imputed.chr10 nthreads=10 > beagle.chr10.imputed.log &

# Run impute 5
nohup /usr/bin/time /home/biona001/impute5_v1.1.4/impute5_1.1.4_static --h ref.chr20.excludeTarget.imp5 --g target.chr20.prephased.vcf.gz --r 20 --o impute5.chr20.result.vcf.gz --threads 10 > impute5.chr20.out & 

# Run Impute5 using chunking
nohup /usr/bin/time julia chunk_impute5.jl 20 ref.chr20.excludeTarget.imp5 target.chr20.prephased.vcf.gz > impute5.chr20.out &
nohup /usr/bin/time julia chunk_impute5.jl 10 ref.chr10.excludeTarget.imp5 target.chr10.prephased.vcf.gz > impute5.chr10.out &

# Get error rate
nohup julia ./error_rate.jl > all.error.out & 

# Run ADMIXTURE
nohup /usr/bin/time julia ./admixture.jl > chr18.admixture.out &
