## ----echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE----------------------
# library(vcfR)
# library(tidyr)
# library(dplyr)
# library(nQuack)

## ----echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE----------------------
# df1 <- vcfR::read.vcfR("output.biallelic.vcf")
# ## Convert vcf to tidy
# ccdf1 <- vcfR::vcfR2tidy(df1)
# ## Subset genotypes
# ccdf1gt <- ccdf1$gt

## ----echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE----------------------
# df1_size <- data.frame(POS=paste0(ccdf1gt$ChromKey, "_", ccdf1gt$POS),
#                        IND=ccdf1gt$Indiv,
#                        DP = as.integer(ccdf1gt$gt_DP))
# df1_size <- df1_size %>%
#             pivot_wider(names_from = POS, values_from = DP)
# names <- df1_size$IND
# rownames(df1_size) <- df1_size$IND
# df1_size <- df1_size[,-1]
# sizemat <- as.matrix(df1_size)
# rownames(sizemat) <- names

## ----echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE----------------------
# ADset  <- data.frame(do.call(rbind, strsplit(ccdf1gt$gt_AD,",")))

## ----echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE----------------------
# df1_ref <- data.frame(POS=paste0(ccdf1gt$ChromKey, "_", ccdf1gt$POS),
#                       IND=ccdf1gt$Indiv,
#                       AD =  as.integer(ADset$X1))
# df1_ref <- df1_ref %>%
#            pivot_wider(names_from = POS, values_from = AD)
# names <- df1_ref$IND
# rownames(df1_ref) <- names
# df1_ref <- df1_ref[,-1]
# refmat <- as.matrix(df1_ref)
# rownames(refmat) <- names

## ----echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE----------------------
# df1_alt <- data.frame(POS=paste0(ccdf1gt$ChromKey, "_", ccdf1gt$POS),
#                       IND=ccdf1gt$Indiv,
#                       AD =  as.integer(ADset$X2))
# df1_alt <- df1_alt %>%
#            pivot_wider(names_from = POS, values_from = AD)
# names <- df1_alt$IND
# rownames(df1_alt) <- names
# df1_alt <- df1_alt[,-1]
# altmat <- as.matrix(df1_alt)
# rownames(altmat) <- names

## ----echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE----------------------
# ## Set path to folder
# outpath <- "03_processed/"
# 
# ## Loop through individuals to pull out information
# for(i in 1:length(names)){
#   t1 <- sizemat[i, ]
#   t2 <- refmat[i, ]
#   t3 <- altmat[i, ]
# 
#   ## Create dataframe
#   all <- data.frame(V1 = t1, V2 = t2, V3 = t3)
#   ## Filter to only biallelic sites in the individual
#   all <- all %>% filter(V2 != 0 & V3 != 0)
#   ## Randomly select A or B
#   allout <- nQuire_reformat(as.matrix(all))
# 
#   outname <- paste0(outpath, names[i], ".csv")
#   write.csv(allout, file = outname, row.names = FALSE)
# }

