Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perl to r #189

Merged
merged 25 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
82d4489
Add tests for current read_seq_len behavior
iimog Mar 25, 2024
4b4517b
Re-implement read_seq_len in R
iimog Jun 6, 2024
7fca588
Ignore vscode dir
iimog Jun 6, 2024
23a70ca
Export S3 methods
iimog Jun 6, 2024
47bd3a2
Re-generate man
iimog Jun 6, 2024
d2f6bc8
Ignore vscode in R build
iimog Jun 6, 2024
be9d8de
S3 generic/method consistency
iimog Jun 6, 2024
997408a
Fix warnings about usage sections
iimog Jun 7, 2024
6288b46
Fix note about ellipsis not being imported
iimog Jun 7, 2024
28d51c1
Update rhub action
iimog Jun 7, 2024
750564f
Remove rtracklayer from Suggests
iimog Jun 13, 2024
33d69c9
Fix package anchor for links in aesthetics
iimog Jun 19, 2024
6db524c
Further decrease image size to fit CRAN size constraint
iimog Jun 19, 2024
2366529
Compress ext gorg.gff file
iimog Jun 19, 2024
f293ca2
Move advanced flip examples to separate vignette
iimog Jun 19, 2024
57eae4f
Ignore pkgdown cache
iimog Jun 19, 2024
44d2170
Add packages into quotes, fix spelling
iimog Jun 21, 2024
e184701
Wrap error producing code in try rather than \dontrun
iimog Jun 25, 2024
18af1ae
Fix write_gff3 and activate example with tempfile
iimog Jun 25, 2024
257a03b
Make remote read_feats example donttest instead of dontrun
iimog Jun 25, 2024
d856c5d
Remove quote for geom
iimog Jun 25, 2024
5dbeffc
Fix missing \value tags in Rd files
iimog Jun 25, 2024
bfe920f
Apply auto-formatting
iimog Jun 25, 2024
20fd831
Fix missing \value Rd-tags
iimog Jun 27, 2024
35e4227
Simplify expression
iimog Jun 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
^R-deprecated$
^data-raw$
^pkgdown$
^LICENSE.md$
^LICENSE.md$
^\.vscode$
24 changes: 12 additions & 12 deletions .github/workflows/rhub.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# R-hub's generic GitHub Actions workflow file. It's canonical location is at
# https://github.com/r-hub/rhub2/blob/v1/inst/workflow/rhub.yaml
# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml
# You can update this file to a newer version using the rhub2 package:
#
# rhub2::rhub_setup()
# rhub::rhub_setup()
#
# It is unlikely that you need to modify this file manually.

Expand Down Expand Up @@ -33,7 +33,7 @@ jobs:

steps:
# NO NEED TO CHECKOUT HERE
- uses: r-hub/rhub2/actions/rhub-setup@v1
- uses: r-hub/actions/setup@v1
with:
config: ${{ github.event.inputs.config }}
id: rhub-setup
Expand All @@ -51,16 +51,16 @@ jobs:
image: ${{ matrix.config.container }}

