align_target_bowtie: Align microbiome reads to set of indexed Bowtie2 libraries

View source: R/align_target.R

align_target_bowtieR Documentation

Align microbiome reads to set of indexed Bowtie2 libraries

Description

This is the main MetaScope target library mapping function, using RBowtie2 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_bowtie()' to remove reads that also map to filter library genomes.

Usage

align_target_bowtie(
  read1,
  read2 = NULL,
  lib_dir,
  libs,
  align_dir,
  align_file,
  bowtie2_options = NULL,
  threads = 8,
  overwrite = FALSE
)

Arguments

read1

Path to the .fastq file to align.

read2

Optional: Location of the mate pair .fastq file to align.

lib_dir

Path to the directory that contains the Bowtie2 indexes.

libs

The basename of the Bowtie2 indexes to align against (without trailing .bt2 or .bt2l extensions).

align_dir

Path to the directory where the output alignment file should be created.

align_file

The basename of the output alignment file (without trailing .bam extension).

bowtie2_options

Optional: Additional parameters that can be passed to the align_target_bowtie() function. To see all the available parameters use Rbowtie2::bowtie2_usage(). Default parameters are the parameters are the default parameters that PathoScope 2.0 uses. NOTE: Users should pass all their parameters as one string and if optional parameters are given then the user is responsible for entering all the parameters to be used by Bowtie2. NOTE: The only parameter that should NOT be specified here is the threads.

threads

The number of threads that can be utilized by the function. Default is 8 threads.

overwrite

Whether existing files should be overwritten. Default is FALSE.

Value

Returns the path to where the output alignment file is stored.

Examples

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

## Create a temporary directory to store reference library
ref_temp <- tempfile()
dir.create(ref_temp)

## Create a temporary directory to store the reference library index files
lib_temp <- tempfile()
dir.create(lib_temp)

## Create a temporary directory to store the bam file
align_temp <- tempfile()
dir.create(align_temp)

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

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

## Create the bowtie index files in the temporary index library directory
mk_bowtie_index(ref_dir = ref_temp, lib_dir = lib_temp, lib_name = "target",
overwrite=FALSE)

## Create object with path to the example reads
readPath <- system.file("extdata", "reads.fastq", package = "MetaScope")

## Align reads to the reference library
align_target_bowtie(read1 = readPath, lib_dir = lib_temp,
libs = "target", align_dir = align_temp, align_file = "bowtie_target",
overwrite = TRUE)

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