From 7a968a25437adc55c83ef3beba16684a8af90cc4 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 20 Oct 2017 15:09:29 +0100 Subject: [PATCH] JAL-547 updated the PID script for 2.10.x series score model architecture --- examples/groovy/PIDmatrix.groovy | 98 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 examples/groovy/PIDmatrix.groovy diff --git a/examples/groovy/PIDmatrix.groovy b/examples/groovy/PIDmatrix.groovy new file mode 100644 index 0000000..4e2ad8d --- /dev/null +++ b/examples/groovy/PIDmatrix.groovy @@ -0,0 +1,98 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ 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. + * + * 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 . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ + +import jalview.analysis.scoremodels.ScoreModels +import jalview.analysis.scoremodels.SimilarityParams + +// call the method below +printSimilarityMatrix(false,true,SimilarityParams.Jalview) + +/** + * prints a sequence similarity matrix in PHYLIP format. + * printSimilarityMatrix(selected-only, include-ids, pidMethod) + * + * Allowed values for pidMethod: + * + * Jalview's Comparison.PID method includes matching gaps + * and counts over the length of the shorter gapped sequence + * SimilarityParams.Jalview; + * + * 'SeqSpace' mode PCA calculation does not count matching + * gaps but uses longest gapped sequence length + * SimilarityParams.SeqSpace; + * + * PID calcs from the Raghava-Barton paper + * SimilarityParams.PID1: ignores gap-gap, does not score gap-residue, + * includes gap-residue in lengths, matches on longer of two sequences. + * + * SimilarityParams.PID2: ignores gap-gap,ignores gap-residue, + * matches on longer of two sequences + * + * SimilarityParams.PID3: ignores gap-gap,ignores gap-residue, + * matches on shorter of sequences only + * + * SimilarityParams.PID4: ignores gap-gap,does not score gap-residue, + * includes gap-residue in lengths,matches on shorter of sequences only. + */ + +void printSimilarityMatrix(boolean selview=false, boolean includeids=true, SimilarityParams pidMethod) { + + def currentAlignFrame = jalview.bin.Jalview.getCurrentAlignFrame() + + jalview.gui.AlignViewport av = currentAlignFrame.getCurrentView() + + jalview.datamodel.AlignmentView seqStrings = av.getAlignmentView(selview) + + if (!selview) { + start = 0 + end = av.getAlignment().getWidth() + seqs = av.getAlignment().getSequencesArray() + } else { + start = av.getSelectionGroup().getStartRes() + end = av.getSelectionGroup().getEndRes() + 1 + seqs = av.getSelectionGroup().getSequencesInOrder(av.getAlignment()) + } + + distanceCalc = ScoreModels.getInstance().getScoreModel("PID", + (jalview.api.AlignmentViewPanel) currentAlignFrame.alignPanel) + + def distance=distanceCalc.findSimilarities( + seqStrings.getSequenceStrings(jalview.util.Comparison.GAP_DASH),pidMethod) + + // output the PHYLIP Matrix + + print distance.width()+" "+distance.height()+"\n" + + p = 0 + + for (v in 1..distance.height()) { + + if (includeids) { + print seqs[p++].getDisplayId(false)+" " + } + + for (r in 1..distance.width()) { + print distance.getValue(v-1,r-1)+" " + } + + print "\n" + } +} -- 1.7.10.2