downsampleBam: Randomly Downsample BAM File to a Target Depth

View source: R/downsampleBam.R

downsampleBamR Documentation

Randomly Downsample BAM File to a Target Depth

Description

Downsampling a BAM file to achieve a specified sequencing depth. Exports the data as a BAM file and/or an RDS file containing a 'GAlignmentPairs' object.

Usage

downsampleBam(
  bamfile,
  genome = NA_character_,
  input_depth = NULL,
  input_mapped_reads_count = NULL,
  output_depth = 0.1,
  output_type = c("bam", "rds"),
  output_dir = NULL,
  return_result = TRUE,
  ...
)

Arguments

bamfile

Path to a BAM file.

genome

Supported values: "hg19", "hg38", "GRCh38", or NA. Sets seqinfo.

input_depth

Target depth, inferred if not supplied.

input_mapped_reads_count

Mapped reads count to infer depth if not supplied.

output_depth

Target output depth after downsampling, default is 0.1.

output_type

Output file formats, default is c("bam", "rds").

output_dir

Directory for output files, defaults to input file directory.

return_result

If TRUE (default), returns result as an R object.

...

Additional parameters for 'bam_to_galp2' function.

Value

'GAlignmentPairs' object with the downsampled reads if return_result.

Examples

## Not run: 
  # Downsample a BAM file to 10% of its original depth
  result <- downsampleBam("/path/to/your.bam", genome = "hg38",
                          output_depth = 0.1, output_type = c("bam", "rds"),
                          return_result = TRUE)

## End(Not run)

hw538/cfDNAPro documentation built on Feb. 17, 2025, 6:09 p.m.