de.unibi.techfak.jpredictor.clustering
Class MultiMotifAlignment

java.lang.Object
  extended by de.unibi.techfak.jpredictor.clustering.RelationMeasure
      extended by de.unibi.techfak.jpredictor.clustering.MotifAlignment
          extended by de.unibi.techfak.jpredictor.clustering.MultiMotifAlignment
All Implemented Interfaces:
Computable, java.lang.Comparable

public class MultiMotifAlignment
extends MotifAlignment

Defines the alignment between two MultiMotifs. Both given multi motifs must be of the same length. Thus it is guarantied that every single motif of the first multi motif has a partner in the second one. Single motif alignments are forwarded to the SingleMotifAlignment which must be provided, when this class is constructed. Since MultiMotifs can be of arbitrary depth (they can in turn comprise MultiMotif as well) a MultiMotifAlignment must be provided as well, when instantiating this class. In the case it may be null the compute() method will instantiate this MultiMotifAlignment at need.

Multi motifs as well as single motifs can have a search direction. This search direction does only affect the outer order of single motifs comprise in the multi motifs but affects in no way the inner order. The search direction MotifSearcher.SEARCH_DIRECTION_PLUS means that the first always comes before the second single motif and so forth. E.g. the MultiMotif A-B-C with the plus orientation is only found as A-B-C, and never as C-B-A. To find it as C-B-A as well MotifSearcher.SEARCH_DIRECTION_MINUS must be set. Normally, for MultiMotifs MotifSearcher.SEARCH_ALL_ORIENTATIONS is set. If both given multi motifs are restrited to one search direction, only one alignment must be calculated, in all other ways, two. After a succesful computation the orientations yielding the optimal alignment can be obtained through a call to getOrientation (int).

The result of the alignment must contain five informations. The first two are for the whole multi motif alignment, which is, first, the orientation of the two motifs for which the best alignment was obtained. It can be got calling function getOrientation(int). Second, the best alignment result, which can be obtained invoking method result(). The last three informations regard the single motif alignments. Third, shift values, fourth, orientations, five, results.

See Also:
MultiMotif, DoubleMotif, SingleMotifAlignment, MotifSearcher.SEARCH_DIRECTION_PLUS, MotifSearcher.SEARCH_DIRECTION_MINUS, MotifSearcher.SEARCH_ALL_ORIENTATIONS

Field Summary
(package private)  MultiMotifAlignment mma
          The alignment class between two multi motifs which must be provided when the class is constructed.
(package private)  java.util.Vector singleAlignments
          After the alignment was computed, stores the alignments for every motif pair belonging to an optimal alignment.
(package private)  SingleMotifAlignment sma
          The alignment class between two single motifs which must be provided when the class is constructed.
 
Fields inherited from class de.unibi.techfak.jpredictor.clustering.MotifAlignment
ml, motifOrientation
 
Fields inherited from class de.unibi.techfak.jpredictor.clustering.RelationMeasure
computationResult
 
Fields inherited from interface de.unibi.techfak.jpredictor.clustering.Computable
COMPUTATION_FAILED, COMPUTATION_PENDING, COMPUTATION_SUCCESS, COMPUTATION_WAITING
 
Constructor Summary
MultiMotifAlignment(SingleMotifAlignment sma, MultiMotifAlignment mma)
          Inits this class with a single motif alignment used to align the single motifs comprised in the multi motifs.
MultiMotifAlignment(SingleMotifAlignment sma, MultiMotifAlignment mma, MultiMotif motif1, MultiMotif motif2)
          Inits this class with a single motif alignment and two multi motifs.
 
Method Summary
 boolean add(Motif m)
           Adds a motif to this alignment class.
 double atomicCombine(double rel0, double rel1)
           Two relations measures are combined to one result, which is not stored but returned.
 double atomicNormalize(double rel, double norm)
           A relations measures is normalized by a certain amount.
 int compute()
          Uses all internal informations available and starts and controlls the computational process.
