Skip to content

Commit 8bab7ee

Browse files
committed
fixes for BiocCheck
1 parent ab1d78e commit 8bab7ee

File tree

70 files changed

+1020
-920
lines changed

Some content is hidden

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

70 files changed

+1020
-920
lines changed

R/AnnotationDb_database.R

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

R/AnnotationDb_select_class.R

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
#' @include annotation_source_class.R
44
#' @seealso [dplyr::left_join()]
55
#' @seealso [AnnotationDbi::select()]
6-
AnnotationDb_select <- function(database,
7-
key_column,
8-
key_type,
9-
database_columns,
10-
drop_na = TRUE,
11-
...) {
6+
AnnotationDb_select <- function(
7+
database,
8+
key_column,
9+
key_type,
10+
database_columns,
11+
drop_na = TRUE,
12+
...) {
1213
out <- struct::new_struct(
1314
"AnnotationDb_select",
1415
database = database,
@@ -123,45 +124,45 @@ setMethod(
123124
definition = function(M, D) {
124125
# get db
125126
db <- do.call(`::`, list(M$database, M$database))
126-
127+
127128
# prepare from:to for left join
128129
by <- M$key_type
129130
names(by) <- M$key_column
130-
131+
131132
# columns
132133
if (any(M$database_columns == ".all")) {
133134
M$database_columns <- AnnotationDbi::columns(db)
134135
}
135-
136+
136137
# select
137138
db <- AnnotationDbi::select(
138139
x = db,
139140
keys = as.character(D$data[[M$key_column]]),
140141
columns = M$database_columns,
141142
keytype = M$key_type
142143
)
143-
144+
144145
# remove NA
145146
if (M$drop_na) {
146147
na <- apply(db, 1, function(x) {
147148
any(is.na(x))
148149
})
149150
db <- db[!na, ]
150151
}
151-
152+
152153
# unique rows
153154
db <- unique(db)
154-
155+
155156
# add the columns
156157
M2 <- add_columns(
157158
new_columns = db,
158159
by = by
159160
)
160161
M2 <- model_apply(M2, D)
161-
162+
162163
# assign to object
163164
M$updated <- predicted(M2)
164-
165+
165166
return(M)
166167
}
167168
)

R/BiocFileCache_database_class.R

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
#' @export
33
#' @include annotation_database_class.R BiocFileCache_database_helpers.R
44
#' @family {database}
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-
...) {
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+
...) {
1213
# new object
1314
out <- struct::new_struct(
1415
"BiocFileCache_database",
@@ -117,13 +118,13 @@ setMethod(
117118
if (is.null(obj$bfc_path)) {
118119
obj$bfc_path <- BiocFileCache::getBFCOption("CACHE")
119120
}
120-
121+
121122
# get path
122123
path <- .get_cached_path(obj)
123-
124+
124125
# read
125126
df <- obj$import_fun(path)
126-
127+
127128
# return
128129
return(df)
129130
}
@@ -142,7 +143,7 @@ setMethod(
142143
query = obj$source,
143144
field = "fpath", exact = TRUE
144145
)$rid
145-
146+
146147
# if not present, then add it
147148
if (!length(rid)) {
148149
rid <- names(
@@ -154,10 +155,11 @@ setMethod(
154155
)
155156
)
156157
}
157-
158-
if (rid %in% BiocFileCache::bfcquery(bfc,
159-
field = "rtype", query = "web"
160-
)$rid) {
158+
159+
if (rid %in% BiocFileCache::bfcquery(
160+
bfc,
161+
field = "rtype",
162+
query = "web")$rid) {
161163
# TRUE if newly added or stale
162164
update <- BiocFileCache::bfcneedsupdate(bfc, rid)
163165
if (is.na(update)) { # FALSE if NA
@@ -166,8 +168,8 @@ setMethod(
166168
} else {
167169
update <- FALSE # cant update if not web resource
168170
}
169-
170-
171+
172+
171173
# download & unzip
172174
if (update & !obj$offline) {
173175
BiocFileCache::bfcdownload(
@@ -178,9 +180,9 @@ setMethod(
178180
verbose = FALSE
179181
)
180182
}
181-
183+
182184
# get path
183185
path <- BiocFileCache::bfcrpath(bfc, rids = rid)
184-
186+
185187
return(path)
186188
}

R/CompoundDb_source_class.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#' @eval get_description('CompoundDb_source')
22
#' @export
33
#' @include annotation_source_class.R annotation_source_class.R
4-
CompoundDb_source <- function(source,
5-
tag = "cdb", ...) {
4+
CompoundDb_source <- function(
5+
source,
6+
tag = "cdb", ...) {
67
out <- struct::new_struct(
78
"CompoundDb_source",
89
source = source,
@@ -33,27 +34,27 @@ setMethod(
3334
definition = function(M, D) {
3435
# check db exists
3536
stopifnot(file.exists(M$source))
36-
37+
3738
# connect
3839
db <- CompoundDb::CompDb(M$source)
39-
40+
4041
# get compounds table
4142
df <- CompoundDb::compounds(
4243
df,
4344
return.type = "data.frame",
4445
columns = compoundVariables(df, includeId = TRUE)
4546
)
46-
47+
4748
# add tag, id col
4849
D$tag <- M$tag
4950
D$id_column <- "compound_id"
50-
51+
5152
# assign to annotation table
5253
D$data <- df
53-
54+
5455
# add to object
5556
M$imported <- D
56-
57+
5758
# done
5859
return(M)
5960
}

R/MTox700plus_database_class.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#' @eval get_description('MTox700plus_database')
22
#' @export
33
#' @include annotation_database_class.R BiocFileCache_database_class.R zzz.R
4-
MTox700plus_database <- function(version = "latest",
5-
bfc_path = NULL,
6-
resource_name = "MetMashR_MTox700plus",
7-
...) {
4+
MTox700plus_database <- function(
5+
version = "latest",
6+
bfc_path = NULL,
7+
resource_name = "MetMashR_MTox700plus",
8+
...) {
89
# new object
910
out <- struct::new_struct(
1011
"MTox700plus_database",
@@ -102,12 +103,12 @@ setMethod(
102103
httr::stop_for_status(response)
103104
# otherwise parse content
104105
J <- httr::content(response, as = "parsed")
105-
106+
106107
# Use BiocFileCache database
107108
obj$source <- J$zipball_url
108109
obj$resource_name <- paste0(obj$resource_name, "_", J$tag_name)
109110
df <- callNextMethod(obj)
110-
111+
111112
# return
112113
return(df)
113114
}

R/PathBank_metabolite_database_class.R

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#' @eval get_description('PathBank_metabolite_database')
22
#' @export
33
#' @include annotation_database_class.R BiocFileCache_database_class.R
4-
PathBank_metabolite_database <- function(version = "primary",
5-
bfc_path = NULL,
6-
resource_name = "MetMashR_PathBank",
7-
...) {
4+
PathBank_metabolite_database <- function(
5+
version = "primary",
6+
bfc_path = NULL,
7+
resource_name = "MetMashR_PathBank",
8+
...) {
89
# new object
910
out <- struct::new_struct(
1011
"PathBank_metabolite_database",
@@ -106,13 +107,13 @@ setMethod(
106107
)
107108
}
108109
obj$source <- db_url
109-
110+
110111
# append version to rname
111112
obj$resource_name <- paste0(obj$resource_name, "_", obj$version)
112-
113+
113114
# reuse BiocFileCache_database
114115
df <- callNextMethod(obj)
115-
116+
116117
# return
117118
return(df)
118119
}

R/annotation_bar_chart.R

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#' @eval get_description('annotation_pie_chart')
22
#' @include annotation_source_class.R
33
#' @export
4-
annotation_bar_chart <- function(factor_name,
5-
label_rotation = FALSE,
6-
label_location = "inside",
7-
label_type = "percent",
8-
legend = FALSE,
9-
...) {
4+
annotation_bar_chart <- function(
5+
factor_name,
6+
label_rotation = FALSE,
7+
label_location = "inside",
8+
label_type = "percent",
9+
legend = FALSE,
10+
...) {
1011
out <- struct::new_struct(
1112
"annotation_bar_chart",
1213
factor_name = factor_name,
@@ -16,7 +17,7 @@ annotation_bar_chart <- function(factor_name,
1617
legend = legend,
1718
...
1819
)
19-
20+
2021
return(out)
2122
}
2223

@@ -111,7 +112,7 @@ setMethod(
111112
group_by(.data[[obj$factor_name]]) %>%
112113
summarise(count = n()) %>%
113114
tidyr::complete(.data[[obj$factor_name]], fill = list(count = 0))
114-
115+
115116
# labels
116117
df$label <- ""
117118
if (obj$label_type == "percent") {
@@ -121,7 +122,7 @@ setMethod(
121122
} else if (obj$label_type == "count") {
122123
df$label <- as.character(df$count)
123124
}
124-
125+
125126
if (obj$label_rotation) {
126127
df$label <- paste0(" ", df$label, " ")
127128
} else {
@@ -131,7 +132,7 @@ setMethod(
131132
df$label <- paste0(df$label)
132133
}
133134
}
134-
135+
135136
# add newlines of spaces to offset depending on rotation
136137
if (!obj$legend) {
137138
if (obj$label_type != "none") {
@@ -143,13 +144,13 @@ setMethod(
143144
df$label <- df[[obj$factor_name]]
144145
}
145146
}
146-
147+
147148
if (!obj$label_rotation) {
148149
df$rotate <- 0
149150
} else {
150151
df$rotate <- -90
151152
}
152-
153+
153154
df$hjust <- 0.5
154155
if (obj$label_rotation) {
155156
if (obj$label_location == "inside") {
@@ -158,7 +159,7 @@ setMethod(
158159
df$hjust <- 1
159160
}
160161
}
161-
162+
162163
# plot
163164
g <- ggplot(
164165
data = df,
@@ -182,15 +183,15 @@ setMethod(
182183
structToolbox:::theme_Publication(12) +
183184
scale_fill_Publication() +
184185
theme_Publication()
185-
186+
186187
# legend
187188
if (!obj$legend) {
188189
g <- g + theme(legend.position = "none")
189190
} else {
190191
g <- g + theme(axis.text.x = element_blank())
191192
}
192-
193-
193+
194+
194195
return(g)
195196
}
196197
)

0 commit comments

Comments
 (0)