@@ -21,8 +21,8 @@ mw_base = function(private,locked){
21
21
22
22
# ' Get slot value from mw_base objects
23
23
# '
24
- # ' Gets the value of a slot from mw_base objects, provided they are not listed as
25
- # ' 'private'.
24
+ # ' Gets the value of a slot from mw_base objects, provided they are not listed
25
+ # ' as 'private'.
26
26
# ' @param x An object derived from mw_base.
27
27
# ' @param name The name of the slot to access.
28
28
# ' @return The assigned to the slot.
@@ -44,10 +44,13 @@ setMethod(f = "$",
44
44
return (slot(x ,name ))
45
45
} else {
46
46
if (! is_slot ) {
47
- stop(paste0(' "' ,name ,' " is not a valid slot for objects of class "' , class(x )[1 ],' "' ))
47
+ stop(paste0(' "' ,name ,
48
+ ' " is not a valid slot for objects of class "' ,
49
+ class(x )[1 ],' "' ))
48
50
}
49
51
if (is_private ) {
50
- stop(paste0(' "' ,name ,' " is a private slot for internal use only.' ))
52
+ stop(paste0(' "' ,name ,
53
+ ' " is a private slot for internal use only.' ))
51
54
}
52
55
}
53
56
}
@@ -97,15 +100,17 @@ setMethod(f = 'is_valid',
97
100
signature = c(' mw_context' ,' character' ,' character' ,' character' ),
98
101
definition = function (context ,input_item ,input_value ,output_item ) {
99
102
100
- name_valid = context @ name %in% c(' study' ,' compound' ,' refmet' ,' gene' ,' protein' ,' moverz' ,' exactmass' )
103
+ name_valid = context @ name %in% c(' study' ,' compound' ,' refmet' ,' gene' ,
104
+ ' protein' ,' moverz' ,' exactmass' )
101
105
input_valid = all(input_item %in% context @ input_items )
102
106
output_valid = all(output_item %in% context @ output_items )
103
107
length_valid = (length(input_value )== length(input_item ))
104
108
length_out_valid = ! (length(input_item )> 1 )
105
109
106
110
err = list ()
107
111
if (! name_valid ) {
108
- err = c(err ,paste0(' name = "' ,input_item ,' " is not a valid context name.\n ' ))
112
+ err = c(err ,paste0(' name = "' ,input_item ,
113
+ ' " is not a valid context name.\n ' ))
109
114
}
110
115
if (! input_valid ) {
111
116
err = c(err ,paste0(' An input_item is not valid for this context.\n ' ))
@@ -116,10 +121,12 @@ setMethod(f = 'is_valid',
116
121
}
117
122
118
123
if (! length_valid ) {
119
- err = c(err ," Length of input_value must be the same as length of input_item.\n " )
124
+ err = c(err ,paste0(" Length of input_value must be the same as',
125
+ ' length of input_item.\n " ))
120
126
}
121
127
if (! length_out_valid ) {
122
- err = c(err ," Length of intput_item is limited to 1 for this context.\n " )
128
+ err = c(err ,paste0(" Length of intput_item is limited to 1 for',
129
+ ' this context.\n " ))
123
130
}
124
131
125
132
if (length(err )> 0 ) {
@@ -138,7 +145,8 @@ mw_moverz_context = function(input_items,ion_types,tol_range,mz_range,...) {
138
145
ion_types = ion_types ,
139
146
tol_range = tol_range ,
140
147
mz_range = mz_range ,
141
- locked = c(' name' ,' input_items' ,' output_items' ,' ion_types' ,' tol_range' ,' mz_range' ),
148
+ locked = c(' name' ,' input_items' ,' output_items' ,' ion_types' ,
149
+ ' tol_range' ,' mz_range' ),
142
150
...
143
151
)
144
152
return (out )
@@ -163,9 +171,11 @@ setMethod(f = 'is_valid',
163
171
164
172
input_valid = all(input_item %in% context @ input_items )
165
173
166
- range_valid2 = as.numeric(input_value [2 ]) > = context @ mz_range [1 ] & as.numeric(input_value [2 ]) < = context @ mz_range [2 ]
174
+ range_valid2 = as.numeric(input_value [2 ]) > = context @ mz_range [1 ] &
175
+ as.numeric(input_value [2 ]) < = context @ mz_range [2 ]
167
176
ion_valid = input_value [3 ] %in% context @ ion_types
168
- range_valid4 = as.numeric(input_value [4 ]) > = context @ tol_range [1 ] & as.numeric(input_value [4 ]) < = context @ tol_range [2 ]
177
+ range_valid4 = as.numeric(input_value [4 ]) > = context @ tol_range [1 ] &
178
+ as.numeric(input_value [4 ]) < = context @ tol_range [2 ]
169
179
database_valid = input_value [1 ] %in% c(' LIPIDS' ,' MB' ,' REFMET' )
170
180
171
181
err = list ()
@@ -179,10 +189,12 @@ setMethod(f = 'is_valid',
179
189
err = c(err ," input_value[4] is out of range for this context.\n " )
180
190
}
181
191
if (! ion_valid ) {
182
- err = c(err ,paste0(' "' ,input_value [3 ], ' " is not a valid ion for this context.\n ' ))
192
+ err = c(err ,paste0(' "' ,input_value [3 ],
193
+ ' " is not a valid ion for this context.\n ' ))
183
194
}
184
195
if (! database_valid ) {
185
- err = c(err ,paste0(' "' ,input_value [1 ], ' " is not a valid database for this context.\n ' ))
196
+ err = c(err ,paste0(' "' ,input_value [1 ],
197
+ ' " is not a valid database for this context.\n ' ))
186
198
}
187
199
if (length(err )> 0 ) {
188
200
stop(err )
@@ -198,7 +210,8 @@ mw_exactmass_context = function(ion_types,lipid_types,...) {
198
210
output_items = ' exactmass' ,
199
211
ion_types = ion_types ,
200
212
lipid_types = lipid_types ,
201
- locked = c(' name' ,' input_items' ,' output_items' ,' ion_types' ,' lipid_types' ),
213
+ locked = c(' name' ,' input_items' ,' output_items' ,' ion_types' ,
214
+ ' lipid_types' ),
202
215
...
203
216
)
204
217
return (out )
@@ -227,10 +240,12 @@ setMethod(f = 'is_valid',
227
240
228
241
err = list ()
229
242
if (! ion_valid ) {
230
- err = c(err ,paste0(' "' ,input_value [2 ], ' " is not a valid ion for this context.\n ' ))
243
+ err = c(err ,paste0(' "' ,input_value [2 ],
244
+ ' " is not a valid ion for this context.\n ' ))
231
245
}
232
246
if (! lipid_valid ) {
233
- err = c(err ,paste0(' "' ,str [1 ], ' " is not a valid Lipid for this context.\n ' ))
247
+ err = c(err ,paste0(' "' ,str [1 ],
248
+ ' " is not a valid Lipid for this context.\n ' ))
234
249
}
235
250
if (length(err )> 0 ) {
236
251
stop(err )
@@ -267,9 +282,11 @@ setMethod(f = 'show',
267
282
cat(' A Metabolomics Workbench "input_item"\n\n ' )
268
283
cat(' Name:\t "' ,object @ name ,' "\n\n ' ,sep = ' ' )
269
284
cat(' Exact pattern matching:\n ' )
270
- cat(paste0(' \t "' ,object @ pattern $ exact ,' "' ,collapse = ' \n ' ),' \n\n ' ,sep = ' ' )
285
+ cat(paste0(' \t "' ,object @ pattern $ exact ,' "' ,
286
+ collapse = ' \n ' ),' \n\n ' ,sep = ' ' )
271
287
cat(' Partial pattern matching:\n ' )
272
- cat(paste0(' \t "' ,object @ pattern $ partial ,' "' ,collapse = ' \n ' ),' \n\n ' ,sep = ' ' )
288
+ cat(paste0(' \t "' ,object @ pattern $ partial ,' "' ,
289
+ collapse = ' \n ' ),' \n\n ' ,sep = ' ' )
273
290
274
291
if (any(object $ example != ' ' )) {
275
292
cat(' Examples: \n ' )
@@ -337,7 +354,8 @@ setMethod(f = 'do_query',
337
354
if (! (all(input_item %in% names(metabolomicsWorkbenchR :: input_item )))) {
338
355
stop(paste0(' An input_item is not valid.' ))
339
356
}
340
- if (! (all(output_item %in% names(metabolomicsWorkbenchR :: output_item )))) {
357
+ if (! (all(output_item %in% names(metabolomicsWorkbenchR :: output_item ))))
358
+ {
341
359
stop(paste0(' An output_item is not valid.' ))
342
360
}
343
361
@@ -347,7 +365,7 @@ setMethod(f = 'do_query',
347
365
348
366
if (length(input_item )> 1 ) {
349
367
input_item = as.list(input_item )
350
- for (k in 1 : length (input_item )) {
368
+ for (k in seq_along (input_item )) {
351
369
input_item [[k ]]= metabolomicsWorkbenchR :: input_item [[k ]]
352
370
}
353
371
} else {
@@ -386,7 +404,8 @@ setMethod(f = 'do_query',
386
404
} else if (is(x ,' character' )) {
387
405
return (x )
388
406
} else {
389
- stop(' input_item list must only contain characters or mw_input_item objects.' )
407
+ stop(paste0(' input_item list must only contain characters' ,
408
+ ' or mw_input_item objects.' ))
390
409
}
391
410
})
392
411
namez = unlist(namez )
@@ -507,7 +526,8 @@ setMethod(f = 'do_query',
507
526
} else if (is(x ,' character' )) {
508
527
return (x )
509
528
} else {
510
- stop(' input_item list must only contain characters or mw_input_item objects.' )
529
+ stop(paste0(' input_item list must only contain characters or' ,
530
+ ' mw_input_item objects.' ))
511
531
}
512
532
})
513
533
namez = unlist(namez )
@@ -637,7 +657,8 @@ setMethod(f = 'check_pattern',
637
657
pattern = I $ pattern [[match ]]
638
658
valid = grepl(x = input_value ,pattern = pattern )
639
659
if (! valid ) {
640
- stop(paste0(' The input_value does not match the required pattern for the provided input_item and output_item.' ))
660
+ stop(paste0(' The input_value does not match the required pattern' ,
661
+ ' for the provided input_item and output_item.' ))
641
662
} else {
642
663
return (TRUE )
643
664
}
@@ -651,7 +672,8 @@ setMethod(f = 'check_puts',
651
672
definition = function (input_item ,output_item ) {
652
673
valid = input_item $ name %in% output_item $ inputs
653
674
if (! valid ) {
654
- stop(paste0(' The input_value is not compatible with the output_item.' ))
675
+ stop(paste0(' The input_value is not compatible with the' ,
676
+ ' output_item.' ))
655
677
} else {
656
678
return (TRUE )
657
679
}
@@ -671,6 +693,11 @@ use_api = function(str,output_item=NULL,input_value=NULL,testing=0) {
671
693
)
672
694
}
673
695
696
+ if (httr :: http_error(response )) {
697
+ status = httr :: http_status(response )
698
+ message(status $ message )
699
+ return ()
700
+ }
674
701
675
702
if (response $ headers $ `content-type` == " image/png" ) {
676
703
# do nothing
@@ -719,7 +746,8 @@ setMethod(f = 'do_query',
719
746
err = list ()
720
747
# check we have a study context
721
748
if (context $ name != ' study' ) {
722
- err = c(err ,' SummarizedExperiment output_item can only be used with "study" context' )
749
+ err = c(err ,paste0(' SummarizedExperiment output_item can only be' ,
750
+ ' used with "study" context' ))
723
751
}
724
752
if (length(err )> 0 ) {
725
753
stop(err )
@@ -733,7 +761,7 @@ setMethod(f = 'do_query',
733
761
734
762
# # multiple analysis might be returned
735
763
out = list ()
736
- for (k in 1 : length (df )) {
764
+ for (k in seq_along (df )) {
737
765
738
766
S = do_query(' study' ,' study_id' ,input_value ,' summary' )
739
767
@@ -760,7 +788,10 @@ setMethod(f = 'do_query',
760
788
# factors
761
789
SM = do_query(' study' ,' study_id' ,input_value ,' factors' )[[1 ]]
762
790
# merge with data samples in case some are missing
763
- SM = merge(data.frame (' local_sample_id' = colnames(X )),SM ,by = ' local_sample_id' ,all = TRUE ,sort = FALSE )
791
+ SM = merge(data.frame (' local_sample_id' = colnames(X )),
792
+ SM ,by = ' local_sample_id' ,
793
+ all = TRUE ,
794
+ sort = FALSE )
764
795
rownames(SM )= SM $ local_sample_id
765
796
766
797
M [[' subject_type' ]]= SM $ subject_type [1 ]
@@ -788,12 +819,12 @@ setMethod(f = 'do_query',
788
819
789
820
X = as.data.frame(t(df ))
790
821
791
- SM = as.data.frame(t(X [1 : nf ,]))
792
- X = X [nf + 1 : nrow(X ),]
822
+ SM = as.data.frame(t(X [seq_len( nf ) ,]))
823
+ X = X [nf + seq_len( nrow(X ) ),]
793
824
794
825
VM = data.frame (metabolite = rownames(X ))
795
826
796
- rownames(X )= 1 : nrow(X )
827
+ rownames(X )= seq_len( nrow(X ) )
797
828
798
829
M = list (
799
830
' data_source' = ' Metabolomics Workbench' ,
@@ -853,12 +884,12 @@ setMethod(f = 'do_query',
853
884
854
885
nf = ncol(fq )- 1
855
886
856
- SM = as.data.frame(t(X [1 : nf ,]))
857
- X = X [nf + 1 : nrow(X ),]
887
+ SM = as.data.frame(t(X [seq_len( nf ) ,]))
888
+ X = X [nf + seq_len( nrow(X ) ),]
858
889
859
890
VM = data.frame (feature_id = rownames(X ))
860
891
861
- rownames(X )= 1 : nrow(X )
892
+ rownames(X )= seq_len( nrow(X ) )
862
893
863
894
M = list (
864
895
' data_source' = ' Metabolomics Workbench (untargeted)' ,
@@ -908,14 +939,19 @@ setMethod(f = 'do_query',
908
939
err = list ()
909
940
# check we have a study context
910
941
if (context $ name != ' study' ) {
911
- err = c(err ,' DatasetExperiment output_item can only be used with "study" context' )
942
+ err = c(err ,paste0(' DatasetExperiment output_item can only be used' ,
943
+ ' with "study" context' ))
912
944
}
913
945
if (length(err )> 0 ) {
914
946
stop(err )
915
947
}
916
948
917
949
# use SE, then convert to DE
918
- SE = do_query(context $ name ,input_item $ name ,input_value ,' SummarizedExperiment' )
950
+ SE = do_query(
951
+ context $ name ,
952
+ input_item $ name ,
953
+ input_value ,
954
+ ' SummarizedExperiment' )
919
955
920
956
if (is(SE ,' SummarizedExperiment' )) {
921
957
DE = as.DatasetExperiment(SE )
@@ -964,7 +1000,11 @@ setMethod(f = 'do_query',
964
1000
definition = function (context ,input_item ,input_value ,output_item ) {
965
1001
966
1002
# use SE then convert
967
- SE = do_query(context $ name ,input_item $ name ,input_value ,' untarg_SummarizedExperiment' )
1003
+ SE = do_query(
1004
+ context $ name ,
1005
+ input_item $ name ,
1006
+ input_value ,
1007
+ ' untarg_SummarizedExperiment' )
968
1008
DE = as.DatasetExperiment(SE )
969
1009
return (DE )
970
1010
})
@@ -1001,14 +1041,19 @@ setMethod(f = 'do_query',
1001
1041
err = list ()
1002
1042
# check we have a study context
1003
1043
if (context $ name != ' study' ) {
1004
- err = c(err ,' MultiAssayExperiment output_item can only be used with "study" context' )
1044
+ err = c(err ,paste0(' MultiAssayExperiment output_item can only be' ,
1045
+ ' used with "study" context' ))
1005
1046
}
1006
1047
if (length(err )> 0 ) {
1007
1048
stop(err )
1008
1049
}
1009
1050
1010
1051
# use SE, then convert to DE
1011
- SE = do_query(context $ name ,input_item $ name ,input_value ,' SummarizedExperiment' )
1052
+ SE = do_query(
1053
+ context $ name ,
1054
+ input_item $ name ,
1055
+ input_value ,
1056
+ ' SummarizedExperiment' )
1012
1057
1013
1058
if (is(SE ,' SummarizedExperiment' )) {
1014
1059
SE = list (SE )
@@ -1017,4 +1062,4 @@ setMethod(f = 'do_query',
1017
1062
1018
1063
SE = MatchedAssayExperiment(SE ,colData = colData(SE [[1 ]]))
1019
1064
return (SE )
1020
- })
1065
+ })
0 commit comments