% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/grs.R
\name{grs_bgen2pgen}
\alias{grs_bgen2pgen}
\title{Convert UKB imputed BGEN files to PGEN on RAP}
\usage{
grs_bgen2pgen(
  chr = 1:22,
  dest = NULL,
  maf = 0.01,
  instance = "standard",
  priority = "low"
)
}
\arguments{
\item{chr}{Integer vector. Chromosomes to process. Default: \code{1:22}.}

\item{dest}{Character scalar. RAP destination path for output PGEN files
(e.g. \code{"/pgen/"}). Must be specified explicitly.}

\item{maf}{Numeric scalar. Minor allele frequency filter passed to plink2
\code{--maf}. Variants with MAF below this threshold are excluded.
Default: \code{0.01}. Must be in \code{(0, 0.5)}.}

\item{instance}{Character scalar. Instance type preset: \code{"standard"}
or \code{"large"}. See Details. Default: \code{"standard"}.}

\item{priority}{Character scalar. Job priority: \code{"low"} or
\code{"high"}. Default: \code{"low"}.}
}
\value{
A character vector of job IDs (one per chromosome), returned
invisibly. Failed submissions are \code{NA}. Use \code{\link{job_ls}},
\code{\link{job_status}}, or \code{\link{job_wait}} to monitor progress.
}
\description{
Submits one Swiss Army Knife job per chromosome to the DNAnexus Research
Analysis Platform, each converting a UKB imputed BGEN file to PGEN format
with a MAF > 0.01 filter applied via plink2. Jobs run in parallel across
chromosomes.
}
\details{
The function auto-generates the plink2 driver script, uploads it once to
the RAP project root (\code{/}) on RAP, then loops over \code{chr} submitting
one job per chromosome. A 500 ms pause between submissions prevents API
rate-limiting.

\strong{Output path is critical.} The driver script writes plink2 output to
\code{/home/dnanexus/out/out/} - the fixed path that Swiss Army Knife
auto-uploads to \code{dest} on completion. Output files per chromosome:
\code{chr\{N\}_maf001.pgen/.pvar/.psam/.log}.

\strong{Instance types:}
\describe{
\item{\code{"standard"}}{\code{mem2_ssd1_v2_x4}: 4 cores, 12 GB RAM.
Suitable for smaller chromosomes (roughly chr 17–22).}
\item{\code{"large"}}{\code{mem2_ssd2_v2_x8}: 8 cores, 28 GB RAM,
640 GB SSD. Required for large chromosomes (roughly chr 1–16) where
standard storage is insufficient.}
}
}
\examples{
\dontrun{
# Test with chr22 first (smallest chromosome)
ids <- grs_bgen2pgen(chr = 22, dest = "/pgen/", priority = "high")

# Small chromosomes - standard instance
ids_small <- grs_bgen2pgen(chr = 15:22, dest = "/pgen/")

# Large chromosomes - upgrade instance to handle storage
ids_large <- grs_bgen2pgen(chr = 1:16, dest = "/pgen/", instance = "large")

# Monitor
job_ls()
}
}
