filter_host: Align reads against one or more filter libraries and...

View source: R/filter_host.R

filter_hostR Documentation

Align reads against one or more filter libraries and subsequently remove mapped reads

Description

After a sample is aligned to a target library with align_target(), we may use filter_host() to remove unwelcome host contamination using filter reference libraries. This function takes as input the name of the .bam file produced via align_target(), and produces a sorted .bam file with any reads that match the filter libraries removed. This resulting .bam file may be used upstream for further analysis.

Usage

filter_host(
  reads_bam,
  libs,
  lib_dir = NULL,
  make_bam = FALSE,
  output = paste(tools::file_path_sans_ext(reads_bam), "filtered", sep = "."),
  settings = align_details,
  YS = 5e+05,
  threads = 8
)

Arguments

reads_bam

The name of a merged, sorted .bam file that has previously been aligned to a reference library. Likely, the output from running an instance of align_target_bowtie().

libs

The basename of the filter libraries (without .bt2 or .bt2l extension)

lib_dir

Path to the directory that contains the filter Bowtie2 index files.

make_bam

Logical, whether to also output a bam file with host reads filtered out. An rds file will be created instead if FALSE. Default is FALSE.

output

The desired name of the output .bam or .rds file. Extension is automatically defined by whether make_bam = TRUE. Default is the basename of unfiltered_bam + .filtered + extension.

settings

A named list specifying alignment parameters for the Rsubread::align() function, which is called inside align_target(). Elements should include type, nthreads, maxMismatches, nsubreads, phredOffset, unique, and nBestLocations. Descriptions of these parameters are available under ?Rsubread::align. Defaults to the global align_details object.

YS

yieldSize, an integer. The number of alignments to be read in from the bam file at once for the creation of an intermediate fastq file. Default is 1000000.

threads

The amount of threads available for the function. Default is 8 threads.

Value

The name of a filtered, sorted .bam file written to the user's current working directory. Or, if make_bam = FALSE, an RDS file containing a data frame of only requisite information to run metascope_id().

Examples

#### Filter reads from bam file that align to any of the filter libraries

## Assuming a bam file has been created previously with align_target()

## Create object with path to the example filter library
refPath <- system.file("extdata","filter.fasta", package = "MetaScope")

## Copy the example filter library to the current directory
file.copy(from = refPath, to = file.path(".", "filter.fasta"))

## Make subread index of filter library
mk_subread_index('filter.fasta')

## Create object with path to the previously aligned bam file
readPath <- system.file("extdata", "subread_target.bam", package = "MetaScope")

## Filter bam file
filter_host(readPath, libs = "filter", threads = 1)


compbiomed/MetaScope documentation built on Aug. 9, 2022, 10:41 a.m.