Add a status column based on significance and estimated change

addDiffStatus(x, ...)

# S4 method for class 'data.frame'
addDiffStatus(
  x,
  fc_col = "logFC",
  sig_col = c("FDR", "hmp_fdr", "p_fdr", "adj.P.Value"),
  alpha = 0.05,
  cutoff = 0,
  up = "Increased",
  down = "Decreased",
  other = "Unchanged",
  missing = "Undetected",
  new_col = "status",
  drop = FALSE,
  ...
)

# S4 method for class 'DataFrame'
addDiffStatus(x, new_col = "status", ...)

# S4 method for class 'GRanges'
addDiffStatus(x, ...)

# S4 method for class 'GRangesList'
addDiffStatus(x, ...)

# S4 method for class 'SummarizedExperiment'
addDiffStatus(x, ...)

Arguments

x

Object to be classified

...

Used to pass arguments between methods

fc_col

Name of the fold-change column

sig_col

Name of the column with significance values

alpha

significance threshold

cutoff

minimum estimated change to be considered in either of the up or down categories

up, down, other

factor levels to annotate regions based on the above criteria

missing

Value to add when either fc_col or sig_col has NA values

new_col

name of the new column to be added

drop

logical(1) Drop unused factor levels from the status column

Value

An object of the same type as provided

Details

This takes a simple object and adds a new column classifying entries into one of three categories, as specified using up, down or other. Results in the new column will always be returned as a factor with levels in order of the values provided in the arguments other, down and up

Examples

## Working with a data.frame
set.seed(101)
df <- data.frame(logFC = rnorm(20), p = rbeta(20, shape1 = 1, shape2 = 20))
df$FDR <- p.adjust(df$p, "fdr")
addDiffStatus(df)
#>         logFC           p        FDR    status
#> 1  -0.3260365 0.060991105 0.08671830 Unchanged
#> 2   0.5524619 0.015486249 0.04602363 Increased
#> 3  -0.6749438 0.071312624 0.08671830 Unchanged
#> 4   0.2143595 0.014576927 0.04602363 Increased
#> 5   0.3107692 0.023011815 0.04602363 Increased
#> 6   1.1739663 0.057043745 0.08671830 Unchanged
#> 7   0.6187899 0.023005485 0.04602363 Increased
#> 8  -0.1127343 0.021889379 0.04602363 Decreased
#> 9   0.9170283 0.011252536 0.04602363 Increased
#> 10 -0.2232594 0.009209459 0.04602363 Decreased
#> 11  0.5264481 0.036822095 0.06137016 Unchanged
#> 12 -0.7948444 0.010761928 0.04602363 Decreased
#> 13  1.4277555 0.022449457 0.04602363 Increased
#> 14 -1.4668197 0.094882971 0.10542552 Unchanged
#> 15 -0.2366834 0.243430913 0.25624307 Unchanged
#> 16 -0.1933380 0.025494544 0.04635372 Decreased
#> 17 -0.8497547 0.019512443 0.04602363 Decreased
#> 18  0.0584655 0.073710555 0.08671830 Unchanged
#> 19 -0.8176704 0.259225245 0.25922524 Unchanged
#> 20 -2.0503078 0.072008584 0.08671830 Unchanged

## This works identically with a GRanges object, amongst others
gr <- GRanges(paste0("chr1:", seq_len(20)))
mcols(gr) <- df
addDiffStatus(gr)
#> GRanges object with 20 ranges and 4 metadata columns:
#>        seqnames    ranges strand |      logFC         p       FDR    status
#>           <Rle> <IRanges>  <Rle> |  <numeric> <numeric> <numeric>  <factor>
#>    [1]     chr1         1      * |  -0.326036 0.0609911 0.0867183 Unchanged
#>    [2]     chr1         2      * |   0.552462 0.0154862 0.0460236 Increased
#>    [3]     chr1         3      * |  -0.674944 0.0713126 0.0867183 Unchanged
#>    [4]     chr1         4      * |   0.214359 0.0145769 0.0460236 Increased
#>    [5]     chr1         5      * |   0.310769 0.0230118 0.0460236 Increased
#>    ...      ...       ...    ... .        ...       ...       ...       ...
#>   [16]     chr1        16      * | -0.1933380 0.0254945 0.0463537 Decreased
#>   [17]     chr1        17      * | -0.8497547 0.0195124 0.0460236 Decreased
#>   [18]     chr1        18      * |  0.0584655 0.0737106 0.0867183 Unchanged
#>   [19]     chr1        19      * | -0.8176704 0.2592252 0.2592252 Unchanged
#>   [20]     chr1        20      * | -2.0503078 0.0720086 0.0867183 Unchanged
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths