Learn R Programming

QCEWAS (version 1.2-3)

translate_header: Translate column names into standard names

Description

This function is used to translate non-standard column names into the standard ones used by EWAS_QC and other functions.

Usage

translate_header(header,
                   standard = c("PROBEID","BETA","SE","P_VAL"),
                   alternative)

Value

translate_header returns an object of class 'list' with 6 components:

header_h

character vector; the translated header. Unknown columns are included under their old names.

missing_h

character vector; the standard column names that were not found. If none, this returns NULL.

unknown_h

character vector; column names that could not be converted to a standard name. Note that these columns are also included in header_h. If none, this returns NULL.

header_N, missing_N, unknown_N

integer; the lengths of the above three vectors

Arguments

header

character vector; the header to be translated.

standard

character vector; the names header should be translated into.

alternative

translation table; see below for more information.

Translation Table

The translation table must meet the following requirements:

  • 2 columns, with the default column names (i.e. the ones in the standard argument) in the first column, and the alternatives in the second.

  • Multiple alternatives are allowed for a single standard name, but every alternative name must be in a separate row.

  • The alternatives must be capitalized.

  • No duplicate alternatives are allowed.

  • A header line is not required, and will be ignored if present.

Details

The function takes the entries in standard one by one, and checks them against the translation table for alternatives. It will report any missing standard headers, as well as duplicate ones.

Examples

Run this code
# For use in this example, the 2 sample files in the
# extdata folder of the QCEWAS library will be copied
# to your current R working directory
if (FALSE) {
file.copy(from = file.path(system.file("extdata", package = "QCEWAS"),
                           "sample2.txt.gz"),
          to = getwd(), overwrite = FALSE, recursive = FALSE)
file.copy(from = file.path(system.file("extdata", package = "QCEWAS"),
                           "translation_table.txt"),
          to = getwd(), overwrite = FALSE, recursive = FALSE)

sample_ewas <- read.table("sample2.txt.gz", header = TRUE,
                          stringsAsFactors = FALSE, nrow = 10)
colnames(sample_ewas)


translation_table <- read.table("translation_table.txt", header = TRUE,
                                stringsAsFactors = FALSE)
sample_translation <- translate_header(header = colnames(sample_ewas),
                                       alternative = translation_table)
sample_translation                                         

colnames(sample_ewas) <- sample_translation$header_h

colnames(sample_ewas)
}

Run the code above in your browser using DataLab