Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Amine GHOZLANE
shaman
Commits
de204f99
Commit
de204f99
authored
Dec 11, 2015
by
Stevenn Volant
Browse files
Ajout Heatmap log2FC
parent
6495d4f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
internal.R
View file @
de204f99
...
...
@@ -66,7 +66,6 @@ CheckCountsTable <- function(counts)
Warning
=
NULL
if
(
ncol
(
taxo
)
<=
1
){
Error
=
"The number of columns of the taxonomy table must be at least 2"
}
if
(
nrow
(
taxo
)
<=
1
){
Error
=
"The number of rows if the taxonomy table must be at least 2"
}
print
(
is.numeric
(
taxo
[
2
,
4
]))
if
(
TRUE
%in%
is.numeric
(
taxo
)){
Error
=
"The taxonomy table must contain only character"
}
for
(
i
in
1
:
ncol
(
taxo
))
...
...
@@ -83,10 +82,8 @@ CheckCountsTable <- function(counts)
{
Error
=
NULL
tmp
=
table
(
rownames
(
counts
)
%in%
rownames
(
taxo
))
print
(
tmp
)
Percent
=
tmp
[
"TRUE"
]
/
sum
(
tmp
)
if
(
is.na
(
Percent
))
Percent
=
0
print
(
Percent
)
if
(
Percent
==
0
){
Error
=
"Counts table and annotation do not matched"
}
return
(
list
(
Error
=
Error
,
Percent
=
Percent
))
...
...
@@ -1254,4 +1251,64 @@ CheckCountsTable <- function(counts)
}
Get_log2FC
<-
function
(
input
,
BaseContrast
,
resDiff
,
info
=
NULL
)
{
VarInt
=
input
$
VarInt
dds
=
resDiff
$
dds
counts
=
resDiff
$
counts
target
=
resDiff
$
target
SelContrast
=
input
$
ContrastList_table_FC
nbCont
=
length
(
SelContrast
)
result
=
list
()
alpha
=
input
$
AlphaVal
cooksCutoff
=
ifelse
(
input
$
CooksCutOff
!=
'Auto'
,
ifelse
(
input
$
CooksCutOff
!=
Inf
,
input
$
CutOffVal
,
Inf
),
TRUE
)
for
(
i
in
1
:
nbCont
)
{
cont
=
as.character
(
SelContrast
[
i
])
result
[[
cont
]]
<-
results
(
dds
,
contrast
=
BaseContrast
[,
cont
],
pAdjustMethod
=
input
$
AdjMeth
,
cooksCutoff
=
cooksCutoff
,
independentFiltering
=
input
$
IndFiltering
,
alpha
=
alpha
)
}
log2FC
=
as.matrix
(
round
(
result
[[
SelContrast
[
1
]]][,
"log2FoldChange"
],
3
))
if
(
nbCont
>
1
)
{
for
(
i
in
2
:
nbCont
)
{
log2FC
=
cbind
(
log2FC
,
round
(
result
[[
SelContrast
[
i
]]][,
"log2FoldChange"
],
3
))
}
colnames
(
log2FC
)
=
names
(
result
)
}
rownames
(
log2FC
)
=
rownames
(
result
[[
SelContrast
[
1
]]])
return
(
log2FC
)
}
Plot_Visu_Heatmap_FC
<-
function
(
input
,
BaseContrast
,
resDiff
){
log2FC
=
Get_log2FC
(
input
,
BaseContrast
,
resDiff
,
info
=
NULL
)
ind_taxo
=
input
$
selectTaxoPlotHM
ind
=
rownames
(
log2FC
)
%in%
ind_taxo
log2FC
=
log2FC
[
ind
,]
col
<-
switch
(
input
$
colors
,
"green-blue"
=
colorRampPalette
(
brewer.pal
(
9
,
"GnBu"
))(
200
),
"blue-white-red"
=
colorRampPalette
(
rev
(
brewer.pal
(
9
,
"RdBu"
)))(
200
),
"purple-white-orange"
=
colorRampPalette
(
rev
(
brewer.pal
(
9
,
"PuOr"
)))(
200
),
"red-yellow-green"
=
colorRampPalette
(
rev
(
brewer.pal
(
9
,
"RdYlGn"
)))(
200
))
#col <- c(colorRampPalette(c("blue","white"))(n = 100),colorRampPalette(c("white", "firebrick1", "firebrick2", "firebrick3", "firebrick4"))(n = 100))
col
<-
c
(
colorRampPalette
(
c
(
"royalblue4"
,
"royalblue3"
,
"royalblue2"
,
"royalblue1"
,
"white"
))(
n
=
100
),
colorRampPalette
(
c
(
"white"
,
"firebrick1"
,
"firebrick2"
,
"firebrick3"
,
"firebrick4"
))(
n
=
100
))
## Transpose matrix if Horizontal
if
(
input
$
SensPlotVisuHM
==
"Horizontal"
)
log2FC
=
t
(
as.matrix
(
log2FC
))
return
(
heatmap.2
(
log2FC
,
dendrogram
=
"row"
,
Rowv
=
TRUE
,
Colv
=
NA
,
na.rm
=
TRUE
,
density.info
=
"none"
,
margins
=
c
(
input
$
lowerMargin
,
input
$
rightMargin
),
trace
=
"none"
,
srtCol
=
input
$
LabelOrientHeatmap
,
col
=
col
,
scale
=
input
$
scaleHeatmap
,
cexRow
=
input
$
LabelSizeHeatmap
,
cexCol
=
input
$
LabelSizeHeatmap
,
offsetCol
=
input
$
LabelColOffsetHeatmap
,
offsetRow
=
input
$
LabelRowOffsetHeatmap
))
}
\ No newline at end of file
server.R
View file @
de204f99
...
...
@@ -569,6 +569,7 @@ shinyServer(function(input, output,session) {
Contrast
=
colnames
(
as.matrix
(
tmp
))
updateSelectInput
(
session
,
"ContrastList"
,
"Contrasts"
,
Contrast
)
updateSelectInput
(
session
,
"ContrastList_table"
,
"Contrasts"
,
Contrast
)
updateSelectInput
(
session
,
"ContrastList_table_FC"
,
"Contrasts"
,
Contrast
)
})
## Add contrast
...
...
@@ -591,6 +592,7 @@ shinyServer(function(input, output,session) {
# Contrast = colnames(as.matrix(tmp))
updateSelectInput
(
session
,
"ContrastList"
,
"Contrasts"
,
Contrast
)
updateSelectInput
(
session
,
"ContrastList_table"
,
"Contrasts"
,
Contrast
)
updateSelectInput
(
session
,
"ContrastList_table_FC"
,
"Contrasts"
,
Contrast
)
})
## Add contrast
...
...
@@ -613,7 +615,7 @@ shinyServer(function(input, output,session) {
if
(
!
is.null
(
createdCont
))
res
=
cbind
(
res
,
createdCont
)
updateSelectInput
(
session
,
"ContrastList"
,
"Contrasts"
,
colnames
(
res
))
updateSelectInput
(
session
,
"ContrastList_table"
,
"Contrasts"
,
colnames
(
res
))
updateSelectInput
(
session
,
"ContrastList_table_FC"
,
"Contrasts"
,
colnames
(
res
))
write.table
(
res
,
namesfile
,
row.names
=
FALSE
)
}
})
...
...
@@ -640,6 +642,7 @@ shinyServer(function(input, output,session) {
else
file.create
(
namesfile
,
showWarnings
=
FALSE
)
updateSelectInput
(
session
,
"ContrastList"
,
"Contrasts"
,
ContrastKept
)
updateSelectInput
(
session
,
"ContrastList_table"
,
"Contrasts"
,
ContrastKept
)
updateSelectInput
(
session
,
"ContrastList_table_FC"
,
"Contrasts"
,
ContrastKept
)
}
})
...
...
@@ -952,14 +955,19 @@ shinyServer(function(input, output,session) {
#####################################################
## PDF
output
$
exportPDFVisu
<-
downloadHandler
(
filename
<-
function
()
{
paste
(
"test"
,
'meta16S.pdf'
,
sep
=
"_"
)},
content
<-
function
(
file
)
{
pdf
(
file
,
width
=
6
,
height
=
4
)
Plot_Visu
(
input
,
ResDiffAnal
())
dev.off
()
}
)
## PDF
output
$
exportPDFVisu
<-
downloadHandler
(
filename
<-
function
()
{
paste
(
"test"
,
'meta16S.ps'
,
sep
=
"_"
)},
content
<-
function
(
file
)
{
resDiff
=
ResDiffAnal
()
BaseContrast
=
read.table
(
namesfile
,
header
=
TRUE
)
#ggsave(filename = filename, Plot_Visu_Heatmap_FC(input,BaseContrast,resDiff),width = input$widthHeat, height = input$heightHeat)
postscript
(
file
,
width
=
input
$
widthHeat
,
height
=
input
$
heightHeat
)
if
(
input
$
HeatMapType
==
"Counts"
)
Plot_Visu_Heatmap
(
input
,
resDiff
)
if
(
input
$
HeatMapType
==
"Log2FC"
)
Plot_Visu_Heatmap_FC
(
input
,
BaseContrast
,
resDiff
)
dev.off
()
}
)
## PNG
...
...
@@ -1106,11 +1114,15 @@ output$RunButton <- renderUI({
output
$
heatmap
<-
renderPlot
({
resDiff
=
ResDiffAnal
()
if
(
!
is.null
(
resDiff
$
dds
))
Plot_Visu_Heatmap
(
input
,
resDiff
)
BaseContrast
=
read.table
(
namesfile
,
header
=
TRUE
)
if
(
!
is.null
(
resDiff
$
dds
))
{
if
(
input
$
HeatMapType
==
"Counts"
)
Plot_Visu_Heatmap
(
input
,
resDiff
)
if
(
input
$
HeatMapType
==
"Log2FC"
)
Plot_Visu_Heatmap_FC
(
input
,
BaseContrast
,
resDiff
)
}
},
height
=
reactive
(
input
$
heightHeat
))
output
$
Boxplot
<-
renderPlot
({
resDiff
=
ResDiffAnal
()
if
(
!
is.null
(
resDiff
$
dds
))
Plot_Visu_Boxplot
(
input
,
resDiff
)
...
...
ui.R
View file @
de204f99
...
...
@@ -296,34 +296,40 @@ body <- dashboardBody(
),
tabItem
(
tabName
=
"HeatmapVisu"
,
fluidRow
(
column
(
width
=
9
,
#d3heatmapOutput(outputId ='d3heatmap', width = "1000p", height = "800px")
plotOutput
(
"heatmap"
)
),
# downloadButton("exportPDFVisu", "Download pdf"),
# downloadButton("exportPNGVisu", "Download png")
#)
column
(
width
=
3
,
box
(
title
=
"Options"
,
width
=
NULL
,
status
=
"primary"
,
solidHeader
=
TRUE
,
collapsible
=
TRUE
,
collapsed
=
FALSE
,
uiOutput
(
"VarIntVisuHM"
),
uiOutput
(
"TaxoToPlotHM"
),
radioButtons
(
inputId
=
"SensPlotVisuHM"
,
label
=
"Type: "
,
choices
=
c
(
"Vertical"
=
"Vertical"
,
"Horizontal"
=
"Horizontal"
),
selected
=
"Vertical"
),
selectInput
(
inputId
=
"scaleHeatmap"
,
label
=
h6
(
strong
(
"Scale:"
)),
choices
=
c
(
"None"
=
"none"
,
"Rows"
=
"row"
,
"Column"
=
"col"
),
selected
=
"none"
)
),
box
(
title
=
"Appearance"
,
width
=
NULL
,
status
=
"primary"
,
solidHeader
=
TRUE
,
collapsible
=
TRUE
,
collapsed
=
TRUE
,
selectInput
(
"colors"
,
label
=
"Gradient of colors:"
,
choices
=
c
(
"green-blue"
,
"blue-white-red"
,
"purple-white-orange"
,
"red-yellow-green"
)),
sliderInput
(
"heightHeat"
,
h6
(
strong
(
"Height"
)),
min
=
100
,
max
=
2000
,
value
=
800
)
)
)
tabItem
(
tabName
=
"HeatmapVisu"
,
fluidRow
(
column
(
width
=
9
,
#d3heatmapOutput(outputId ='d3heatmap', width = "1000p", height = "800px")
plotOutput
(
"heatmap"
)
),
column
(
width
=
3
,
box
(
title
=
"Options"
,
width
=
NULL
,
status
=
"primary"
,
solidHeader
=
TRUE
,
collapsible
=
TRUE
,
collapsed
=
FALSE
,
selectInput
(
inputId
=
"HeatMapType"
,
label
=
h6
(
strong
(
"Data"
)),
choices
=
c
(
"Counts"
=
"Counts"
,
"Log2FC"
=
"Log2FC"
),
selected
=
"Counts"
),
selectInput
(
"ContrastList_table_FC"
,
h6
(
strong
(
"Contrast list"
)),
""
,
multiple
=
TRUE
),
uiOutput
(
"VarIntVisuHM"
),
uiOutput
(
"TaxoToPlotHM"
),
radioButtons
(
inputId
=
"SensPlotVisuHM"
,
label
=
"Type: "
,
choices
=
c
(
"Vertical"
=
"Vertical"
,
"Horizontal"
=
"Horizontal"
),
selected
=
"Vertical"
),
selectInput
(
inputId
=
"scaleHeatmap"
,
label
=
h6
(
strong
(
"Scale:"
)),
choices
=
c
(
"None"
=
"none"
,
"Rows"
=
"row"
,
"Column"
=
"col"
),
selected
=
"none"
),
downloadButton
(
"exportPDFVisu"
,
"Download pdf"
)
),
box
(
title
=
"Appearance"
,
width
=
NULL
,
status
=
"primary"
,
solidHeader
=
TRUE
,
collapsible
=
TRUE
,
collapsed
=
TRUE
,
selectInput
(
"colors"
,
label
=
"Gradient of colors:"
,
choices
=
c
(
"green-blue"
,
"blue-white-red"
,
"purple-white-orange"
,
"red-yellow-green"
)),
sliderInput
(
"heightHeat"
,
h6
(
strong
(
"Height"
)),
min
=
100
,
max
=
2000
,
value
=
800
),
sliderInput
(
"widthHeat"
,
h6
(
strong
(
"Width"
)),
min
=
100
,
max
=
2000
,
value
=
800
),
sliderInput
(
"LabelSizeHeatmap"
,
h6
(
strong
(
"Label size"
)),
min
=
0.1
,
max
=
2
,
value
=
0.7
,
step
=
0.1
),
sliderInput
(
"LabelOrientHeatmap"
,
h6
(
strong
(
"Label orientation"
)),
min
=
0
,
max
=
90
,
value
=
0
,
step
=
5
),
sliderInput
(
"LabelColOffsetHeatmap"
,
h6
(
strong
(
"Label column offset"
)),
min
=
0
,
max
=
4
,
value
=
0
,
step
=
0.5
),
sliderInput
(
"LabelRowOffsetHeatmap"
,
h6
(
strong
(
"Label row offset"
)),
min
=
0
,
max
=
4
,
value
=
0
,
step
=
0.5
),
sliderInput
(
"rightMargin"
,
h6
(
strong
(
"Right margin"
)),
min
=
0
,
max
=
20
,
value
=
6
,
step
=
1
),
sliderInput
(
"lowerMargin"
,
h6
(
strong
(
"Lower margin"
)),
min
=
0
,
max
=
20
,
value
=
6
,
step
=
1
)
)
)
),
)
),
tabItem
(
tabName
=
"BoxplotVisu"
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment