R/Pheatmap_Viz.R

Defines functions Pheatmap_Viz

Documented in Pheatmap_Viz

#' Provides expression data for select genes and samples
#' @export 
#' @param DE_Input Object generated by DEseq2_export or Limma_export functions.
#' @param selected_contrast name or numeric value to retrieve differential 
#' expression data. See names(Hotgenes_input$Output_DE).
#' @param hotList vector of gene symbols to select
#' @param samples_ids vector of sample ids to select
#' @param readouts index of normalized data to use.
#' See names(Hotgenes_input$Normalized_Expression).
#' @param ncut numeric value for the maximum number of genes to show.
#' @param lfc_cut absolute logfoldchange cutoff.

    Pheatmap_Viz<-function(DE_Input=NULL,
    hotList=NULL,samples_ids=1,readouts=1,ncut=NULL,
    selected_contrast=1,lfc_cut=0){
    
    # selecting normalized data -----------------------------------------------
    
    gene_levels<-DE_Input$Normalized_Expression[[readouts]]
    
    # hotlist input
    if(is.null(hotList)){
    contrast_name<-names(DE_Input$Output_DE[selected_contrast])
    contrast_name_lists <- setNames(vector(length(contrast_name),
    mode="list"), contrast_name)
    
    for (i in contrast_name) {
    sig_ids<-rownames(DE_Input$Output_DE[[i]]
    [abs(DE_Input$Output_DE[[i]]$log2FoldChange)>=lfc_cut,])
    contrast_name_lists[[i]]<-sig_ids
    }
    
    gene_ids<-unique(unlist(contrast_name_lists, use.names = FALSE))
    
    } else if(!is.null(hotList)){
    contrast_name<-NULL
    lfc_cut<-NULL
    ncut<-NULL
    gene_ids<-hotList
    }
    
    if(is.null(ncut)){
    ncut<-length(gene_ids)
    gene_id_cut<-gene_ids[seq(1,ncut)]
    }else if(!is.null(ncut)){
    gene_id_cut<-gene_ids[seq(1,ncut)]
    }
    dm <- gene_levels[gene_id_cut,samples_ids]
    return(dm)
    }
Rvirgenslane/Hotgenes documentation built on June 15, 2024, 2:16 a.m.