Skip to content

Commit

Permalink
Update vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
jwokaty committed Jul 10, 2024
1 parent ffe2b68 commit cd864f9
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 80 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Imports:
AnVIL,
BiocFileCache,
dplyr,
GenomicRanges,
httr,
purrr,
rtracklayer,
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ exportMethods(bb_example)
exportMethods(bb_list_beds)
exportMethods(bb_list_bedsets)
exportMethods(bb_metadata)
exportMethods(bb_metadata_files)
exportMethods(bb_to_granges)
exportMethods(bb_to_grangeslist)
importFrom(AnVIL,Service)
Expand All @@ -19,6 +18,7 @@ importFrom(BiocFileCache,bfcdownload)
importFrom(BiocFileCache,bfcneedsupdate)
importFrom(BiocFileCache,bfcquery)
importFrom(BiocFileCache,bfcrpath)
importFrom(GenomicRanges,GRangesList)
importFrom(R.utils,gunzip)
importFrom(dplyr,bind_rows)
importFrom(dplyr,filter)
Expand Down
29 changes: 3 additions & 26 deletions R/bedbaser.R
Original file line number Diff line number Diff line change
Expand Up @@ -267,31 +267,6 @@ setMethod(
}
)

setGeneric(name = "bb_metadata_files",
def = function(x, id) { standardGeneric("bb_metadata_files") })

#' BED files metadata
#'
#' @param id integer() BED record identifier
#'
#' @importFrom httr content
#'
#' @return tibble() file metadata
#'
#' @examples
#' client <- BEDbase()
#' ex_bed <- bb_example(client, "bed")
#' mdf <- bb_metadata_files(client, ex_bed$id)
#'
#' @export
setMethod(
"bb_metadata_files", "BEDbase",
function(x, id) {
md <- bb_metadata(x, id, "bed", TRUE)
.format_metadata_files(md$files)
}
)

setGeneric(name = "bb_to_granges",
def = function(x, id, file_type = c("bed", "bigbed"),
extra_cols = NULL, quietly = FALSE) {
Expand Down Expand Up @@ -349,6 +324,8 @@ setGeneric(name = "bb_to_grangeslist",
#' @param id integer() BEDset record identifier
#' @param quietly logical() (defaults to FALSE) display messages
#'
#' @importFrom GenomicRanges GRangesList
#'
#' @return GRangesList() object
#'
#' @examples
Expand All @@ -360,7 +337,7 @@ setGeneric(name = "bb_to_grangeslist",
setMethod(
"bb_to_grangeslist", "BEDbase",
function(x, id, quietly = FALSE) {
beds <- bb_beds_in_bedset(client, id)
beds <- bb_beds_in_bedset(x, id)
gros <- list()
for (id in beds$id) {
gro <- bb_to_granges(x, id, "bed", quietly = quietly)
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
#' @examples
#' client <- BEDbase()
#' ex_bed <- bb_example(client, "bed")
#' md <- bb_metadata(client, ex_bed$id, "bed", TRUE).
#' md <- bb_metadata(client, ex_bed$id, "bed", TRUE)
#' file_path <- .get_file_path(md$files$bed_file$access_methods[[1]]$access_url$url,
#' "bed")
#' .bed_file_to_granges(file_path, bed_type, bed_format)
Expand Down
23 changes: 0 additions & 23 deletions man/bb_metadata_files-BEDbase-method.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion man/dot-bed_file_to_granges.Rd

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

Binary file removed tests/testthat/.test-bedbaser.R.swp
Binary file not shown.
70 changes: 42 additions & 28 deletions vignettes/bedbaser.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -92,45 +92,59 @@ bb_beds_in_bedset(client, "excluderanges")

### Search for a BED file by keyword

Search for BED files by keywords:
Search for BED files by keywords. `bb_bed_text_search()` returns all BED files
scored against a query.

```{r bb_search, eval=FALSE}
# Currently not working correctly
results <- bb_search(client, "hg13")
results
bb_bed_text_search(client, "hg13", limit = 10)
```

## Import a BED into a GRanges object

`bb_to_granges` creates a GRanges object from a BED record identifier. It uses
`rtracklayer` to import the BED file. When column names are not known for BEDX+Y
formats, a name is given indicating its position in the BED file.
`bb_to_granges` downloads and imports a BED file into `rtracklayer` to
create a GRanges object when given a BED record identifier.

Note: Still in development, working for broadPeak, narrowPeak, and BEDX+0
For BEDX+Y formats, a named list with column types may be passed through
`extra_cols` if the column name and type are known. Otherwise, `bb_to_granges`
attempts to guess the types and assigns column names. `bb_to_granges` assigns
the proper name and types for broad peak and narrow peak files.

`bb_to_granges` also attempts to pass the genome to `rtracklayer`

```{r bb_to_granges}
rec_id1 <- "bbad85f21962bb8d972444f7f9a3a932"
bed1 <- bb_metadata(client, rec_id1, rec_type = "bed")
print(paste(bed1$name, "is in", bed1$bed_type, "format."))
obj1 <- bb_to_granges(client, rec_id1, file_type="bed", quietly = TRUE)
obj1
# The following imports a BED4+1. Since we don't know the last column, we take
# the column name and type from reading the table, which is V5.
bed2 <- bb_metadata(client, example_bed$id, rec_type = "bed")
print(paste(bed2$name, "is in", bed2$bed_type, "format."))
obj2 <- bb_to_granges(client, example_bed$id, file_type="bed", quietly = TRUE)
obj2
# This is the same as
# file_path <- "/home/meatbag/.cache/R/bedbaser/5611ae9d790f_04c46b96264ef40bca93f03b10345da5.bed"
# import.bed(file_path, extraCols = c(V5 = numeric))
```x`
ex_bed <- bb_example(client, "bed")
ex_bed$bed_type
ex_bed$genome_alias
bb_to_granges(client, ex_bed$id, "bed")
ex_bed <- bb_example(client, "bed")
ex_bed$bed_type
bb_to_granges(client, ex_bed$id, "bed", extra_cols = c("testing" = "character"))
id <- "bbad85f21962bb8d972444f7f9a3a932"
md <- bb_metadata(client, id, "bed", TRUE)
md$bed_format
md$bed_type
bb_to_granges(client, id, "bed")
```

`bb_to_granges` can also import big BED files.

```{r bb_to_granges_big_bed}
ex_bed <- bb_example(client, "bed")
bb_to_granges(client, ex_bed$id, "bigbed")
```
# Import a BEDset into a GRangesList

`bb_to_grangeslist` creates GRangesList object given a BEDset record identifier.

```{r bb_to_grangeslist}
id <- "lola_hg38_ucsc_features"
bb_to_grangeslist(client, id)
```

## SessionInfo()

```{r sessionInfo}
sessionInfo()
```
Notes: For metadata in R, maybe create a tibble from some reasonable level of untested data, then demo use of tidy::unnest_wider() / unnest_longer(), GRanges as plyranges?

Can you specify the column names interactively?
```

0 comments on commit cd864f9

Please sign in to comment.