baobab.bio.permutation
Class SignedPermutationBPGraph

java.lang.Object
  extended by baobab.bio.permutation.SignedPermutationBPGraph
All Implemented Interfaces:
PermutationBPGraph, java.lang.Comparable
Direct Known Subclasses:
ComplexSignedPermutationBPGraph, WeightedSignedPermutationBPGraph

public class SignedPermutationBPGraph
extends java.lang.Object
implements PermutationBPGraph

The SignedPermutationBPGraph class represents a signed permutation pair and its breakpoint graph (the SignedPermutationBPGraph class does not deal with hurdles)

Version:
1.0, May 2006
Author:
Marilia D. V. Braga

Constructor Summary
SignedPermutationBPGraph(int[] permutationList)
          Creates a new linear permutation (assumes the identity permutation as target)
SignedPermutationBPGraph(int[] permutationList, boolean isLinear)
          Creates a new permutation (assumes the identity permutation as target)
SignedPermutationBPGraph(int[] permutationList, boolean isLinear, double[] weights)
          Creates a new permutation (assumes the identity permutation as target)
SignedPermutationBPGraph(int[] permutationList, double[] weights)
          Creates a new linear permutation (assumes the identity permutation as target)
SignedPermutationBPGraph(int[] originList, int[] targetList)
          Creates a new linear permutation
SignedPermutationBPGraph(int[] originList, int[] targetList, boolean isLinear)
          Creates a new permutation
SignedPermutationBPGraph(int[] originList, int[] targetList, boolean isLinear, double[] weightList)
          Creates a new permutation
SignedPermutationBPGraph(java.util.Vector<java.lang.String> origin, java.util.Vector<java.lang.String> target, boolean isLinear)
          Creates a new permutation
SignedPermutationBPGraph(java.util.Vector<java.lang.String> origin, java.util.Vector<java.lang.String> target, boolean isLinear, java.util.Vector<java.lang.Double> weightList)
          Creates a new permutation
 