steps:
- uses: r-hub/rhub2/actions/rhub-checkout@v1
- uses: r-hub/rhub2/actions/rhub-platform-info@v1
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/platform-info@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/rhub2/actions/rhub-setup-deps@v1
- uses: r-hub/actions/setup-deps@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/rhub2/actions/rhub-run-check@v1
- uses: r-hub/actions/run-check@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
Expand All @@ -78,20 +78,20 @@ jobs:
steps:
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-tinytex@v2
- uses: r-hub/rhub2/actions/rhub-checkout@v1
- uses: r-hub/rhub2/actions/rhub-setup-r@v1
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/setup-r@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
- uses: r-hub/rhub2/actions/rhub-platform-info@v1
- uses: r-hub/actions/platform-info@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/rhub2/actions/rhub-setup-deps@v1
- uses: r-hub/actions/setup-deps@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
- uses: r-hub/rhub2/actions/rhub-run-check@v1
- uses: r-hub/actions/run-check@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ vignettes-manual-export/
/doc/
/Meta/
gggenomes.Rcheck
.vscode
gggenomes_*.tar.gz
vignettes/gggenomes_cache
13 changes: 6 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ Authors@R: c(
person("Markus J.", "Ankenbrand", email = "[email protected]", role = c("aut")),
person("Bart", "van Adrichem", role = c("aut")),
person("Kristina", "Haslinger", email = "[email protected]", role = c("ctb", "sad")))
Description: An extension of ggplot2 for creating complex genomic
maps. It builds on the power of ggplot2 and tidyverse adding new ggplot-style
geoms & positions and dplyr-style verbs to manipulate the underlying data. It
implements a layout concept inspired by ggraph and introduces tracks to bring
tidyness to the mess that is genomics data.
Description: An extension of 'ggplot2' for creating complex genomic
maps. It builds on the power of 'ggplot2' and 'tidyverse' adding new 'ggplot2'-style
geoms & positions and 'dplyr'-style verbs to manipulate the underlying data. It
implements a layout concept inspired by 'ggraph' and introduces tracks to bring
tidiness to the mess that is genomics data.
License: MIT + file LICENSE
URL: https://github.com/thackl/gggenomes
BugReports: https://github.com/thackl/gggenomes/issues
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
Depends:
Expand All @@ -43,7 +43,6 @@ Imports:
ellipsis
Suggests:
testthat,
rtracklayer,
ggtree,
patchwork,
Hmisc,
Expand Down
13 changes: 13 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ S3method(add_subfeats,gggenomes)
S3method(add_subfeats,gggenomes_layout)
S3method(add_sublinks,gggenomes)
S3method(add_sublinks,gggenomes_layout)
S3method(as_bounds,default)
S3method(as_bounds,numeric)
S3method(as_feats,default)
S3method(as_feats,tbl_df)
S3method(as_links,default)
Expand Down Expand Up @@ -73,6 +75,8 @@ S3method(track_ids,gggenomes)
S3method(track_ids,gggenomes_layout)
S3method(track_info,gggenomes)
S3method(track_info,gggenomes_layout)
S3method(tracks,gggenomes)
S3method(tracks,gggenomes_layout)
export("%<>%")
export("%>%")
export(GeomFeatText)
Expand Down Expand Up @@ -113,6 +117,7 @@ export(genes)
export(geom_bin_label)
export(geom_coverage)
export(geom_feat)
export(geom_feat_label)
export(geom_feat_note)
export(geom_feat_tag)
export(geom_feat_text)
Expand All @@ -122,6 +127,7 @@ export(geom_gene_note)
export(geom_gene_tag)
export(geom_gene_text)
export(geom_link)
export(geom_link_label)
export(geom_link_line)
export(geom_seq)
export(geom_seq_break)
Expand Down Expand Up @@ -160,6 +166,8 @@ export(qc)
export(qw)
export(read_alitv)
export(read_bed)
export(read_blast)
export(read_context)
export(read_fai)
export(read_feats)
export(read_gbk)
Expand All @@ -170,6 +178,7 @@ export(read_seq_len)
export(read_seqs)
export(read_subfeats)
export(read_sublinks)
export(read_vcf)
export(require_vars)
export(scale_color_variant)
export(scale_shape_variant)
Expand All @@ -191,8 +200,12 @@ export(track)
export(track_ids)
export(track_info)
export(unnest_exons)
export(vars_track)
export(width)
export(width0)
export(write_gff3)
import(dplyr)
import(ellipsis)
import(ggplot2)
import(grid)
import(rlang)
Expand Down
51 changes: 33 additions & 18 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
#' TRUE/FALSE vector
#' @param ... the two columns bewteen which values are to be swapped in
#' dplyr::select-like syntax
#' @return a tibble with conditionally swapped start and end
#' @examples
#' x <- tibble::tibble(start = c(10,100), end=c(30, 50))
#' x <- tibble::tibble(start = c(10, 100), end = c(30, 50))
#' # ensure start of a range is always smaller than the end
#' swap_if(x, start > end, start, end)
swap_if <- function(x, condition, ...){
swap_if <- function(x, condition, ...) {
i <- tidyselect::eval_select(rlang::expr(c(...)), x)
if(length(i) != 2 || length(unique(i)) != 2)
if (length(i) != 2 || length(unique(i)) != 2) {
rlang::abort("need to select exactly 2 different columns for swapping")
}
# eval condition in data context
j <- transmute(x, j = {{condition}})$j
j <- transmute(x, j = {{ condition }})$j
# swap
x[j,rev(i)] <- x[j,i]
x[j, rev(i)] <- x[j, i]
x
}

Expand All @@ -26,13 +28,15 @@ swap_if <- function(x, condition, ...){
#' @param x vector (coerced to character)
#' @param collapse character string to separate elements.
#' @keywords internal
comma <- function(x, collapse = ","){
paste(x, collapse=collapse)
#' @noRd
comma <- function(x, collapse = ",") {
paste(x, collapse = collapse)
}

#' Get path to gggenomes example files
#' @export
#' @param file name of example file
#' @return path to example file
ex <- function(file = NULL) {
if (is.null(file)) {
dir(system.file("extdata", package = "gggenomes"))
Expand All @@ -42,21 +46,23 @@ ex <- function(file = NULL) {
}

# are there any arguments in ...
has_dots <- function(env = parent.frame()){
has_dots <- function(env = parent.frame()) {
length(ellipsis__dots(env)) > 0
}

shared_names <- function(x, ...){
shared_names <- function(x, ...) {
names <- c(...)
names[names %in% names2(x)]
}

# split a vector of tuples c(a1,b2,a2,b2) into a list of two vectors
# list(a=c(a1,a2), b=c(b1,b2))
vec_unzip <- function(x, names=NULL, ignore_odd=FALSE){
if(!ignore_odd && length(x)%%2){
abort(str_glue("Won't unzip a vector of uneven length {(length(x))}\n",
"Disable error with `ignore_odd=TRUE`"))
vec_unzip <- function(x, names = NULL, ignore_odd = FALSE) {
if (!ignore_odd && length(x) %% 2) {
abort(str_glue(
"Won't unzip a vector of uneven length {(length(x))}\n",
"Disable error with `ignore_odd=TRUE`"
))
}

i <- c(TRUE, FALSE)
Expand All @@ -79,14 +85,15 @@ magrittr::`%<>%`
#'
#' @export
#' @param key variable to split by
#' @return a list of tibbles
#' @keywords internal
#' @examples
#' tibble::tibble(x=c(1,1,1,2), y=c("B", "A", "B", "B"), z="foo") %>%
#' tibble::tibble(x = c(1, 1, 1, 2), y = c("B", "A", "B", "B"), z = "foo") %>%
#' split_by(x)
split_by <- function(.data, key){
split_by <- function(.data, key) {
keys <- pull(.data, !!enquo(key))

if(length(keys) == 0) stop("no keys to index by found\n")
if (length(keys) == 0) stop("no keys to index by found\n")

l <- split(.data, keys)
l[unique(keys)]
Expand All @@ -101,7 +108,7 @@ split_by <- function(.data, key){
#' Took inspiration from
#' \href{https://stackoverflow.com/questions/520810/does-r-have-quote-like-operators-like-perls-qw}{stackoverflow/qw}
#' and \href{https://github.com/jebyrnes/multifunc/blob/master/R/qw.R}{github/Jarrett Byrnes}
#'
#'
#' @export
#' @param x A single string of elements to be split at whitespace chars.
#' @return A vector of quoted words.
Expand All @@ -120,10 +127,18 @@ qc <- function(...) sapply(match.call()[-1], deparse)
# CRAN Workaround for unexported useful tidyverse internals
# https://stackoverflow.com/questions/32535773/using-un-exported-function-from-another-r-package
ggplot2__ggname <- utils::getFromNamespace("ggname", "ggplot2")
ggplot2__rd_aesthetics <- utils::getFromNamespace("rd_aesthetics", "ggplot2")
ggplot2__rd_aesthetics <- \(x, y) utils::getFromNamespace("rd_aesthetics", "ggplot2")(x, y) |> stringr::str_replace(stringr::fixed("link[="), "link[ggplot2:")
ggplot2__scales_list <- utils::getFromNamespace("scales_list", "ggplot2")
ggplot2__guides_list <- utils::getFromNamespace("guides_list", "ggplot2")
ggplot2__make_labels <- utils::getFromNamespace("make_labels", "ggplot2")
ellipsis__dots <- utils::getFromNamespace("dots", "ellipsis")
scales__force_all <- utils::getFromNamespace("force_all", "scales")
purrr__as_mapper.default <- utils::getFromNamespace("as_mapper.default", "purrr")

# Additional fix for seamingly unused package in imports due to the workaround above
# https://forum.posit.co/t/new-r-cmd-check-note-in-r-4-2-0-for-imports-field/143153/4
#' @import ellipsis
#' @noRd
dummy <- function() {
ellipsis::safe_median
}
2 changes: 1 addition & 1 deletion R/add_tracks.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' Add different types of tracks
#'
#'
#' @name add_tracks
#' @param x object to add the tracks to (e.g. gggenomes, gggenomes_layout)
#' @param ... named data.frames, i.e. genes=gene_df, snps=snp_df
Expand Down
19 changes: 10 additions & 9 deletions R/aes.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# thomasp85/ggraph https://github.com/thomasp85/ggraph/blob/master/R/aaa.R
aes_intersect <- function(aes1, aes2) {
structure(
c(as.list(aes1), aes2[!names(aes2) %in% names(aes1)]),
class = 'uneval'
)
structure(
c(as.list(aes1), aes2[!names(aes2) %in% names(aes1)]),
class = "uneval"
)
}

aes_nudge_by_strand <- function(mapping, nudge_by_strand, keys = c("y", "yend")){
if(is.null(nudge_by_strand))
aes_nudge_by_strand <- function(mapping, nudge_by_strand, keys = c("y", "yend")) {
if (is.null(nudge_by_strand)) {
return(mapping)
}

# modify y/yend aes
is_integer(nudge_by_strand) || is_double(nudge_by_strand) ||
stop("nudge_by_strand needs to be numeric")

for(k in keys){
if(is.null(mapping[[k]])) stop("'", k, "' not defined, cannot modify")
for (k in keys) {
if (is.null(mapping[[k]])) stop("'", k, "' not defined, cannot modify")

mapping[[k]] <- rlang::parse_expr(paste0(rlang::quo_text(mapping[[k]]),'+ display_strand * ',-nudge_by_strand))
mapping[[k]] <- rlang::parse_expr(paste0(rlang::quo_text(mapping[[k]]), "+ display_strand * ", -nudge_by_strand))
}
mapping
}
Loading
Loading