bam2fastq: Bam/Sam file to fastq file conversion

View source: R/fastqIO.R

bam2fastqR Documentation

Bam/Sam file to fastq file conversion

Description

Convert either paired or unpaired Bam file into fastq files.

Usage

  bam2fastq(bamFn, OUTPUT_PER_RG=TRUE, OUTPUT_DIR=".", paired=FALSE,
            fastqFns=sub("(\.bam|\.sam)$", "fastq", bamFn),
            fastq2Fns=sub("(\.bam|\.sam)$", "_R2.fastq", bamFn)
            )

Arguments

bamFn

character(1): path of input Bam/Sam files

OUTPUT_PER_RG

boolean(1): whether or not to output one fastq per RG. When TRUE, paired, fastqFns and fastq2Fns are ignoreed.

OUTPUT_DIR

boolean(1): the output dir for fastqs.

fastqFns

character(1): paths of first end of read file.

fastq2Fns

character(2): optional paths of second end of paired read file.

paired

boolean(1): paired-end or single-end read file.

Details

The conversion is done with picard's SamToFastq.

Rsamtools::testPairedEndBam cannot be used to test for paired or not. It doesn't work on Bam converted from fastq, due to the lack of header. paired has to be specified explicitly.

Value

invisible filenames of first read files.

Author(s)

Ge Tan

See Also

fastqs2bam

Examples

  ## Not run: 
    bamFn <- "/srv/gstore/projects/p2497/HiSeq4000_20171222_RUN420_o3705_fixedRG/20171222.A-SiCSeq_SCs_P5_unmapped.bam"
    bamFn <- "/scratch/gtan/p2497-SCCountQC/20171222.A-SiCSeq_SCs_P5_subset.bam"
    
    ## Split into one Fastq
    fastqFn <- bam2fastq(bamFn, fastqFns=sub("\\.bam$", ".fastq", basename(bamFn)), 
                         paired=FALSE)
    ## Split by RG
    fastqFn <- bam2fastq(bamFn, OUTPUT_PER_RG=TRUE, OUTPUT_DIR=".", paired=FALSE)
  
## End(Not run)

uzh/ezRun documentation built on Dec. 26, 2024, 9:53 a.m.