R/getGeneInfo.R

Defines functions getGeneInfo

Documented in getGeneInfo

#' Retrieve information for top contributing genes for a given IC or PC
#'
#' Generate a dataframe with gene information for
#' top contributors for a given IC or PC
#'
#' @param input_list ICA or PCA object generated by `runICA()` or `runPCA`
#' @param comp_idx Component number to be plotted.
#' @param geneinfo_df Dataframe containing information about the gene positions.
#'                    This is used to generate the gene weight plot.
#' @param n_peaks Number of top contributors to show. Default is set to 10.
#' @return dataframe with positional information of genes
#'
#'
#'
#' @examples
#' data(expr_data, probe_info)
#'
#' ica_result <- runICA(expr_data)
#' getGeneInfo(input_list = ica_result,
#'               comp_idx = 1,
#'               geneinfo_df = probe_info,
#'               n_peaks = 10)
#'
#' @export
getGeneInfo <-
    function(input_list = NULL,
             comp_idx = NULL,
             geneinfo_df = NULL,
             n_peaks = 10) {
        if (is.null(input_list)) {
            stop("Please specify the input ICA or PCA object")
        }
        if (is.null(comp_idx)) {
            stop("Please specify the component of interest")
        }
        if (is.null(geneinfo_df)) {
            stop("Please specify the gene information data.frame")
        }

        top_peaks <- input_list$peaks[[comp_idx]][seq_len(n_peaks)]

        gene_subset <- geneinfo_df[match(names(top_peaks),
                                         geneinfo_df$phenotype), ]
        gene_subset$gene_weigth <- top_peaks

        return(gene_subset)

    }
jinhyunju/picaplot documentation built on May 19, 2019, 10:35 a.m.