From: MorellThomas Date: Fri, 1 Dec 2023 09:14:20 +0000 (+0100) Subject: Applying adjustablenw_params.patch (JAL-4159) X-Git-Tag: Release_2_11_4_0~31^2~31 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=407387056950213aa8a06321ad05a90bbe1e460b;p=jalview.git Applying adjustablenw_params.patch (JAL-4159) --- diff --git a/.gitignore b/.gitignore index 59c4a99..4a81616 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ TESTNG /jalviewApplet.jar /benchmarking/lib *.class +*.patch /site /site-resources /libjs diff --git a/src/jalview/analysis/AlignSeq.java b/src/jalview/analysis/AlignSeq.java index fa90f74..d394024 100755 --- a/src/jalview/analysis/AlignSeq.java +++ b/src/jalview/analysis/AlignSeq.java @@ -20,8 +20,6 @@ */ package jalview.analysis; -import java.util.Locale; - import jalview.analysis.scoremodels.PIDModel; import jalview.analysis.scoremodels.ScoreMatrix; import jalview.analysis.scoremodels.ScoreModels; @@ -46,10 +44,9 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.StringTokenizer; +import java.util.Locale; /** - * - * * @author $author$ * @version $Revision$ */ @@ -57,12 +54,13 @@ public class AlignSeq { private static final int MAX_NAME_LENGTH = 30; - //&! - //private static final int GAP_OPEN_COST = 120; - private static final int GAP_OPEN_COST = 100; + private static final int DEFAULT_OPENCOST = 120; + + private static final int DEFAULT_EXTENDCOST = 20; + + private int GAP_OPEN_COST=DEFAULT_OPENCOST; - //private static final int GAP_EXTEND_COST = 20; - private static final int GAP_EXTEND_COST = 5; + private int GAP_EXTEND_COST=DEFAULT_EXTENDCOST; private static final int GAP_INDEX = -1; @@ -156,12 +154,12 @@ public class AlignSeq /** * Creates a new AlignSeq object. * - * @param s1 - * DOCUMENT ME! - * @param s2 - * DOCUMENT ME! + * @param s1,string1 + * s1 reference sequence for string1 + * @param s2,string2 + * s2 reference sequence for string2 * @param type - * DOCUMENT ME! + * molecule type, either AlignSeq.PEP or AlignSeq.DNA */ public AlignSeq(SequenceI s1, String string1, SequenceI s2, String string2, String type) @@ -170,6 +168,23 @@ public class AlignSeq string2.toUpperCase(Locale.ROOT), type); } + public AlignSeq(SequenceI s1, SequenceI s2, String type, int opencost, + int extcost) + { + this(s1,s2,type); + GAP_OPEN_COST=opencost; + GAP_EXTEND_COST=extcost; + } + + public AlignSeq(SequenceI s12, String string1, SequenceI s22, + String string2, String type2, int defaultOpencost, + int defaultExtendcost) + { + this(s12,string1,s22,string2,type2); + GAP_OPEN_COST=defaultOpencost; + GAP_EXTEND_COST=defaultExtendcost; + } + /** * DOCUMENT ME! * @@ -325,6 +340,13 @@ public class AlignSeq public void seqInit(SequenceI s1, String string1, SequenceI s2, String string2, String type) { + seqInit(s1,string1,s2,string2,type,GAP_OPEN_COST,GAP_EXTEND_COST); + } + public void seqInit(SequenceI s1, String string1, SequenceI s2, + String string2, String type, int opening,int extension) + { + GAP_OPEN_COST=opening; + GAP_EXTEND_COST=extension; this.s1 = s1; this.s2 = s2; setDefaultParams(type); @@ -791,25 +813,26 @@ public class AlignSeq { int n = seq1.length; int m = seq2.length; - + final int GAP_EX_COST=GAP_EXTEND_COST; + final int GAP_OP_COST = GAP_OPEN_COST; // top left hand element score[0][0] = scoreMatrix.getPairwiseScore(s1str.charAt(0), s2str.charAt(0)) * 10; - E[0][0] = -GAP_EXTEND_COST; + E[0][0] = -GAP_EX_COST; F[0][0] = 0; // Calculate the top row first for (int j = 1; j < m; j++) { // What should these values be? 0 maybe - E[0][j] = max(score[0][j - 1] - GAP_OPEN_COST, - E[0][j - 1] - GAP_EXTEND_COST); - F[0][j] = -GAP_EXTEND_COST; + E[0][j] = max(score[0][j - 1] - GAP_OP_COST, + E[0][j - 1] - GAP_EX_COST); + F[0][j] = -GAP_EX_COST; float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(0), s2str.charAt(j)); - score[0][j] = max(pairwiseScore * 10, -GAP_OPEN_COST, - -GAP_EXTEND_COST); + score[0][j] = max(pairwiseScore * 10, -GAP_OP_COST, + -GAP_EX_COST); traceback[0][j] = 1; } @@ -817,9 +840,9 @@ public class AlignSeq // Now do the left hand column for (int i = 1; i < n; i++) { - E[i][0] = -GAP_OPEN_COST; - F[i][0] = max(score[i - 1][0] - GAP_OPEN_COST, - F[i - 1][0] - GAP_EXTEND_COST); + E[i][0] = -GAP_OP_COST; + F[i][0] = max(score[i - 1][0] - GAP_OP_COST, + F[i - 1][0] - GAP_EX_COST); float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(i), s2str.charAt(0)); @@ -832,10 +855,10 @@ public class AlignSeq { for (int j = 1; j < m; j++) { - E[i][j] = max(score[i][j - 1] - GAP_OPEN_COST, - E[i][j - 1] - GAP_EXTEND_COST); - F[i][j] = max(score[i - 1][j] - GAP_OPEN_COST, - F[i - 1][j] - GAP_EXTEND_COST); + E[i][j] = max(score[i][j - 1] - GAP_OP_COST, + E[i][j - 1] - GAP_EX_COST); + F[i][j] = max(score[i - 1][j] - GAP_OP_COST, + F[i - 1][j] - GAP_EX_COST); float pairwiseScore = scoreMatrix.getPairwiseScore(s1str.charAt(i), s2str.charAt(j)); @@ -1013,7 +1036,13 @@ public class AlignSeq public static AlignSeq doGlobalNWAlignment(SequenceI s1, SequenceI s2, String type) { - AlignSeq as = new AlignSeq(s1, s2, type); + return doGlobalNWAlignment(s1, s2, type, DEFAULT_OPENCOST,DEFAULT_EXTENDCOST); + } + public static AlignSeq doGlobalNWAlignment(SequenceI s1, SequenceI s2, + String type, int opencost,int extcost) + { + + AlignSeq as = new AlignSeq(s1, s2, type,opencost,extcost); as.calcScoreMatrix(); as.traceAlignment(); diff --git a/src/jalview/analysis/PaSiMap.java b/src/jalview/analysis/PaSiMap.java index 4a670bf..ca49dc8 100755 --- a/src/jalview/analysis/PaSiMap.java +++ b/src/jalview/analysis/PaSiMap.java @@ -202,7 +202,7 @@ public class PaSiMap implements Runnable { try { - PairwiseAlignPanel alignment = new PairwiseAlignPanel(seqs, true); + PairwiseAlignPanel alignment = new PairwiseAlignPanel(seqs, true, 100, 5); float[][] scores = alignment.getAlignmentScores(); //bigger index first -- eg scores[14][13] Hashtable connectivity = seqs.calculateConnectivity(scores, dim); diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 3deb8e0..49bd4e9 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -3787,7 +3787,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, else { JInternalFrame frame = new JInternalFrame(); - frame.setContentPane(new PairwiseAlignPanel(viewport, false)); + frame.setContentPane(new PairwiseAlignPanel(viewport)); Desktop.addInternalFrame(frame, MessageManager.getString("action.pairwise_alignment"), 600, 500); diff --git a/src/jalview/gui/PairwiseAlignPanel.java b/src/jalview/gui/PairwiseAlignPanel.java index fafee94..a499365 100755 --- a/src/jalview/gui/PairwiseAlignPanel.java +++ b/src/jalview/gui/PairwiseAlignPanel.java @@ -47,6 +47,10 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel private float[][] alignmentScores; // scores used by PaSiMap + private int GAP_OPEN_COST; + + private int GAP_EXTEND_COST; + AlignmentViewport av; Vector sequences; @@ -60,9 +64,9 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel */ public PairwiseAlignPanel(AlignmentViewport viewport) { - this(viewport, false); + this(viewport, false, 120, 20); // default penalties used in AlignSeq } - public PairwiseAlignPanel(AlignmentViewport viewport, boolean endGaps) + public PairwiseAlignPanel(AlignmentViewport viewport, boolean endGaps, int gapOpenCost, int gapExtendCost) { super(); this.av = viewport; @@ -104,7 +108,7 @@ public class PairwiseAlignPanel extends GPairwiseAlignPanel for (int j = 0; j < i; j++) { AlignSeq as = new AlignSeq(seqs[i], seqStrings[i], seqs[j], - seqStrings[j], type); + seqStrings[j], type, gapOpenCost, gapExtendCost); if (as.s1str.length() == 0 || as.s2str.length() == 0) { diff --git a/test/jalview/analysis/AlignSeqTest.java b/test/jalview/analysis/AlignSeqTest.java index a9a9730..03bdd0b 100644 --- a/test/jalview/analysis/AlignSeqTest.java +++ b/test/jalview/analysis/AlignSeqTest.java @@ -76,4 +76,16 @@ public class AlignSeqTest String s = "aArRnNzZxX *.-?"; assertArrayEquals(expected, as.indexEncode(s)); } + @Test(groups= {"Functional"}) + public void testGlobalAlignment() + { + String seq1="CAGCTAGCG",seq2="CCATACGA"; + Sequence sq1=new Sequence("s1",seq1),sq2=new Sequence("s2",seq2); + // AlignSeq doesn't report the unaligned regions at either end of sequences + //String alseq1="-CAGCTAGCG-",alseq2="CCA--TA-CGA"; + // so we check we have the aligned segment correct only + String alseq1="CAGCTAGCG",alseq2="CA--TA-CG"; + AlignSeq as = AlignSeq.doGlobalNWAlignment(sq1,sq2,AlignSeq.DNA); + assertEquals(as.getAStr1()+"\n"+as.getAStr2(),alseq1+"\n"+alseq2); + } } diff --git a/test/jalview/gui/PairwiseAlignmentPanelTest.java b/test/jalview/gui/PairwiseAlignmentPanelTest.java index 34e5877..750698a 100644 --- a/test/jalview/gui/PairwiseAlignmentPanelTest.java +++ b/test/jalview/gui/PairwiseAlignmentPanelTest.java @@ -55,7 +55,7 @@ public class PairwiseAlignmentPanelTest sg.setEndRes(35); viewport.setSelectionGroup(sg); - PairwiseAlignPanel testee = new PairwiseAlignPanel(viewport, false); + PairwiseAlignPanel testee = new PairwiseAlignPanel(viewport); String text = ((JTextArea) PA.getValue(testee, "textarea")).getText(); String expected = "Score = 80.0\n" + "Length of alignment = 4\n" @@ -80,7 +80,7 @@ public class PairwiseAlignmentPanelTest DataSourceType.PASTE); AlignViewport viewport = af.getViewport(); - PairwiseAlignPanel testee = new PairwiseAlignPanel(viewport, false); + PairwiseAlignPanel testee = new PairwiseAlignPanel(viewport); String text = ((JTextArea) PA.getValue(testee, "textarea")).getText(); String expected = "Score = 80.0\n" + "Length of alignment = 4\n"