Computes the minimal number of inversions required to sort a signed permutation using the Hannenhalli and Pevzner algorithm.
Arguments
- x
Either a GBreaks object or a signed permutation vector. If
x
is a GBreaks object, a permutation vector will be extracted usingpermutationVector
.
Details
This function uses several internal helper functions (e.g., extendedPermutation
,
breakpoint_graph
, hurdles_count
, superhurdles_count
, and others) to
compute properties of the breakpoint graph and identify cycles, hurdles and superhurdles.
It also depends on permutationVector()
, which is defined in another .R file.
This algorithm was designed to work in a single, linear chromosome alignment. Although the function still works if the GBreaks object involves more than one chromosome, the returned value for the minimal number of inversions will imply in non-usual inversions if different chromosomes have orthologous regions.
See also
permutationVector
for generating the permutation vector.
Examples
if (FALSE) { # \dontrun{
# Example using a permutation vector directly
# Suppose we want to sort the permutation p = c(1, 3, -2, 4)
inversionDistance(c(1, 3, -2, 4))
# Example using a GBreaks object
example <- GRanges(c("chrA:100-190", "chrA:200-290", "chrA:300-390", "chrA:400-490", "chrA:500-590", "chrA:600-690"))
strand(example) <- c( "+", "-", "-", "-", "+", "+" )
example$query <- GRanges(c("chrA:100-190", "chrA:300-390", "chrA:200-290", "chrA:400-490", "chrA:600-690", "chrA:500-590"))
gb_example <- GBreaks(example)
inversionDistance(gb_example)} # }