bam_reheader_R: Replace the header from a .bam file

View source: R/align_target.R

bam_reheader_RR Documentation

Replace the header from a .bam file

Description

This function replaces the header from one .bam file with a header from a different .sam file. This function mimics the function of the 'reheader' function in samtools. It is not intended for use by users.

Usage

bam_reheader_R(
  head,
  old_bam,
  new_bam = paste(tools::file_path_sans_ext(old_bam), "h.bam", sep = "")
)

Arguments

head

A file name and location for the .sam file with the new header.

old_bam

A file name and location for the .bam file which you would like to reheader.

new_bam

A file name for the new .bam file with a replaced header. Defaults to the same base filename plus 'h.bam'. For example, 'example.bam' will be written as 'exampleh.bam'.

Value

This function will return a new .bam file with a replaced header. 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 = "example1.bam")
# Rsubread::align(index = "target_2", readfile1 = readPath,
# output_file = "example2.bam")

# bam_files <- c('example1.bam','example2.bam')
# com_head <- combined_header(bam_files)
# bam_reheader_R(com_head, 'example2.bam')

## Note that the following would be an equivalent command if samtools is installed
# system2("samtools reheader header_tmp.sam example2.bam > example2h.bam")


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