Commit 947909fd authored by Leon-Charles Tranchevent's avatar Leon-Charles Tranchevent
Browse files

Limma analysis: support of GPL files for getting gene annotations.

parent bdb15ba2
#' @title Get gene annotations from a text file.
#'
#' @description This function reads a TSV file and extract the relevant
#' information into a data-frame.
#'
#' So far, the key column (containing the probe_id) is always the first one and
#' the other colums are all considered to contain relevant annotations. The
#' first row is considered as the header row.
#'
#' @param folder A path to the folder where the file resides.
#' @param filename The name of the file.
#' @param entities The actual set of object ids for which we want gene annotations.
#' @return A data-frame of the provided entities, annotated.
get_gene_annots_from_file <- function(folder, filename, entities) {
# We define the full path.
file_path <- paste0(folder, filename)
# We read the file into a data-frame.
gene_annots <- read.delim(file_path, row.names = NULL, stringsAsFactors = FALSE)
# We do a bit of cleaning.
gene_annots[is.na(gene_annots)] <- ""
rownames(gene_annots) <- gene_annots$PROBEID
gene_annots <- gene_annots[entities, ]
rownames(gene_annots) <- seq(1, length(rownames(gene_annots)))
return(gene_annots)
}
#' @title Get Gene annotations for affy arrays.
#' @title Get gene annotations from a BioConductor package.
#'
#' @description This function reads the library defined by the array type and
#' extract the relevant information into a data-frame.
#'
#' @param array_type A string representing the array type.
#' @param affy_library_name A string representing the library name (usually the array
#' type followed by ".db".
#' @param entities The actual set of object ids for which we want gene annotations.
#' It can for instance be probe ids or gene ids. The parameter keytype has to be
#' modified accordingly. By default, the expected type is probe id.
......@@ -12,11 +13,10 @@
#' @param keytype The type of key used. It will be used to map between the annotations
#' and the provided list of entities. The default is probe id.
#' @return A data-frame of the provided entities, annotated.
get_affy_annots <- function(array_type, entities,
get_gene_annots_from_package <- function(affy_library_name, entities,
columns = c("PROBEID", "SYMBOL", "ENSEMBL", "ENTREZID"),
keytype = "PROBEID") {
# We define the library name (removing underscores and adding .db).
affy_library_name <- paste0(stringr::str_to_lower(stringr::str_remove(array_type, "_")), ".db")
# We load the library given its name.
cmd <- substitute(gene_annots <- AnnotationDbi::select(
x = local_db,
keys = entities,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment