hpo_to_matrix: HPO to matrix

View source: R/hpo_to_matrix.R

hpo_to_matrixR Documentation

HPO to matrix

Description

Convert gene-phenotype associations from the Human Phenotype Ontology (HPO) into a gene x phenotype matrix. The returned matrix is sparse and binary, such that 1 indicates a the gene is associated with a given phenotype according to the HPO annotation, and 0 indicates it is not. By default, full phenotype names are used as the column names (e.g. "Abnormality of body height"), however you can instead set them to the HPO IDs by changing the formula argument to: formula = "gene_symbol ~ hpo_id". Phenotypes that are not present in the phenotype_to_genes annotations are omitted from the final matrix.

Usage

hpo_to_matrix(
  terms = NULL,
  phenotype_to_genes = load_phenotype_to_genes(),
  formula = "gene_symbol ~ hpo_id",
  fun.aggregate = mean,
  value.var = "evidence_score_sum",
  fill = 0,
  run_cor = FALSE,
  as_matrix = TRUE,
  as_sparse = TRUE,
  method = "pearson",
  verbose = TRUE
)

Arguments

terms

A subset of HPO IDs to include. Set to NULL (default) to include all terms.

phenotype_to_genes

Output of load_phenotype_to_genes mapping phenotypes to gene annotations.

formula

A formula of the form LHS ~ RHS to cast, see Details.

fun.aggregate

Should the data be aggregated before casting? If the formula doesn't identify a single observation for each cell, then aggregation defaults to length with a message.

To use multiple aggregation functions, pass a list; see Examples.

value.var

Name of the column whose values will be filled to cast. Function guess() tries to, well, guess this column automatically, if none is provided.

Cast multiple value.var columns simultaneously by passing their names as a character vector. See Examples.

fill

Value with which to fill missing cells. If fun.aggregate is present, takes the value by applying the function on a 0-length vector.

run_cor

Return a matrix of pairwise correlations.

as_matrix

Return the results as a matrix (TRUE). Otherwise, will return the results as a data.table with an extra column "gene_symbol".

as_sparse

Convert the data to a sparse matrix. Only used when as_matrix=TRUE.

method

Method to construct plot with.

verbose

Print messages.

Value

A gene x phenotype matrix, or a phenotype x phenotype matrix if run_cor=TRUE.

Examples

phenos <- example_phenos()
X <- hpo_to_matrix(terms = phenos$hpo_id)

neurogenomics/HPOExplorer documentation built on July 17, 2024, 3:12 p.m.