bam_to_bigwig: Convert a BAM file to a BigWig

Description Usage Arguments Details Value Examples

View source: R/bam_to_bigwig.R

Description

Given an input BAM file, convert this to the BigWig format which can then be used in get_coverage().

Usage

1
2
3
4
5
6
7
bam_to_bigwig(
  bam_file,
  prefix = file.path(tempdir(), basename(bam_file)),
  min_unique_qual = FALSE,
  double_count = FALSE,
  overwrite = FALSE
)

Arguments

bam_file

A character(1) with the path to the input BAM file.

prefix

A character(1) specifying the output file prefix. This function creates a BigWig file called {prefix}.all.bw. By default, the prefix is the BAM file name and the file is created in the tempdir() and will be deleted after you close your R session.

min_unique_qual

A integer(1) specifying a mapping quality threshold and only bases above this will be used to generate the BigWig. If set to FALSE this argument is not used by Megadepth. Otherwise it will generate files {prefix}.unique.bw and {prefix}.unique.tsv.

double_count

A logical(1) determining whether to count the overlapping ends of paired ends reads twice.

overwrite

A logical(1) specifying whether to overwrite the output file(s), if they exist already.

Details

Note that this functionality is currently not supported on Windows by Megadepth.

Value

A character() with the path to the output files(s).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Install the latest version if necessary
install_megadepth(force = TRUE)

## Find the example BAM file
example_bam <- system.file("tests", "test.bam",
    package = "megadepth", mustWork = TRUE
)

## Create the BigWig file
## Currently Megadepth does not support this on Windows
if (!xfun::is_windows()) {
    example_bw <- bam_to_bigwig(example_bam, overwrite = TRUE)

    ## Path to the output file(s) generated by bam_to_bigwig()
    example_bw

    ## Use the all.bw file in get_coverage(), first find an annotation file
    annotation_file <- system.file("tests", "testbw2.bed",
        package = "megadepth", mustWork = TRUE
    )

    ## Compute the coverage
    bw_cov <- get_coverage(
        example_bw["all.bw"],
        op = "mean",
        annotation = annotation_file
    )
    bw_cov
}

megadepth documentation built on Feb. 5, 2021, 2:03 a.m.