X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fanalysis%2FNJTree.java;h=f08a436dbb57b8079f60dee65438b033f992dbc7;hb=7b39c1ea0410b4cc8410b69b2d008ed0af3b6cb5;hp=144ec2c6ea14328cb69c066c38a6d06b9663f2ee;hpb=59d682209891099d46b960509907c79e3fb276fe;p=jalview.git
diff --git a/src/jalview/analysis/NJTree.java b/src/jalview/analysis/NJTree.java
index 144ec2c..f08a436 100644
--- a/src/jalview/analysis/NJTree.java
+++ b/src/jalview/analysis/NJTree.java
@@ -1,28 +1,40 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
+ * Copyright (C) 2014 The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.analysis;
-import java.util.*;
-
-import jalview.datamodel.*;
-import jalview.io.*;
-import jalview.schemes.*;
-import jalview.util.*;
+import jalview.api.analysis.ScoreModelI;
+import jalview.datamodel.AlignmentView;
+import jalview.datamodel.BinaryNode;
+import jalview.datamodel.CigarArray;
+import jalview.datamodel.NodeTransformI;
+import jalview.datamodel.SeqCigar;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+import jalview.datamodel.SequenceNode;
+import jalview.io.NewickFile;
+import jalview.schemes.ResidueProperties;
+
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Vector;
/**
* DOCUMENT ME!
@@ -206,7 +218,7 @@ public class NJTree
* DOCUMENT ME!
*/
public NJTree(SequenceI[] sequence, AlignmentView seqData, String type,
- String pwtype, int start, int end)
+ String pwtype, ScoreModelI sm, int start, int end)
{
this.sequence = sequence;
this.node = new Vector();
@@ -233,7 +245,7 @@ public class NJTree
type = "AV";
}
- if (!(pwtype.equals("PID")))
+ if (sm == null && !(pwtype.equals("PID")))
{
if (ResidueProperties.getScoreMatrix(pwtype) == null)
{
@@ -253,8 +265,7 @@ public class NJTree
noseqs = i++;
- distance = findDistances(this.seqData
- .getSequenceStrings(Comparison.GapChars.charAt(0)));
+ distance = findDistances(sm);
// System.err.println("Made distances");// dbg
makeLeaves();
// System.err.println("Made leaves");// dbg
@@ -312,7 +323,7 @@ public class NJTree
for (int j = 0; j < seqs.length; j++)
{
- seqs[j] = (SequenceI) list.get(j);
+ seqs[j] = list.get(j);
}
seqmatcher = new SequenceIdMatcher(seqs);
@@ -715,100 +726,26 @@ public class NJTree
}
/**
- * DOCUMENT ME!
+ * Calculate a distance matrix given the sequence input data and score model
*
- * @return DOCUMENT ME!
+ * @return similarity matrix used to compute tree
*/
- public float[][] findDistances(String[] sequenceString)
+ public float[][] findDistances(ScoreModelI _pwmatrix)
{
- float[][] distance = new float[noseqs][noseqs];
- if (pwtype.equals("PID"))
+ float[][] distance = new float[noseqs][noseqs];
+ if (_pwmatrix == null)
{
- for (int i = 0; i < (noseqs - 1); i++)
+ // Resolve substitution model
+ _pwmatrix = ResidueProperties.getScoreModel(pwtype);
+ if (_pwmatrix == null)
{
- for (int j = i; j < noseqs; j++)
- {
- if (j == i)
- {
- distance[i][i] = 0;
- }
- else
- {
- distance[i][j] = 100 - Comparison.PID(sequenceString[i],
- sequenceString[j]);
-
- distance[j][i] = distance[i][j];
- }
- }
+ _pwmatrix = ResidueProperties.getScoreMatrix("BLOSUM62");
}
}
- else
- {
- // Pairwise substitution score (with no gap penalties)
- ScoreMatrix pwmatrix = ResidueProperties.getScoreMatrix(pwtype);
- if (pwmatrix == null)
- {
- pwmatrix = ResidueProperties.getScoreMatrix("BLOSUM62");
- }
- int maxscore = 0;
- int end = sequenceString[0].length();
- for (int i = 0; i < (noseqs - 1); i++)
- {
- for (int j = i; j < noseqs; j++)
- {
- int score = 0;
-
- for (int k = 0; k < end; k++)
- {
- try
- {
- score += pwmatrix.getPairwiseScore(
- sequenceString[i].charAt(k),
- sequenceString[j].charAt(k));
- } catch (Exception ex)
- {
- System.err.println("err creating BLOSUM62 tree");
- ex.printStackTrace();
- }
- }
-
- distance[i][j] = (float) score;
-
- if (score > maxscore)
- {
- maxscore = score;
- }
- }
- }
-
- for (int i = 0; i < (noseqs - 1); i++)
- {
- for (int j = i; j < noseqs; j++)
- {
- distance[i][j] = (float) maxscore - distance[i][j];
- distance[j][i] = distance[i][j];
- }
- }
-
- }
+ distance = _pwmatrix.findDistances(seqData);
return distance;
- // else
- /*
- * else if (pwtype.equals("SW")) { float max = -1;
- *
- * for (int i = 0; i < (noseqs - 1); i++) { for (int j = i; j < noseqs; j++)
- * { AlignSeq as = new AlignSeq(sequence[i], sequence[j], "pep");
- * as.calcScoreMatrix(); as.traceAlignment(); as.printAlignment(System.out);
- * distance[i][j] = (float) as.maxscore;
- *
- * if (max < distance[i][j]) { max = distance[i][j]; } } }
- *
- * for (int i = 0; i < (noseqs - 1); i++) { for (int j = i; j < noseqs; j++)
- * { distance[i][j] = max - distance[i][j]; distance[j][i] = distance[i][j];
- * } } }/
- */
}
/**