merge_bam_files: Merge multiple .bam files

View source: R/align_target.R

merge_bam_filesR Documentation

Merge multiple .bam files

Description

This function merges .bam files. It first used the combined_header function to generate a combined header for all the files, reheaders the files, and then merges and sorts the .bam files. This is similar to the 'samtools merge' function, but it allows the .bam files to have different headers. It is not intended for use by users.

Usage

merge_bam_files(
  bam_files,
  destination,
  head_file = paste(destination, "_header.sam", sep = "")
)

Arguments

bam_files

A list of file names for the .bam files to be merged.

destination

A file name and location for the merged .bam file.

head_file

A file name and location for the combined header file. Defaults to the destination . For example, 'example.bam' will be written as 'exampleh.bam'.

Value

This function merges .bam files and combines them into a single file. The function also outputs the new .bam filename.

Examples


# refPath <- system.file("extdata","target.fasta", package = "MetaScope")
# file.copy(from = refPath, to = file.path(".", "target.fasta"))
# mk_subread_index('target.fasta', split = .02)

# readPath <- system.file("extdata", "reads.fastq", package = "MetaScope")
# Rsubread::align(index = "target_1", readfile1 = readPath,
# output_file = "target1.bam", maxMismatches = 3)
# Rsubread::align(index = "target_2", readfile1 = readPath,
# output_file = "target2.bam")

# bam_files <- c('target1.bam','target2.bam')
# com_head <- combined_header(bam_files)
# bam_reheader_R(com_head, 'target1.bam')
# bam_reheader_R(com_head, 'target2.bam')
# bam_files <- c('target1h.bam','target2h.bam')
# merged_all <- merge_bam_files(bam_files, 'example_merged')


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