Skip to content

Commit

Permalink
tag internals and clean up function reference some more, resolves #25
Browse files Browse the repository at this point in the history
  • Loading branch information
thackl committed Feb 1, 2021
1 parent bd6c319 commit ed441ad
Show file tree
Hide file tree
Showing 33 changed files with 56 additions and 80 deletions.
5 changes: 0 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by roxygen2: do not edit by hand

S3method(activate,tbl_genome_layout)
S3method(add_clusters,gggenomes)
S3method(add_clusters,gggenomes_layout)
S3method(add_feats,gggenomes)
Expand Down Expand Up @@ -81,8 +80,6 @@ export(PositionPile)
export(PositionSixframe)
export(PositionStrand)
export(PositionStrandpile)
export(activate)
export(active)
export(add_clusters)
export(add_feats)
export(add_links)
Expand Down Expand Up @@ -190,7 +187,5 @@ importFrom(jsonlite,fromJSON)
importFrom(magrittr,"%<>%")
importFrom(magrittr,"%>%")
importFrom(readr,read_tsv)
importFrom(rlang,enquo)
importFrom(rlang,quo_text)
importFrom(tidyr,unnest)
importFrom(tidyr,unnest_wider)
1 change: 1 addition & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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)
}
Expand Down
24 changes: 0 additions & 24 deletions R/activate.R

This file was deleted.

