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.

### 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.

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

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

  `variantFilter(x)`: Get the list of variant indices.

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

  `currentRanges(x)`: Get the ranges selected in the current iteration.

  `currentVariants(x)`: Get the variants selected in the current iteration. Returns a `DataFrame` where the row name is the variant.id, "variant" is the variant position as a `link{GRanges}`, "range" is the range the variant is from, and any columns in either `variantData` or the metadata columns of `currentRanges` are included.

  `resetIterator(x)`: Set the filter to the first block, range, or set of ranges (the same variants that are selected when the iterator object is created).

### 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")
    seqResetFilter(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)
    seqResetFilter(iterator)

    # iterate by windows
    seqSetFilterChrom(seqData, include="22")
    iterator <- SeqVarWindowIterator(seqData)
    seqGetData(iterator, "variant.id")
    while (iterateFilter(iterator)) {
        print(seqGetData(iterator, "variant.id"))
    }
    seqResetFilter(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)
    resetIterator(iterator)

    seqClose(iterator)

[Package SeqVarTools version 1.26.0 Index]