private  double computeSingleMotifs(Motif m1, Motif m2, double resultSoFar)
          Two motifs, either single or multi, are aligned.
 Motif consensus(int normX, int normY)
          The returned motif is a multi motif.
 MotifAlignment getSingleAlignment(int alignmentNumber)
           Returns the alignment for every motif comprised in the MultiMotifs given to this class.
 RelationMeasure newInstance()
          Creates a copy of this relation measure as if it was newly instantiated through a call to the constructor.
 int optimum(double rel0, double rel1)
           Compares two relation measure results.
 java.lang.String toString()
          Creates a short string of this relation measure and maybe some results if available.
 
Methods inherited from class de.unibi.techfak.jpredictor.clustering.MotifAlignment
clear, consensus, getOrientation
 
Methods inherited from class de.unibi.techfak.jpredictor.clustering.RelationMeasure
atomicCombine, compareTo, optimum, result
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sma

SingleMotifAlignment sma
The alignment class between two single motifs which must be provided when the class is constructed. Set in the constructor.


mma

MultiMotifAlignment mma
The alignment class between two multi motifs which must be provided when the class is constructed. Set in the constructor. Used when in the multi motifs given to this class another multi motif is comprised. Initially set to this. Must not be null. In the compute()-method every alignment between two multi motifs is done by creating a new instance of this field.


singleAlignments

java.util.Vector singleAlignments
After the alignment was computed, stores the alignments for every motif pair belonging to an optimal alignment.

Constructor Detail

MultiMotifAlignment

public MultiMotifAlignment(SingleMotifAlignment sma,
                           MultiMotifAlignment mma)
                    throws java.lang.NullPointerException
Inits this class with a single motif alignment used to align the single motifs comprised in the multi motifs.

Parameters:
sma - The alignment between two motifs.
mma - The alignment between two multi motifs. Can be null in which case this class is used.
Throws:
java.lang.NullPointerException - If sma is null.

MultiMotifAlignment

public MultiMotifAlignment(SingleMotifAlignment sma,
                           MultiMotifAlignment mma,
                           MultiMotif motif1,
                           MultiMotif motif2)
                    throws java.lang.NullPointerException,
                           java.lang.IllegalArgumentException
Inits this class with a single motif alignment and two multi motifs. The single motifs comprised in the multi motifs are aligned with the given alignment.

Parameters:
sma - The alignment between single motifs.
mma - The alignment between two multi motifs. Can be null , if no multi motif is comprised in the motifs to be aligned in this class.
motif1 - The first multi motif to align against the second.
motif2 - The second multi motif to align against the first.
Throws:
java.lang.NullPointerException - If sma is null.
java.lang.IllegalArgumentException - If one of the two motifs could not be added.
See Also:
add(Motif)
Method Detail

getSingleAlignment

public MotifAlignment getSingleAlignment(int alignmentNumber)
                                  throws java.lang.IndexOutOfBoundsException

Returns the alignment for every motif comprised in the MultiMotifs given to this class. It depends on the orientation set for the multi motifs which single motifs belong to the first alignment. E.g. A-B-C is aligned to D-E-F, but A-B-C is only searched in the minus orientation, but D-E-F in both. In this case the first alignment would either be C-D or C-F.

Note, that the alignment returned must not neccessarilly be a SingleMotifAlignment but can also be a MultiMotifAlignment .

Parameters:
alignmentNumber - The index within the previously set MultiMotif.
Returns:
Returns the alignment of two single motifs.
Throws:
java.lang.IndexOutOfBoundsException - If alignmentNumber is less than zero or greater or equal to the number of motifs comprised in the MultiMotifs set previously.
See Also:
SingleMotifAlignment, MultiMotifAlignment

add

public boolean add(Motif m)
Description copied from class: MotifAlignment

Adds a motif to this alignment class. The motif is always appent to the existing motifs. Depending on the used alignment class other motifs are accepted.

It is recommended that implementing classes should not perform any time consuming operations here, but rather doing them in the compute() method.

