snpgdsSlidingWindow {SNPRelate} | R Documentation

## Sliding window

### Description

Apply a user-defined function with a sliding window.

### Usage

    snpgdsSlidingWindow(gdsobj, sample.id=NULL, snp.id=NULL,
        FUN=NULL, winsize=100000L, shift=10000L, unit=c("basepair", "locus"),
        winstart=NULL, autosome.only=FALSE, remove.monosnp=TRUE, maf=NaN,
        missing.rate=NaN, as.is=c("list", "numeric", "array"),
        with.id=c("snp.id", "snp.id.in.window", "none"), num.thread=1,
        verbose=TRUE, ...)

### Arguments

`gdsobj` | an object of class `SNPGDSFileClass`, a SNP GDS file
`sample.id` | a vector of sample id specifying selected samples; if NULL, all samples are used
`snp.id` | a vector of snp id specifying selected SNPs; if NULL, all SNPs are used
`FUN` | a character or a user-defined function, see details
`winsize` | the size of sliding window
`shift` | the amount of shifting the sliding window
`unit` | `"basepair"` – `winsize` and `shift` are applied with SNP coordinate of basepair; `"locus"` – `winsize` and `shift` are applied according to the SNP order in the GDS file
`winstart` | `NULL` – no specific starting position; an integer – a starting position for all chromosomes; or a vector of integer – the starting positions for each chromosome
`autosome.only` | if `TRUE`, use autosomal SNPs only; if it is a numeric or character value, keep SNPs according to the specified chromosome
`remove.monosnp` | if TRUE, remove monomorphic SNPs
`maf` | to use the SNPs with ">= maf" only; if NaN, no MAF threshold
`missing.rate` | to use the SNPs with "<= missing.rate" only; if NaN, no missing threshold
`as.is` | save the value returned from `FUN` as "list" or "numeric"; "array" is equivalent to "numeric" except some cases, see details
`with.id` | "snp.id", "snp.id.in.window" or "none"
`num.thread` | the number of (CPU) cores used; if `NA`, detect the number of cores automatically
`verbose` | if TRUE, show information
`...` | optional arguments to `FUN`

### Details

If `FUN="snpgdsFst"`, two additional arguments `"population"` and `"method"` should be specified. `"population"` and `"method"` are defined in `snpgdsFst`. `"as.is"` could be "list" (returns a list of the values from `snpgdsFst`), "numeric" ( population-average Fst, returns a vector) or "array" (population-average and -specific Fst, returns a ‘# of pop + 1’-by-‘# of windows’ matrix, and the first row is population-average Fst).

### Value

Return a list

### Author(s)

Xiuwen Zheng

### Examples

    # open an example dataset (HapMap)
    genofile <- snpgdsOpen(snpgdsExampleFileName())

    # sliding windows
    rv <- snpgdsSlidingWindow(genofile, winsize=500000, shift=100000,
        FUN=function(...) NULL)

    # plot
    plot(rv$chr1.num, ylab="# of SNPs in the sliding window")

    # close the genotype file
    snpgdsClose(genofile)

[Package SNPRelate version 1.28.0 Index]