Browse code

fix/update tests

Gavin Rhys Lloyd authored on 07/02/2020 09:54:30
Showing 45 changed files

... ...
@@ -75,30 +75,29 @@ Collate:
75 75
     'wilcox_test_class.R'
76 76
     'zzz.R'
77 77
 Depends: struct (>= 0.99.3)
78
-Imports: ggplot2,
79
- pmp,
80
- gridExtra,
81
- sp,
82
- scales,
83
- stats,
84
- methods,
78
+Imports: datasets,
79
+    ggplot2,
80
+    ggthemes,
81
+    grid,
82
+    gridExtra,
83
+    methods,
84
+    scales,
85
+    sp,
86
+    stats
87
+RoxygenNote: 7.0.2
88
+Suggests: agricolae,
89
+ BiocStyle,
85 90
  car,
86
- grid,
87
- reshape2,
88
- agricolae,
91
+ covr,
89 92
  emmeans,
90
- nlme,
91
- ggthemes,
93
+ pmp,
92 94
  ggdendro,
93
- datasets
94
-RoxygenNote: 7.0.2
95
-Suggests: 
96
- testthat,
97
- covr,
98 95
  knitr,
99
- rmarkdown,
100
- BiocStyle,
96
+ nlme,
101 97
  pls,
102
- Rtsne
98
+ reshape2,
99
+ rmarkdown,
100
+ Rtsne,
101
+ testthat
103 102
 VignetteBuilder: knitr
104 103
 biocViews: WorkflowStep
... ...
@@ -97,14 +97,12 @@ exportMethods(model_predict)
97 97
 exportMethods(model_reverse)
98 98
 exportMethods(model_train)
99 99
 exportMethods(run)
100
-import(ggdendro)
101 100
 import(ggplot2)
102 101
 import(ggthemes)
103 102
 import(grid)
104 103
 import(gridExtra)
105 104
 import(methods)
106 105
 import(pmp)
107
-import(reshape2)
108 106
 import(scales)
109 107
 import(stats)
110 108
 import(struct)
... ...
@@ -14,7 +14,7 @@
14 14
 #' @export HSD
15 15
 #' @examples
16 16
 #' M = HSD()
