Skip to content

Commit c99073f

Browse files
author
jasenfinch
committed
The plotExplanatoryHeatmap() method for the Analysis S4 class now returns a warning and skips plotting if an error is encountered
1 parent 2f6f162 commit c99073f

File tree

3 files changed

+52
-10
lines changed

3 files changed

+52
-10
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* Fixed the margin value displayed in plots from [`plotSupervisedRF()`](https://jasenfinch.github.io/metabolyseR/reference/plotSupervisedRF.html)
44

5+
* The [`plotExplanatoryHeatmap()`](https://jasenfinch.github.io/metabolyseR/reference/plotExplanatoryHeatmap.html) method for the [`Analysis`](https://jasenfinch.github.io/metabolyseR/reference/Analysis-class.html) S4 class now returns a warning and skips plotting if an error is encountered whilst trying to plot a heat map.
6+
57
# metabolyseR 0.15.2
68

79
* Added the argument `refactor` to the method [`transformTICnorm()`](https://jasenfinch.github.io/metabolyseR/reference/transform.html) to enable the feature intensities of total ion count (TIC) normalised data to be refactored back to a range consistent with the original data by multiplying the normalised values by the median TIC.

R/plotExplanatoryHeatmap.R

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -475,17 +475,28 @@ setMethod('plotExplanatoryHeatmap',
475475
'should be of class RandomForest or Univariate'),
476476
call. = FALSE)
477477
}
478-
478+
479479
x %>%
480-
map(~plotExplanatoryHeatmap(
481-
.x,
482-
threshold = threshold,
483-
title = response(.x),
484-
distanceMeasure = distanceMeasure,
485-
clusterMethod = clusterMethod,
486-
featureNames = featureNames,
487-
featureLimit = featureLimit
488-
))
480+
map(
481+
~{
482+
heat_map <- try(plotExplanatoryHeatmap(
483+
.x,
484+
threshold = threshold,
485+
title = response(.x),
486+
distanceMeasure = distanceMeasure,
487+
clusterMethod = clusterMethod,
488+
featureNames = featureNames,
489+
featureLimit = featureLimit
490+
))
491+
492+
if (!is(heat_map,'try-error')) {
493+
return(heat_map)
494+
} else {
495+
warning('Errors encounted in plotting heatmap, skipping.',call. = FALSE)
496+
}
497+
498+
}
499+
)
489500
}
490501
)
491502

tests/testthat/test-plotExplanatoryHeatmap.R

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,32 @@ test_that('plotExplanatoryHeatmap throws error when unsupervised random forest s
6868
randomForest(cls = NULL)
6969
expect_error(plotExplanatoryHeatmap(d))
7070
})
71+
72+
test_that('plotExplanatoryHeatmap throws error when unsupervised random forest supplied',{
73+
p <- analysisParameters(c('pre-treatment','modelling'))
74+
75+
parameters(p,'pre-treatment') <- preTreatmentParameters(
76+
list(
77+
keep = 'classes',
78+
occupancyFilter = 'maximum',
79+
transform = 'TICnorm'
80+
)
81+
)
82+
83+
changeParameter(p,'cls') <- 'day'
84+
changeParameter(p,'classes') <- c('H')
85+
86+
p@modelling[[1]]$cls <- NULL
87+
p@modelling[[1]] <- c(
88+
list(
89+
cls = NULL),
90+
p@modelling[[1]]
91+
)
92+
93+
analysis <- metabolyse(
94+
metaboData::abr1$neg,
95+
metaboData::abr1$fact,
96+
p)
97+
98+
expect_warning(plotExplanatoryHeatmap(analysis))
99+
})

0 commit comments

Comments
 (0)