hlpr_summarize_trajectory_df: Join and summarize compiled trajectory data.frames

View source: R/h.R

hlpr_summarize_trajectory_dfR Documentation

Join and summarize compiled trajectory data.frames

Description

Joins a compiled trajectory data.frame with the desired information and summarizes those.

Usage

hlpr_summarize_trajectory_df(
  object,
  ctdf,
  binwidth = 5,
  variables,
  whole_sample = FALSE,
  method_gs = "mean",
  verbose = TRUE,
  summarize_with = c("mean"),
  with_sd = TRUE,
  drop_all_na = TRUE,
  normalize = FALSE
)

Arguments

object

An object of class spata2.

ctdf

A compiled trajectory data.frame containing the variables 'barcodes', 'sample', 'x', 'y', 'projection_length', 'trajectory_part'.

binwidth

Numeric value. Denotes the binwidth with which to sort all relevant barcode spots into groups that are then aligned with respect to the chosen trajectory's direction.#'

variables

Character vector. The variables of interest:

  • Gene sets: Must be in getGeneSets()

  • Genes: Must be in getGenes()

  • Features: Must be numeric ones of getFeatureNames()

whole_sample

Logical. If TRUE, normalization of the values used takes place in the light of the complete sample.

method_gs

Character value. The method according to which gene sets will be handled specified as a character of length one. This can be either 'mean or one of 'gsva', 'ssgsea', 'zscore', or 'plage'. The latter four will be given to gsva::GSVA().

verbose

Logical. If set to TRUE informative messages regarding the computational progress will be printed.

(Warning messages will always be printed.)

summarize_with

Character value. Name of the function with which to summarize.

normalize

Logical. If set to TRUE values will be scaled to 0-1.

Hint: Variables that are uniformly expressed can not be scaled and are discarded.

Details

Initially the compiled trajectory data.frame of the specified trajectory is joined with the respective input of variables via joinWithVariables().

The argument binwidth refers to the amount of which the barcode-spots of the given trajectory will be summarized with regards to the trajectory's direction: The amount of binwidth and the previously specified 'trajectory width' in createTrajectories() determine the length and width of the sub-rectangles in which the rectangle the trajectory embraces are splitted and in which all barcode-spots are binned. Via dplyr::summarize() the variable-means of every sub-rectangle are calculated. These mean-values are then arranged according to the trajectory's direction.

Eventually the data.frame is shifted via tidyr::pivot_longer() to a data.frame in which every observation refers to the mean-value of one of the specified variable-elements (e.g. a specified gene set) of the particular sub-rectangle. The returned data.frame contains the following variables:

  • trajectory_part: Character. Specifies the trajectory's sub-part of the observation. (Negligible if there is only one trajectory part.)

  • trajectory_part_order: Numeric. Indicates the order within the trajectory-part. (Negligible if there is only one trajectory part.)

  • trajectory_order: Numeric. Indicates the order within the whole trajectory.

  • gene_sets, genes or features: Character. The respective gene sets, gene or feature the value refers to.

  • values: Numeric. The actual summarized values.


kueckelj/SPATA2 documentation built on March 16, 2024, 10:25 a.m.