#!/bin/bash

pheno=$1
pop=$2

thr=12
mem=96000

covarFile=/mnt/project/import/ukbb_qced.covar.txt.gz
phenoFile=/mnt/project/import/ukbb_qced.${pheno}.txt.gz
popFile=/mnt/project/import/population/ukbb_qced.${pop}.txt.gz
pruneFile=/mnt/project/genotypes/pruning/ukb22418.hg38.${pop}.1000_100_09.prune.in.gz
pfile=/mnt/project/genotypes/ukb22418.hg38

cd /home/dnanexus/

cp /mnt/project/tool/plink2 . && chmod 755 plink2
docker pull skoyamamd/regenie:v3.1.3.gz

cp $covarFile .
cp $phenoFile .
cp $popFile .
cp $pruneFile .
cp $pfile.{pgen,pvar,psam} .

./plink2 \
  --pfile $(basename $pfile) \
  --extract $(basename $pruneFile) \
  --keep $(basename $popFile) \
  --make-pgen \
  --autosome \
  --threads ${thr} \
  --maf 0.01 \
  --memory ${mem} \
  --out ukb22418.hg38.${pop}.pruned

## Run step1

docker run -v /home/dnanexus/:/home/dnanexus skoyamamd/regenie:v3.1.3.gz regenie \
  --step 1 \
  --pgen /home/dnanexus/ukb22418.hg38.${pop}.pruned \
  --covarFile /home/dnanexus/$(basename $covarFile) \
  --catCovarList SEX,ARRAY \
  --phenoFile /home/dnanexus/$(basename $phenoFile) \
  --bsize 1000 \
  --qt \
  --apply-rint \
  --threads ${thr} \
  --out /home/dnanexus/out/out/ukb22418.${pheno}.${pop}

