Skip to content

Commit

Permalink
The plotExplanatoryHeatmap() method for the Analysis S4 class now ret…
Browse files Browse the repository at this point in the history
…urns a warning and skips plotting if an error is encountered
  • Loading branch information
jasenfinch committed Aug 23, 2023
1 parent 2f6f162 commit c99073f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

* 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.

# metabolyseR 0.15.2

* 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.
Expand Down
31 changes: 21 additions & 10 deletions R/plotExplanatoryHeatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -475,17 +475,28 @@ setMethod('plotExplanatoryHeatmap',
'should be of class RandomForest or Univariate'),
call. = FALSE)
}

x %>%
map(~plotExplanatoryHeatmap(
.x,
threshold = threshold,
title = response(.x),
distanceMeasure = distanceMeasure,
clusterMethod = clusterMethod,
featureNames = featureNames,
featureLimit = featureLimit
))
map(
~{
heat_map <- try(plotExplanatoryHeatmap(
.x,
threshold = threshold,
title = response(.x),
distanceMeasure = distanceMeasure,
clusterMethod = clusterMethod,
featureNames = featureNames,
featureLimit = featureLimit
))

if (!is(heat_map,'try-error')) {
return(heat_map)
} else {
warning('Errors encounted in plotting heatmap, skipping.',call. = FALSE)
}

}
)
}
)

Expand Down
29 changes: 29 additions & 0 deletions tests/testthat/test-plotExplanatoryHeatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,32 @@ test_that('plotExplanatoryHeatmap throws error when unsupervised random forest s
randomForest(cls = NULL)
expect_error(plotExplanatoryHeatmap(d))
})

test_that('plotExplanatoryHeatmap throws error when unsupervised random forest supplied',{
p <- analysisParameters(c('pre-treatment','modelling'))

parameters(p,'pre-treatment') <- preTreatmentParameters(
list(
keep = 'classes',
occupancyFilter = 'maximum',
transform = 'TICnorm'
)
)

changeParameter(p,'cls') <- 'day'
changeParameter(p,'classes') <- c('H')

p@modelling[[1]]$cls <- NULL
p@modelling[[1]] <- c(
list(
cls = NULL),
p@modelling[[1]]
)

analysis <- metabolyse(
metaboData::abr1$neg,
metaboData::abr1$fact,
p)

expect_warning(plotExplanatoryHeatmap(analysis))
})

0 comments on commit c99073f

Please sign in to comment.