# The 'guide symbol' at the start of each row of score values is optional
# Values may be integer or floating point, delimited by tab, space, comma or combinations
#
- A R N D C Q E G H I L K M F P S T W Y V B Z X -
+ A R N D C Q E G H I L K M F P S T W Y V B Z X *
A 4 -1 -2 -2 0 -1 -1 0 -2 -1 -1 -1 -1 -2 -1 1 0 -3 -2 0 -2 -1 0 -4
R -1 5 0 -2 -3 1 0 -2 0 -3 -2 2 -1 -3 -2 -1 -1 -3 -2 -3 -1 0 -1 -4
N -2 0 6 1 -3 0 0 0 1 -3 -3 0 -2 -3 -2 1 0 -4 -2 -3 3 0 -1 -4
B -2 -1 3 4 -3 0 1 -1 0 -3 -4 0 -3 -3 -2 0 -1 -4 -3 -3 4 1 -1 -4
Z -1 0 0 1 -3 3 4 -2 0 -3 -3 1 -1 -3 -1 0 -1 -3 -2 -2 1 4 -1 -4
X 0 -1 -1 -1 -2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -2 0 0 -2 -1 -1 -1 -1 -1 -4
-- -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 1
+* -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 1
# Scores are not case sensitive, unless column(s) are provided for lower case characters
# Values may be integer or floating point, delimited by tab, space, comma or combinations
#
- A R N D C Q E G H I L K M F P S T W Y V B Z X -
+ A R N D C Q E G H I L K M F P S T W Y V B Z X *
A 2 -2 0 0 -2 0 0 1 -1 -1 -2 -1 -1 -3 1 1 1 -6 -3 0 0 0 0 -8
R -2 6 0 -1 -4 1 -1 -3 2 -2 -3 3 0 -4 0 0 -1 2 -4 -2 -1 0 -1 -8
N 0 0 2 2 -4 1 1 0 2 -2 -3 1 -2 -3 0 1 0 -4 -2 -2 2 1 0 -8
B 0 -1 2 3 -4 1 3 0 1 -2 -3 1 -2 -4 -1 0 0 -5 -3 -2 3 2 -1 -8
Z 0 0 1 3 -5 3 3 0 2 -2 -3 0 -2 -5 0 0 -1 -6 -4 -2 2 3 -1 -8
X 0 -1 0 -1 -3 -1 -1 -1 -1 -1 -1 -1 -1 -2 -1 0 0 -4 -2 -1 -1 -1 -1 -8
-- -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 1
+* -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 1
int gapExtend = 20;
- float[][] lookup;
-
- int gapIndex = 23;
-
StringBuffer output = new StringBuffer();
String type; // AlignSeq.PEP or AlignSeq.DNA
private ScoreMatrix scoreModel;
+ private static final int GAP_INDEX = -1;
+
/**
* Creates a new AlignSeq object.
*
return;
}
- seq1 = new int[s1str.length()];
-
- seq2 = new int[s2str.length()];
-
score = new float[s1str.length()][s2str.length()];
E = new float[s1str.length()][s2str.length()];
type = moleculeType;
scoreModel = ScoreModels.getInstance().getDefaultModel(
PEP.equals(type));
- lookup = scoreModel.getMatrix();
- gapIndex = scoreModel.getGapIndex();
}
/**
else if (trace == 1)
{
j--;
- aseq1[count] = gapIndex;
+ aseq1[count] = GAP_INDEX;
sb1.replace(sb1.length() - 1, sb1.length(), "-");
}
else if (trace == -1)
{
i--;
- aseq2[count] = gapIndex;
+ aseq2[count] = GAP_INDEX;
sb2.replace(sb2.length() - 1, sb2.length(), "-");
}
seq1start = i + 1;
seq2start = j + 1;
- if (aseq1[count] != gapIndex)
+ if (aseq1[count] != GAP_INDEX)
{
aseq1[count] = seq1[i];
sb1.append(s1str.charAt(i));
}
- if (aseq2[count] != gapIndex)
+ if (aseq2[count] != GAP_INDEX)
{
aseq2[count] = seq2[j];
sb2.append(s2str.charAt(j));
public int findTrace(int i, int j)
{
int t = 0;
- float max = score[i - 1][j - 1] + (lookup[seq1[i]][seq2[j]] * 10);
+ // float pairwiseScore = lookup[seq1[i]][seq2[j]];
+ float pairwiseScore = scoreModel.getPairwiseScore(s1str.charAt(i),
+ s2str.charAt(j));
+ float max = score[i - 1][j - 1] + (pairwiseScore * 10);
if (F[i][j] > max)
{
int m = seq2.length;
// top left hand element
- score[0][0] = lookup[seq1[0]][seq2[0]] * 10;
+ score[0][0] = scoreModel.getPairwiseScore(s1str.charAt(0),
+ s2str.charAt(0)) * 10;
E[0][0] = -gapExtend;
F[0][0] = 0;
E[0][j] = max(score[0][j - 1] - gapOpen, E[0][j - 1] - gapExtend);
F[0][j] = -gapExtend;
- score[0][j] = max(lookup[seq1[0]][seq2[j]] * 10, -gapOpen, -gapExtend);
+ float pairwiseScore = scoreModel.getPairwiseScore(s1str.charAt(0),
+ s2str.charAt(j));
+ score[0][j] = max(pairwiseScore * 10, -gapOpen, -gapExtend);
traceback[0][j] = 1;
}
E[i][0] = -gapOpen;
F[i][0] = max(score[i - 1][0] - gapOpen, F[i - 1][0] - gapExtend);
- score[i][0] = max(lookup[seq1[i]][seq2[0]] * 10, E[i][0], F[i][0]);
+ float pairwiseScore = scoreModel.getPairwiseScore(s1str.charAt(i),
+ s2str.charAt(0));
+ score[i][0] = max(pairwiseScore * 10, E[i][0], F[i][0]);
traceback[i][0] = -1;
}
E[i][j] = max(score[i][j - 1] - gapOpen, E[i][j - 1] - gapExtend);
F[i][j] = max(score[i - 1][j] - gapOpen, F[i - 1][j] - gapExtend);
+ float pairwiseScore = scoreModel.getPairwiseScore(s1str.charAt(i),
+ s2str.charAt(j));
score[i][j] = max(score[i - 1][j - 1]
- + (lookup[seq1[i]][seq2[j]] * 10), E[i][j], F[i][j]);
+ + (pairwiseScore * 10), E[i][j], F[i][j]);
traceback[i][j] = findTrace(i, j);
}
}
public static void displayMatrix(Graphics g, int[][] mat, int n, int m,
int psize)
{
- // TODO method dosen't seem to be referenced anywhere delete??
+ // TODO method doesn't seem to be referenced anywhere delete??
int max = -1000;
int min = 1000;
bestm = msq;
}
}
- System.out.println("Best Score for " + (matches.size() + 1) + " :"
- + bestscore);
+ // System.out.println("Best Score for " + (matches.size() + 1) + " :"
+ // + bestscore);
matches.add(bestm);
aligns.add(bestaseq);
al.deleteSequence(bestm);
public class ScoreMatrix implements SimilarityScoreModelI,
PairwiseScoreModelI
{
+ private static final char GAP_CHARACTER = Comparison.GAP_DASH;
+
/*
* an arbitrary score to assign for identity of an unknown symbol
* (this is the value on the diagonal in the * column of the NCBI matrix)
private static final int UNKNOWN_IDENTITY_SCORE = 1;
/*
- * this fields records which gap character (if any) is used in the alphabet;
- * space, dash or dot are recognised as gap symbols
- */
- private char gapCharacter = '0';
-
- /*
* Jalview 2.10.1 treated gaps as X (peptide) or N (nucleotide)
* for pairwise scoring; 2.10.2 uses gap score (last column) in
* score matrix (JAL-2397)
short pos = 0;
for (char c : alphabet)
{
- if (Comparison.isGap(c))
- {
- gapCharacter = c;
- }
-
if (c <= MAX_ASCII)
{
index[c] = pos;
}
/**
- * Answers the matrix index for the gap character, or -1 if unmapped in the
- * matrix. Use this method only if using <code>getMatrix</code> in order to
- * compute scores directly (without symbol lookup) for efficiency.
- *
- * @return
- * @see #getMatrix()
- */
- public int getGapIndex()
- {
- return getMatrixIndex(gapCharacter);
- }
-
- /**
* Returns the pairwise score for substituting c with d. If either c or d is
* an unexpected character, returns 1 for identity (c == d), else the minimum
* score value in the matrix.
SimilarityParamsI options)
{
char gapChar = scoreGapAsAny ? (seqstrings.isNa() ? 'N' : 'X')
- : gapCharacter;
+ : GAP_CHARACTER;
String[] seqs = seqstrings.getSequenceStrings(gapChar);
return findSimilarities(seqs, options);
}
}
}
- char c1 = i >= len1 ? gapCharacter : seq1.charAt(i);
- char c2 = i >= len2 ? gapCharacter : seq2.charAt(i);
+ char c1 = i >= len1 ? GAP_CHARACTER : seq1.charAt(i);
+ char c2 = i >= len2 ? GAP_CHARACTER : seq2.charAt(i);
boolean gap1 = Comparison.isGap(c1);
boolean gap2 = Comparison.isGap(c2);
assertEquals(sm.getPairwiseScore('D', 'A'), -4f);
// unknown-to-self gets a score of 1
assertEquals(sm.getPairwiseScore('D', 'D'), 1f);
-
- assertEquals(sm.getGapIndex(), -1); // no gap symbol
}
@Test(
assertEquals(sm.getMatrixIndex('D'), 3);
assertEquals(sm.getMatrixIndex('X'), 22);
assertEquals(sm.getMatrixIndex('x'), 22);
- assertEquals(sm.getMatrixIndex('-'), 23);
- assertEquals(sm.getMatrixIndex('*'), -1);
+ assertEquals(sm.getMatrixIndex('-'), -1);
+ assertEquals(sm.getMatrixIndex('*'), 23);
assertEquals(sm.getMatrixIndex('.'), -1);
assertEquals(sm.getMatrixIndex(' '), -1);
assertEquals(sm.getMatrixIndex('?'), -1);
}
@Test(groups = "Functional")
- public void testGetGapIndex()
- {
- ScoreMatrix sm = ScoreModels.getInstance().getBlosum62();
- assertEquals(sm.getGapIndex(), 23);
- }
-
- @Test(groups = "Functional")
public void testGetSize()
{
ScoreMatrix sm = ScoreModels.getInstance().getBlosum62();
assertEquals(sm.getMatrixIndex('-'), 1);
assertEquals(sm.getMatrixIndex(' '), -1);
assertEquals(sm.getMatrixIndex('.'), -1);
-
- assertEquals(sm.getGapIndex(), 1);
}
@Test(groups = "Functional")
assertFalse(sm.isDNA());
assertTrue(sm.isProtein());
assertEquals(20, sm.getSize());
- assertEquals(sm.getGapIndex(), -1);
assertEquals(sm.getPairwiseScore('A', 'A'), 7f);
assertEquals(sm.getPairwiseScore('A', 'R'), -3f);
assertNotNull(sm);
assertEquals(sm.getSize(), 3);
- assertEquals(sm.getGapIndex(), -1);
assertEquals(sm.getName(), "MyTest");
assertEquals(sm.getDescription(), "My description");
assertEquals(sm.getPairwiseScore('A', 'A'), 1.0f);