4 changes: 3 additions & 1 deletion R/coords.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' The virtual x-start of the full length seq in the plot
#'
#' Together with the seq strand, this is sufficient to project feats
#' @keywords internal
anchor <- function(x, start, strand){
x - (start-1) * strand_int(strand)
}
Expand All @@ -9,13 +10,14 @@ anchor <- function(x, start, strand){
#'
#' @param seq_anchor the virtual x-start of the full length sequence in plot
#' space
#' @keywords internal
x <- function(start, end, strand, seq_x, seq_start, seq_strand){
a <- anchor(seq_x, seq_start, seq_strand)
b <- if_reverse(strand, end, start-1)
a + b * strand_int(seq_strand)
}

#' @rdname x
#' @keywords internal
xend <- function(start, end, strand, seq_x, seq_start, seq_strand){
a <- anchor(seq_x, seq_start, seq_strand)
b <- if_reverse(strand, start-1, end)#, end + width(start,end))
Expand Down
2 changes: 2 additions & 0 deletions R/feats.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#' @param ... passed on to `layout_seqs()`
#' @return a tbl_df with plot coordinates
#' @export
#' @keywords internal
as_feats <- function(x, seqs, ..., everything=TRUE){
UseMethod("as_feats")
}
Expand Down Expand Up @@ -66,6 +67,7 @@ as_feats.tbl_df <- function(x, seqs, ..., everything=TRUE){
#' example after focusing in on a subregion. Choices are to "drop" them, "keep"
#' them or "trim" them to the subregion boundaries.
#' @param ... not used
#' @keywords internal
layout_feats <- function(x, seqs, keep="strand",
marginal=c("trim", "drop", "keep"), ...){
marginal <- match.arg(marginal)
Expand Down
8 changes: 5 additions & 3 deletions R/gggenomes.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ gggenomes <- function(seqs=NULL, genes=NULL, feats=NULL, links=NULL, ...,
#' ggplot.default tries to `fortify(data)` and we don't want that here
#'
#' @export
#' @keywords internal
ggplot.gggenomes_layout <- function(data, mapping = aes(), ...,
environment = parent.frame()) {
if (!missing(mapping) && !inherits(mapping, "uneval")) {
Expand Down Expand Up @@ -134,15 +135,15 @@ layout_genomes <- function(seqs=NULL, genes=NULL, feats=NULL, links=NULL,
seqs <- mutate(seqs, bin_id = {{ infer_bin_id }})
}else{
if(is.null(feats) & is.null(links))
stop("Need at least one of: seqs, genes, feats or links")
abort("Need at least one of: seqs, genes, feats or links")

# infer dummy seqs
if(!is.null(feats)){
write("No seqs provided, inferring seqs from feats", stderr())
inform("No seqs provided, inferring seqs from feats")
seqs <- infer_seqs_from_feats(feats[[1]], {{infer_bin_id}}, {{infer_start}},
{{infer_end}}, {{infer_length}})
}else if(!is.null(links)){
write("No seqs or feats provided, inferring seqs from links", stderr())
inform("No seqs or feats provided, inferring seqs from links")
seqs <- infer_seqs_from_links(links[[1]], {{infer_bin_id}}, {{infer_start}},
{{infer_end}}, {{infer_length}})
}
Expand All @@ -165,6 +166,7 @@ layout_genomes <- function(seqs=NULL, genes=NULL, feats=NULL, links=NULL,
#' and error because dim(gggenome_layout) is undefined. Return dim of primary
#' table instead
#' @export
#' @keywords internal
dim.gggenomes_layout <- function(x) dim(get_seqs(x))

#' @export
Expand Down
2 changes: 2 additions & 0 deletions R/links.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#' @param x link data convertible to a link layout
#' @inheritParams as_feats
#' @export
#' @keywords internal
as_links <- function(x, seqs, ..., everything=TRUE){
UseMethod("as_links")
}
Expand Down Expand Up @@ -64,6 +65,7 @@ as_links.tbl_df <- function(x, seqs, ..., everything=TRUE){
#'
#' @inheritParams as_links
#' @param ... not used
#' @keywords internal
layout_links <- function(x, seqs, keep="strand", adjacent_only = TRUE,
marginal=c("trim", "drop", "keep"), ...){
marginal <- match.arg(marginal)
Expand Down
4 changes: 3 additions & 1 deletion R/pull_tracks.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ pull_track.gggenomes_layout <- function(.x, .track_id=1, ..., .track_type=NULL,
#' giving the position from the left/right.
#' @param track_type restrict to these types of tracks - affects position-based
#' selection
#' @param ignore_pos names of tracks to ignore when selecting by position.
#' @return The selected track_id as an unnamed string
vars_track <- function(x, track_id, track_type = c("seqs", "feats", "links"),
ignore_pos = NULL){
Expand Down Expand Up @@ -246,7 +247,8 @@ vars_track <- function(x, track_id, track_type = c("seqs", "feats", "links"),
})
}

#' Error messages for `vars_track``
#' Error messages for vars_track
#' @keywords internal
vars_track_error <- function(bad_value, track_ids, ignore_pos){
if(is_function(bad_value)) bad_value <- "<function>"
if(is.numeric(bad_value)) bad_value <- as.character(bad_value)
Expand Down
3 changes: 3 additions & 0 deletions R/seqs.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#'
#' as_seqs(chr)
#' @export
#' @keywords internal
as_seqs <- function(x, ...){
UseMethod("as_seqs")
}
Expand Down Expand Up @@ -164,6 +165,8 @@ get_seqs.gggenomes <- function(x){
get_seqs.gggenomes_layout <- function(x){
x$seqs[["seqs"]]
}

#' @rdname get_seqs
#' @export
set_seqs <- function(x, value){
UseMethod("set_seqs")
Expand Down
1 change: 1 addition & 0 deletions R/subfeats.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ add_subfeat_tracks <- function(x, parent_track_id, tracks, transform){
#' annotations, e.g. genes and protein blast results.
#' @return a tbl_df with plot coordinates
#' @export
#' @keywords internal
as_subfeats <- function(x, seqs, feats, ..., everything=TRUE){
UseMethod("as_subfeats")
}
Expand Down
1 change: 1 addition & 0 deletions R/sublinks.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ add_sublink_tracks <- function(x, parent_track_id, tracks, transform){
#' annotations, e.g. genes and protein blast results.
#' @return a tbl_df with plot coordinates
#' @export
#' @keywords internal
as_sublinks <- function(x, seqs, feats, ..., everything=TRUE){
UseMethod("as_sublinks")
}
Expand Down
1 change: 1 addition & 0 deletions R/tracks.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ tracks.gggenomes_layout <- function(x, track_type = c("seqs", "feats", "links"))


#' Convert a list of tibbles into tracks with magic
#' @keywords internal
as_tracks <- function(tracks, tracks_exprs, reserved_ids=NULL){
# capture for df naming before first eval of tracks
track_name <- as_label(enexpr(tracks))
Expand Down
6 changes: 4 additions & 2 deletions R/vars.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ require_vars <- function(x, vars, warn_only=FALSE){

if(length(missing_vars) > 0)
if(warn_only)
warning("Required column(s) missing: ", paste(missing_vars, collapse=","))
warn(c("Required column(s) missing: ", str_glue("{missing_vars}")))
else
stop("Required column(s) missing: ", paste(missing_vars, collapse=","))
abort(c("Required column(s) missing: ", str_glue("{missing_vars}")))
x
}

Expand All @@ -45,6 +45,7 @@ require_vars <- function(x, vars, warn_only=FALSE){
#' @param any if TRUE not all but at least one variable has to exists
#' @return TRUE/FALSE
#' @export
#' @keywords internal
has_vars <- function(x, vars, any=FALSE){
if(any)
any(vars %in% names(x))
Expand All @@ -56,6 +57,7 @@ has_vars <- function(x, vars, any=FALSE){
#'
#' equivalent to base::match.arg, but returns all choices on arg=NULL if
#' several.ok=TRUE
#' @keywords internal
match_arg <- function (arg, choices, several.ok = FALSE){
if (missing(choices)) {
formal.args <- formals(sys.function(sysP <- sys.parent()))
Expand Down
32 changes: 7 additions & 25 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ reference:
- geom_gene
- geom_feat
- geom_link
- ends_with(c("_text", "_tag", "_note"))
- ends_with("_text|_tag|_note")
- starts_with("geom")
- starts_with("position_")
- starts_with("use_")
- starts_with("theme_")
- title: "Manipulate plot & data"
- contents:
- pick
Expand All @@ -37,37 +37,21 @@ reference:
- file_formats
- def_names
- def_types
- starts_with("write")
- title: "Under the hood"
desc: >
Functions that power gggenomes under the hood. Useful for developers and power-users.
- contents:
- layout
- layout_feats
- layout_links
- require_vars
- get_seqs
- starts_with("as_")
- starts_with("track")
- require_vars
- vars_track
- swap_if
- in_range
- anchor
- width
- x
- track_ids
- track_types
- vars_track
- activate
- comma
- dim.gggenomes_layout
- ggplot.gggenomes_layout
- has_vars
- introduce
- match_arg
- theme_gggenomes_clean
- track_nrows
- track_type
- vars_track_error
- write_gff3
- title: "Handling files"
- title: "Handle files"
- contents:
- ext_to_format
- file_exts
Expand All @@ -78,8 +62,6 @@ reference:
figures:
fig.width: 10
fig.height: 5
# dev.args:
# type: "cairo"
template:
params:
bootswatch: cosmo
14 changes: 0 additions & 14 deletions man/activate.Rd

This file was deleted.

1 change: 1 addition & 0 deletions man/anchor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/as_feats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/as_links.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/as_seqs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/as_subfeats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/as_sublinks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/as_tracks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/comma.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/dim.gggenomes_layout.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/get_seqs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/ggplot.gggenomes_layout.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/has_vars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/layout_feats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/layout_links.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/match_arg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ed441ad

Please sign in to comment.