Method Summary
static java.util.Vector<int[]> blocksToIntArrays(java.util.Collection blocks)
          Transforms the collection of blocks to a collection of arrays of int (with length = 2)
 boolean canCollapse()
          Tests whether this permutation can be collapsed
 java.lang.Object clone()
           
 SignedPermutationBPGraph collapse(boolean monooriented)
          Collapses this permutation (eliminating adjacencies)
 int compareTo(java.lang.Object object)
          Compares this block to another block
 boolean containsUnorientedComponent()
          Tests whether this permutation contains an unoriented component (hurdle)
 boolean equals(SignedPermutationBPGraph perm)
           
 double getAverageWeightOfInterval(int startPos, int endPos)
          Gets the average weight of an interval of the permutation
 java.util.TreeSet<BPGraphPoint> getBreakpoints()
          Gets the breakpoint list of this block
 BPGraphCycle getCycle(int number)
          Gets the list of cycles of this group of cycles
 java.util.SortedSet<BPGraphCycle> getCycles()
          Gets the list of cycles of this group of cycles
 java.lang.String getData()
           
 BPGraphPoint getFirstPoint()
          Gets the first point of the permutation
 PermutationBPGraphFormatter getFormatter()
          Gets this breakpoint graph formatter
 java.lang.String[] getIntToNamesMap()
           
 BPGraphPoint getLastPoint()
          Gets the last point of the permutation
 int getLastPointIndex()
          Gets the position of the last point of the permutation
 int getLongestNameLength()
          Gets the longest length of a value name in the breakpoint graph
 int[] getMappedPositions()
           
 int getMappedValueAt(int pos)
          Gets the value of the mapped element located at a specified position of the permutation
 int[] getMappedValues()
           
 int[] getMappedValuesAroundPosition(int pos)
          Gets the two values around a position of the permutation
 int getMiddleOfInterval(int startPos, int endPos, double[] dist)
          Gets the middle position of an interval of the permutation
 int getMinimalReversalDistance()
          Gets the minimal reversal distance of this permutation (considering only the number of cycles property)
 java.lang.String getNameAt(int pos)
          Gets the name of the element located at a specified position of the permutation
 java.lang.String getNameOf(int value)
          Gets the name of the element represented by the given value of the permutation
 java.util.Hashtable<java.lang.String,java.lang.Integer> getNamesToIntMap()
           
 SignedPermutationBPGraph getNotCollapsed()
           
 int getNumberOfBreakpoints()
          Gets the number of breakpoints
 int getNumberOfCycles()
          Gets the number of cycles of this group of cycles
 java.util.SortedSet getOrientedCycles()
          Gets the list of oriented cycles of this group of cycles
 PermutationBPGraph getPermutationBPGraph()
          Gets this permutation
 BPGraphPoint getPointAt(int pos)
          Gets a point at a specific position of the permutation
 BPGraphPoint getPointBetweenMapped(int value1, int value2)
          Gets a point between two values of the permutation
 java.util.SortedSet<BPGraphPoint> getPoints()
          Gets all points which belong to this group of cycles
 int getPositionOf(int value)
          Gets the position where a specified element of the permutation is located
 int getPositionOf(java.lang.String name)
          Gets the position of the element identified by the given name
 int getPositionOfMapped(int value)
          Gets the position where a specified mapped element of the permutation is located
 int getReversalDistance()
          Gets the reversal distance of this permutation
 SignedPermutationBPGraphReversalFilter getReversalFilter()
          Gets the reversal filter of this permutation
 java.lang.String getSignedDescription(java.lang.String name, boolean isReverted)
           
 java.util.Hashtable<java.lang.String,java.lang.String[]> getSignedDescriptor()
           
 double getTotalWeight()
          Gets the total weight (the sum of the weights of all values) of this permutation
 java.util.SortedSet<BPGraphCycle> getUnorientedCycles()
          Gets the list of non-oriented cycles of this group of cycles
 java.util.TreeSet<java.lang.String> getUnsignedDescription(java.lang.String name)
           
 java.util.Hashtable<java.lang.String,java.util.TreeSet<java.lang.String>> getUnsignedDescriptor()
           
 int getValueAt(int pos)
          Gets the value of the element located at a specified position of the permutation
 double[] getWeightMap()
          Gets the weights of the values of this permutation (map[i] is the weight of the value mapped to the integer i)
 double getWeightOf(java.lang.String name)
          Gets the weight of the value identified by the given name
 double getWeightOfInterval(int startPos, int endPos)
          Gets the total weight of an interval of the permutation
 boolean isAdjacency()
          Tests whether this permutation is sorted
 boolean isCycleBreakingReversal(int start, int end)
          Tests whether a reversal is safe (the permutation obtained after performing such a reversal has a smaller reversal distance than this permutation)
 boolean isLinear()
          Tests whether the permutation is linear or circular
 boolean isOriented()
          Tests whether this cycle group is oriented
 boolean isRevertedAt(int pos)
          Gets the value of the element located at a specified position of the permutation
 boolean isSorted()
          Tests whether this permutation is sorted
 int length()
          Gets the length of the block (the number of values of the permutation between its start and end points)
 SignedPermutationBPGraph revert(BPGraphPoint start, BPGraphPoint end)
          Reverts the permutation between the specified points
 SignedPermutationBPGraph revert(BPGraphReversalBlock block)
          Reverts the specified block of the permutation
 SignedPermutationBPGraph revert(int start, int end)
          Reverts the permutation between the specified positions
 SignedPermutationBPGraph revertToNewPermutation(BPGraphPoint start, BPGraphPoint end)
          Make a new permutation, by reverting the permutation between the specified positions
 SignedPermutationBPGraph revertToNewPermutation(int start, int end)
          Make a new permutation, by reverting the permutation between the specified positions
 void setDescriptor(java.util.Hashtable<java.lang.String,java.lang.String[]> signedDescriptor, java.util.Hashtable<java.lang.String,java.util.TreeSet<java.lang.String>> sortedUnsignedDescriptor)
           
 int size()
          Gets the size (or the number of values) of the permutation
 int[] toIntArray()
          Gets a representation of the block as an array of int, with size 2, representing its start and end positions
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface baobab.bio.permutation.PermutationBPGraph
getNumberOfCycles
 

Constructor Detail

SignedPermutationBPGraph

public SignedPermutationBPGraph(int[] permutationList)
Creates a new linear permutation (assumes the identity permutation as target)

Parameters:
permutationList - the list of signed integers (from +/-1 to +/-n), as an array of int

SignedPermutationBPGraph

public SignedPermutationBPGraph(int[] permutationList,
                                double[] weights)
Creates a new linear permutation (assumes the identity permutation as target)

Parameters:
permutationList - the list of signed integers (from +/-1 to +/-n), as an array of int
weights - the weights of the values in permutationList

SignedPermutationBPGraph

public SignedPermutationBPGraph(int[] permutationList,
                                boolean isLinear,
                                double[] weights)
Creates a new permutation (assumes the identity permutation as target)

Parameters:
permutationList - the list of signed integers (from +/-1 to +/-n), as an array of int
isLinear - indicates whether the permutation is linear or circular
weights - the weights of the values in permutationList

