pcatsneexp: Perform and plot PCA and tSNE of NTB experiment dataset

Description Usage Arguments Value Author(s) Examples

View source: R/pcatsneexp.R

Description

A function that produces cluster plots for results of Principal Component Analysis and t-distributed Stochastic Neighbor Embedding of a z-scored NTB dataset and returns a list containing the results (see examples for easy way to access individually). (Requires function 'getexpdata' internally.) For right formatting of your files, please consider the "ReadMe for ntbgraphics".

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
pcatsneexp(
  directory,
  pca = TRUE,
  tsne = TRUE,
  analysis = c("2arm_ko", "2arm_tg", "2arm_sd", "2arm_treat", "4arm_sd_ko",
    "4arm_sd_tg", "4arm_treat_ko", "4arm_treat_tg"),
  ordercolumns = c("ntb", "rdoc", "manual"),
  ordercolumns_manual,
  exclude.animals = FALSE,
  orderlevelcond = c("other", "gtblock", "etblock", "2rev"),
  return.matrix.mean = FALSE,
  directional = FALSE,
  absoluteval = FALSE,
  perplex = 1,
  theta = 0.5,
  ellipse_pca = FALSE,
  ellipse_tsne = FALSE,
  ellconf = 0.75,
  ellalpha = 0.2,
  pastetitle = "PCA",
  pastetitle2 = "tSNE",
  saveplotdir = directory
)

Arguments

directory

specifies file directory of 'Meta Behavior' and 'Animal List' files within quotation marks (mind correct spelling of both files and 'directory'!); no default

pca

boolean the defines if pca should be executed; default: TRUE

tsne

boolean the defines if tsne should be executed; default: TRUE

analysis

specifies the kind of experiment performed within quotation marks; "2arm_ko","2arm_tg", "2arm_sd", "2arm_treat", "4arm_sd_ko", "4arm_sd_tg", "4arm_treat_ko", "4arm_treat_tg" (tg for transgenic, ko for knockout; 4arm_sd_x assumes a stress paradigm with social defeat (sd) and housing or handling control (hc) as control; 4arm_treat_x assumes a treatment paradigm with treated (treat) and untreated (untreat) animals; 2arm_x assumes wildtype controls (wt) for tg and ko, housing or handling controls (hc) for sd and untreated controls (untreat) for treated animals; ('analysis' defines the kind of experiment performed, respectively the kind of analysis preferred - you can easily perform 2arm analysis for 4arm experiments looking only at the groups of interest, but not the other way around); default: "2arm_ko"

ordercolumns

defines the order paradigm of experiment column appearance in internal table within quotation marks: "ntb", "rdoc", "manual"; order of experiments may be customized manually with "manual" (-> use 'ordercolumns_manual' for exact appearance; there, you may also choose to exclude experiments - this may be the only useful application of this parameter in this functions' context); default: "ntb"

ordercolumns_manual

customizes order of appearance and especially appearance itself of experiment columns in internal table and final analysis (experiments that are not listed will not be included); only if 'ordercolumns' = "manual"; user has to provide a vector containing characters within quotation marks (e.g. by using c("Meanspeed", "SerialLearn")) with all experiments he wants to include into the final analysis; no need for specification if 'ordercolumns' is not "manual" default: FALSE

exclude.animals

excluding animals from analysis by RFID; user has to provide a vector containing characters within quotation marks (e.g. by using c("900200000067229", "900200000065167")) with all animals he wants to exclude from the final analysis; if FALSE is provided, no animal will be excluded; default: FALSE

orderlevelcond

defines order of factor levels of conditions within quotation marks: "other", "gtblock", "etblock", "2rev"; definition of order of groups in legend: "other" for alphabetical order in case of 4arm; also for default order of 2arm experiments (which lists the 'control' first, then the 'condition'); "gtblock" for order wt_x, wt_y, tg_x, tg_y; "etblock" for order x_hc, y_hc, x_sd, y_sd; "2rev" for inverse order of 2arm default only, meaning listing the 'condition' first, then the 'control'; default: "other"

directional

specifies which directionality paradigm should be applied; several options are available, manual specification is also possible; if "rdoc" within quotation marks is provided, columns 'Rotations', 'FreezeBase', 'Timeimmobile', 'Baseline', 'Activity', 'Choices' and 'Meanspeed' are multiplied by -1; if "emptcf4" within quotation marks is provided, columns 'Center', 'Choices' and 'Meanspeed' are multiplied by -1; you may alternatively provide a vector containing characters within quotation marks (e.g. by using c("Nocturnal", "inhibition75")) with all columns you wants to have multiplied by -1; only applied if 'return.matrix' is TRUE and only useful if 'absoluteval' is FALSE; default: FALSE

absoluteval

boolean that specifies if only absolute values of z-scored matrix should be given and analyzed; default: FALSE

perplex

defines perplexity parameter (should not be bigger than (nrow[matrix] - 1)/3); default: 1

theta

defines theta in the range of 0 to 1 (speed/accuracy trade-off; increase for less accuracy, set to 0 for exact TSNE); default: 0.5

ellipse_pca

boolean that defines if conficdence interval ellipses should be displayed in standard PCA plot; default: FALSE

ellipse_tsne

boolean that defines if conficdence interval ellipses should be displayed in tSNE plot; default: FALSE

ellconf

defines confidence level for ellipses in all plots (where applicable) between 0 and 1: default: 0.75

ellalpha

defines transparency of ellipses in all plots (where applicable); takes values between 0 for high transparency/low intensity and 1 for low transparency/high intensity of filling: default: 0.2

pastetitle

customizes title of PCA plots within quotation marks; title for PCA will be "pastetitle", title for PCA with ellipse will be "pastetitle Ellipse"; default: "PCA"

pastetitle2

defines title of tSNE plot within quotation marks; default: "tSNE"

saveplotdir

file directory where to save plots within quotation marks; you may set to FALSE if you do not want to save plot to PDF; default: location of Behavior and Animal List files as specified in 'directory'

return.matrix, mean

boolean that specifies if matrix and following analysis should only consist of the mean of each group for each experiment; grouping follows specification of groups to be analyzed as defined by 'analysis'; default: FALSE

Value

three cluster plots (two for PCA, one for tSNE) and a list containing the results

Author(s)

Paul Volkmann

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
pcatsneexp(paste0(system.file("extdata/", package = "ntbgraphics", mustWork = T),"/"))

results <- pcatsneexp(directory = paste0(system.file("extdata/", package = "ntbgraphics", mustWork = T),"/"),
                                    analysis = "4arm",
                                    exclude.animals = c("900200000068816"),
                                    orderlevelcond = "gtblock",
                                    directional = c("Center", "inhibition75"),
                                    perplex =  1,
                                    theta = 0.8,
                                    ellipse_tsne = TRUE,
                                    ellconf = 0.95,
                                    ellalpha = 0.10,
                                    pastetitle = "new_testdata_pca_09-04-2044",
                                    pastetitle2 = "new_testdata_tsne_09-04-2044",
                                    saveplotdir = FALSE)
         results_pca <- results[["pca_analysis"]]
         results_tsne <- results[["tsne_analysis"]]

volkmannp/ntbgraphics documentation built on March 3, 2020, 1:25 p.m.