snpgdsSlidingWindow: Sliding window

Description Usage Arguments Details Value Author(s) Examples

View source: R/AllUtilities.R

Description

Apply a user-defined function with a sliding window.

Usage

1
2
3
4
5
6
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# 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)

Example output

Loading required package: gdsfmt
SNPRelate -- supported by Streaming SIMD Extensions 2 (SSE2)
Sliding Window Analysis:
Excluding 8 SNPs (monomorphic: TRUE, MAF: NaN, missing rate: NaN)
Working space: 279 samples, 9,080 SNPs
    using 1 (CPU) core
    window size: 500000, shift: 100000 (basepair)
Chromosome Set: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
Mon May 21 20:46:51 2018, Chromosome 1 (716 SNPs), 2448 windows
Mon May 21 20:46:51 2018, Chromosome 2 (742 SNPs), 2416 windows
Mon May 21 20:46:51 2018, Chromosome 3 (609 SNPs), 1985 windows
Mon May 21 20:46:51 2018, Chromosome 4 (562 SNPs), 1894 windows
Mon May 21 20:46:51 2018, Chromosome 5 (566 SNPs), 1797 windows
Mon May 21 20:46:51 2018, Chromosome 6 (565 SNPs), 1694 windows
Mon May 21 20:46:51 2018, Chromosome 7 (472 SNPs), 1573 windows
Mon May 21 20:46:51 2018, Chromosome 8 (488 SNPs), 1445 windows
Mon May 21 20:46:51 2018, Chromosome 9 (416 SNPs), 1393 windows
Mon May 21 20:46:51 2018, Chromosome 10 (483 SNPs), 1343 windows
Mon May 21 20:46:51 2018, Chromosome 11 (447 SNPs), 1338 windows
Mon May 21 20:46:51 2018, Chromosome 12 (427 SNPs), 1316 windows
Mon May 21 20:46:51 2018, Chromosome 13 (344 SNPs), 948 windows
Mon May 21 20:46:51 2018, Chromosome 14 (281 SNPs), 847 windows
Mon May 21 20:46:51 2018, Chromosome 15 (262 SNPs), 774 windows
Mon May 21 20:46:51 2018, Chromosome 16 (278 SNPs), 873 windows
Mon May 21 20:46:51 2018, Chromosome 17 (207 SNPs), 773 windows
Mon May 21 20:46:51 2018, Chromosome 18 (266 SNPs), 753 windows
Mon May 21 20:46:51 2018, Chromosome 19 (120 SNPs), 627 windows
Mon May 21 20:46:51 2018, Chromosome 20 (229 SNPs), 602 windows
Mon May 21 20:46:51 2018, Chromosome 21 (126 SNPs), 311 windows
Mon May 21 20:46:51 2018, Chromosome 22 (116 SNPs), 312 windows
Mon May 21 20:46:51 2018, Chromosome 23 (358 SNPs), 1507 windows
Mon May 21 20:46:51 2018 	Done.

SNPRelate documentation built on Nov. 8, 2020, 5:31 p.m.