SignedPermutationBPGraph

public SignedPermutationBPGraph(int[] permutationList,
                                boolean isLinear)
Creates a new permutation (assumes the identity permutation as target)

Parameters:
permutationList - the list of signed integers (from +/-1 to +/-n), as an array of int
isLinear - indicates whether the permutation is linear or circular

SignedPermutationBPGraph

public SignedPermutationBPGraph(int[] originList,
                                int[] targetList)
Creates a new linear permutation

Parameters:
originList - the origin list of signed integers (from +/-1 to +/-n), as an array of int
targetList - the target list of signed integers (from +/-1 to +/-n), as an array of int

SignedPermutationBPGraph

public SignedPermutationBPGraph(int[] originList,
                                int[] targetList,
                                boolean isLinear)
Creates a new permutation

Parameters:
originList - the origin list of signed integers (from +/-1 to +/-n), as an array of int
targetList - the target list of signed integers (from +/-1 to +/-n), as an array of int
isLinear - indicates whether the permutation is linear or circular

SignedPermutationBPGraph

public SignedPermutationBPGraph(int[] originList,
                                int[] targetList,
                                boolean isLinear,
                                double[] weightList)
Creates a new permutation

Parameters:
originList - the origin list of signed integers (from +/-1 to +/-n), as an array of int
targetList - the target list of signed integers (from +/-1 to +/-n), as an array of int
isLinear - indicates whether the permutation is linear or circular
weightList - the weights of the values in originList

SignedPermutationBPGraph

public SignedPermutationBPGraph(java.util.Vector<java.lang.String> origin,
                                java.util.Vector<java.lang.String> target,
                                boolean isLinear)
Creates a new permutation

Parameters:
origin - the origin list of signed markers
target - the target list of signed markers
isLinear - indicates whether the permutation is linear or circular

SignedPermutationBPGraph

public SignedPermutationBPGraph(java.util.Vector<java.lang.String> origin,
                                java.util.Vector<java.lang.String> target,
                                boolean isLinear,
                                java.util.Vector<java.lang.Double> weightList)
Creates a new permutation

Parameters:
origin - the origin list of signed markers represented as Strings (when a value starts with "-" it is assumed to be in reversed orientation)
target - the target list of signed markers represented as Strings (when a value starts with "-" it is assumed to be in reversed orientation)
isLinear - indicates whether the permutation is linear or circular
weightList - the weights of the values in origin
Method Detail

getTotalWeight

public double getTotalWeight()
Gets the total weight (the sum of the weights of all values) of this permutation

Returns:
the total weight of this permutation

getWeightMap

public double[] getWeightMap()
Gets the weights of the values of this permutation (map[i] is the weight of the value mapped to the integer i)

Returns:
the array of doubles with all weights

getWeightOf

public double getWeightOf(java.lang.String name)
Gets the weight of the value identified by the given name

Parameters:
name - the name of the value
Returns:
the corresponding weight

getAverageWeightOfInterval

public double getAverageWeightOfInterval(int startPos,
                                         int endPos)
Gets the average weight of an interval of the permutation

Parameters:
startPos - the start of the interval
endPos - the end of the interval
Returns:
the average weight

getWeightOfInterval

public double getWeightOfInterval(int startPos,
                                  int endPos)
Gets the total weight of an interval of the permutation

Parameters:
startPos - the start of the interval
endPos - the end of the interval
Returns:
the total weight

getMiddleOfInterval

public int getMiddleOfInterval(int startPos,
                               int endPos,
                               double[] dist)
Gets the middle position of an interval of the permutation

Parameters:
startPos - the start position of the interval
endPos - the end position of the interval
dist - an array of lenght 2 to store the total weight of two different intervals of the permutation (dist[0] is the weight of the interval that starts in startPos and ends in the middle position, dist[1] is the weight of the interval that starts in the middle position and ends in the endPos)
Returns:
the middle position

getLongestNameLength

public int getLongestNameLength()
Description copied from interface: PermutationBPGraph
Gets the longest length of a value name in the breakpoint graph

Specified by:
getLongestNameLength in interface PermutationBPGraph
Returns:
the longest length of a value name

isLinear

public boolean isLinear()
Tests whether the permutation is linear or circular

Specified by:
isLinear in interface PermutationBPGraph
Returns:
true / false

getFirstPoint

public BPGraphPoint getFirstPoint()
Gets the first point of the permutation

Specified by:
getFirstPoint in interface PermutationBPGraph
Returns:
the start point

getLastPointIndex

public int getLastPointIndex()
Gets the position of the last point of the permutation

