@@ -85,6 +85,7 @@ setMethod(f="method.apply",
85
85
definition = function (M ,D )
86
86
{
87
87
X = dataset.data(D )
88
+ CN = colnames(X ) # keep a copy of the original colnames
88
89
y = dataset.sample_meta(D )[[M $ factor_names ]]
89
90
L = levels(y )
90
91
if (length(L )!= 2 ) {
@@ -112,11 +113,12 @@ setMethod(f="method.apply",
112
113
}
113
114
114
115
}
115
- X = X [! (D $ sample_meta [[M $ paired_factor ]] %in% out ),]
116
- y = y [! (D $ sample_meta [[M $ paired_factor ]] %in% out )]
116
+ D $ data = D $ data [! (D $ sample_meta [[M $ paired_factor ]] %in% out ),]
117
+ D $ sample_meta = D $ sample_meta [! (D $ sample_meta [[M $ paired_factor ]] %in% out ),]
118
+ y = dataset.sample_meta(D )[[M $ factor_names ]]
117
119
118
120
# sort the data by sample id so that theyre in the right order for paired ttest
119
- X = apply(X ,2 ,function (x ) {
121
+ X = apply(D $ data ,2 ,function (x ) {
120
122
a = x [y == L [1 ]]
121
123
b = x [y == L [2 ]]
122
124
ay = y [y == L [1 ]]
@@ -125,27 +127,37 @@ setMethod(f="method.apply",
125
127
b = b [order(by )]
126
128
return (c(a ,b ))
127
129
})
128
- # also make sure the meta data is in the right order
129
- y = y [order(D $ sample_meta [[M $ paired_factor ]])]
130
130
131
131
# put back into dataset object
132
132
D $ data = as.data.frame(X )
133
- D $ sample_meta [[M $ paired_factor ]]= y
133
+ D $ sample_meta [[M $ factor_names ]]= D $ sample_meta [[M $ factor_names ]][order(D $ sample_meta [[M $ paired_factor ]])]
134
+ D $ sample_meta [[M $ paired_factor ]]= D $ sample_meta [[M $ paired_factor ]][order(D $ sample_meta [[M $ paired_factor ]])]
135
+ y = dataset.sample_meta(D )[[M $ factor_names ]]
136
+
137
+ # check number per class
138
+ # if less then 2 then remove
139
+ FF = filter_na_count(threshold = 2 ,factor_name = M $ factor_names )
140
+ FF = method.apply(FF ,D )
141
+ D = predicted(FF )
142
+
143
+ # check equal numbers per class. if not equal then exclude.
144
+ out = FF $ count [,1 ]!= FF $ count [,2 ]
145
+ D $ data = D $ data [,! out ]
134
146
}
135
147
136
- # check number per class
137
- # if less then 2 then remove
138
- FF = filter_na_count(threshold = 2 ,factor_name = M $ factor_names )
139
- FF = method.apply(FF ,D )
140
- D = predicted(FF )
148
+
149
+
141
150
X = D $ data
142
- y = D $ sample_meta [[M $ paired_factor ]]
143
- print(FF $ count )
151
+ y = D $ sample_meta [[M $ factor_names ]]
144
152
145
153
output = apply(X ,2 ,function (x ) {
146
154
a = unlist(t.test(x [y == L [1 ]],x [y == L [2 ]],paired = M $ paired )[c(" statistic" ," p.value" ," parameter" ,' conf.int' ,' estimate' )])
147
155
})
148
- output = as.data.frame(t(output ),stringsAsFactors = FALSE )
156
+
157
+ temp = data.frame (row.names = CN ) # make sure we get result for all features, even if NA
158
+ output = merge(temp ,as.data.frame(t(output ),stringsAsFactors = FALSE ),by = 0 ,all = TRUE )
159
+ rownames(output )= output $ Row.names
160
+ output = output [,- 1 ]
149
161
output $ p.value = p.adjust(output $ p.value ,method = param.value(M ,' mtc' ))
150
162
output.value(M ,' t_statistic' )= output $ statistic.t
151
163
output.value(M ,' p_value' )= output $ p.value
0 commit comments