org.specrunner.util.aligner.core
Class NeedlemanWunschAligner

java.lang.Object
  extended by org.specrunner.util.aligner.core.NeedlemanWunschAligner
All Implemented Interfaces:
IStringAligner

public class NeedlemanWunschAligner
extends Object
implements IStringAligner

Default alignment implementation, a Needleman-Wunsch algorithm.

Author:
Thiago Santos

Field Summary
protected  String expected
          The expected value.
protected  StringBuilder expectedAligned
          The expected value aligned.
protected  char fillCharacter
          The character to be using on error report.
protected  String received
          The received string.
protected  StringBuilder receivedAligned
          The received value aligned.
 
Constructor Summary
NeedlemanWunschAligner(String expected, String received)
          Creates an aligner with default fill character.
NeedlemanWunschAligner(String expected, String received, char fillCharacter)
          Creates an aligner with both strings and fill character.
 
Method Summary
protected  void align()
          Perform alignment.
protected  List<Character> alphabet(String a, String b)
          Creates the local alphabet.
protected  int[][] calculate(String a, String b, List<Character> list, int[][] s, int d)
          Calculate the matrix of gaps.
 String getExpected()
          The expected string.
 StringBuilder getExpectedAligned()
          The base string aligned.
 char getFillCharacter()
          Fill character in alignment.
 String getReceived()
          The received string.
 StringBuilder getReceivedAligned()
          The received string aligned.
protected  int penalty(int size)
          Calculate penalty.
protected  int[][] scoring(int size)
          The scoring matrix.
protected  String toString(int[][] d)
          String representation of a matrix.
protected  void traceback(String a, String b, List<Character> list, int[][] s, int d, int[][] f)
          Fill the alignment result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

expected

protected String expected
The expected value.


expectedAligned

protected StringBuilder expectedAligned
The expected value aligned.


fillCharacter

protected char fillCharacter
The character to be using on error report.


received

protected String received
The received string.


receivedAligned

protected StringBuilder receivedAligned
The received value aligned.

Constructor Detail

NeedlemanWunschAligner

public NeedlemanWunschAligner(String expected,
                              String received)
Creates an aligner with default fill character.

Parameters:
expected - The expected string.
received - The received string.

NeedlemanWunschAligner

public NeedlemanWunschAligner(String expected,
                              String received,
                              char fillCharacter)
Creates an aligner with both strings and fill character.

Parameters:
expected - The expected string.
received - The received string.
fillCharacter - The fill character.
Method Detail

getExpected

public String getExpected()
Description copied from interface: IStringAligner
The expected string.

Specified by:
getExpected in interface IStringAligner
Returns:
Base string.

getExpectedAligned

public StringBuilder getExpectedAligned()
Description copied from interface: IStringAligner
The base string aligned.

Specified by:
getExpectedAligned in interface IStringAligner
Returns:
The string expected filled with 'fill character' where necessary.

getFillCharacter

public char getFillCharacter()
Description copied from interface: IStringAligner
Fill character in alignment.

Specified by:
getFillCharacter in interface IStringAligner
Returns:
The fill alignment.

getReceived

public String getReceived()
Description copied from interface: IStringAligner
The received string.

Specified by:
getReceived in interface IStringAligner
Returns:
Received string.

getReceivedAligned

public StringBuilder getReceivedAligned()
Description copied from interface: IStringAligner
The received string aligned.

Specified by:
getReceivedAligned in interface IStringAligner
Returns:
The string received filled with 'fill character' where necessary.

align

protected void align()
Perform alignment.


alphabet

protected List<Character> alphabet(String a,
                                   String b)
Creates the local alphabet.

Parameters:
a - Left string.
b - Right string.
Returns:
The list of characters.

calculate

protected int[][] calculate(String a,
                            String b,
                            List<Character> list,
                            int[][] s,
                            int d)
Calculate the matrix of gaps.

Parameters:
a - The left string.
b - The right string.
list - The alphabet.
s - The scoring matrix.
d - The penalty.
Returns:
The proximity matrix.

scoring

protected int[][] scoring(int size)
The scoring matrix.

Parameters:
size - The size.
Returns:
The scoring matrix.

penalty

protected int penalty(int size)
Calculate penalty.

Parameters:
size - The size of alphabet.
Returns:
The penalty.

traceback

protected void traceback(String a,
                         String b,
                         List<Character> list,
                         int[][] s,
                         int d,
                         int[][] f)
Fill the alignment result.

Parameters:
a - The left string.
b - The right string.
list - The alphabet.
s - The scoring matrix.
d - The penalty.
f - The current proximity matrix.

toString

protected String toString(int[][] d)
String representation of a matrix.

Parameters:
d - The matrix.
Returns:
The string for the matrix.


Copyright © 2014. All rights reserved.