From: Jim Procter Date: Wed, 7 Jan 2015 17:56:40 +0000 (+0000) Subject: JAL-1483 refactor NJTree constructor to allow preconfigured scoremodel to be passed... X-Git-Tag: Jalview_2_9~123^2~4 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=7b39c1ea0410b4cc8410b69b2d008ed0af3b6cb5;p=jalview.git JAL-1483 refactor NJTree constructor to allow preconfigured scoremodel to be passed in with alignment view --- diff --git a/src/jalview/analysis/NJTree.java b/src/jalview/analysis/NJTree.java index ec5b79b..f08a436 100644 --- a/src/jalview/analysis/NJTree.java +++ b/src/jalview/analysis/NJTree.java @@ -218,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(); @@ -245,7 +245,7 @@ public class NJTree type = "AV"; } - if (!(pwtype.equals("PID"))) + if (sm == null && !(pwtype.equals("PID"))) { if (ResidueProperties.getScoreMatrix(pwtype) == null) { @@ -265,7 +265,7 @@ public class NJTree noseqs = i++; - distance = findDistances(); + distance = findDistances(sm); // System.err.println("Made distances");// dbg makeLeaves(); // System.err.println("Made leaves");// dbg @@ -323,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); @@ -730,16 +730,18 @@ public class NJTree * * @return similarity matrix used to compute tree */ - public float[][] findDistances() + public float[][] findDistances(ScoreModelI _pwmatrix) { float[][] distance = new float[noseqs][noseqs]; - - // Pairwise substitution score (with no gap penalties) - ScoreModelI _pwmatrix = ResidueProperties.getScoreModel(pwtype); if (_pwmatrix == null) { - _pwmatrix = ResidueProperties.getScoreMatrix("BLOSUM62"); + // Resolve substitution model + _pwmatrix = ResidueProperties.getScoreModel(pwtype); + if (_pwmatrix == null) + { + _pwmatrix = ResidueProperties.getScoreMatrix("BLOSUM62"); + } } distance = _pwmatrix.findDistances(seqData); return distance; diff --git a/src/jalview/appletgui/TreePanel.java b/src/jalview/appletgui/TreePanel.java index 2fb34b0..9530dd1 100644 --- a/src/jalview/appletgui/TreePanel.java +++ b/src/jalview/appletgui/TreePanel.java @@ -21,11 +21,14 @@ package jalview.appletgui; import jalview.analysis.NJTree; +import jalview.api.analysis.ScoreModelI; +import jalview.api.analysis.ViewBasedAnalysisI; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentView; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SequenceI; import jalview.io.NewickFile; +import jalview.schemes.ResidueProperties; import jalview.util.MessageManager; import java.awt.BorderLayout; @@ -232,8 +235,27 @@ public class TreePanel extends EmbmenuFrame implements ActionListener, seqs = av.getSelectionGroup().getSequencesInOrder( av.getAlignment()); } - - tree = new NJTree(seqs, seqStrings, type, pwtype, start, end); + ScoreModelI sm = ResidueProperties.getScoreModel(pwtype); + if (sm instanceof ViewBasedAnalysisI) + { + try + { + sm = sm.getClass().newInstance(); + ((ViewBasedAnalysisI) sm) + .configureFromAlignmentView(treeCanvas.ap); + } catch (Exception q) + { + System.err.println("Couldn't create a scoremodel instance for " + + sm.getName()); + q.printStackTrace(); + } + tree = new NJTree(seqs, seqStrings, type, pwtype, sm, start, end); + } + else + { + tree = new NJTree(seqs, seqStrings, type, pwtype, null, start, + end); + } } tree.reCount(tree.getTopNode()); diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index 5bedf36..6ce68b3 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -313,8 +313,26 @@ public class TreePanel extends GTreePanel seqs = av.getSelectionGroup().getSequencesInOrder( av.getAlignment()); } - - tree = new NJTree(seqs, seqStrings, type, pwtype, start, end); + ScoreModelI sm = ResidueProperties.getScoreModel(pwtype); + if (sm instanceof ViewBasedAnalysisI) + { + try + { + sm = sm.getClass().newInstance(); + ((ViewBasedAnalysisI) sm) + .configureFromAlignmentView(treeCanvas.ap); + } catch (Exception q) + { + Cache.log.error("Couldn't create a scoremodel instance for " + + sm.getName()); + } + tree = new NJTree(seqs, seqStrings, type, pwtype, sm, start, end); + } + else + { + tree = new NJTree(seqs, seqStrings, type, pwtype, null, start, + end); + } showDistances(true); }