custom_sampnames: Creates custom sample names to be used in plots

View source: R/custom_sampnames.R

custom_sampnamesR Documentation

Creates custom sample names to be used in plots

Description

This helper function creates custom sample names for plot data object functions

Usage

custom_sampnames(
  omicsData,
  firstn = NULL,
  from = NULL,
  to = NULL,
  delim = NULL,
  components = NULL,
  pattern = NULL,
  ...
)

Arguments

omicsData

an object of the class 'pepData', 'proData', 'metabData', 'lipidData', 'nmrData', or 'seqData', created by as.pepData, as.proData, as.metabData, as.lipidData, as.nmrData, or as.seqData, respectively.

firstn

an integer specifying the first n characters to keep as the sample name. This argument is optional.

from

an integer specifying the start of the range of characters to keep as the sample name. This argument is optional. If this argument is specified, 'to' must also be specified.

to

an integer specifying the end of the range of characters to keep as the sample name. This argument is optional. If this argument is specified, 'from' must also be specified.

delim

character delimiter by which to separate sample name components. This argument is optional. If this argument is specified, 'components' must also be specified.

components

integer vector specifying which components separated by the delimiter should be kept as the custom sample name. This argument is optional. If this argument is specified, 'delim' must also be specified.

pattern

character string specifying the regex pattern to use to extract substrings from the sample names

...

extra arguments passed to regexpr if pattern is specified

Details

This function can be used to create custom (and shorter) sample names to be used when plotting so that axis labels are not so long that they interfere with the graph itself. To use the custom sample names when plotting, specify the optional argument 'use_VizSampNames = TRUE'.

Value

Object of same class as omicsData, with added column in f_data named 'VizSampNames'.

Examples


library(pmartRdata)

mypep <- edata_transform(omicsData = pep_object, data_scale = "log2")
plot(mypep)

# specify new names using firstn argument
results <- custom_sampnames(omicsData = mypep, firstn = 9)
plot(results, use_VizSampNames = TRUE)

# specify new names using from and to arguments
results <- custom_sampnames(omicsData = mypep, from = 1, to = 9)
plot(results, use_VizSampNames = TRUE)

# specify new names using delim and components arguments
results <- custom_sampnames(omicsData = mypep, delim = "_", components = c(1, 2))
plot(results, use_VizSampNames = TRUE)

## specify new names using pattern arguments (regex)

# match everything after "Sample_"
pattern1 <- "[0-9]+_[0-9A-Za-z]+_[A-Z]"

results <- custom_sampnames(omicsData = mypep, pattern = pattern1)
plot(results, use_VizSampNames = TRUE)

# match "Sample_" and the number after it
pattern2 <- "^Sample_[0-9]+"

results <- custom_sampnames(omicsData = mypep, pattern = pattern2)
plot(results, use_VizSampNames = TRUE)


pmartR/pmartR documentation built on April 24, 2024, 10:22 p.m.