Iterator {SeqVarTools} | R Documentation

## Iterators

### Description

Extends `SeqVarData` to provide iterators over variants.

### Details

Iterator classes allow for iterating filters over blocks of variants, ranges, or sliding windows.

For `SeqVarBlockIterator`, each call to `iterateFilter` will select the next unit of `variantBlock` variants.

For `SeqVarRangeIterator`, each call to `iterateFilter` will select the next range in `variantRanges`.

`SeqVarWindowIterator` is an extension of `SeqVarRangeIterator` where the ranges are determined automatically by sliding a window of size `windowSize` base pairs by steps of `windowShift` across the genome. Only windows containing unique sets of variants are kept.

For `SeqVarListIterator`, each call to `iterateFilter` will select the next set of ranges in `variantRanges`.

Any filter set on the object previously will be applied in addition to the selected blocks or ranges. The original filter can be restored after iteration by calling `restoreFilter`.

### Constructors

  `SeqVarBlockIterator(seqData, variantBlock=10000, verbose=TRUE)`: Returns a `SeqVarBlockIterator` object with the filter set to the first block.

  `seqData` is a `SeqVarData` object.

  `variantBlock` is an integer specifying the number of variants in an iteration block.

  `verbose` is a logical indicator for verbose output.

  `SeqVarRangeIterator(seqData, variantRanges=GRanges(), verbose=TRUE)`: Returns a `SeqVarRangeIterator` object with the filter set to the first range.

  `seqData` is a `SeqVarData` object.

  `variantRanges` is a `GRanges` object specifying the ranges for iteration.

  `verbose` is a logical indicator for verbose output.

  `SeqVarWindowIterator(seqData, windowSize=10000, windowShift=5000, verbose=TRUE)`: Returns a `SeqVarWindowIterator` object with the filter set to the first window.

  `seqData` is a `SeqVarData` object.

  `windowSize` is the size in base pairs of the sliding window.

  `windowShift` is the size in base pairs of the step for each consecutive window.

  `verbose` is a logical indicator for verbose output.

  `SeqVarListIterator(seqData, variantRanges, verbose=TRUE)`: Returns a `SeqVarRangeIterator` object with the filter set to the first range.

  `seqData` is a `SeqVarData` object.

  `variantRanges` is a `GRangesList` object specifying the ranges for iteration.

  `verbose` is a logical indicator for verbose output.

### Accessors

  `iterateFilter(x)`: Advance the filter to the next block, range, or set of ranges. Returns `TRUE` while there are still variants left to be read, `FALSE` if the end of iteration is reached.

  `restoreFilter(x)`: Restore the filter to its value prior to the creation of the Iterator object.

  `variantBlock(x)`: Get the size of the variant block.

  `lastVariant(x)`, `lastVariant(x)<- value`: Get or set the last variant from the previous call to `iterateFilter`.

  `variantRanges(x)`: Get the variant ranges.

  `lastRange(x)`, `lastRange(x)<- value`: Get or set the last range (for `SeqVarRangeIterator`) or set of ranges (for `SeqVarListIterator`) from the previous call to `iterateFilter`.

### Author(s)

Stephanie Gogarten

### See Also

`SeqVarGDSClass`, `SeqVarData`, `seqSetFilter`

### Examples

    gds <- seqOpen(seqExampleFileName("gds"))
    seqData <- SeqVarData(gds)

    # iterate by blocks
    seqSetFilter(seqData, variant.sel=seq(1,1000,2))
    iterator <- SeqVarBlockIterator(seqData, variantBlock=10)
    seqGetData(iterator, "variant.id")
    iterateFilter(iterator)
    seqGetData(iterator, "variant.id")
    restoreFilter(iterator)

    # iterate by ranges
    library(GenomicRanges)
    gr <- GRanges(seqnames=rep(1,3), ranges=IRanges(start=c(1e6, 2e6, 3e6), width=1e6))
    iterator <- SeqVarRangeIterator(seqData, variantRanges=gr)
    granges(iterator)
    iterateFilter(iterator) # no variants in the second range
    granges(iterator)
    iterateFilter(iterator)
    granges(iterator)
    iterateFilter(iterator)
    restoreFilter(iterator)

    # iterate by windows
    seqSetFilterChrom(seqData, include="22")
    iterator <- SeqVarWindowIterator(seqData)
    seqGetData(iterator, "variant.id")
    while (iterateFilter(iterator)) {
        print(seqGetData(iterator, "variant.id"))
    }
    restoreFilter(iterator)

    # iterate by list of ranges
    gr <- GRangesList(
      GRanges(seqnames=rep(22,2), ranges=IRanges(start=c(16e6, 17e6), width=1e6)),
      GRanges(seqnames=rep(22,2), ranges=IRanges(start=c(18e6, 20e6), width=1e6)))
    iterator <- SeqVarListIterator(seqData, variantRanges=gr)
    granges(iterator)
    iterateFilter(iterator)
    granges(iterator)
    iterateFilter(iterator)
    restoreFilter(iterator)

    seqClose(iterator)

[Package SeqVarTools version 1.16.1 Index]