Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 25 additions & 4 deletions R/breakpointGraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ bp_count <- function(p_extended){
sum(abs(diff(p_extended)) != 1 )
}

#' Number of Cycles
#' Number of Non-Trivial Cycles
#'
#' This function computes the number of cycles in a breakpoint graph.
#' This function computes the number of **non-trivial** cycles in a breakpoint graph.
#' Non-trivial cycles are cycles with more than 2 vertices, whereas trivial cycles are cycles with 2 vertices that represent common adjacencies.
#'
#' @param g The breakpoint graph.
#'
Expand All @@ -136,10 +137,30 @@ bp_count <- function(p_extended){
#'
#' @family Breakpoint graph functions
#'
cycle_count <- function(g){
cycle_nontrivial_count <- function(g){
sum(components(g)$csize > 1)
}

#' Number of Cycles
#'
#' This function computes the number of cycles (trivial and non-trivial) in a breakpoint graph.
#' Non-trivial cycles are cycles with more than 2 vertices, whereas trivial cycles are cycles with 2 vertices that represent common adjacencies.
#'
#' @param g The breakpoint graph.
#'
#' @return The number of cycles in a breakpoint graph.
#'
#' @importFrom igraph components
#'
#' @author Priscila Biller
#'
#' @family Breakpoint graph functions
#'
cycle_count <- function(g){
isolated_vertices <- sum(degree(g) == 0)
cycle_nontrivial_count(g) + isolated_vertices/2
}

#' Connected components
#'
#' Connected components of the breakpoint graph.
Expand Down Expand Up @@ -542,7 +563,7 @@ is_fortress <- function(superhurdles){
#' @return A list containing the following properties of the breakpoint graph:
#' 1. `N` : the total number of places where a breakpoint could occur (which is the same as the `number_aligned_blocks + 1`);
#' 2. `nbBreakpoints` : the total number of breakpoints in the extended permutation;
#' 3. `nbCycles` : the total number of cycles in the breakpoint graph.
#' 3. `nbCycles` : the total number of cycles in the breakpoint graph (trivial and non-trivial cycles).
#'
#' @references Hannenhalli, Sridhar, and Pavel A. Pevzner. "Transforming cabbage into turnip: polynomial algorithm for sorting signed permutations by reversals." Journal of the ACM (JACM) 46.1 (1999): 1-27.
#'
Expand Down
2 changes: 1 addition & 1 deletion R/inversionDistance.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ inversionDistance <- function(x){
hurdles <- hurdles_count(bp_graph, p_extended)
superhurdles <- superhurdles_count(hurdles, bp_graph, p_extended)

bp_count(p_extended) - cycle_count(bp_graph) + sum(hurdles$hurdle) + is_fortress(superhurdles)
bp_count(p_extended) - cycle_nontrivial_count(bp_graph) + sum(hurdles$hurdle) + is_fortress(superhurdles)

}
1 change: 1 addition & 0 deletions man/bp_count.Rd

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

3 changes: 2 additions & 1 deletion man/breakpointGraphProperties.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/breakpoint_graph.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/components_graph.Rd

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

6 changes: 4 additions & 2 deletions man/cycle_count.Rd

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

35 changes: 35 additions & 0 deletions man/cycle_nontrivial_count.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/extendedPermutation.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/hurdles_count.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/is_fortress.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/is_interleaving.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/superhurdles_count.Rd

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

Loading