Maps various column name formats to standard names used by GLOWr functions. This function recognizes common variations in GWAS summary statistics files and converts them to a consistent naming scheme. Returns data with attributes containing mapping metadata to track which columns were renamed and whether mappings were user-specified or auto-detected.

standardize_column_names(
  data,
  column_mapping = NULL,
  format_hint = "auto",
  verbose = 1
)

Arguments

data

data.frame containing GWAS summary statistics

column_mapping

Named list providing custom column mappings. Each element should be named with a standard column name (e.g., "MAF", "P") and contain the corresponding column name in your data

format_hint

Character string suggesting the data format ("gwas_catalog", "csv", etc.). Used to help with ambiguous cases

verbose

Integer verbosity level (0=silent, 1=messages)

Value

data.frame with standardized column names and two attributes:

  • column_mappings: Named list showing original -> standard mappings applied

  • mapping_sources: Named list indicating "user-specified" or "auto-detected" for each mapping

Details

Standard column names:

  • MAF: Minor allele frequency

  • P: P-value

  • BETA: Effect size

  • N: Sample size

  • rsID: SNP identifier

  • CHR: Chromosome

  • POS: Position

Note: This function only renames columns. It does NOT harmonize MAF values. MAF harmonization (converting MAF > 0.5 to 1 - MAF) is handled separately by prepare_B_training_data.

Mapping Source Tracking:

The function tracks whether each column mapping was user-specified (via column_mapping parameter) or auto-detected. This metadata is stored as attributes on the returned data.frame and can be accessed via: attr(data, "column_mappings") and attr(data, "mapping_sources").

Computational Complexity:

O(n x c x v) where n = rows, c = columns, v = number of variation patterns. In practice, very fast since c and v are small (typically c < 50, v < 10).

Examples

if (FALSE) { # \dontrun{
# Example with custom column names
my_data <- data.frame(
  snp = paste0("rs", 1:10),
  freq = runif(10, 0.1, 0.9),
  pval = runif(10, 1e-5, 0.1)
)

standardized <- standardize_column_names(
  data = my_data,
  column_mapping = list(
    rsID = "snp",
    MAF = "freq",
    P = "pval"
  )
)

# Check mapping sources
print(attr(standardized, "column_mappings"))
print(attr(standardized, "mapping_sources"))
} # }