% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/duckhts.R
\name{rduckhts_bam}
\alias{rduckhts_bam}
\title{Create SAM/BAM/CRAM Table}
\usage{
rduckhts_bam(
  con,
  table_name,
  path,
  region = NULL,
  index_path = NULL,
  reference = NULL,
  standard_tags = FALSE,
  auxiliary_tags = FALSE,
  sequence_encoding = NULL,
  quality_representation = NULL,
  cigar_representation = NULL,
  scan_mode = NULL,
  decompression_threads = 2,
  overwrite = FALSE
)
}
\arguments{
\item{con}{A DuckDB connection with DuckHTS loaded}

\item{table_name}{Name for the created table}

\item{path}{Path to the SAM/BAM/CRAM file}

\item{region}{Optional genomic region (e.g., "chr1:1000-2000")}

\item{index_path}{Optional explicit path to index file (.bai/.csi/.crai)}

\item{reference}{Optional reference file path for CRAM files}

\item{standard_tags}{Logical. If TRUE, include typed standard SAMtags columns. Default FALSE.}

\item{auxiliary_tags}{Logical. If TRUE, include AUXILIARY_TAGS map of non-standard tags. Default FALSE.}

\item{sequence_encoding}{Character. Sequence encoding for the SEQ column:
\code{"string"} (default) returns decoded bases as \code{VARCHAR};
\code{"nt16"} returns raw htslib nt16 4-bit codes as \code{UTINYINT[]}.}

\item{quality_representation}{Character. Quality representation for the QUAL column:
\code{"string"} (default) returns canonical Phred+33 text;
\code{"phred"} returns raw Phred values as \code{UTINYINT[]}.}

\item{cigar_representation}{Character. CIGAR representation for the CIGAR column:
\code{"string"} (default) returns SAM text such as \code{"36M"};
\code{"binary"} returns packed BAM operations as \code{UINTEGER[]} where each
element is \code{(len << 4) | op}.}

\item{scan_mode}{Optional scan mode. Use \code{"auto"} (default extension
behavior) or \code{"sequential"} to force full-file streaming instead of
index-backed count/parallel scan paths. Sequential mode is incompatible
with \code{region}.}

\item{decompression_threads}{Integer. Number of htslib decompression worker
threads per file handle. Default \code{2}. Use \code{0} to disable worker
threads.}

\item{overwrite}{Logical. If TRUE, overwrites existing table}
}
\value{
Invisible TRUE on success
}
\description{
Creates a DuckDB table from SAM, BAM, or CRAM files using the DuckHTS extension.
}
\examples{
library(DBI)
library(duckdb)

con <- rduckhts_connect()
bam_path <- system.file("extdata", "range.bam", package = "Rduckhts")
rduckhts_bam(con, "reads", bam_path, overwrite = TRUE)
dbGetQuery(con, "SELECT COUNT(*) FROM reads WHERE FLAG & 4 = 0")
dbDisconnect(con, shutdown = TRUE)

}
