Fix Set labels for legibility

fixSetLabels(
  x,
  wrap = TRUE,
  width = 25,
  maxNchar = Inf,
  suffix = "...",
  nodeType = c("Set", "Gene", "any"),
  adjustCase = TRUE,
  removeGrep = "^(KEGG|PID|REACTOME|BIOCARTA|NABA|SA|SIG|ST)[_.]",
  words_from = c("als", "ii", "iii", "iv", "v", "tgf", "nfkb", "trna", "rrna", "mirna",
    "mrna", "snrna", "snorna", "scrna", "lincrna"),
  words_to = c("ALS", "II", "III", "IV", "V", "TGF", "NFKB", "tRNA", "rRNA", "miRNA",
    "mRNA", "snRNA", "snoRNA", "scRNA", "lincRNA"),
  ...
)

Arguments

x

character vector, or igraph object. When an igraph object is supplied, the V(g)$name attribute is used as the basis of generating a label, which is then stored as V(g)$label.

wrap

logical indicating whether to apply word wrap, based upon the supplied width argument.

width

integer value used when wrap=TRUE, it is sent to base::strwrap().

maxNchar

numeric value or Inf to limit the maximum characters allowed for each string. This option is preferred when wrap=TRUE is not feasible, for example heatmap labels. When NULL or Inf no limit is applied. See base::nchar().

suffix

character value used as a suffix when maxNchar is used, the string is shortened so that the shortened string and suffix values are maxNchar characters long. It serves as an indicator that the string label has been shortened.

nodeType

character value compared to the vertex attribute "nodeType" when the input x is an igraph object. This option is used to restrict label changes to certain nodes. When NULL or nodeType="any" then all node labels are updated.

adjustCase

logical indicating whether to adjust the uppercase and lowercase lettering.

removeGrep

character regular expression pattern used to remove patterns from the resulting label. The default values remove the prefix used in MsigDB canonical pathway names, which is a prefix indicating the source of each pathway.

words_from, words_to

character vectors of words to match in case-insensitive manner, to be replaced with fixed-case alternatives. It uses perl-based regular expression matching in base::gsub(), and the \\b expression to enforce a word boundary, either via delimiter, whitespace, or the end of the string.

...

additional arguments are ignored.

Value

vector or igraph object, to match the input x.

Details

This function is a convenient wrapper for several steps that edit gene set and pathways labels to be slightly more legible. It operates on either a character vector, or an igraph object.

Examples

x <- c("KEGG_INSULIN_SIGNALING_PATHWAY",
   "KEGG_T_CELL_RECEPTOR_SIGNALING_PATHWAY",
   "KEGG_NEUROTROPHIN_SIGNALING_PATHWAY");
fixSetLabels(x);
#> [1] "Insulin Signaling\nPathway"         "T Cell Receptor\nSignaling Pathway"
#> [3] "Neurotrophin Signaling\nPathway"   

jamba::nullPlot();
jamba::drawLabels(txt=x,
   preset=c("top", "center", "bottom"));