PolyGeniusData

Create a new PolyGeniusData object

Description

Creates a new instance of a PolyGeniusData coupling:

  • PRS model information — extracted from the provided models

  • Genotype information — available from the provided genotype information

This method enables two complementary behaviors depending on the expressions supplied on the left (i, observation-side) and right (j, model-side):

  1. Sub-setting mode — If an index/expression can be evaluated in the caller’s environment (numeric / character / logical), or the fetched value resolves to a logical vector aligned with the chosen side, the object is subset accordingly and a new PolyGeniusData is returned.

  2. Fetching mode — Otherwise, expressions are resolved via x$fetch() and the requested observation/model information is returned. If only one side is provided, the corresponding table is returned. If both sides are provided, a named list with ⁠$obs⁠ and ⁠$mod⁠ tables is returned (class “PolyGeniusDataFetchResult”).

Note that if both sides are supplied they must resolve to the same mode. Otherwise an error is riased (e.g., subsetting observations while fetching models or vise versa is not permitted).

subset() for PolyGeniusData provides a convenient interface. It accepts one expression for the observation side (obs) and one for the model side (mod), evaluates each in either the caller’s environment or by calling fetch (to disambiguate logical predicates), validates the indices, and returns a new subsetted PolyGeniusData.

This method intentionally does not fetch values to return them. If you wish to retrieve observation/model information (rather than subset the object), use the bracket method x[i, j] or call x$fetch(…) directly.

Usage

PolyGeniusData(
  name,
  models,
  genotypes,
  obs = NULL,
  obsm = NULL,
  obsp = NULL,
  obsu = NULL,
  mod = NULL,
  modm = NULL,
  modp = NULL,
  modu = NULL,
  uns = NULL
)

## S3 method for class 'PolyGeniusData'
x[i, j, drop = FALSE]

## S3 method for class 'PolyGeniusData'
x[[..., exact = TRUE]]

## S3 method for class 'PolyGeniusData'
subset(x, obs, mod, ...)

Arguments

name

Name for PolyGeniusData object

models

A PolyGeniusModel or PolyGeniusModelSet containing PRSs

genotypes

A GenotypeInfo or GenotypeInfoSet object

obs

For PolyGeniusData(): optional named list/data frame of observation-level annotations appended into data$obs. For subset(): observation-side predicate or index (unquoted). May be a logical/numeric/character index that evaluates in the caller, or a single logical expression that resolves (via fetch) to a logical vector of length n_obs.

obsm

Optional named list of observation-aligned rectangular objects appended into data$obsm

obsp

Optional named list of observation-by-observation rectangular objects appended into data$obsp

obsu

Optional named list of unstructured observation-related objects appended into data$obsu

mod

For PolyGeniusData(): optional named list/data frame of model-level annotations appended into data$mod. For subset(): model-side predicate or index (unquoted). Same as obs but aligned to models.

modm

Optional named list of model-aligned rectangular objects appended into data$modm

modp

Optional named list of model-by-model rectangular objects appended into data$modp

modu

Optional named list of unstructured model-related objects appended into data$modu

uns

Optional named list of unstructured objects appended into data$uns

x

A PolyGeniusData object.

i

Observation-side index or expression(s) (unquoted). May be a direct index (numeric/character/logical) that evaluates in the caller, or an expression(s) to be resolved via fetch().

j

Model-side index or expression(s) (unquoted). Same semantics as i but aligned to models.

drop

Ignored; included for S3 signature compatibility.

Ignored; for S3 signature compatibility.

exact

Ignored (S3 compatibility).

Details

A special case is when a single logical expression is to be fetched for either observations or models, as it is unclear if it should be used as a logical vector for subsetting the PolyGeniusData object or alternatively to be returned. To resolve ambiguity

Value

A new PolyGeniusData object

  • In Subsetting mode: a new PolyGeniusData subsetted on observations/models.

  • In Fetching mode: a table (single side) or a list with $obs and $mod tables of class “PolyGeniusDataFetchResult” (both sides).

  • If both i and j are missing: NULL.

Whatever x[ , c(<name>)] returns (typically a tibble).

A new PolyGeniusData subsetted on observations and/or models.

Examples

## Not run: 
# Subset observations by logical predicate to be evaluated in the caller's environment (if both age and sex exist in the environment)
# or by data$fetch(age, sex, .context="obs")
# they 
data[age > 65 & sex == "M", ]

# Subset models by name
data[, c("prs_1","prs_3")]

# Fetch observation-side columns (resolved via fetch) 
dat[, c(age, PCA)]

# Fetch both sides at once
dat[c(trait, gwas), c(age, PCA)]

## End(Not run)

## Not run: 
# Subset observations by predicate (evaluates in caller)
subset(data, obs = age > 65 & sex == "M")

# Subset models by name
subset(data, mod = c("prs_1", "prs_3"))

# Use a logical column that lives inside the object (resolves to a single logical via fetch)
subset(data, obs = case_status == 1)

# If you intend to fetch (not subset), use the bracket method:
data[, c(age, PCA)]

## End(Not run)