Specified by:
add in class MotifAlignment
Parameters:
m - The motif to appent to the list.
Returns:
true, if the motif was added, false otherwise, e.g. if the motif did not met the constraint, maybe a MultiMotif was given, where a single one was expected, or vice versa.
See Also:
MultiMotif, SequenceMotif, PSPMotif

consensus

public Motif consensus(int normX,
                       int normY)
The returned motif is a multi motif.

Specified by:
consensus in class MotifAlignment
Parameters:
normX - The normalization for the first motif.
normY - The normalization for the second motif.
Returns:
The consensus motif over the last two aligned motifs.

computeSingleMotifs

private double computeSingleMotifs(Motif m1,
                                   Motif m2,
                                   double resultSoFar)
Two motifs, either single or multi, are aligned. The resulting alignment instance is stored in the singleAlignment-vector. The result itself is combined with the given resultSoFar.

Parameters:
m1 -
m2 -
resultSoFar -
Returns:
The new overall result.

compute

public int compute()
Description copied from interface: Computable
Uses all internal informations available and starts and controlls the computational process. In its simplest case it is a method to calculate a formula, a more complicate way would be to run e.g. a whole clustering through this method.

Returns:
A status code about the process, e.g. COMPUTATION_SUCCESS.
See Also:
Computable.COMPUTATION_SUCCESS, Computable.COMPUTATION_FAILED

optimum

public int optimum(double rel0,
                   double rel1)
Description copied from class: RelationMeasure

Compares two relation measure results. Returns -1, zero or 1, if the first (rel0) measure is worse, equal, or better than the second one (rel1). The terms worse and better depend on the implementation of the RelationMeasure inheriting this method. Usually, when dealing with distances, the lower the better. On the other side, when dealing with likelihoods the higher the better.

Note, that it is possible to mix up optimization of different relation measures, e.g. distances and likelihoods, since this method works on any numbers.

Specified by:
optimum in class RelationMeasure
Parameters:
rel0 - The first relation measure to be compared to the second.
rel1 - The second relation measure to be compared to the first.
Returns:
-1, zero or 1 in case the first result is worse, equal or better than the second one.

atomicCombine

public double atomicCombine(double rel0,
                            double rel1)
Description copied from class: RelationMeasure

Two relations measures are combined to one result, which is not stored but returned. This method provides a way to calculate the combined result, when the way how to do this is not known. For instance, distance relation measures normally sum up over single results while likelihood/probabilities are multiplied.

Note, that it is possible to mix up optimization of different relation measures, e.g. distances and likelihoods, since this method works on any numbers.

Specified by:
atomicCombine in class RelationMeasure
Parameters:
rel0 - The first relation measure to be compared to the second.
rel1 - The second relation measure to be compared to the first.
Returns:
The result of combining two relation measures, e.g. through adding them up, or multiplying them or such.

atomicNormalize

public double atomicNormalize(double rel,
                              double norm)
Description copied from class: RelationMeasure

A relations measures is normalized by a certain amount. This method provides a way to normalize a relation measure after numbers of them were combined. For instance, distance relation measures normally are normalized by dividing through the count, while likelihoods are rooted.

Note, that it is possible to mix up optimization of different relation measures, e.g. distances and likelihoods, since this method works on any numbers.

Specified by:
atomicNormalize in class RelationMeasure
Parameters:
rel - The relation measure to be normalized.
norm - The normalization value.
Returns:
The result of normalizing a relation measures. Or Double.NaN in case of error.

newInstance

public RelationMeasure newInstance()
Description copied from class: RelationMeasure
Creates a copy of this relation measure as if it was newly instantiated through a call to the constructor. Note: if a class relies on really unique relation measures that are never shared with other instances it should call this method in the constructor. This might be the case, if a class uses a relation measures to store results of partially results.

Specified by:
newInstance in class RelationMeasure
Returns:
A copy of the relation measure as if it was newly instantiated.

toString

public java.lang.String toString()
Description copied from class: RelationMeasure
Creates a short string of this relation measure and maybe some results if available.

Specified by:
toString in class RelationMeasure
Returns:
A string with a short description of the class.