read.snps: Read genotype matrix from file.

Description Usage Arguments Details Value See Also Examples

Description

read.snps is wrapper around scan that also converts into native matrix format.

Usage

1
2
read.snps(file, ncols = NULL, na = NA, what = integer(),
  extractIDs = TRUE, quiet = TRUE, ...)

Arguments

file

Filename or connection.

ncols

Integer, number of columns in file, including ID column. When NULL (default), automagically detected with get_ncols.

na

Missing values; entries with this value are replaced with NA..

what

The typeof of data to be read, e.g. integer(), numeric(), or character().

extractIDs

Logical, default TRUE, trim of first column and use as rownames.

quiet

logical: if FALSE, scan() will print a line, saying how many items have been read.

...

Passed on to scan.

Details

Assumes a file format with no header and first column are IDs. If no ID column, use extractIDs = FALSE. Usually white-space delimted, but separator can be set with sep argument as per scan. For file format example see Siccuracy.

If ID columns contains alphabetical elements, use what=character(). This will however return a character matrix. Use e.g. storage.mode(m) <- 'integer' to convert to integer-based, keeping all other attributes.

Value

Native matrix.

See Also

write.snps, typeof, get_ncols, scan, and Oxford, SHAPEIT, and VCF formats.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Make test data
tmpfile <- tempfile()
write.snps(Siccuracy:::make.true(5, 10), tmpfile)
M <- read.snps(tmpfile)

# Process the genotypes in chunks:
# Setting mode to 'r' is very important to avoid resetting the pointer at file head!
ncols <- get_ncols(tmpfile)
f <- file(tmpfile, 'r') 
while (TRUE) {
  M <- read.snps(f, nlines=500, ncols=ncols)
  if (nrow(M) == 0) break
}
close(f)

stefanedwards/Siccuracy documentation built on May 30, 2019, 10:44 a.m.