R: Extraction of alignments from given genetic regions and BAM...

extractGeneRegions {rbamtools} | R Documentation

## Extraction of alignments from given genetic regions and BAM files into a set of output BAM files.

### Description

The function `extractGeneRegions` writes aligns or some part of the stored aligns in a BAM file as reads into a BAM output file.

### Usage

    extractGeneRegions(src, trg, gl)

### Arguments

`src` | `sampleBamFiles`: List of source BAM files where alignments are read from. BAM index files must exist and be present in src object.

`trg` | `sampleBamFiles`: List of target BAM files where alignments are written to.

`gl` | `geneList`: Objects from which genetic regions are taken.

### Details

Reference sequence names in `geneList` object must all match sequence names in source BAM files.

### Value

Numeric. Number of written alignments for each file.

### Author(s)

Wolfgang Kaisers

### Examples

    # + + + + + + + + + + + + + + + + + + #
    # A) Create sampleBamFiles objects
    # + + + + + + + + + + + + + + + + + + #
    bam <- system.file("extdata","accepted_hits.bam",package="rbamtools")
    outdir <- tempdir()
    # Input sampleBamFiles object
    ibs <- sampleBamFiles(bam)
    # Output sampleBamFiles object
    obs <- sampleBamFiles(file.path(outdir, "outu.bam"))
    # + + + + + + + + + + + + + + + + + + #
    # B) Create geneList Object
    # + + + + + + + + + + + + + + + + + + #
    rfile <- system.file("extdata",
                "hs.ucsc.small.RData",
                    package="refGenome")

    ucr <- loadGenome(rfile)
    gt <- getGeneTable(ucr)
    gl <- geneList(ucr, gt$gene_id)

    extractGeneRegions(ibs, obs, gl)
    bamFiles(obs) <- file.path(outdir, bamSort(obs, "out"))
    bamIdxFiles(obs) <- paste(bamFiles(obs), "bai", sep=".")
    createIndex(obs)

[Package rbamtools version 2.16.17 Index]