Skip to content

Commit

Permalink
add reactive when under 2000 and event when upper to this treshold
Browse files Browse the repository at this point in the history
  • Loading branch information
fsoubes committed May 16, 2018
1 parent 477e388 commit 35006a9
Show file tree
Hide file tree
Showing 13 changed files with 707 additions and 223 deletions.
25 changes: 0 additions & 25 deletions data/TOXA_HEGU_MA0191_AllChip_pData.csv

This file was deleted.

26 changes: 21 additions & 5 deletions function/heatmtruncated.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
require(dplyr)
require(RColorBrewer)
#gsub("[^A-Z|_]", "", x)

#' distcor is a function that computes the distance correlation

## Add jackknife correlation good for false positives with the pval methods add citation ....


#' distcos is a function that computes the cosine similarity for a given matrix
#'
#' @param x
#'
#' @return a matrix distance
#'
#' @export

distcos <- function(x){ #Jonathan Chang
as.dist(1 - x%*%t(x)/(sqrt(rowSums(x^2) %*% t(rowSums(x^2)))))
}



#' distcor is a function that computes the pearson correlation
#'
#' @param x
#'
Expand All @@ -13,7 +30,7 @@ require(RColorBrewer)
distcor<-function(x) {as.dist(1-cor(t(x),use="pairwise.complete.obs"))}