Specified by:
getLastPointIndex in interface PermutationBPGraph
Returns:
the last point position

getLastPoint

public BPGraphPoint getLastPoint()
Gets the last point of the permutation

Specified by:
getLastPoint in interface PermutationBPGraph
Returns:
the last point

getPermutationBPGraph

public PermutationBPGraph getPermutationBPGraph()
Gets this permutation

Returns:
this permutation

getMappedValues

public int[] getMappedValues()

getMappedPositions

public int[] getMappedPositions()

getMinimalReversalDistance

public int getMinimalReversalDistance()
Gets the minimal reversal distance of this permutation (considering only the number of cycles property)

Returns:
the minimal reversal distance

getReversalDistance

public int getReversalDistance()
Gets the reversal distance of this permutation

Returns:
the reversal distance

size

public int size()
Gets the size (or the number of values) of the permutation

Specified by:
size in interface PermutationBPGraph
Returns:
the size of the permutation

getPointAt

public BPGraphPoint getPointAt(int pos)
Gets a point at a specific position of the permutation

Specified by:
getPointAt in interface PermutationBPGraph
Parameters:
pos - the given position
Returns:
the point at the given position

getPointBetweenMapped

public BPGraphPoint getPointBetweenMapped(int value1,
                                          int value2)
Gets a point between two values of the permutation

Parameters:
value1 - the first value
value2 - the second value
Returns:
the point between values

getMappedValuesAroundPosition

public int[] getMappedValuesAroundPosition(int pos)
Gets the two values around a position of the permutation

Parameters:
pos - the given position
Returns:
the values around the given position as an array of int

getMappedValueAt

public int getMappedValueAt(int pos)
Gets the value of the mapped element located at a specified position of the permutation

Specified by:
getMappedValueAt in interface PermutationBPGraph
Parameters:
pos - the specified position
Returns:
the value of the mapped element

getValueAt

public int getValueAt(int pos)
Gets the value of the element located at a specified position of the permutation

Specified by:
getValueAt in interface PermutationBPGraph
Parameters:
pos - the specified position
Returns:
the value of the element

getPositionOf

public int getPositionOf(java.lang.String name)
Gets the position of the element identified by the given name

Specified by:
getPositionOf in interface PermutationBPGraph
Parameters:
name - the given name
Returns:
the position of the element

getNameAt

public java.lang.String getNameAt(int pos)
Gets the name of the element located at a specified position of the permutation

Specified by:
getNameAt in interface PermutationBPGraph
Parameters:
pos - the specified position
Returns:
the name of the element

getNameOf

public java.lang.String getNameOf(int value)
Gets the name of the element represented by the given value of the permutation

Parameters:
value - the specified value
Returns:
the name of the element

getIntToNamesMap

public java.lang.String[] getIntToNamesMap()

getNamesToIntMap

public java.util.Hashtable<java.lang.String,java.lang.Integer> getNamesToIntMap()

isRevertedAt

public boolean isRevertedAt(int pos)
Gets the value of the element located at a specified position of the permutation

Specified by:
isRevertedAt in interface PermutationBPGraph
Parameters:
pos - the specified position
Returns:
the value of the element

getPositionOf

public int getPositionOf(int value)
Gets the position where a specified element of the permutation is located

Specified by:
getPositionOf in interface PermutationBPGraph
Parameters:
value - the value of the specified element
Returns:
the position

getPositionOfMapped

public int getPositionOfMapped(int value)
Gets the position where a specified mapped element of the permutation is located

Specified by:
getPositionOfMapped in interface PermutationBPGraph
Parameters:
value - the value of the specified mapped element
Returns:
the position

revert

public SignedPermutationBPGraph revert(BPGraphReversalBlock block)
                                throws PermutationException
Reverts the specified block of the permutation

Parameters:
block - the block to be reverted
Returns:
the resulting Permutation, after performing the reversion
Throws:
PermutationException

revert

public SignedPermutationBPGraph revert(BPGraphPoint start,
                                       BPGraphPoint end)
                                throws PermutationException
Reverts the permutation between the specified points

Parameters:
start - the beginning of the reversion block
end - the end of the reversion block
Returns:
the resulting Permutation, after performing the reversion
Throws:
PermutationException

revert

public SignedPermutationBPGraph revert(int start,
                                       int end)
Reverts 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

revertToNewPermutation

public SignedPermutationBPGraph revertToNewPermutation(BPGraphPoint start,
                                                       BPGraphPoint end)
                                                throws PermutationException
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
Throws:
PermutationException

revertToNewPermutation

