2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 import jalview.analysis.scoremodels.ScoreModels
23 import jalview.analysis.scoremodels.SimilarityParams
25 // generate matrix for current selection using standard Jalview PID
27 printSimilarityMatrix(true,true,SimilarityParams.Jalview)
30 * this function prints a sequence similarity matrix in PHYLIP format.
31 * printSimilarityMatrix(selected-only, include-ids, pidMethod)
33 * Allowed values for pidMethod:
35 * Jalview's Comparison.PID method includes matching gaps
36 * and counts over the length of the shorter gapped sequence
37 * SimilarityParams.Jalview;
39 * 'SeqSpace' mode PCA calculation does not count matching
40 * gaps but uses longest gapped sequence length
41 * SimilarityParams.SeqSpace;
43 * PID calcs from the Raghava-Barton paper
44 * SimilarityParams.PID1: ignores gap-gap, does not score gap-residue,
45 * includes gap-residue in lengths, matches on longer of two sequences.
47 * SimilarityParams.PID2: ignores gap-gap,ignores gap-residue,
48 * matches on longer of two sequences
50 * SimilarityParams.PID3: ignores gap-gap,ignores gap-residue,
51 * matches on shorter of sequences only
53 * SimilarityParams.PID4: ignores gap-gap,does not score gap-residue,
54 * includes gap-residue in lengths,matches on shorter of sequences only.
57 void printSimilarityMatrix(boolean selview=false, boolean includeids=true, SimilarityParams pidMethod) {
59 def currentAlignFrame = jalview.bin.Jalview.getCurrentAlignFrame()
61 jalview.gui.AlignViewport av = currentAlignFrame.getCurrentView()
63 jalview.datamodel.AlignmentView seqStrings = av.getAlignmentView(selview)
65 if (!selview || av.getSelectionGroup()==null) {
67 end = av.getAlignment().getWidth()
68 seqs = av.getAlignment().getSequencesArray()
70 start = av.getSelectionGroup().getStartRes()
71 end = av.getSelectionGroup().getEndRes() + 1
72 seqs = av.getSelectionGroup().getSequencesInOrder(av.getAlignment())
75 distanceCalc = ScoreModels.getInstance().getScoreModel("PID",
76 (jalview.api.AlignmentViewPanel) currentAlignFrame.alignPanel)
78 def distance=distanceCalc.findSimilarities(
79 seqStrings.getSequenceStrings(jalview.util.Comparison.GAP_DASH),pidMethod)
81 // output the PHYLIP Matrix
83 print distance.width()+" "+distance.height()+"\n"
87 for (v in 1..distance.height()) {
90 print seqs[p++].getDisplayId(false)+" "
93 for (r in 1..distance.width()) {
94 print distance.getValue(v-1,r-1)+" "