#' disteuc is a function that computes the euclidean correlation
#' disteuc is a function that computes the euclidean distance matrices
#'
#' @param x
#'
Expand Down Expand Up @@ -290,8 +307,7 @@ plotHeatmaps=function(exprData,geneSet,groups,workingPath=getwd(),fileType="png"

#RowSideColor: color palette to be used for rowSide cluster colors
# can also be gray.colors(k, start = 0.2, end = 0.9) to get k colors of gray scale



if(is.null(showcol))
showcol = F

Expand Down
6 changes: 4 additions & 2 deletions server/checkboxcontrast.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ observeEvent(input$noTests, {
#'


choix_test <- eventReactive(input$heatm, {
#choix_test <- eventReactive(input$heatm, {
choix_test <- reactive({
return(input$test)
}, ignoreNULL = F)
})
#, ignoreNULL = F)


# choix_test <- reactive({
Expand Down
9 changes: 7 additions & 2 deletions server/checkboxgrp.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ observeEvent(input$noIndividus, {
#'

choix_grp <- reactive({
req(input$indiv)

inFile <- input$file
if (is.null(inFile))
return(NULL)

return(input$indiv)
})

Expand All @@ -74,12 +77,14 @@ list_ind <- reactive({
#' @return \newgroup an eventreactive factor with the corresponding groups selected
#'

new_group <- eventReactive(input$heatm, {
#new_group <- eventReactive(input$heatm, {
new_group <- reactive({
inFile <- input$file
if (is.null(inFile))
return(NULL)
csvf()[[2]][csvf()[[2]]$Grp %in% choix_grp(),]
}, ignoreNULL = F)
})
#}, ignoreNULL = F)



Expand Down
1 change: 1 addition & 0 deletions server/groupcolor.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mycolgrp <- reactive ({
unique() %>%
droplevels()


return(mygrpcol)
})

Expand Down
186 changes: 15 additions & 171 deletions server/heatmapshiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,8 @@
###############################


hm <- eventReactive(input$heatm, {
heatmapfinal(isplot = F)
})

#' heatmapfinal is an isolate function that only react to a user's click on the heatmap button
#'
#' @param heatmapobj[[1]] a data frame with all the individuals selected
#' @param formated a data frame with the indexes corresponding to the sigificant genes
#' @param new_group a data frame with the corresponding groups
#' @param workingPath the current user's repository
#' @param my_palette a vector of colors
#' @param k a numeric value which aim is to defined the treshold value to cut the dendogram input$clusters
#' @param Rowdistfun a character value set by the user to defined the method to calculate the dendogram matrix distance for the genes input$dist
#' @param Coldistfun a character value set by the user to defined the method to calculate the dendogram matrix distance for the contrasts input$dist
#' @param mycex a numeric value which aim is to change the size of the legend in the heatmap defined by the user input$legsize
#' @param cexrow a numeric value to change the size of the police legend for the rows input$rowsize
#' @param cexcol a numeric value to change the size of the police legend for the columns input$colsize
#' @param meanGrp a boolean value to compute or not the mean of each contrasts in the heatmap input$meangrp
#' @param mypal a list of values
#' @param showcol a boolean value used to hide or show the colnames input$colname
#' @param showrow a boolean value used to hide or show the rownames input$rowname
#' @param genename a data frame
#' @param notplot a boolean value for applying dev.off or not on the heatmap
#' @param rowv dendogram object
#' @param ColOrd positive numbers, used as cex.axis in for the row or column axis labeling
#' @param gpcol matrix with colors associated to each groups
#' @param gpcolr matrix with gray color depending on the clusters
#' @param distfunTRIX function that computes whether euclidian or pearson for Hierarchical Clustering
#'
#' @return a data frame with the cluster and the corresponding genes
#'
#' @export
#'


heatmapfinal <- function(isplot = T) {
plotHeatmaps(
heatmapobj[[1]],
formated(),
droplevels(new_group()$Grp),
workingPath = wd_path,
my_palette = colorRampPalette(c(
choix_col1(), my_intermediate(), choix_col3()
))(n = 75),
mycex = input$legsize ,
cexrow = input$rowsize ,
cexcol = input$colsize ,
mypal = unlist(colors()),
showcol = colname(),
showrow = rowname(),
genename = csvf()[[3]],
notplot = isplot,
rowv = heatmapobj[[4]],
ColvOrd = heatmapobj[[3]],
gpcol = heatmapobj[[5]],
gpcolr = heatmapobj[[6]],
distfunTRIX = heatmapobj[[2]]
)
}

#' rowname is a reactive function which aim is to hide or show the rownames
#'
#' @param input$rowname a boolean radio button input
Expand Down Expand Up @@ -95,132 +37,34 @@ colname <- reactive({


heatmapobj <- NULL # declare outside the observeEvent
formatidus <- NULL

observeEvent(input$heatm, {


#' hmbis is an event reactive function that pre-computed hierarchical clustering on microarray data
#'
#' @param new_data a data frame with all the individuals selected
#' @param formated a data frame with the indexes corresponding to the sigificant genes
#' @param new_group a data frame with the corresponding groups
#' @param workingPath the current user's repository
#' @param k a numeric value which aim is to defined the treshold value to cut the dendogram input$clusters
#' @param Rowdistfun a function used to compute the distance for the rows
#' @param Coldistfun a function used to compute the distance for the columns
#' @param meanGrp a boolean value to computes the mean for each groups; default = F
#'
#' @return a list of objects which aim is to being passed as argument in the plotHeatmaps function
#'
#' @export
#'


hmbis <- eventReactive(input$heatm, {

isolate( # isolate in order to avoid that reactive values update the heatmap
truncatedhat(
data.matrix(new_data()),
formated(),
droplevels(new_group()$Grp),
workingPath = wd_path,
k = input$clusters,
Rowdistfun = input$dist ,
Coldistfun = input$dist,
meanGrp = input$meangrp
)
)
})

heatmapobj <<- hmbis() # a static variable
observe({



output$distPlot <- renderPlot({
isolate({
if (!is.null(formated()))
withProgress(message = 'Plotting heatmap:', # Add sliderbar when loading heatmap
value = 0,
{
n <- NROW(formated()) #number of row in the formated dataframe

for (i in 1:n) {
incProgress(1 / n, detail = "Please wait...")
}

heatmapfinal(isplot = F)
})
})
}, width = 900 , height = 1200, res = 100)


output$save <- downloadHandler(filename <- function() {
paste0(basename(file_path_sans_ext("myfile")),
'_heatmap.',
input$form,
sep = '')
},
content <- function(file) {
if (input$form == "emf")

emf(
file,
width = 7,
height = 7,
pointsize = 12,
coordDPI = 300
)

else if (input$form == "png")
png(
file,
width = 900,
height = 1200,
units = "px",
pointsize = 12,
res = 100
)
heatid <- input$matrixapp
if (grepl("Heatmap", heatid)) {
formatidus <<- length(formated())
if (formatidus < 2000)
source(file.path("server", "plotreact.R"), local = TRUE)$value #
else
eps(file,
width = 7,
height = 7)

if (!is.null(formated()))
withProgress(message = 'Saving heatmap:',
value = 0,
{
n <- NROW(formated())

for (i in 1:n) {
incProgress(1 / n, detail = "Please wait...")
}

heatmapfinal(isplot = F)

})

dev.off()


})

source(file.path("server", "plotreact2.R"), local = TRUE)$value #
}

output$downloadcut <- downloadHandler(
filename = function() {
paste(basename(file_path_sans_ext(input$filename)), '_clustered', '.csv', sep ='')
paste(basename(file_path_sans_ext(input$filename)),
'_clustered',
'.csv',
sep = '')
},
content = function(file) {
write.csv(heatmapfinal(isplot = T), file, row.names = FALSE)
}
)

output$clustering <-
renderDataTable(heatmapfinal(isplot = T)) # Summary of the significant genes depending on the pvalue with FC set to (1.2,2,4,6,10)

output$clustering <- renderDataTable(heatmapfinal(isplot = T)) # Summary of the significant genes depending on the pvalue with FC set to (1.2,2,4,6,10)
})



# cutedhm <- reactive({
# req(hm())
# cut02 = cut(hm()$rowDendrogram, h = input$cutheatm)
Expand All @@ -234,4 +78,4 @@ observeEvent(input$heatm, {
# dfclust = heatmtoclust( hm(), formated(), data.matrix(new_data()), csvf()[[3]], input$cutheatm)
#
# return(dfclust)
# })
# })
33 changes: 18 additions & 15 deletions server/indexselected.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@
#' @param input$method2 character method, default = BH
#' @param input$pval numeric pvalue
#' @param input$maxgen numeric maxgen, default = NULL
#'
#'
#' @return \formated a reactive data frame with the indexes corresponding to the sigificant genes
#'


formated <- reactive({

#req(!is.null(user_group()))
#treated = formating(new_test(), csvf()[[1]], input$pval)
treated = decTestTRiX(
user_group()[[1]],
user_group()[[2]],
user_group()[[3]],
DEGcutoff = input$pval,
FC = input$fc,
cutoff_meth = input$method2

,maxDE = input$maxgen

)
req(user_group())

df <- csvf()
if (is.null(df))
return(NULL)

else
treated = decTestTRiX(
user_group()[[1]],
user_group()[[2]],
user_group()[[3]],
DEGcutoff = input$pval,
FC = input$fc,
cutoff_meth = input$method2,
maxDE = input$maxgen

)
return(treated)
})

Loading

0 comments on commit 35006a9

Please sign in to comment.