## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----load-example-bam---------------------------------------------------------
library(BamScale)

bam <- ompBAM::example_BAM("Unsorted")

## ----metadata-access----------------------------------------------------------
x <- bam_read(
    file = bam,
    what = c("qname", "flag", "rname", "pos", "mapq", "cigar"),
    as = "data.frame",
    threads = 2
)

head(x)

## ----scanbamparam-filtering---------------------------------------------------
param <- Rsamtools::ScanBamParam(
    what = c("qname", "flag", "mapq"),
    mapqFilter = 20L,
    flag = Rsamtools::scanBamFlag(isUnmappedQuery = FALSE)
)

filtered <- bam_read(
    file = bam,
    param = param,
    as = "data.frame",
    threads = 2
)

head(filtered)

## ----galignments-output-------------------------------------------------------
ga <- bam_read(
    file = bam,
    what = c("qname", "flag", "rname", "pos", "cigar", "strand"),
    as = "GAlignments",
    threads = 2
)

ga

## ----seqqual-compatible-------------------------------------------------------
seqqual_compatible <- bam_read(
    file = bam,
    what = c("qname", "seq", "qual"),
    as = "data.frame",
    seqqual_mode = "compatible",
    threads = 2
)

head(seqqual_compatible)

## ----seqqual-compact----------------------------------------------------------
seqqual_compact <- bam_read(
    file = bam,
    what = c("qname", "qwidth", "seq", "qual"),
    as = "data.frame",
    seqqual_mode = "compact",
    threads = 2
)

head(seqqual_compact)

seqqual_decoded <- decode_seqqual_compact(seqqual_compact)
head(seqqual_decoded)

## ----bam-count-example--------------------------------------------------------
counts <- bam_count(bam, threads = 2)
counts

## ----intro-session-info-------------------------------------------------------
sessionInfo()