17
-HSD = function(alpha=0.05,mtc='fdr',formula,unblanaced=FALSE,...) {
17
+HSD = function(alpha=0.05,mtc='fdr',formula,unbalanced=FALSE,...) {
18 18
     out=struct::new_struct('HSD',
19 19
         alpha=alpha,
20 20
         mtc=mtc,
... ...
@@ -162,7 +162,7 @@ setMethod(f="model_apply",
162 162
 
163 163
             # for each combination of factors...
164 164
             out2=lapply(FF,function(x) {
165
-                A=HSD.test(LM,x,group = FALSE)$comparison
165
+                A=agricolae::HSD.test(LM,x,group = FALSE)$comparison
166 166
                 if (ALIAS) {
167 167
                     A[!is.na(A)]=NA # replace with NA if alias are present
168 168
                 }
... ...
@@ -9,7 +9,7 @@
9 9
 #' @export PCA
10 10
 #' @examples
11 11
 #' M = PCA()
12
-PCA = function(umber_components=2,...) {
12
+PCA = function(number_components=2,...) {
13 13
     out=struct::new_struct('PCA',
14 14
         number_components=number_components,
15 15
         ...)
... ...
@@ -79,7 +79,7 @@ setMethod(f="chart_plot",
79 79
 #' @param label_filter Only include labels for samples in the group specified by label_filter.
80 80
 #' If zero length then all labels will be included.
81 81
 #' @param label_factor The sample_meta column to use for labelling the samples.
82
-#' If zero length then the rownames will be used.
82
+#' If 'rownames' then the rownames will be used.
83 83
 #' @param label_size The text size of the labels.NB ggplot units, not font size units.
84 84
 #' Default 3.88.
85 85
 #' @param ... additional slots and values passed to struct_class
... ...
@@ -94,10 +94,10 @@ pca_scores_plot = function(
94 94
     factor_name,
95 95
     ellipse='all',
96 96
     label_filter=character(0),
97
-    label_factor=character(0),
97
+    label_factor='rownames',
98 98
     label_size=3.88,
99 99
     ...) {
100
-    out=struct::new_struct(pca_scores_plot,
100
+    out=struct::new_struct('pca_scores_plot',
101 101
         components=components,
102 102
         points_to_label=points_to_label,
103 103
         factor_name=factor_name,
... ...
@@ -356,6 +356,8 @@ pca_biplot_plot = function(
356 356
     prototype = list(name='Feature boxplot',
357 357
         description='plots a boxplot of a chosen feature for each group of a DatasetExperiment.',
358 358
         type="boxlot",
359
+        .params=c('components','points_to_label','factor_name','scale_factor','style','label_features'),
360
+
359 361
         components=entity(name='Components to plot',
360 362
             value=c(1,2),
361 363
             type='numeric',
... ...
@@ -483,7 +485,7 @@ setMethod(f="chart_plot",
483 485
 #' @include PCA_class.R
484 486
 #' @examples
485 487
 #' C = pca_loadings_plot()
486
-pca_loadings_plot = function(components=c(1,2),style='points',label_featurs=FALSE,...) {
488
+pca_loadings_plot = function(components=c(1,2),style='points',label_features=FALSE,...) {
487 489
     out=struct::new_struct('pca_loadings_plot',
488 490
         components=components,
489 491
         style=style,
... ...
@@ -629,17 +631,23 @@ setMethod(f="chart_plot",
629 631
 
630 632
 #' pca_dstat_plot class
631 633
 #'
632
-#' Line plot showing percent variance and cumulative percent variance for the computed components.
634
+#' Bar chart showing mahalanobis distance from the mean in PCA scores space. A threshold is
635
+#' plotted at a chosen confidence as an indicator for rejecting outliers.
633 636
 #'
634 637
 #' @import struct
638
+#' @param number_components The number of components to use.
639
+#' @param alpha The confidence level to plot.
635 640
 #' @param ... additional slots and values passed to struct_class
636 641
 #' @return struct object
637 642
 #' @export PCA_dstat
638 643
 #' @include PCA_class.R
639 644
 #' @examples
640 645
 #' C = PCA_dstat()
641
-PCA_dstat = function(...) {
642
-    out=struct::new_struct('PCA_dstat',...)
646
+PCA_dstat = function(number_components=2,alpha=0.05,...) {
647
+    out=struct::new_struct('PCA_dstat',
648
+        number_components=number_components,
649
+        alpha=alpha,
650
+        ...)
643 651
     return(out)
644 652
 }
645 653
 
... ...
@@ -652,6 +660,8 @@ PCA_dstat = function(...) {
652 660
     prototype = list(name='d-statistic plot',
653 661
         description='a bar chart of the d-statistics for samples in the input PCA model',
654 662
         type="bar",
663
+        .params=c('number_components','alpha'),
664
+
655 665
         number_components=entity(value = 2,
656 666
             name = 'number of principal components',
657 667
             description = 'number of principal components to use for the plot',
... ...
@@ -39,7 +39,7 @@ plsda_scores_plot = function(components=c(1,2),points_to_label='none',factor_nam
39 39
         description='scatter plot of PLSDA component scores',
40 40
         type="scatter",
41 41
         libraries=c('pls','ggplot2'),
42
-        .params=c('components','points_to_label,factor_name'),
42
+        .params=c('components','points_to_label','factor_name','groups'),
43 43
 
44 44
         components=entity(name='Components to plot',
45 45
             value=c(1,2),
... ...
@@ -8,7 +8,7 @@
8 8
 #' @export PLSR
9 9
 #' @examples
10 10
 #' M = PLSR()
11
-PLSR = function(number_components=c(1,2),factor_name,...) {
11
+PLSR = function(number_components=2,factor_name,...) {
12 12
     out=struct::new_struct('PLSR',
13 13
         number_components=number_components,
14 14
         factor_name=factor_name,
... ...
@@ -16,7 +16,7 @@
16 16
 #' @return struct object
17 17
 #' @export balanced_accuracy
18 18
 balanced_accuracy = function(...) {
19
-    out=struct::new_struct(out,...)
19
+    out=struct::new_struct('balanced_accuracy',...)
20 20
     return(out)
21 21
 }
22 22
 
... ...
@@ -48,7 +48,7 @@ blank_filter = function(fold_change=20,blank_label='blank',qc_label='QC',factor_
48 48
         type = 'filter',
49 49
         predicted = 'filtered',
50 50
         libraries='pmp',
51
-        .params=c('blank_label','qc_label','factor_name','fraction_in_blank'),
51
+        .params=c('fold_change','blank_label','qc_label','factor_name','fraction_in_blank'),
52 52
         .outputs=c('filtered','flags'),
53 53
 
54 54
         blank_label=ents$blank_label,
... ...
@@ -25,7 +25,7 @@
25 25
 
26 26
 classical_lsq = function(alpha=0.05,mtc='fdr',factor_names,intercept=TRUE,...) {
27 27
 
28
-    out=struct::new_struct(out,
28
+    out=struct::new_struct('classical_lsq',
29 29
         alpha = alpha,
30 30
         mtc = mtc,
31 31
         factor_names = factor_names,
... ...
@@ -57,11 +57,11 @@ classical_lsq = function(alpha=0.05,mtc='fdr',factor_names,intercept=TRUE,...) {
57 57
         type="univariate",
58 58
         predicted='p_value',
59 59
         .params=c('alpha','mtc','factor_names','intercept'),
60
-        .outputs=c('coefficients','p_value','significant','r_squared','adj_r-squared'),
60
+        .outputs=c('coefficients','p_value','significant','r_squared','adj_r_squared'),
61 61
 
62 62
         intercept=entity(name='Include intercept',
63 63
             type='logical',
64
-            description='TRUE or FALSE to include the intercept term when fitting the model_',
64
+            description='TRUE or FALSE to include the intercept term when fitting the model',
65 65
             value=TRUE
66 66
         ),
67 67
 
... ...
@@ -28,8 +28,14 @@
28 28
 #' @param ... additional slots and values passed to struct_class
29 29
 #' @return struct object
30 30
 #' @export confounders_clsq
31
-confounders_clsq = function(alpha=0.05,mtc='fdr',factor_name,confounding_factors,threshold,...) {
32
-    out=struct::new_struct(out,...)
31
+confounders_clsq = function(alpha=0.05,mtc='fdr',factor_name,confounding_factors,threshold=0.15,...) {
32
+    out=struct::new_struct('confounders_clsq',
33
+        alpha=alpha,
34
+        mtc=mtc,
35
+        factor_name=factor_name,
36
+        confounding_factors=confounding_factors,
37
+        threshold=threshold,
38
+        ...)
33 39
     return(out)
34 40
 }
35 41
 
... ...
@@ -57,7 +63,7 @@ confounders_clsq = function(alpha=0.05,mtc='fdr',factor_name,confounding_factors
57 63
         type="univariate",
58 64
         predicted='p_value',
59 65
         .params=c('alpha','mtc','factor_name','confounding_factors','threshold'),
60
-        .outputs=c('coefficients','p_value','significant','percent_change','significant'),
66
+        .outputs=c('coefficients','p_value','significant','percent_change','potential_confounders'),
61 67
 
62 68
         threshold=entity(name='Confounding factor threshold',
63 69
             type='numeric',
... ...
@@ -97,12 +103,12 @@ setMethod(f="model_apply",
97 103
     definition=function(M,D)
98 104
     {
99 105
         # classical least squares model
100
-        clsq=classical_lsq(intercept=TRUE,alpha=M$alpha,mtc=M$mtc)
106
+        clsq=classical_lsq(intercept=TRUE,alpha=M$alpha,mtc=M$mtc,factor_names='dummy')
101 107
 
102 108
         # make list of all factors
103 109
         factor_names=c(M$factor_name,M$confounding_factors)
104 110
 
105
-        # do a regression including the main factor and the counfounders one at a time
111
+        # do a regression including the main factor and the confounders one at a time
106 112
         temp=matrix(NA,nrow=ncol(D$data),ncol=length(factor_names)) # coefficients
107 113
         pvals=temp # p-values
108 114
         nm=character(length(factor_names))
... ...
@@ -110,12 +116,12 @@ setMethod(f="model_apply",
110 116
             fn=unique(c(factor_names[1],factor_names[i]))
111 117
 
112 118
             # for each factor name check the na count
113
-            FF=filter_na_count(threshold=2)
119
+            FF=filter_na_count(threshold=2,factor_name='dummy')
114 120
             excl=matrix(NA,nrow=ncol(D$data),ncol=length(fn))
115 121
             colnames(excl)=fn
116 122
             for (k in fn) {
117 123
                 if (is.factor(D$sample_meta[,k])) {
118
-                    FF$factor_name=k
124
+                    FF$factor_name=k # replace dummy factor name
119 125
                     FF=model_apply(FF,D)
120 126
                     excl[,k]=FF$flags$flags
121 127
                 } else {
... ...
@@ -131,7 +137,7 @@ setMethod(f="model_apply",
131 137
                 excl=fn #
132 138
             }
133 139
 
134
-            clsq$factor_names=excl
140
+            clsq$factor_names=excl # put real factor names instead of dummy
135 141
             clsq=model_apply(clsq,D)
136 142
 
137 143
             nm[i]=paste0(fn,collapse='_')
... ...
@@ -195,7 +201,7 @@ setMethod(f="model_apply",
195 201
 #' @param ... additional slots and values passed to struct_class
196 202
 #' @return struct object
197 203
 #' @export confounders_lsq.barchart
198
-confounders_lsq.barchart = function(feature_to_plot,threshold,...) {
204
+confounders_lsq.barchart = function(feature_to_plot,threshold=10,...) {
199 205
     out=struct::new_struct('confounders_lsq.barchart',
200 206
         feature_to_plot=feature_to_plot,
201 207
         threshold=threshold,
... ...
@@ -284,7 +290,7 @@ setMethod(f="chart_plot",
284 290
 #' @param ... additional slots and values passed to struct_class
285 291
 #' @return struct object
286 292
 #' @export confounders_lsq.boxplot
287
-confounders_lsq.boxplot = function(threshold,...) {
293
+confounders_lsq.boxplot = function(threshold=10,...) {
288 294
     out=struct::new_struct('confounders_lsq.boxplot',
289 295
         threshold=threshold,
290 296
         ...)
... ...
@@ -17,7 +17,7 @@
17 17
 #' @return A struct chart object
18 18
 #' @export feature_boxplot
19 19
 feature_boxplot = function(label_outliers=TRUE,feature_to_plot,factor_name,show_counts=TRUE,...) {
20
-    out=struct::new_struct('feature_box_plot',
20
+    out=struct::new_struct('feature_boxplot',
21 21
         label_outliers=label_outliers,
22 22
         feature_to_plot=feature_to_plot,
23 23
         factor_name=factor_name,
... ...
@@ -248,6 +248,10 @@ setMethod(f="chart_plot",
248 248
 #' chart_plot(C,D)
249 249
 #'
250 250
 #' @import struct
251
+#' @param label_outliers TRUE or FALSE to label outliers on the plot.
252
+#' @param by_sample TRUE to plot missing values by sample, or FALSE to plot for features.
253
+#' @param factor_name The sample_meta column to use.
254
+#' @param show_counts TRUE to show a count of the number of items used to create the boxplot on the chart.
251 255
 #' @param ... additional slots and values passed to struct_class
252 256
 #' @return struct object
253 257
 #' @export mv_boxplot
... ...
@@ -275,6 +279,8 @@ mv_boxplot = function(label_outliers=TRUE,by_sample=TRUE,factor_name,show_counts
275 279
     prototype = list(name='Missing value boxplots',
276 280
         description='Histogram ofmissing values per sample/feature.',
277 281
         type="histogram",
282
+        .params=c('label_outliers','by_sample','factor_name','show_counts'),
283
+
278 284
         label_outliers=entity(name='Label outliers',
279 285
             value=TRUE,
280 286
             type='logical',
... ...
@@ -501,10 +507,10 @@ setMethod(f="chart_plot",
501 507
 #' @param ... additional slots and values passed to struct_class
502 508
 #' @return struct object
503 509
 #' @export DatasetExperiment.boxplot
504
-DatasetExperiment.boxplot = function(factor_name,by_sample=TRUE,per_class=TRUE,number,...) {
510
+DatasetExperiment.boxplot = function(factor_name,by_sample=TRUE,per_class=TRUE,number=50,...) {
505 511
     out=struct::new_struct('DatasetExperiment.boxplot',
506 512
         factor_name=factor_name,
507
-        by_sample-by_sample,
513
+        by_sample=by_sample,
508 514
         per_class=per_class,
509 515
         number=number,
510 516
         ...)
... ...
@@ -633,6 +639,7 @@ compare_dist = function(factor_name,...) {
633 639
     prototype = list(name='Compare distributions',
634 640
         description='Distributions and box plots to compare two datasets',
635 641
         type="mixed",
642
+        .params=c('factor_name'),
636 643
         factor_name=entity(name='Factor name',
637 644
             value='factor',
638 645
             type='character',
... ...
@@ -725,16 +732,15 @@ setMethod(f="chart_plot",
725 732
 #'
726 733
 #' plots a DatasetExperiment as a heatmap
727 734
 #'
728
-#' @import struct
729
-#' @import reshape2
730 735
 #' @param ... additional slots and values passed to struct_class
736
+#' @param na_colour A hex colour code to use for missing values
731 737
 #' @return struct object
732 738
 #' @export DatasetExperiment.heatmap
733 739
 #' @examples
734 740
 #' C = DatasetExperiment.heatmap()
735
-DatasetExperiment.heatmap = function(...) {
736
-    out=.DatasetExperiment.heatmap()
737
-    out=struct::new_struct(out,...)
741
+DatasetExperiment.heatmap = function(na_colour='#FF00E4',...) {
742
+    out=struct::new_struct('DatasetExperiment.heatmap',
743
+        na_colour=na_colour,...)
738 744
     return(out)
739 745
 }
740 746
 
... ...
@@ -749,6 +755,8 @@ DatasetExperiment.heatmap = function(...) {
749 755
     prototype = list(name='DatasetExperiment heatmap',
750 756
         description='plots a heatmap of a DatasetExperiment',
751 757
         type="scatter",
758
+        libraries='reshape2',
759
+        .params=c('na_colour'),
752 760
 
753 761
         na_colour=entity(name='NA colour',
754 762
             value='#FF00E4',
... ...
@@ -758,14 +766,13 @@ DatasetExperiment.heatmap = function(...) {
758 766
     )
759 767
 )
760 768
 
761
-#' @param ... additional slots and values passed to struct_class
762 769
 #' @export
763 770
 #' @template chart_plot
764 771
 setMethod(f="chart_plot",
765 772
     signature=c("DatasetExperiment.heatmap",'DatasetExperiment'),
766 773
     definition=function(obj,dobj)
767 774
     {
768
-        X=melt(as.matrix(dobj$data))
775
+        X=reshape2::melt(as.matrix(dobj$data))
769 776
         colnames(X)=c('Sample','Feature','Peak area')
770 777
         p=ggplot(data=X,aes(x=`Feature`,y=`Sample`,fill=`Peak area`)) + geom_raster() +
771 778
             scale_colour_Publication()+
... ...
@@ -19,7 +19,7 @@
19 19
 #' @return struct object
20 20
 #' @export filter_by_name
21 21
 filter_by_name = function(mode='exclude',dimension='sample',names,...) {
22
-    out=struct::new_struct(filter_by_name,
22
+    out=struct::new_struct('filter_by_name',
23 23
         mode=mode,
24 24
         dimension=dimension,
25 25
         names=names,
... ...
@@ -16,7 +16,7 @@
16 16
 #' @return struct object
17 17
 #' @export filter_smeta
18 18
 filter_smeta = function(mode='include',levels,factor_name,...) {
19
-    out=struct::new_struct(filter_smeta,
19
+    out=struct::new_struct('filter_smeta',
20 20
         mode=mode,
21 21
         levels=levels,
22 22
         factor_name=factor_name,
... ...
@@ -75,7 +75,7 @@ setMethod(f="model_apply",
75 75
         } else {
76 76
             stop('mode must be "include" or "exclude"')
77 77
         }
78
-        D=D[!out,,drop=FALSE]
78
+        D=D[!out,]
79 79
         # drop excluded levels from factors
80 80
         D$sample_meta=droplevels(D$sample_meta)
81 81
         output_value(M,'filtered')=D
... ...
@@ -99,8 +99,8 @@ setMethod(f="model_apply",
99 99
         s=p<M$alpha
100 100
         names(s)=colnames(X)
101 101
 
102
-        M$p_value=p
103
-        M$significant=s
102
+        M$p_value=as.data.frame(p)
103
+        M$significant=as.data.frame(s)
104 104
 
105 105
         return(M)
106 106
     }
... ...
@@ -8,7 +8,7 @@
8 8
 #' @examples
9 9
 #' M = glog_transform()
10 10
 glog_transform = function(qc_label='QC',factor_name,...) {
11
-    out=struct::new_struct('glog',
11
+    out=struct::new_struct('glog_transform',
12 12
         qc_label=qc_label,
13 13
         factor_name=factor_name,
14 14
         ...)
... ...
@@ -27,8 +27,8 @@ glog_transform = function(qc_label='QC',factor_name,...) {
27 27
         lambda_opt='numeric'
28 28
     ),
29 29
 
30
-    prototype=list(name = 'generalised logarithm transform',
31
-        description = 'applies a glog tranform using using QC samples as reference samples.',
30
+    prototype=list(name = 'Generalised logarithm transform',
31
+        description = 'Applies a glog transform using using QC samples as reference samples.',
32 32
         type = 'normalisation',
33 33
         predicted = 'transformed',
34 34
         libraries = 'pmp',
... ...
@@ -101,7 +101,6 @@ setMethod(f="model_apply",
101 101
 #' @param ... additional slots and values passed to struct_class
102 102
 #' @return struct object
103 103
 #' @export hca_dendrogram
104
-#' @import ggdendro
105 104
 #' @include hca_class.R
106 105
 #' @examples
107 106
 #' C = hca_dendrogram()
... ...
@@ -113,7 +112,8 @@ hca_dendrogram = function(...) {
113 112
 
114 113
 .hca_dendrogram<-setClass(
115 114
     "hca_dendrogram",
116
-    contains='chart'
115
+    contains='chart',
116
+    prototype = list(libraries='ggdendro')
117 117
 )
118 118
 
119 119
 #' @export
... ...
@@ -2,14 +2,14 @@
2 2
 #'
3 3
 #' Applies a k-nearest neighbour approach to impute missing values.
4 4
 #' @param neighbours The number of neighbours to use for imputation.
5
-#' @param sample_max Maximum proportion of missing values in any sample.
6
-#' @param feature_max Maximum proportion of missing values in any feature.
5
+#' @param sample_max Maximum percentage of missing values in any sample. Default = 50.
6
+#' @param feature_max Maximum percentage of missing values in any feature. Default = 50.
7 7
 #' @param ... additional slots and values passed to struct_class
8 8
 #' @return struct object
9 9
 #' @export knn_impute
10 10
 #' @examples
11 11
 #' M = knn_impute()
12
-knn_impute = function(neighbours=5,sample_max=0.5,feature_max=0.5,...) {
12
+knn_impute = function(neighbours=5,sample_max=50,feature_max=50,...) {
13 13
     out=struct::new_struct('knn_impute',
14 14
         neighbours=neighbours,
15 15
         sample_max=sample_max,
... ...
@@ -71,7 +71,7 @@ setMethod(f="model_apply",
71 71
         smeta=D$sample_meta
72 72
         x=D$data
73 73
 
74
-        imputed = mv_imputation(t(as.matrix(x)),method='knn',k = opt$neighbours,rowmax=opt$feature_max/100,colmax=opt$sample_max/100,maxp = NULL,FALSE)
74
+        imputed = pmp::mv_imputation(t(as.matrix(x)),method='knn',k = opt$neighbours,rowmax=opt$feature_max/100,colmax=opt$sample_max/100,maxp = NULL,FALSE)
75 75
         D$data = as.data.frame(t(imputed))
76 76
 
77 77
         output_value(M,'imputed') = D
... ...
@@ -12,10 +12,10 @@
12 12
 #' @export linear_model
13 13
 #' @examples
14 14
 #' M = linear_model()
15
-linear_model = function(formula,na_action='na_omit',contrasts=list(),...) {
15
+linear_model = function(formula,na_action='na.omit',contrasts=list(),...) {
16 16
     out=struct::new_struct('linear_model',
17 17
         formula=formula,
18
-        na_action=nna_action,
18
+        na_action=na_action,
19 19
         contrasts=contrasts,
20 20
         ...)
21 21
     return(out)
... ...
@@ -67,7 +67,7 @@ setMethod(f="model_apply",
67 67
             var_names_ex=var_names
68 68
         }
69 69
 
70
-        FF=full_fact(var_names_ex)
70
+        FF=structToolbox:::full_fact(var_names_ex)
71 71
         FF=apply(FF,1,function(x) var_names_ex[x==1])
72 72
         FF=FF[-1]
73 73
 
... ...
@@ -78,7 +78,7 @@ setMethod(f="model_apply",
78 78
             dona=FALSE
79 79
 
80 80
             testlm=tryCatch({ # if any warnings/messages set p-values to NA as unreliable
81
-                LM=lme(lmer_formula$f,random=lmer_formula$random,method='ML',data=temp,na.action=na.omit)
81
+                LM=nlme::lme(lmer_formula$f,random=lmer_formula$random,method='ML',data=temp,na.action=na.omit)
82 82
             }, warning=function(w) {
83 83
                 NA
84 84
             }, message=function(m) {
... ...
@@ -17,7 +17,7 @@ mv_feature_filter = function(threshold=20,qc_label='QC',method='QC',factor_name,
17 17
         threshold=threshold,
18 18
         qc_label=qc_label,
19 19
         method=method,
20
-        factor_name,
20
+        factor_name=factor_name,
21 21
         ...)
22 22
     return(out)
23 23
 }
... ...
@@ -87,10 +87,10 @@ setMethod(f="model_train",
87 87
 
88 88
         s=strsplit(opt$method,'_')[[1]][1]
89 89
 
90
-        filtered = filter_peaks_by_fraction(t(x), min_frac = opt$threshold/100, classes=smeta[[M$factor_name]], method=s,qc_label=opt$qc_label)
90
+        filtered = pmp::filter_peaks_by_fraction(t(x), min_frac = opt$threshold/100, classes=smeta[[M$factor_name]], method=s,qc_label=opt$qc_label,remove_peaks = FALSE)
91 91
         #D$data = as.data.frame(t(filtered$df))
92 92
 
93
-        flags<-data.frame(filtered$flags)
93
+        flags<-data.frame(attributes(filtered)$flags)
94 94
 
95 95
         output_value(M,'flags') = flags
96 96
 
... ...
@@ -58,11 +58,11 @@ setMethod(f="model_apply",
58 58
         smeta=D$sample_meta
59 59
         x=D$data
60 60
 
61
-        filtered = filter_samples_by_mv(x,max_perc_mv=opt$mv_threshold/100,D$sample_meta[,1])
61
+        filtered = pmp::filter_samples_by_mv(x,max_perc_mv=opt$mv_threshold/100,D$sample_meta[,1],remove_samples = FALSE)
62 62
 
63
-        flags<-data.frame(filtered$flags)
63
+        flags<-data.frame(attributes(filtered)$flags)
64 64
 
65
-        D=D[flags$flags==1,,drop=FALSE]
65
+        D=D[flags$filter_samples_by_mv_flags==1,,drop=FALSE]
66 66
 
67 67
         output_value(M,'filtered') = D
68 68
         output_value(M,'flags') = flags
... ...
@@ -1,4 +1,4 @@
1
-#' Probabilistic Quotient Nomalisation
1
+#' Probabilistic Quotient Normalisation
2 2
 #'
3 3
 #' Applies PQN using QC samples as reference samples
4 4
 #' @param qc_label = The label for qc samples in the chosen sample_meta column.
... ...
@@ -8,8 +8,11 @@
8 8
 #' @export pqn_norm
9 9
 #' @examples
10 10
 #' M = pqn_norm()
11
-pqn_norm = function(...) {
12
-    out=struct::new_struct('pqn_norm',qc_label='QC',factor_name,...)
11
+pqn_norm = function(qc_label='QC',factor_name=factor_name,...) {
12
+    out=struct::new_struct('pqn_norm',
13
+        qc_label=qc_label,
14
+        factor_name=factor_name,
15
+        ...)
13 16
     return(out)
14 17
 }
15 18
 
... ...
@@ -59,11 +62,11 @@ setMethod(f="model_apply",
59 62
         smeta=D$sample_meta
60 63
         x=D$data
61 64
 
62
-        normalised = pqn_normalisation(t(x), classes=smeta[,M$factor_name],qc_label=opt$qc_label) # operates on transpose of x
63
-        D$data = as.data.frame(t(normalised$df))
65
+        normalised = pmp::pqn_normalisation(t(x), classes=smeta[,M$factor_name],qc_label=opt$qc_label) # operates on transpose of x
66
+        D$data = as.data.frame(t(normalised))
64 67
 
65 68
         output_value(M,'normalised') = D
66
-        output_value(M,'coeff') = data.frame('coeff'=normalised$coef,row.names = rownames(x))
69
+        output_value(M,'coeff') = data.frame('coeff'=attributes(normalised)$flags,row.names = rownames(x))
67 70
 
68 71
         return(M)
69 72
     }
... ...
@@ -12,7 +12,11 @@
12 12
 #' M = rsd_filter()
13 13
 #'
14 14
 rsd_filter = function(rsd_threshold=20,qc_label='QC',factor_name,...) {
15
-    out=struct::new_struct('rsd_filter',...)
15
+    out=struct::new_struct('rsd_filter',
16
+        rsd_threshold=rsd_threshold,
17
+        qc_label=qc_label,
18
+        factor_name=factor_name,
19
+        ...)
16 20
     return(out)
17 21
 }
18 22
 
... ...
@@ -23,14 +27,15 @@ rsd_filter = function(rsd_threshold=20,qc_label='QC',factor_name,...) {
23 27
         qc_label='entity',
24 28
         factor_name='entity',
25 29
         filtered='entity',
26
-        flags='entity'
30
+        flags='entity',
31
+        rsd_qc='entity'
27 32
     ),
28 33
     prototype=list(name = 'RSD filter',
29 34
         description = 'Filters features by calculating the relative standard deviation (RSD) for the QC samples and removing features with RSD greater than the threshold.',
30 35
         type = 'filter',
31 36
         predicted = 'filtered',
32 37
         .params=c('rsd_threshold','qc_label','factor_name'),
33
-        .outputs=c('filtered','flags'),
38
+        .outputs=c('filtered','flags','rsd_qc'),
34 39
 
35 40
         rsd_threshold=entity(name = 'RSD threhsold',
36 41
             description = 'Features with RSD greater than the threshold are removed.',
... ...
@@ -56,6 +61,11 @@ rsd_filter = function(rsd_threshold=20,qc_label='QC',factor_name,...) {
56 61
             description = 'RSD and a flag indicating whether the feature was rejected by the filter or not.',
57 62
             type='data.frame',
58 63
             value=data.frame()
64
+        ),
65
+        rsd_qc=entity(name = 'RSD',
66
+            description = 'The calculated RSD of the QC class',
67
+            type='data.frame',
68
+            value=data.frame()
59 69
         )
60 70
     )
61 71
 )
... ...
@@ -69,13 +79,14 @@ setMethod(f="model_apply",
69 79
         opt=param_list(M)
70 80
         smeta=D$sample_meta
71 81
         x=D$data
72
-        rsd_filtered = filter_peaks_by_rsd(t(x), max_rsd = opt$rsd_threshold, classes=smeta[[opt$factor_name]], qc_label=opt$qc_label)
82
+        rsd_filtered = pmp::filter_peaks_by_rsd(t(x), max_rsd = opt$rsd_threshold, classes=smeta[[opt$factor_name]], qc_label=opt$qc_label,remove_peaks=FALSE)
73 83
 
74
-        flags<-data.frame(rsd_filtered$flags)
75
-        D=D[,flags[,2]==1,drop=FALSE]
84
+        flags<-attributes(rsd_filtered)$flags
85
+        D=D[,flags[,2]==1]
76 86
 
77 87
         output_value(M,'filtered') = D
78
-        output_value(M,'flags') = data.frame(rsd_filtered$flags,stringsAsFactors = F)
88
+        output_value(M,'flags') = data.frame('rsd_flags'=flags[,2])
89
+        output_value(M,'rsd_qc') = data.frame('rsd_qc'=flags[,1])
79 90
         return(M)
80 91
     }
81 92
 )
... ...
@@ -115,10 +126,10 @@ setMethod(f="chart_plot",
115 126
     {
116 127
         t=param_value(dobj,'rsd_threshold')
117 128
         A=output_value(dobj,'flags')
118
-        A$rsd_QC=log2(A$rsd_QC)
129
+        A$rsd_qc=log2(dobj$rsd_qc[,1])
119 130
         A$features=factor(A$rsd_flags,levels=c(1,0),labels=c('accepted','rejected'))
120 131
 
121
-        out=ggplot(data=A, aes_(x=~rsd_QC,fill=~features)) +
132
+        out=ggplot(data=A, aes_(x=~rsd_qc,fill=~features)) +
122 133
             geom_histogram(boundary=log2(t),color='white') +
123 134
             xlab('log2(RSD), QC samples') +
124 135
             ylab('Count') +
... ...
@@ -49,7 +49,7 @@ ttest = function(alpha=0.05,mtc='fdr',factor_names,paired=FALSE,paired_factor=ch
49 49
         type="univariate",
50 50
         predicted='p_value',
51 51
         stato_id="STATO:0000304",
52
-        .params=c('alpha','mtc','factor_name','paired','paired_factor'),
52
+        .params=c('alpha','mtc','factor_names','paired','paired_factor'),
53 53
         .outputs=c('t_statistic','p_value','dof','significant','conf_int','estimates'),
54 54
 
55 55
         factor_names=entity(name='Factor names',
... ...
@@ -8,7 +8,7 @@ DatasetExperiment.boxplot(
8 8
   factor_name,
9 9
   by_sample = TRUE,
10 10
   per_class = TRUE,
11
-  number,
11
+  number = 50,
12 12
   ...
13 13
 )
14 14
 }
... ...
@@ -4,9 +4,11 @@
4 4
 \alias{DatasetExperiment.heatmap}
5 5
 \title{DatasetExperiment.heatmap class}
6 6
 \usage{
7
-DatasetExperiment.heatmap(...)
7
+DatasetExperiment.heatmap(na_colour = "#FF00E4", ...)
8 8
 }
9 9
 \arguments{
10
+\item{na_colour}{A hex colour code to use for missing values}
11
+
10 12
 \item{...}{additional slots and values passed to struct_class}
11 13
 }
12 14
 \value{
... ...
@@ -4,7 +4,7 @@
4 4
 \alias{HSD}
5 5
 \title{HSD model class}
6 6
 \usage{
7
-HSD(alpha = 0.05, mtc = "fdr", formula, unblanaced = FALSE, ...)
7
+HSD(alpha = 0.05, mtc = "fdr", formula, unbalanced = FALSE, ...)
8 8
 }
9 9
 \arguments{
10 10
 \item{alpha}{The p-value threshold. Default alpha = 0.05.}
... ...
@@ -13,9 +13,9 @@ HSD(alpha = 0.05, mtc = "fdr", formula, unblanaced = FALSE, ...)
13 13
 
14 14
 \item{formula}{The formula to use. See \code{lm} for details.}
15 15
 
16
-\item{...}{additional slots and values passed to struct_class}
17
-
18 16
 \item{unbalanced}{TRUE or FALSE to apply correction for unbalanced designs. Default is FALSE.}
17
+
18
+\item{...}{additional slots and values passed to struct_class}
19 19
 }
20 20
 \value{
21 21
 struct object
... ...
@@ -4,12 +4,12 @@
4 4
 \alias{PCA}
5 5
 \title{PCA model class}
6 6
 \usage{
7
-PCA(umber_components = 2, ...)
7
+PCA(number_components = 2, ...)
8 8
 }
9 9
 \arguments{
10
-\item{...}{additional slots and values passed to struct_class}
11
-
12 10
 \item{number_components}{The number of principal components to retain}
11
+
12
+\item{...}{additional slots and values passed to struct_class}
13 13
 }
14 14
 \value{
15 15
 struct object
... ...
@@ -4,16 +4,21 @@
4 4
 \alias{PCA_dstat}
5 5
 \title{pca_dstat_plot class}
6 6
 \usage{
7
-PCA_dstat(...)
7
+PCA_dstat(number_components = 2, alpha = 0.05, ...)
8 8
 }
9 9
 \arguments{
10
+\item{number_components}{The number of components to use.}
11
+
12
+\item{alpha}{The confidence level to plot.}
13
+
10 14
 \item{...}{additional slots and values passed to struct_class}
11 15
 }
12 16
 \value{
13 17
 struct object
14 18
 }
15 19
 \description{
16
-Line plot showing percent variance and cumulative percent variance for the computed components.
20
+Bar chart showing mahalanobis distance from the mean in PCA scores space. A threshold is
21
+plotted at a chosen confidence as an indicator for rejecting outliers.
17 22
 }
18 23
 \examples{
19 24
 C = PCA_dstat()
... ...
@@ -4,7 +4,7 @@
4 4
 \alias{PLSR}
5 5
 \title{PLSR model class}
6 6
 \usage{
7
-PLSR(number_components = c(1, 2), factor_name, ...)
7
+PLSR(number_components = 2, factor_name, ...)
8 8
 }
9 9
 \arguments{
10 10
 \item{number_components}{The number of PLS components to calculate.}
... ...
@@ -9,7 +9,7 @@ confounders_clsq(
9 9
   mtc = "fdr",
10 10
   factor_name,
11 11
   confounding_factors,
12
-  threshold,
12
+  threshold = 0.15,
13 13
   ...
14 14
 )
15 15
 }
... ...
@@ -4,7 +4,7 @@
4 4
 \alias{confounders_lsq.barchart}
5 5
 \title{barchart of percent change}
6 6
 \usage{
7
-confounders_lsq.barchart(feature_to_plot, threshold, ...)
7
+confounders_lsq.barchart(feature_to_plot, threshold = 10, ...)
8 8
 }
9 9
 \arguments{
10 10
 \item{feature_to_plot}{the name or index of the feature to be plotted}
... ...
@@ -4,7 +4,7 @@
4 4
 \alias{confounders_lsq.boxplot}
5 5
 \title{boxplot of percent change}
6 6
 \usage{
7
-confounders_lsq.boxplot(threshold, ...)
7
+confounders_lsq.boxplot(threshold = 10, ...)
8 8
 }
9 9
 \arguments{
10 10
 \item{threshold}{the threshold to be plotted (in \%)}
... ...
@@ -4,14 +4,14 @@
4 4
 \alias{knn_impute}
5 5
 \title{knn missing value imputation}
6 6
 \usage{
7
-knn_impute(neighbours = 5, sample_max = 0.5, feature_max = 0.5, ...)
7
+knn_impute(neighbours = 5, sample_max = 50, feature_max = 50, ...)
8 8
 }
9 9
 \arguments{
10 10
 \item{neighbours}{The number of neighbours to use for imputation.}
11 11
 
12
-\item{sample_max}{Maximum proportion of missing values in any sample.}
12
+\item{sample_max}{Maximum percentage of missing values in any sample. Default = 50.}
13 13
 
14
-\item{feature_max}{Maximum proportion of missing values in any feature.}
14
+\item{feature_max}{Maximum percentage of missing values in any feature. Default = 50.}
15 15
 
16 16
 \item{...}{additional slots and values passed to struct_class}
17 17
 }
... ...
@@ -4,7 +4,7 @@
4 4
 \alias{linear_model}
5 5
 \title{linear model class}
6 6
 \usage{
7
-linear_model(formula, na_action = "na_omit", contrasts = list(), ...)
7
+linear_model(formula, na_action = "na.omit", contrasts = list(), ...)
8 8
 }
9 9
 \arguments{
10 10
 \item{formula}{The formula to use.}
... ...
@@ -13,14 +13,13 @@ mv_boxplot(
13 13
 )
14 14
 }
15 15
 \arguments{
16
-\item{label_outliers}{[TRUE] or FALSE to label outliers on the plot
17
-plot}
16
+\item{label_outliers}{TRUE or FALSE to label outliers on the plot.}
18 17
 
19
-\item{by_sample}{by_sample [TRUE] to plot by sample or FALSE to plot by features}
18
+\item{by_sample}{TRUE to plot missing values by sample, or FALSE to plot for features.}
20 19
 
21
-\item{factor_name}{the sample_meta column to use}
20
+\item{factor_name}{The sample_meta column to use.}
22 21
 
23
-\item{show_counts}{[TRUE] or FALSE to include the number of samples on the plot}
22
+\item{show_counts}{TRUE to show a count of the number of items used to create the boxplot on the chart.}
24 23
 
25 24
 \item{...}{additional slots and values passed to struct_class}
26 25
 }
... ...
@@ -7,7 +7,7 @@
7 7
 pca_loadings_plot(
8 8
   components = c(1, 2),
9 9
   style = "points",
10
-  label_featurs = FALSE,
10
+  label_features = FALSE,
11 11
   ...
12 12
 )
13 13
 }
... ...
@@ -16,9 +16,9 @@ pca_loadings_plot(
16 16
 
17 17
 \item{style}{Plot style for loadings. Can be 'points' (default) or 'arrows'.}
18 18
 
19
-\item{...}{additional slots and values passed to struct_class}
20
-
21 19
 \item{label_features}{TRUE or FALSE to label features on the plot. Default is FALSE.}
20
+
21
+\item{...}{additional slots and values passed to struct_class}
22 22
 }
23 23
 \value{
24 24
 struct object
... ...
@@ -10,7 +10,7 @@ pca_scores_plot(
10 10
   factor_name,
11 11
   ellipse = "all",
12 12
   label_filter = character(0),
13
-  label_factor = character(0),
13
+  label_factor = "rownames",
14 14
   label_size = 3.88,
15 15
   ...
16 16
 )
... ...
@@ -30,7 +30,7 @@ You can provide up to two factors for this plot.}
30 30
 If zero length then all labels will be included.}
31 31
 
32 32
 \item{label_factor}{The sample_meta column to use for labelling the samples.
33
-If zero length then the rownames will be used.}
33
+If 'rownames' then the rownames will be used.}
34 34
 
35 35
 \item{label_size}{The text size of the labels.NB ggplot units, not font size units.
36 36
 Default 3.88.}
... ...
@@ -2,16 +2,16 @@
2 2
 % Please edit documentation in R/pqn_norm_method_class.R
3 3
 \name{pqn_norm}
4 4
 \alias{pqn_norm}
5
-\title{Probabilistic Quotient Nomalisation}
5
+\title{Probabilistic Quotient Normalisation}
6 6
 \usage{
7
-pqn_norm(...)
7
+pqn_norm(qc_label = "QC", factor_name = factor_name, ...)
8 8
 }
9 9
 \arguments{
10
-\item{...}{additional slots and values passed to struct_class}
11
-
12 10
 \item{qc_label}{= The label for qc samples in the chosen sample_meta column.}
13 11
 
14 12
 \item{factor_name}{The sample_meta column name containing QC labels.}
13
+
14
+\item{...}{additional slots and values passed to struct_class}
15 15
 }
16 16
 \value{
17 17
 struct object
... ...
@@ -11,5 +11,5 @@ test_that('ttest',{
11 11
   M = fisher_exact(factor_name='Species',factor_pred=pred)
12 12
   # apply
13 13
   M = model_apply(M,D)
14
-  expect_true(all(M$significant))
14
+  expect_true(all(M$significant[,1]))
15 15
 })
... ...
@@ -70,7 +70,7 @@ test_that('kfold xval grid plot',{
70 70
   # run
71 71
   I=run(I,D,B)
72 72
   # chart
73
-  C = kfoldxcv_grid()
73
+  C = kfoldxcv_grid(factor_name='Species')
74 74
   gg=chart_plot(C,I)
75 75
   expect_true(is(gg[[1]],'ggplot'))
76 76
 })
... ...
@@ -6,7 +6,7 @@ test_that('pmp mv_feature within_all',{
6 6
   D$data[,1]=NA
7 7
 
8 8
   # filter
9
-  FF=mv_feature_filter(qc_label='versicolor',method='within_all',factor_name='Species')
9
+  FF=mv_feature_filter(qc_label='versicolor',method='within_all',factor_name='Species',threshold = 20)
10 10
   FF=model_apply(FF,D)
11 11
   expect_equal(ncol(FF$filtered$data),3)
12 12
 })
... ...
@@ -6,8 +6,7 @@ test_that('rsd filter',{
6 6
   # method
7 7
   M = rsd_filter(qc_label='virginica',factor_name='Species',rsd_threshold=100)
8 8
   # apply
9
-  M=model_apply(M,D)
10
-  expect_true(all(M$flags$rsd_flags==1))
9
+ expect_true(all(M$flags==1))
11 10
 })
12 11
 
13 12
 test_that('blank filter histogram',{
... ...
@@ -4,7 +4,7 @@ test_that('split data',{
4 4
   # DatasetExperiment
5 5
   D=iris_DatasetExperiment()
6 6
   # method
7
-  M = split_data()
7
+  M = split_data(p=0.75)
8 8
   # apply
9 9
   M = model_apply(M,D)
10 10
   expect_equal(nrow(M$testing$data),38)