Skip to content

Commit 5ce82bb

Browse files
committed
apply bioc style guide...
...using styler and biocthis::biocstyle
1 parent d20d524 commit 5ce82bb

File tree

86 files changed

+1167
-1180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1167
-1180
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ Imports:
4141
ggplot2,
4242
utils,
4343
rlang,
44-
cowplot
44+
cowplot,
45+
stats
4546
Collate:
4647
'generics.R'
4748
'zzz.R'

R/AnnotationDb_database.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
#' @include annotation_database_class.R
44
#' @family annotation databases
55
#' @seealso [AnnotationDbi::AnnotationDb]
6-
AnnotationDb_database <- function(
7-
source,
8-
table,
9-
...) {
6+
AnnotationDb_database <- function(source,
7+
table,
8+
...) {
109
# new object
1110
out <- struct::new_struct(
1211
"AnnotationDb_database",

R/AnnotationDb_select_class.R

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
#' @include annotation_source_class.R
44
#' @seealso [dplyr::left_join()]
55
#' @seealso [AnnotationDbi::select()]
6-
AnnotationDb_select <- function(
7-
database,
8-
key_column,
9-
key_type,
10-
database_columns,
11-
drop_na = TRUE,
12-
...) {
6+
AnnotationDb_select <- function(database,
7+
key_column,
8+
key_type,
9+
database_columns,
10+
drop_na = TRUE,
11+
...) {
1312
out <- struct::new_struct(
1413
"AnnotationDb_select",
1514
database = database,
@@ -124,45 +123,45 @@ setMethod(
124123
definition = function(M, D) {
125124
# get db
126125
db <- do.call(`::`, list(M$database, M$database))
127-
126+
128127
# prepare from:to for left join
129128
by <- M$key_type
130129
names(by) <- M$key_column
131-
130+
132131
# columns
133132
if (any(M$database_columns == ".all")) {
134133
M$database_columns <- AnnotationDbi::columns(db)
135134
}
136-
135+
137136
# select
138137
db <- AnnotationDbi::select(
139138
x = db,
140139
keys = as.character(D$data[[M$key_column]]),
141140
columns = M$database_columns,
142141
keytype = M$key_type
143142
)
144-
143+
145144
# remove NA
146145
if (M$drop_na) {
147146
na <- apply(db, 1, function(x) {
148147
any(is.na(x))
149148
})
150149
db <- db[!na, ]
151150
}
152-
151+
153152
# unique rows
154153
db <- unique(db)
155-
154+
156155
# add the columns
157156
M2 <- add_columns(
158157
new_columns = db,
159158
by = by
160159
)
161160
M2 <- model_apply(M2, D)
162-
161+
163162
# assign to object
164163
M$updated <- predicted(M2)
165-
164+
166165
return(M)
167166
}
168167
)

R/BiocFileCache_database_class.R

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
#' @export
33
#' @include annotation_database_class.R BiocFileCache_database_helpers.R
44
#' @family database
5-
BiocFileCache_database <- function(
6-
source,
7-
bfc_path = NULL,
8-
resource_name,
9-
bfc_fun = .cache_as_is,
10-
import_fun = read.csv,
11-
offline = FALSE,
12-
...) {
5+
BiocFileCache_database <- function(source,
6+
bfc_path = NULL,
7+
resource_name,
8+
bfc_fun = .cache_as_is,
9+
import_fun = read.csv,
10+
offline = FALSE,
11+
...) {
1312
# new object
1413
out <- struct::new_struct(
1514
"BiocFileCache_database",
@@ -119,13 +118,13 @@ setMethod(
119118
if (is.null(obj$bfc_path)) {
120119
obj$bfc_path <- BiocFileCache::getBFCOption("CACHE")
121120
}
122-
121+
123122
# get path
124123
path <- .get_cached_path(obj)
125-
124+
126125
# read
127126
df <- obj$import_fun(path)
128-
127+
129128
# return
130129
return(df)
131130
}
@@ -144,7 +143,7 @@ setMethod(
144143
query = obj$source,
145144
field = "fpath", exact = TRUE
146145
)$rid
147-
146+
148147
# if not present, then add it
149148
if (!length(rid)) {
150149
rid <- names(
@@ -156,11 +155,12 @@ setMethod(
156155
)
157156
)
158157
}
159-
158+
160159
if (rid %in% BiocFileCache::bfcquery(
161160
bfc,
162-
field = "rtype",
163-
query = "web")$rid) {
161+
field = "rtype",
162+
query = "web"
163+
)$rid) {
164164
# TRUE if newly added or stale
165165
update <- BiocFileCache::bfcneedsupdate(bfc, rid)
166166
if (is.na(update)) { # FALSE if NA
@@ -169,8 +169,8 @@ setMethod(
169169
} else {
170170
update <- FALSE # cant update if not web resource
171171
}
172-
173-
172+
173+
174174
# download & unzip
175175
if (update & !obj$offline) {
176176
BiocFileCache::bfcdownload(
@@ -181,9 +181,9 @@ setMethod(
181181
verbose = FALSE
182182
)
183183
}
184-
184+
185185
# get path
186186
path <- BiocFileCache::bfcrpath(bfc, rids = rid)
187-
187+
188188
return(path)
189189
}

R/CompoundDb_source_class.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#' @eval get_description('CompoundDb_source')
22
#' @export
33
#' @include annotation_source_class.R annotation_source_class.R
4-
CompoundDb_source <- function(
5-
source,
6-
tag = "cdb", ...) {
4+
CompoundDb_source <- function(source,
5+
tag = "cdb", ...) {
76
out <- struct::new_struct(
87
"CompoundDb_source",
98
source = source,
@@ -35,27 +34,27 @@ setMethod(
3534
definition = function(M, D) {
3635
# check db exists
3736
stopifnot(file.exists(M$source))
38-
37+
3938
# connect
4039
db <- CompoundDb::CompDb(M$source)
41-
40+
4241
# get compounds table
4342
df <- CompoundDb::compounds(
4443
df,
4544
return.type = "data.frame",
4645
columns = compoundVariables(df, includeId = TRUE)
4746
)
48-
47+
4948
# add tag, id col
5049
D$tag <- M$tag
5150
D$id_column <- "compound_id"
52-
51+
5352
# assign to annotation table
5453
D$data <- df
55-
54+
5655
# add to object
5756
M$imported <- D
58-
57+
5958
# done
6059
return(M)
6160
}

R/MTox700plus_database_class.R

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#' @eval get_description('MTox700plus_database')
22
#' @export
33
#' @include annotation_database_class.R BiocFileCache_database_class.R zzz.R
4-
MTox700plus_database <- function(
5-
version = "latest",
6-
bfc_path = NULL,
7-
resource_name = "MetMashR_MTox700plus",
8-
...) {
4+
MTox700plus_database <- function(version = "latest",
5+
bfc_path = NULL,
6+
resource_name = "MetMashR_MTox700plus",
7+
...) {
98
# new object
109
out <- struct::new_struct(
1110
"MTox700plus_database",
@@ -58,8 +57,8 @@ MTox700plus_database <- function(
5857
description = paste0(
5958
"The version number of the MTox700+ database to import. ",
6059
"Available versions are listed ",
61-
'\\href{https://github.com/michabohealthscience/MTox700plus/',
62-
'releases}{here}.',
60+
"\\href{https://github.com/michabohealthscience/MTox700plus/",
61+
"releases}{here}.",
6362
' `version` should match the tag of the release e.g. `"v1.0"`.',
6463
' For convenience `version = "latest"` will always retrieve ',
6564
"the most recent release. To prevent unecessary downloads ",
@@ -104,12 +103,12 @@ setMethod(
104103
httr::stop_for_status(response)
105104
# otherwise parse content
106105
J <- httr::content(response, as = "parsed")
107-
106+
108107
# Use BiocFileCache database
109108
obj$source <- J$zipball_url
110109
obj$resource_name <- paste0(obj$resource_name, "_", J$tag_name)
111110
df <- callNextMethod(obj)
112-
111+
113112
# return
114113
return(df)
115114
}

R/PathBank_metabolite_database_class.R

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#' @eval get_description('PathBank_metabolite_database')
22
#' @export
33
#' @include annotation_database_class.R BiocFileCache_database_class.R
4-
PathBank_metabolite_database <- function(
5-
version = "primary",
6-
bfc_path = NULL,
7-
resource_name = "MetMashR_PathBank",
8-
...) {
4+
PathBank_metabolite_database <- function(version = "primary",
5+
bfc_path = NULL,
6+
resource_name = "MetMashR_PathBank",
7+
...) {
98
# new object
109
out <- struct::new_struct(
1110
"PathBank_metabolite_database",
@@ -108,13 +107,13 @@ setMethod(
108107
)
109108
}
110109
obj$source <- db_url
111-
110+
112111
# append version to rname
113112
obj$resource_name <- paste0(obj$resource_name, "_", obj$version)
114-
113+
115114
# reuse BiocFileCache_database
116115
df <- callNextMethod(obj)
117-
116+
118117
# return
119118
return(df)
120119
}

R/add_columns_class.R

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
#' @include annotation_source_class.R
44
#' @seealso [dplyr::left_join()]
55
add_columns <- function(new_columns, by, ...) {
6-
7-
if (nrow(new_columns)==0 & ncol(new_columns)==0) {
8-
new_columns = data.frame(id=NA)
9-
colnames(new_columns)[1]=by[1]
6+
if (nrow(new_columns) == 0 & ncol(new_columns) == 0) {
7+
new_columns <- data.frame(id = NA)
8+
colnames(new_columns)[1] <- by[1]
109
}
11-
10+
1211
check <- all(by %in% colnames(new_columns))
1312
if (!check) {
1413
stop('parameter "by" must be a column name of the "new_columns",
1514
" data.frame')
1615
}
17-
16+
1817
out <- struct::new_struct(
1918
"add_columns",
2019
new_columns = new_columns,

R/add_labels_class.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ add_labels <- function(labels, replace = FALSE, ...) {
6969
)
7070

7171
setValidity("add_labels", method = function(object) {
72-
check = FALSE
72+
check <- FALSE
7373
if (length(object$labels) > 0) {
7474
check <- is.null(names(object$labels))
7575
}

0 commit comments

Comments
 (0)