Skip to content

Commit a4fd613

Browse files
committed
fix broken tests
updated fold change to account for control_group param added to ttest
1 parent e1a7e05 commit a4fd613

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: structToolbox
22
Type: Package
33
Title: Data processing & analysis tools for Metabolomics and other omics
4-
Version: 1.17.2
4+
Version: 1.17.3
55
Authors@R: c(
66
person(
77
c("Gavin","Rhys"),

R/fold_change_class.R

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ setMethod(f="model_apply",
199199

200200
counter=1
201201

202-
D$sample_meta[[M$factor_name]]=ordered(D$sample_meta[[M$factor_name]])
202+
D$sample_meta[[M$factor_name]]=factor(D$sample_meta[[M$factor_name]])
203203

204204
# for all pairs of groups
205205
for (A in 1:(length(L)-1)) {
@@ -209,12 +209,28 @@ setMethod(f="model_apply",
209209
FG=filter_smeta(factor_name=M$factor_name,mode='include',levels=L[c(A,B)])
210210
FG=model_apply(FG,D)
211211
# change to ordered factor so that we make use of control group
212-
FG$filtered$sample_meta[[M$factor_name]]=ordered(FG$filtered$sample_meta[[M$factor_name]],levels=L[c(A,B)])
212+
#FG$filtered$sample_meta[[M$factor_name]]=ordered(FG$filtered$sample_meta[[M$factor_name]],levels=L[c(A,B)])
213213

214214
if (M$method=='geometric') {
215215

216+
control_group = NULL
217+
if (length(M$control_group)>0) {
218+
if (L[B] == M$control_group) {
219+
control_group = M$control_group
220+
221+
}
222+
}
223+
216224
# apply t-test
217-
TT=ttest(alpha=0.05,mtc='none',factor_names=M$factor_name,paired=M$paired,paired_factor=M$sample_name,conf_level=M$conf_level)
225+
TT=ttest(
226+
alpha=0.05,
227+
mtc='none',
228+
factor_names=M$factor_name,
229+
paired=M$paired,
230+
paired_factor=M$sample_name,
231+
conf_level=M$conf_level,
232+
control_group=control_group)
233+
218234
TT=model_apply(TT,predicted(FG))
219235
# log2(fold change) is the difference in estimate.mean from ttest
220236
if (M$paired) {

tests/testthat/test-foldchange.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test_that('fold_change',{
1717
D$data[1:25,3] = NA
1818

1919
# unpaired
20-
FF = fold_change(factor_name='Species',method="geometric")
20+
FF = fold_change(factor_name='Species',method="geometric",control_group='versicolor')
2121
FF = model_apply(FF,D)
2222
m=exp(mean(log(D$data[D$sample_meta$Species=='virginica',1]))) / exp(mean(log((D$data[D$sample_meta$Species=='versicolor',1]))))
2323
expect_equal(FF$fold_change[1,1],m,tolerance=0.00001)

tests/testthat/test-ttest.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test_that('ttest',{
88
ttest(factor_names='Species')
99
# apply
1010
M = model_apply(M,D)
11-
expect_equal(M[2]$t_statistic[1,1],-15.386,tolerance=0.0005)
11+
expect_equal(M[2]$t_statistic[1,1],15.386,tolerance=0.0005)
1212
})
1313

1414

@@ -68,11 +68,11 @@ test_that('paired-ttest',{
6868

6969
# 50 pairs - 1 without pair - 1 with an NA - 1 for ttest
7070
expect_equal(M$dof[1],47)
71-
expect_equal(M$t_statistic[1,1],-5.195,tolerance=0.0005)
71+
expect_equal(M$t_statistic[1,1],5.195,tolerance=0.0005)
7272

7373
# 50 pairs - 1 without pair - 1 for ttest
7474
expect_equal(M$dof[2],48)
75-
expect_equal(M$t_statistic[2,1],-3.014,tolerance=0.0005)
75+
expect_equal(M$t_statistic[2,1],3.014,tolerance=0.0005)
7676

7777
# check order dependence
7878
expect_equal(M$t_statistic[1,1],M2$t_statistic[1,1],tolerance=0.00005)

0 commit comments

Comments
 (0)