@Test
public void testSameSimilarity3() {
final StemStructureAlphabet stemAlphabet = StemStructureAlphabet
.getInstance();
ScoringMatrix structureScoringMatrix = new ScoringMatrix(
"matrix/Structure-sim-RIBOSUM85-60.matrix", stemAlphabet);
GlobalStemSimilarity sim = new GlobalStemSimilarity(
structureScoringMatrix, new AffineGapGlobalSequenceAlignment(
10, 10, RnaAlphabet.getInstance(),
new AffineGapScoringMatrix(
"matrix/NUC-Affine-sim-RIBOSUM85-60.matrix",
RnaAlphabet.getInstance())));
StemStructure str1 = new StemStructure(">1", new CharBuffer(
"AGAGGUAAAAUGCAUCU"), new CharBuffer("((..(((...)))..))"));
StemStructure str2 = new StemStructure(">1", new CharBuffer(
"AGAGAAAAUAUCU"), new CharBuffer("((..(...)..))"));
sim.setStem1(str1);
sim.setStem2(str2);
sim.run();
double score = sim.getAlignmentScore();
String[] alignment = sim.getAlignment();
for (int i = 0; i < alignment[0].length(); i++) {
System.out.print(" "
+ Arrays.toString(stemAlphabet.decodePair(alignment[0]
.charAt(i))));
}
System.out.println();
for (int i = 0; i < alignment[1].length(); i++) {
System.out.print(" "
+ Arrays.toString(stemAlphabet.decodePair(alignment[1]
.charAt(i))));
}
System.out.println();
sim.setStem1(str1);
sim.setStem2(str1);
sim.run();
double scoreSelf = sim.getAlignmentScore();
double diff = scoreSelf - score;
double expected = structureScoringMatrix.score(
stemAlphabet.mapAndHash("U|G"), stemAlphabet.mapAndHash("U|G"))
+ structureScoringMatrix.score(stemAlphabet.mapAndHash("G|C"),
stemAlphabet.mapAndHash("G|C"))
- (structureScoringMatrix.score(stemAlphabet.mapAndHash("U|G"),
stemAlphabet.emptyLetterHashed()) + structureScoringMatrix
.score(stemAlphabet.mapAndHash("G|C"),
stemAlphabet.emptyLetterHashed()));
Assert.assertEquals(expected, diff, 0.01);
}