# This assumes 97 chromosomes! It will probably work for fewer, but not much more

# The gunther bams get concated onto the end of the NoGunther bams, so samps and pops must match this as well. 


VCF=$1 # variants that have been masked and thinned
REF=$2 # refence genome
BAMSForGunther=$3 # historical bams to reduce reference bias using Gunther and Nettelblad scripts
BAMSNoGunther=$4 # modern bams to not alter

# first run the gunther scripts

# convert VCF to bed format
python3 /home/asharo/scripts/VCFToBed.py $VCF forGunther

HomeDir=`pwd`

mkdir guntherBams

# need to move to Gunther directory for this part

cd /scratch3/andrew/GuntherRefBiasOptions/refbias/

Ran=$RANDOM

mkdir tmp.$Ran

# run gunther
/scratch3/andrew/GuntherRefBiasOptions/refbias/remap_modified_reads.trout.multiBams.sh $BAMSForGunther $HomeDir/forGunther.bed $REF $HomeDir/guntherBams/ $HomeDir/forGunther.tsv ./tmp.$Ran/

# gunther will create bams in the guntherBams folder, with new names
cat /dev/null > $HomeDir/guntherModifiedBams.list
for B in `cat $BAMSForGunther`; do
	Bbase=`basename $B .bam`
	Bnew=./guntherBams/$Bbase.remapmodread.filter.bam
	echo $Bnew >> $HomeDir/guntherModifiedBams.list
done

# remove temp directory
rm -r ./tmp.$Ran/

cd $HomeDir

# next we cat the gunther bams onto the end of the provided bams file
cat $BAMSNoGunther ./guntherModifiedBams.list > fullBams.list

BAMS=fullBams.list

