align_target: Align microbiome reads to a set of reference libraries

View source: R/align_target.R

align_targetR Documentation

Align microbiome reads to a set of reference libraries

Description

This is the main MetaScope target library mapping function, using Rsubread and multiple libraries. Aligns to each library separately, filters unmapped reads from each file, and then merges and sorts the .bam files from each library into one output file. If desired, output can be passed to 'filter_host()' to remove reads that also map to filter library genomes.

Usage

align_target(
  reads,
  libs,
  lib_dir = NULL,
  project_name = tools::file_path_sans_ext(reads),
  settings = align_details
)

Arguments

reads

Location of the .fastq file to align

libs

A vector of character strings giving the basenames of the Subread index files for alignment. These should be located in the same directory and the current directory if lib_dir=NULL.

lib_dir

path to the library index files (all libraries should be here)

project_name

A name for the project, which names the output .bam file (e.g. project_name.bam). Defaults to the basename of the reads file.

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.

Value

This function writes a merged and sorted .bam file after aligning to all reference libraries given, along with a summary report file, to the user's working directory. The function also outputs the new .bam filename.

Examples

#### Align example reads to an example reference library using Rsubread

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

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

## Make and align to a single reference library
mk_subread_index("target.fasta")
readPath <- system.file("extdata", "reads.fastq", package = "MetaScope")
align_details <- get0("align_details", envir = asNamespace("MetaScope"))
target_map <- align_target(readPath, "target", project_name="subread_target")
target_map_sam <- Rsamtools::asSam(target_map, overwrite = TRUE)

## Make and align to multiple reference libraries
mk_subread_index('target.fasta', split = .02)
targLibs <- c("target_1", "target_2")
readPath <- system.file("extdata", "reads.fastq",package = "MetaScope")
target_map <- align_target(readPath, targLibs, project_name = "subread_target")


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