#!/usr/bin/env bash -x
"C:/Users/Cooper/Documents/Personalized_Genomics/me/WGSExtractv4/cygwin64/usr/local/bin/samtools.exe" depth -aa "C:/Users/Cooper/Documents/Personalized_Genomics/me/Nebula/Raw_Data/NG1RDRPK1V.cram" | "C:/Users/Cooper/Documents/Personalized_Genomics/me/WGSExtractv4/cygwin64/bin/gawk.exe" '{ names[$1]=$1 ; if($3==0){zero[$1]++} else {nz[$1]++ ; sumnz[$1]+=$3 ; 
              if($3>7){nI[$1]++ ; sumnI[$1]+=$3} else {if($3>3){n7[$1]++ ; sumn7[$1]+=$3} else 
              {n3[$1]++ ; sumn3[$1]+=$3} } } } END {
              printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
                "chr","zero","nonzero","sum nz","fract nz","avg nz","avg all",
                "TotalBC","Bet1-3","sum Bet1-3","Bet4-7","sum Bet4-7","Gtr7","sum Gtr7");
              for (x in names) { totalbc = zero[x]+nz[x]+1 ; 
                printf("%s\t%d\t%d\t%d\t%f\t%f\t%f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
                x,zero[x],nz[x],sumnz[x],nz[x]/totalbc,sumnz[x]/(nz[x]+1),sumnz[x]/totalbc,
                totalbc-1,n3[x],sumn3[x],n7[x],sumn7[x],nI[x],sumnI[x]) } }' > "C:/Users/Cooper/Documents/Personalized_Genomics/me/WGSExtractv4/out/NG1RDRPK1V_bincvg.csv"