diff --git a/DESCRIPTION b/DESCRIPTION index 3478eb9..1dcfe6a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: metabolyseR Title: Methods for Pre-Treatment, Data Mining and Correlation Analyses of Metabolomics Data -Version: 0.15.2 +Version: 0.15.3 Authors@R: person("Jasen", "Finch", email = "jsf9@aber.ac.uk", role = c("aut", "cre")) Description: A tool kit for pre-treatment, modelling, feature selection and correlation analyses of metabolomics data. URL: https://jasenfinch.github.io/metabolyseR/ diff --git a/NEWS.md b/NEWS.md index dd64624..40b1446 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# metabolyseR 0.15.3 + +* 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. diff --git a/R/plotExplanatoryHeatmap.R b/R/plotExplanatoryHeatmap.R index dee1c2d..26104fc 100644 --- a/R/plotExplanatoryHeatmap.R +++ b/R/plotExplanatoryHeatmap.R @@ -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) + } + + } + ) } ) diff --git a/R/plotSupervisedRF.R b/R/plotSupervisedRF.R index caf321e..2383b25 100644 --- a/R/plotSupervisedRF.R +++ b/R/plotSupervisedRF.R @@ -75,7 +75,10 @@ setMethod('plotSupervisedRF', labelSize = labelSize) + labs( caption = str_c('Margin: ', - rf@metrics$.estimate[4] %>% + rf %>% + metrics() %>% + filter(.metric == 'margin') %>% + pull(.estimate) %>% round(3))) if (isTRUE(ROC) & rf@type == 'classification') { diff --git a/tests/testthat/test-plotExplanatoryHeatmap.R b/tests/testthat/test-plotExplanatoryHeatmap.R index 07b23de..3be7366 100644 --- a/tests/testthat/test-plotExplanatoryHeatmap.R +++ b/tests/testthat/test-plotExplanatoryHeatmap.R @@ -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)) +})