bam_reheader_R: Replace the header from a .bam file

Description Usage Arguments Value Examples

Description

This function replaces the header from one .bam file with a header from a different .sam file. This function mimicks the function of the 'reheader' function in samtools.

Usage

1
2
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 for which you want 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
download_refseq('viral', compress = FALSE)
mk_subread_index('viral.fasta', split = .0005)
readPath <- system.file("extdata", "virus_example.fastq", package = "animalcules.preprocess")
Rsubread::align(index = "viral_1", readfile1 = readPath, output_file = "virus_example1.bam")
Rsubread::align(index = "viral_2", readfile1 = readPath, output_file = "virus_example2.bam")
bam_files <- c('virus_example1.bam','virus_example2.bam')
com_head <- combined_header(bam_files)
bam_reheader_R(com_head, 'virus_example2.bam')
## Note that the following would be an equivalent command if samtools is installed
#system("samtools reheader header_tmp.sam virus_example2.bam > virus_example2h.bam")

wevanjohnson/animalcules.preprocess documentation built on May 11, 2019, 8:26 p.m.