Skip to content

Commit 3def7e2

Browse files
Refactor: remove dead code, relocate functions, migrate globals to .data$
- Remove unused interpolate_color() and first_child variable from plot-structure.R - Move compute_ror() and compute_odds_ratios() to odds-ratios.R - Move nucleotide_colors() and region_colors() to palettes.R - Extract build_modomics_entries() helper to deduplicate modomics.R - Fix roxygen tag ordering and add missing @examples - Fix vignette cross-reference to rewiring article - Fix pkgdown double-listing of plot functions - Convert expect_error/expect_warning to expect_snapshot in tests - Add tests for read_fasta, read_mod_annotations, compute_ror, read_pipeline_results - Migrate all bare column names to .data$ pronoun or quoted strings - Delete R/globals.R (162 lines of globalVariables no longer needed) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 17564f5 commit 3def7e2

32 files changed

+587
-653
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export(structure_trnas)
6868
export(tabulate_deseq)
6969
export(tidy_deseq_results)
7070
export(trna_regions)
71-
import(Biostrings)
7271
import(S4Vectors)
7372
import(SummarizedExperiment)
7473
import(ggplot2)

R/clover-se.R

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,31 +110,33 @@ create_clover <- function(
110110

111111
#' Read FASTA reference
112112
#'
113-
#' @examples
114-
#' fa <- clover_example("ecoli/trna_only.fa.gz")
115-
#' read_fasta(fa)
116-
#'
117-
#' @param fa path to fasta file
113+
#' @param fa Path to a FASTA file.
118114
#'
119115
#' @return A [Biostrings::DNAStringSet].
120-
#' @import Biostrings
116+
#'
121117
#' @export
118+
#'
119+
#' @examples
120+
#' fa <- clover_example("ecoli/trna_only.fa.gz")
121+
#' read_fasta(fa)
122122
read_fasta <- function(fa) {
123123
Biostrings::readDNAStringSet(fa)
124124
}
125125

126126
#' Read modifications file
127127
#'
128-
#' TSV file with 4 columns:
128+
#' Read a TSV file with 4 columns: `ref`, `pos`, `mod_full`, `mod1`.
129129
#'
130-
#' 1. `ref`
131-
#' 2. `pos`
132-
#' 3. `mod_full`
133-
#' 4. `mod1`
130+
#' @param mods Path to a modifications TSV file.
134131
#'
135-
#' @param mods path to modifications file
136132
#' @return A tibble.
133+
#'
137134
#' @export
135+
#'
136+
#' @examples
137+
#' \dontrun{
138+
#' read_mod_annotations("modifications.tsv")
139+
#' }
138140
read_mod_annotations <- function(mods) {
139141
readr::read_tsv(mods, show_col_types = FALSE)
140142
}

R/deseq.R

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ abundance_count_matrix <- function(charging_data, min_count = 10) {
2727
abundance <- charging_data |>
2828
dplyr::mutate(
2929
total_count = as.integer(
30-
round(counts_charged + counts_uncharged)
30+
round(.data$counts_charged + .data$counts_uncharged)
3131
)
3232
) |>
33-
dplyr::select(ref, sample_id, total_count) |>
33+
dplyr::select("ref", "sample_id", "total_count") |>
3434
tidyr::pivot_wider(
35-
names_from = sample_id,
36-
values_from = total_count,
35+
names_from = "sample_id",
36+
values_from = "total_count",
3737
values_fill = 0L
3838
)
3939

@@ -72,22 +72,22 @@ abundance_count_matrix <- function(charging_data, min_count = 10) {
7272
charging_count_matrix <- function(charging_data, min_count = 10) {
7373
long <- charging_data |>
7474
dplyr::mutate(
75-
counts_charged = as.integer(round(counts_charged)),
76-
counts_uncharged = as.integer(round(counts_uncharged))
75+
counts_charged = as.integer(round(.data$counts_charged)),
76+
counts_uncharged = as.integer(round(.data$counts_uncharged))
7777
) |>
7878
tidyr::pivot_longer(
79-
cols = c(counts_charged, counts_uncharged),
79+
cols = dplyr::all_of(c("counts_charged", "counts_uncharged")),
8080
names_to = "charge_status",
8181
values_to = "count"
8282
) |>
8383
dplyr::mutate(
84-
charge_status = sub("^counts_", "", charge_status),
85-
col_name = paste0(sample_id, "_", charge_status)
84+
charge_status = sub("^counts_", "", .data$charge_status),
85+
col_name = paste0(.data$sample_id, "_", .data$charge_status)
8686
) |>
87-
dplyr::select(ref, col_name, count) |>
87+
dplyr::select("ref", "col_name", "count") |>
8888
tidyr::pivot_wider(
89-
names_from = col_name,
90-
values_from = count,
89+
names_from = "col_name",
90+
values_from = "count",
9191
values_fill = 0L
9292
)
9393

R/globals.R

Lines changed: 0 additions & 161 deletions
This file was deleted.

R/identity.R

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,18 @@ identity_elements <- function(
108108

109109
result <- result |>
110110
dplyr::select(
111-
amino_acid,
112-
domain,
113-
sprinzl_pos,
114-
nucleotide,
115-
region,
116-
type,
117-
strength,
118-
pair_pos,
119-
pair_type,
120-
against_aars,
121-
universal,
122-
description
111+
"amino_acid",
112+
"domain",
113+
"sprinzl_pos",
114+
"nucleotide",
115+
"region",
116+
"type",
117+
"strength",
118+
"pair_pos",
119+
"pair_type",
120+
"against_aars",
121+
"universal",
122+
"description"
123123
)
124124

125125
if (!is.null(amino_acid)) {
@@ -487,7 +487,7 @@ plot_identity_panel <- function(
487487
find_sprinzl_id <- function(trna, sprinzl_coords) {
488488
parts <- strsplit(trna, "-")[[1]]
489489
if (length(parts) >= 3) {
490-
parts[3] <- gsub("T", "U", parts[3])
490+
parts[3] <- chartr("T", "U", parts[3])
491491
}
492492
rna_name <- paste(parts, collapse = "-")
493493
pattern <- paste0("^nuc-", rna_name, "-")

R/modomics.R

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,7 @@ modomics_mods <- function(fasta, organism, min_identity = 0.7) {
6464
"Processing {nrow(modomics_seqs)} MODOMICS sequence{?s}."
6565
)
6666

67-
modomics_entries <- purrr::map(
68-
seq_len(nrow(modomics_seqs)),
69-
function(i) {
70-
mods <- extract_mod_positions(
71-
modomics_seqs$seq[i],
72-
mod_dict
73-
)
74-
plain_seq <- strip_modifications(
75-
modomics_seqs$seq[i],
76-
mod_dict
77-
)
78-
list(
79-
subtype = modomics_seqs$subtype[i],
80-
anticodon = modomics_seqs$anticodon[i],
81-
mods = mods,
82-
plain_seq = plain_seq
83-
)
84-
}
85-
)
67+
modomics_entries <- build_modomics_entries(modomics_seqs, mod_dict)
8668

8769
cli::cli_inform(
8870
"Matching MODOMICS sequences to reference FASTA."
@@ -123,6 +105,28 @@ modomics_organisms <- function() {
123105
gsub("_", " ", tools::file_path_sans_ext(rds_files))
124106
}
125107

108+
build_modomics_entries <- function(modomics_seqs, mod_dict) {
109+
purrr::map(
110+
seq_len(nrow(modomics_seqs)),
111+
function(i) {
112+
mods <- extract_mod_positions(
113+
modomics_seqs$seq[i],
114+
mod_dict
115+
)
116+
plain_seq <- strip_modifications(
117+
modomics_seqs$seq[i],
118+
mod_dict
119+
)
120+
list(
121+
subtype = modomics_seqs$subtype[i],
122+
anticodon = modomics_seqs$anticodon[i],
123+
mods = mods,
124+
plain_seq = plain_seq
125+
)
126+
}
127+
)
128+
}
129+
126130
load_cached_modifications <- function() {
127131
path <- system.file(
128132
"extdata",
@@ -212,25 +216,7 @@ fetch_modomics_mods <- function(
212216
"Processing {nrow(modomics_seqs)} MODOMICS sequence{?s}."
213217
)
214218

215-
modomics_entries <- purrr::map(
216-
seq_len(nrow(modomics_seqs)),
217-
function(i) {
218-
mods <- extract_mod_positions(
219-
modomics_seqs$seq[i],
220-
mod_dict
221-
)
222-
plain_seq <- strip_modifications(
223-
modomics_seqs$seq[i],
224-
mod_dict
225-
)
226-
list(
227-
subtype = modomics_seqs$subtype[i],
228-
anticodon = modomics_seqs$anticodon[i],
229-
mods = mods,
230-
plain_seq = plain_seq
231-
)
232-
}
233-
)
219+
modomics_entries <- build_modomics_entries(modomics_seqs, mod_dict)
234220

235221
cli::cli_inform(
236222
"Matching MODOMICS sequences to reference FASTA."

0 commit comments

Comments
 (0)