public SignedPermutationBPGraph revertToNewPermutation(int start,
                                                       int end)
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

isAdjacency

public boolean isAdjacency()
Tests whether this permutation is sorted

Returns:
true/false

isSorted

public boolean isSorted()
Tests whether this permutation is sorted

Specified by:
isSorted in interface PermutationBPGraph
Returns:
true / false

isCycleBreakingReversal

public boolean isCycleBreakingReversal(int start,
                                       int end)
Tests whether a reversal is safe (the permutation obtained after performing such a reversal has a smaller reversal distance than this permutation)

Parameters:
start - the start of the given reversal
end - the end of the given reversal
Returns:
true / false

containsUnorientedComponent

public boolean containsUnorientedComponent()
Tests whether this permutation contains an unoriented component (hurdle)

Returns:
true/false

getReversalFilter

public SignedPermutationBPGraphReversalFilter getReversalFilter()
Gets the reversal filter of this permutation

Returns:
the reversal filter

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

equals

public boolean equals(SignedPermutationBPGraph perm)

getFormatter

public PermutationBPGraphFormatter getFormatter()
Description copied from interface: PermutationBPGraph
Gets this breakpoint graph formatter

Specified by:
getFormatter in interface PermutationBPGraph
Returns:
the breakpoint graph formatter

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getData

public java.lang.String getData()

canCollapse

public boolean canCollapse()
Tests whether this permutation can be collapsed

Returns:
true/false

collapse

public SignedPermutationBPGraph collapse(boolean monooriented)
Collapses this permutation (eliminating adjacencies)

Parameters:
monooriented - false = eliminate all adjacencies; true = eliminate the adjacencies at the same DNA strand
Returns:
the collapsedPermutation

setDescriptor

public void setDescriptor(java.util.Hashtable<java.lang.String,java.lang.String[]> signedDescriptor,
                          java.util.Hashtable<java.lang.String,java.util.TreeSet<java.lang.String>> sortedUnsignedDescriptor)

getUnsignedDescriptor

public java.util.Hashtable<java.lang.String,java.util.TreeSet<java.lang.String>> getUnsignedDescriptor()

getSignedDescriptor

public java.util.Hashtable<java.lang.String,java.lang.String[]> getSignedDescriptor()

getUnsignedDescription

public java.util.TreeSet<java.lang.String> getUnsignedDescription(java.lang.String name)

getSignedDescription

public java.lang.String getSignedDescription(java.lang.String name,
                                             boolean isReverted)

getNotCollapsed

public SignedPermutationBPGraph getNotCollapsed()

getBreakpoints

public java.util.TreeSet<BPGraphPoint> getBreakpoints()
Gets the breakpoint list of this block

Returns:
a Collection with the list of breakpoints (each breakpoint is represented by a Point)

getNumberOfBreakpoints

public int getNumberOfBreakpoints()
Gets the number of breakpoints

Returns:
the number of breakpoints

getNumberOfCycles

public int getNumberOfCycles()
Gets the number of cycles of this group of cycles

Returns:
the number of cycles

getCycles

public java.util.SortedSet<BPGraphCycle> getCycles()
Gets the list of cycles of this group of cycles

Returns:
a Vector with the list of cycles

getOrientedCycles

public java.util.SortedSet getOrientedCycles()
Gets the list of oriented cycles of this group of cycles

Returns:
a Vector with the list of cycles

isOriented

public boolean isOriented()
Tests whether this cycle group is oriented


getPoints

public java.util.SortedSet<BPGraphPoint> getPoints()
Gets all points which belong to this group of cycles

Returns:
a Collection with the list of points

getCycle

public BPGraphCycle getCycle(int number)
Gets the list of cycles of this group of cycles

Returns:
a Vector with the list of cycles

getUnorientedCycles

public java.util.SortedSet<BPGraphCycle> getUnorientedCycles()
Gets the list of non-oriented cycles of this group of cycles

Returns:
a Vector with the list of cycles

length

public int length()
Gets the length of the block (the number of values of the permutation between its start and end points)

Returns:
the length

toIntArray

public int[] toIntArray()
Gets a representation of the block as an array of int, with size 2, representing its start and end positions

Returns:
representation of the block as an array of int

compareTo

public int compareTo(java.lang.Object object)
Compares this block to another block

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
object - the other block
Returns:
the result of the comparison, as an int

blocksToIntArrays

public static java.util.Vector<int[]> blocksToIntArrays(java.util.Collection blocks)
Transforms the collection of blocks to a collection of arrays of int (with length = 2)

Parameters:
blocks - a collection of blocks
Returns:
a collection containing the blocks as arrays of int