Skip to content

Commit

Permalink
bridgeRegions maps unaligned regions flanked by colinear regions.
Browse files Browse the repository at this point in the history
Fixes #13
  • Loading branch information
charles-plessy committed Feb 25, 2022
1 parent e01dab6 commit 14d3856
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Collate:
'bp_coverage.R'
'bp_heatmap.R'
'bp_pair_analysis.R'
'bridgeRegions.R'
'chain_contigs.R'
'cleanGaps.R'
'zipWithNext.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(as)
export(bp_coverage)
export(bp_heatmap)
export(bp_pair_analysis)
export(bridgeRegions)
export(chain_contigs)
export(cleanGaps)
export(coalesce_contigs)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
will call `getSeq()` automatically.
* New "mid" option to the `direction` argument of `get_bps()`, to output
breakpoints at mid-distance between ranges.
* New `bridgeRegions()` function that maps unaligned regions of the _target_ to
the _query_ genome when they are flanked by colinear regions.

## Backwards-incompatible changes

Expand Down
53 changes: 53 additions & 0 deletions R/bridgeRegions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#' Bridge regions
#'
#' Maps unaligned regions of the _target_ to the _query_ genome when they are
#' flanked by colinear regions.
#'
#' @note Because some aligned regions can be directly adjacent (no gaps), the
#' returned `GBreaks` object may contain ranges of width zero, where the _start_
#' coordinate is 1 nucleotide higher than the _end_ coordinate.
#'
#' @references Bridge regions have also been called \dQuote{simultaneous gaps}
#' in the comparison of the mouse and human genomes by Kent WJ, Baertsch R,
#' Hinrichs A, Miller W, Haussler D. (_Evolution's cauldron: duplication,
#' deletion, and rearrangement in the mouse and human genomes._ Proc Natl Acad
#' Sci U S A. 2003;100(20):11484-11489. doi:10.1073/pnas.1932072100)
#'
#' @param gb A [`GBreaks`] object.
#'
#' @return Returns a new `GBreaks` object of shorter length.
#'
#' @family Colinearity functions
#' @family modifier functions
#'
#' @author Charles Plessy
#'
#' @examples
#' exampleColinear5
#' bridgeRegions(exampleColinear5)
#'
#' # Note the zero-width ranges when aligned regions are directly adjacent.
#' exampleColinear3
#' bridgeRegions(exampleColinear3)
#'
#' @export

bridgeRegions <- function(gb) {
# Collect colinear regions and discard the rest
colinearRegions <- filterColinearRegions(flagColinearAlignments(gb), rename = FALSE)
# Turn the runs of [(TRUE)n, FALSE]n into indices identifying each colinear region
idx <- c(0, head(cumsum(!colinearRegions$colinear), -1))
# Split into a GRangesList
gbl <- split(colinearRegions, idx)
# Collect gap ranges in the target and query genomes of each colinear regions.
br <- endoapply(gbl, \(gb) {
# Check strand
onMinus <- all(strand(gb) == "-")
# Need to subtract 1 temporarly because some ranges are adjacent (no gap).
GBreaks(target = cleanGaps(gb - 1) -1,
query = cleanGaps(gb$query -1) -1 |> sort(decreasing = onMinus))
}) |> unlist()
# Remove names and return
names(br) <- NULL
br
}
1 change: 1 addition & 0 deletions man/GOC.Rd

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

62 changes: 62 additions & 0 deletions man/bridgeRegions.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/chain_contigs.Rd

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

2 changes: 2 additions & 0 deletions man/coalesce_contigs.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/dist2next.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/filterColinearRegions.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/flagColinearAlignments.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/flagPairs.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/forceSeqLengths.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/guessSeqLengths.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/mergeSeqLevels.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/reverse.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/swap.Rd

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

0 comments on commit 14d3856

Please sign in to comment.