-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prepare release v0.6.8 See merge request tron/bnt_neoants/splice2neo!126
- Loading branch information
Showing
16 changed files
with
6,159 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
|
||
#' LiftOver junction IDs using the liftOver tool | ||
#' | ||
#' This can be used to liftOver junctions to personalized genome coordinates. | ||
#' | ||
#' @param junc_df a data.frame with at least one column `junc_id` containing junction IDs | ||
#' @param chain_file path to a chain file for the UCSC liftOver tool. See also \code{\link[rtracklayer]{liftOver}} | ||
#' @return a data.frame like the input `junc_df` with the following additional columns: | ||
#' - `junc_id_lifted_is_unique` a logical vector indicating if the liftOver was successful and unique (1-to-1 correspondence). | ||
#' - `junc_id_lifted_collapsed` a character vector with the lifted junction IDs. | ||
#' Multiple IDs are separated by `|`. | ||
#' NA represent junc_ids that could not be lifted. | ||
#' - `junc_id_lifted` a character vector with a unique lifted junction IDs. | ||
#' Potentially multiple lifted IDs are combined by the minmal start and maximal | ||
#' end coordinate. NA represent junc_ids that could not be lifted. | ||
#' | ||
#' @examples | ||
#' | ||
#' chain_file = system.file(package="liftOver", "extdata", "hg38ToHg19.over.chain") | ||
#' junc_df <- toy_junc_df | ||
#' liftover_junc_id(junc_df, chain_file) | ||
#' | ||
#'@export | ||
liftover_junc_id <- function(junc_df, chain_file){ | ||
|
||
|
||
# convert junc_id into GenomicRanges object | ||
gr <- junc_to_gr(junc_df$junc_id) | ||
|
||
# read chain file | ||
chain <- rtracklayer::import.chain(chain_file) | ||
|
||
# Lift over junc ranges to genomic position in the personalized genome | ||
junc_id_lifted_grl <- rtracklayer::liftOver(gr, chain) | ||
|
||
junc_df %>% | ||
dplyr::mutate( | ||
|
||
# add lifted junctions ranges as a list | ||
junc_id_lifted_lst = as.list(junc_id_lifted_grl), | ||
|
||
# check if liftOver was successful and unique | ||
junc_id_lifted_is_unique = purrr::map_lgl(junc_id_lifted_lst, ~ length(.x) == 1), | ||
|
||
# covert back to junc_id and collapse multiple IDs with `|`, and replace empty junc_id with NA | ||
junc_id_lifted_collapsed = junc_id_lifted_lst %>% | ||
purrr::map(as.character) %>% | ||
purrr::map_chr(stringr::str_c, collapse = "|") %>% | ||
dplyr::na_if(""), | ||
|
||
# build unique lifted junctions by minimal start and maximal end | ||
# coordinate of potentially multiple lifted junction ranges | ||
junc_id_lifted = junc_id_lifted_lst %>% | ||
|
||
# take min start and max end across potentially multiple junctions | ||
purrr::map(base::range) %>% | ||
|
||
# convert to junc_id and replace empty entries with NA | ||
purrr::map(as.character) %>% | ||
purrr::map_if(is_empty, ~ NA_character_) %>% | ||
unlist() | ||
|
||
) %>% | ||
|
||
# remove temporary column | ||
dplyr::select(-junc_id_lifted_lst) | ||
|
||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
test_that("liftover_junc_id works on toy example data", { | ||
|
||
chain_file = system.file(package="liftOver", "extdata", "hg38ToHg19.over.chain") | ||
|
||
junc_df <- toy_junc_df | ||
|
||
junc_df_lifted <- liftover_junc_id(junc_df, chain_file) | ||
|
||
expect_equal(nrow(junc_df_lifted), nrow(junc_df)) | ||
expect_true(all(c("junc_id_lifted_is_unique", "junc_id_lifted") %in% names(junc_df_lifted))) | ||
|
||
}) | ||
|
||
|
||
|
||
test_that("liftover_junc_id works with non-unique mappings", { | ||
|
||
chain_file = system.file(package="liftOver", "extdata", "hg38ToHg19.over.chain") | ||
|
||
junc_df <- toy_junc_df %>% | ||
head(3) %>% | ||
add_row(junc_id = "chr2:10000000-10050000:-") %>% | ||
add_row(junc_id = "chr7:123-456:+") | ||
|
||
junc_df_lifted <- liftover_junc_id(junc_df, chain_file) | ||
|
||
expect_equal(nrow(junc_df_lifted), nrow(junc_df)) | ||
expect_false(all(junc_df_lifted$junc_id_lifted_is_unique)) | ||
expect_true(all(junc_df_lifted$junc_id_lifted_is_unique[1:3])) | ||
expect_true(any(is.na(junc_df_lifted$junc_id_lifted))) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters