read_eigenvec: Read Plink eigenvec file

Description Usage Arguments Value See Also Examples

View source: R/read_eigenvec.R

Description

This function reads a Plink eigenvec file, parsing columns strictly. First two must be 'fam' and 'id', which are strings, and all remaining columns (eigenvectors) must be numeric.

Usage

1
read_eigenvec(file, ext = "eigenvec", comment = "#", verbose = TRUE)

Arguments

file

The input file path, potentially excluding extension.

ext

File extension (default "eigenvec") can be changed if desired. Set to NA to force file to exist as-is.

comment

A string used to identify comments. Any text after the comment characters will be silently ignored. Passed to readr::read_table(). '#' (default) works for Plink 2 eigenvec files, which have a header lines that starts with this character (the header is therefore ignored).

verbose

If TRUE (default) function reports the path of the file being written (after autocompleting the extension).

Value

A list with two elements:

See Also

write_eigenvec() for writing an eigenvec file.

Plink 1 eigenvec format reference: https://www.cog-genomics.org/plink/1.9/formats#eigenvec

Plink 2 eigenvec format reference: https://www.cog-genomics.org/plink/2.0/formats#eigenvec

GCTA eigenvec format reference: https://cnsgenomics.com/software/gcta/#PCA

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# to read "data.eigenvec", run like this:
# data <- read_eigenvec("data")
# this also works
# data <- read_eigenvec("data.eigenvec")
#
# either way you get a list with these two items:
# numeric eigenvector matrix
# data$eigenvec
# fam/id tibble
# data$fam

# The following example is more awkward
# because package sample data has to be specified in this weird way:

# read an existing *.eigenvec file created by GCTA
file <- system.file("extdata", 'sample-gcta.eigenvec', package = "genio", mustWork = TRUE)
data <- read_eigenvec(file)
# numeric eigenvector matrix
data$eigenvec
# fam/id tibble
data$fam

# can specify without extension
file <- sub('\\.eigenvec$', '', file) # remove extension from this path on purpose
file # verify .eigenvec is missing
data <- read_eigenvec(file) # load it anyway!
data$eigenvec

# read an existing *.eigenvec file created by Plink 2
file <- system.file("extdata", 'sample-plink2.eigenvec', package = "genio", mustWork = TRUE)
data <- read_eigenvec(file)
# numeric eigenvector matrix
data$eigenvec
# fam/id tibble
data$fam

genio documentation built on July 27, 2021, 1:06 a.m.