baobab.bio.permutation
Class PermutationUtil

java.lang.Object
  extended by baobab.bio.permutation.PermutationUtil

public class PermutationUtil
extends java.lang.Object

The PermutationUtil class contains utility methods which deal with permutations as arrays of int

Author:
Marilia D. V. Braga

Constructor Summary
PermutationUtil()
           
 
Method Summary
static int calculateSignedReversalDistance(int[] permutation)
          Calculates the reversal distance between a given signed permutation and the identity
static int calculateSignedReversalDistance(int[] permutation, boolean isLinear)
          Calculates the reversal distance between a given signed permutation and the identity
static int calculateSignedReversalDistance(int[] origin, int[] target)
          Calculates the reversal distance between the given origin and target signed permutations
static int calculateSignedReversalDistance(int[] origin, int[] target, boolean isLinear)
          Calculates the reversal distance between the given origin and target signed permutations
static java.util.Hashtable<java.lang.String,java.lang.Integer> canonizePermutations(java.util.Vector<java.lang.String> origin, java.util.Vector<java.lang.String> target)
          Canonize the origin and the target permutations - eliminate insertions/deletions, replace each gene by a number between 1 and n (n is the number of common elements between the origin and the target permutations)
static java.util.Vector<int[]> collapse(int[] permutation, boolean isLinear)
          Collapses a permutation (eliminating the adjacencies)
static int[] collapseBk(int[] permutation, boolean isLinear)
          Collapses a permutation (eliminating the adjacencies)
static boolean containsUnorientedComponent(int[] permutation, boolean isLinear)
          Tests whether the permutation contains an unoriented component (hurdle)
static java.util.Vector<int[]> generateAllPermutations(int size)
           
static java.util.Vector<int[]> generateAllPermutations(int size, int distance, boolean isLinear)
           
static int[] getIdentityPermutation(int size)
          Generates the identity permutation of a given size
static boolean isValidPermutation(int[] permutation, boolean isLinear)
          Tests whether the permutation is valid
static int[] mapPermutation(int[] origin, int[] target)
          Maps the origin permutation, respecting a direct map between the target and the identity permutation
static int OLD_calculateSignedReversalDistance(int[] origin, int[] target, boolean isLinear)
          Calculates the reversal distance between the given origin and target signed permutations
static int[][] revertSigned(int[] permutation, int[] positions, int start, int end, boolean isLinear)
          Make a new permutation, by reverting the permutation between the specified positions
static int[] revertSigned(int[] permutation, int start, int end, boolean isLinear)
          Make a new permutation, by reverting the permutation between the specified positions
static int[] revertUnsigned(int[] permutation, int start, int end, boolean isLinear)
          Make a new permutation, by reverting the permutation between the specified positions
static int[] transpose(int[] permutation, int start, int middle, int end)
          Make a new permutation, by transposing blocks at the permutation between the specified positions
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PermutationUtil

public PermutationUtil()
Method Detail

getIdentityPermutation

public static int[] getIdentityPermutation(int size)
Generates the identity permutation of a given size

Parameters:
size - the given size
Returns:
the identity permutation as an array of int

isValidPermutation

public static boolean isValidPermutation(int[] permutation,
                                         boolean isLinear)
Tests whether the permutation is valid

Parameters:
permutation - the given permutation
Returns:
true / false

collapse

public static java.util.Vector<int[]> collapse(int[] permutation,
                                               boolean isLinear)
Collapses a permutation (eliminating the adjacencies)

Parameters:
permutation - the given permutation
isLinear -
Returns:
the collapsedPermutation

collapseBk

public static int[] collapseBk(int[] permutation,
                               boolean isLinear)
Collapses a permutation (eliminating the adjacencies)

Parameters:
permutation - the given permutation
isLinear -
Returns:
the collapsedPermutation

mapPermutation

public static int[] mapPermutation(int[] origin,
                                   int[] target)
Maps the origin permutation, respecting a direct map between the target and the identity permutation

Parameters:
origin - the origin permutation
target - the target permutation
Returns:
the mapped permutation

