as.BGData: Convert Other Objects to BGData Objects

View source: R/BGData.R

as.BGDataR Documentation

Convert Other Objects to BGData Objects

Description

Converts other objects to BGData objects by loading supplementary phenotypes and map files referenced by the object to be used for the sample information and variant information, respectively.

Currently supported are BEDMatrix objects, plain or nested in ColumnLinkedMatrix objects.

Usage

as.BGData(x, alternatePhenotypeFile = NULL, ...)

## S3 method for class 'BEDMatrix'
as.BGData(x, alternatePhenotypeFile = NULL, ...)

## S3 method for class 'ColumnLinkedMatrix'
as.BGData(x, alternatePhenotypeFile = NULL,
  ...)

## S3 method for class 'RowLinkedMatrix'
as.BGData(x, alternatePhenotypeFile = NULL,
  ...)

Arguments

x

An object. Currently supported are BEDMatrix objects, plain or nested in ColumnLinkedMatrix objects.

alternatePhenotypeFile

Path to an alternate phenotype file.

...

Additional arguments to the read.table or fread call (if data.table package is installed) call to parse the alternate pheno file.

Details

The .ped and .raw formats only allows for a single phenotype. If more phenotypes are required it is possible to store them in an alternate phenotype file. The path to such a file can be provided with alternatePhenotypeFile and will be merged with the existing sample information. The first and second columns of that file must contain family and within-family IDs, respectively.

For BEDMatrix objects: If a .fam file (which corresponds to the first six columns of a .ped or .raw file) of the same name and in the same directory as the .bed file exists, the sample information will be populated with the data stored in that file. Otherwise a stub that only contains an IID column populated with the rownames of geno(x) will be generated. The same will happen for a .bim file for the variant information.

For ColumnLinkedMatrix objects: See the case for BEDMatrix objects, but only the .fam file of the first node of the LinkedMatrix will be read and used for the sample information, and the .bim files of all nodes will be combined and used for the variant information.

Value

A BGData object.

See Also

readRAW() to convert text files to BGData objects. BGData-class, BEDMatrix-class, ColumnLinkedMatrix-class for more information on the above mentioned classes. read.table and fread to learn more about extra arguments that can be passed via ....

Examples

# Path to example data
path <- system.file("extdata", package = "BGData")

# Convert a single BEDMatrix object to a BGData object
chr1 <- BEDMatrix::BEDMatrix(paste0(path, "/chr1.bed"))
bg1 <- as.BGData(chr1)

# Convert multiple BEDMatrix objects in a ColumnLinkedMatrix to a BGData object
chr2 <- BEDMatrix::BEDMatrix(paste0(path, "/chr2.bed"))
chr3 <- BEDMatrix::BEDMatrix(paste0(path, "/chr3.bed"))
clm <- ColumnLinkedMatrix(chr1, chr2, chr3)
bg2 <- as.BGData(clm)

# Load additional (alternate) phenotypes
bg3 <- as.BGData(clm, alternatePhenotypeFile = paste0(path, "/pheno.txt"))

QuantGen/BGData documentation built on Sept. 30, 2023, 1:01 p.m.