*/
package jalview.analysis.scoremodels;
-import jalview.api.analysis.ScoreModelI;
+import jalview.api.analysis.DistanceModelI;
import jalview.datamodel.AlignmentView;
import jalview.util.Comparison;
-public abstract class PairwiseSeqScoreModel implements ScoreModelI
+public class PairwiseDistanceModel implements DistanceModelI
{
- abstract public float getPairwiseScore(char c, char d);
+ PairwiseScoreModelI scoreModel;
+ /**
+ * Constructor given something to provide pairwise scores for residues
+ *
+ * @param sm
+ */
+ public PairwiseDistanceModel(PairwiseScoreModelI sm)
+ {
+ scoreModel = sm;
+ }
+
+ /**
+ * Returns a matrix of [i][j] values representing distances between pairs of
+ * sequences
+ */
@Override
public float[][] findDistances(AlignmentView seqData)
{
String[] sequenceString = seqData
- .getSequenceStrings(Comparison.GapChars.charAt(0));
+ .getSequenceStrings(Comparison.GAP_SPACE);
int noseqs = sequenceString.length;
float[][] distance = new float[noseqs][noseqs];
+ /*
+ * calculate similarity scores for the upper half of the matrix
+ * as [i, j] = the sum of pairwise scores of corresponding
+ * positions of sequence[i] and sequence[j]
+ */
float maxscore = 0;
int end = sequenceString[0].length();
for (int i = 0; i < (noseqs - 1); i++)
{
try
{
- score += getPairwiseScore(sequenceString[i].charAt(k),
+ score += scoreModel.getPairwiseScore(
+ sequenceString[i].charAt(k),
sequenceString[j].charAt(k));
} catch (Exception ex)
{
}
}
+ /*
+ * subtract similarity scores from the maximum value to
+ * convert to a distance measure; also populate the lower
+ * half of the result matrix with this value
+ */
+ // FIXME this assumes the score matrix is symmetric - it may not be?
for (int i = 0; i < (noseqs - 1); i++)
{
for (int j = i; j < noseqs; j++)
return distance;
}
- abstract public float[][] getMatrix();
+ @Override
+ public String getName()
+ {
+ return scoreModel.getName();
+ }
+
+ @Override
+ public boolean isDNA()
+ {
+ return scoreModel.isDNA();
+ }
+
+ @Override
+ public boolean isProtein()
+ {
+ return scoreModel.isProtein();
+ }
+
+ public PairwiseScoreModelI getScoreModel()
+ {
+ return scoreModel;
+ }
}