canonizePermutations

public static java.util.Hashtable<java.lang.String,java.lang.Integer> canonizePermutations(java.util.Vector<java.lang.String> origin,
                                                                                           java.util.Vector<java.lang.String> target)
Canonize the origin and the target permutations - eliminate insertions/deletions, replace each gene by a number between 1 and n (n is the number of common elements between the origin and the target permutations)

Parameters:
origin - the origin permutation
target - the target permutation
Returns:
the canonical permutations

revertSigned

public static int[] revertSigned(int[] permutation,
                                 int start,
                                 int end,
                                 boolean isLinear)
Make a new permutation, by reverting the permutation between the specified positions

Parameters:
start - the beginning of the reversion block
end - the end of the reversion block
Returns:
the resulting permutation, after performing the reversion

revertSigned

public static int[][] revertSigned(int[] permutation,
                                   int[] positions,
                                   int start,
                                   int end,
                                   boolean isLinear)
Make a new permutation, by reverting the permutation between the specified positions

Parameters:
start - the beginning of the reversion block
end - the end of the reversion block
Returns:
the resulting permutation, after performing the reversion

revertUnsigned

public static int[] revertUnsigned(int[] permutation,
                                   int start,
                                   int end,
                                   boolean isLinear)
Make a new permutation, by reverting the permutation between the specified positions

Parameters:
start - the beginning of the reversion block
end - the end of the reversion block
Returns:
the resulting permutation, after performing the reversion

transpose

public static int[] transpose(int[] permutation,
                              int start,
                              int middle,
                              int end)
Make a new permutation, by transposing blocks at the permutation between the specified positions

Parameters:
start - the beginning of the first block
middle - the end of the first block / beginning of the second block
end - the end of the second block
Returns:
the resulting permutation, after performing the transposition

calculateSignedReversalDistance

public static int calculateSignedReversalDistance(int[] permutation)
Calculates the reversal distance between a given signed permutation and the identity

Parameters:
permutation - the origin permutation, as an array of int
Returns:
the reversal distance

calculateSignedReversalDistance

public static int calculateSignedReversalDistance(int[] permutation,
                                                  boolean isLinear)
Calculates the reversal distance between a given signed permutation and the identity

Parameters:
permutation - the origin permutation, as an array of int
isLinear - indicates whether the permutation is linear or circular
Returns:
the reversal distance

calculateSignedReversalDistance

public static int calculateSignedReversalDistance(int[] origin,
                                                  int[] target)
Calculates the reversal distance between the given origin and target signed permutations

Parameters:
origin - the origin permutation, as an array of int
target - the target permutation, as an array of int
Returns:
the reversal distance

calculateSignedReversalDistance

public static int calculateSignedReversalDistance(int[] origin,
                                                  int[] target,
                                                  boolean isLinear)
Calculates the reversal distance between the given origin and target signed permutations

Parameters:
origin - the origin permutation, as an array of int
target - the target permutation, as an array of int
isLinear - indicates whether the permutation is linear or circular
Returns:
the reversal distance

containsUnorientedComponent

public static boolean containsUnorientedComponent(int[] permutation,
                                                  boolean isLinear)
Tests whether the permutation contains an unoriented component (hurdle)

Parameters:
permutation - the origin permutation, as an array of int
isLinear - indicates whether the permutation is linear or circular
Returns:
true / false

OLD_calculateSignedReversalDistance

public static int OLD_calculateSignedReversalDistance(int[] origin,
                                                      int[] target,
                                                      boolean isLinear)
Calculates the reversal distance between the given origin and target signed permutations

Parameters:
origin - the origin permutation, as an array of int
target - the target permutation, as an array of int
isLinear - indicates whether the permutation is linear or circular
Returns:
the reversal distance

generateAllPermutations

public static java.util.Vector<int[]> generateAllPermutations(int size)

generateAllPermutations

public static java.util.Vector<int[]> generateAllPermutations(int size,
                                                              int distance,
                                                              boolean isLinear)