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


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.


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



Location of the .fastq file to align


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.


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


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


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.


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.


#### 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
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.