From: kiramt Date: Tue, 26 Sep 2017 18:35:30 +0000 (+0100) Subject: Merge remote-tracking branch 'origin/bug/JAL-2742' into X-Git-Tag: Release_2_10_4~55^2~1^2~103 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=7012b60c122812320c562563505e308ce485d7e7;hp=7c70de6dbc24545b9da5aac77896220d15394fb9;p=jalview.git Merge remote-tracking branch 'origin/bug/JAL-2742' into feature/JAL-2674take2 Conflicts: src/jalview/datamodel/CigarArray.java --- diff --git a/src/jalview/datamodel/CigarArray.java b/src/jalview/datamodel/CigarArray.java index d90b3cd..2aa3efb 100644 --- a/src/jalview/datamodel/CigarArray.java +++ b/src/jalview/datamodel/CigarArray.java @@ -172,35 +172,29 @@ public class CigarArray extends CigarBase hideStart = region[0]; hideEnd = region[1]; - // edit hidden regions to selection range - // TODO possible bug here in original code: if hideEnd==last we continue - // but shouldn't this be a single D at start? - if (hideStart < last) + // just move on if hideEnd is before last + if (hideEnd < last) { - if (hideEnd > last) - { - hideStart = last; - } - else - { - continue; - } + continue; } - + // exit if next region is after end if (hideStart > end) { break; } - if (hideEnd > end) + // truncate region at start if last falls in region + if ((hideStart < last) && (hideEnd >= last)) { - hideEnd = end; + hideStart = last; } - if (hideStart > hideEnd) + // truncate region at end if end falls in region + if (hideEnd > end) // already checked that hideStart<=end { - break; + hideEnd = end; } + /** * form operations... */ @@ -213,7 +207,7 @@ public class CigarArray extends CigarBase } // Final match if necessary. - if (last < end) + if (last <= end) { addOperation(CigarArray.M, end - last + 1); } diff --git a/test/jalview/datamodel/CigarArrayTest.java b/test/jalview/datamodel/CigarArrayTest.java new file mode 100644 index 0000000..12f31fc --- /dev/null +++ b/test/jalview/datamodel/CigarArrayTest.java @@ -0,0 +1,126 @@ +/* + * 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. + */ +package jalview.datamodel; + +import static org.testng.Assert.assertEquals; + +import jalview.gui.JvOptionPane; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class CigarArrayTest +{ + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + + @Test(groups = "Functional") + public void TestConstructor() + { + SequenceI seq1 = new Sequence("sq1", + "ASFDDABACBACBACBACBACBACBABCABCBACBABCAB"); + Sequence seq2 = new Sequence("sq2", + "TTTTTTACBCBABCABCABCABCBACBACBABCABCABCBA"); + + // construct alignment + AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 }); + + // hide columns + HiddenColumns hc = new HiddenColumns(); + hc.hideColumns(3, 6); + hc.hideColumns(16, 20); + + // select group + SequenceGroup sg1 = new SequenceGroup(); + sg1.addSequence(seq1, false); + sg1.setStartRes(2); + sg1.setEndRes(23); + + CigarArray cig = new CigarArray(al, hc, sg1); + String result = cig.getCigarstring(); + assertEquals(result, "1M4D9M5D3M"); + + // group starts at hidden cols + sg1.setStartRes(3); + cig = new CigarArray(al, hc, sg1); + result = cig.getCigarstring(); + assertEquals(result, "4D9M5D3M"); + + // group starts at last but 1 hidden col + sg1.setStartRes(5); + cig = new CigarArray(al, hc, sg1); + result = cig.getCigarstring(); + assertEquals(result, "2D9M5D3M"); + + // group starts at last hidden col + /* sg1.setStartRes(6); + cig = new CigarArray(al, hc, sg1); + result = cig.getCigarstring(); + assertEquals(result, "1D9M5D3M"); + */ + // group starts just after hidden region + sg1.setStartRes(7); + cig = new CigarArray(al, hc, sg1); + result = cig.getCigarstring(); + assertEquals(result, "9M5D3M"); + + // group ends just before start of hidden region + sg1.setStartRes(5); + sg1.setEndRes(15); + cig = new CigarArray(al, hc, sg1); + result = cig.getCigarstring(); + assertEquals(result, "2D9M"); + + // group ends at start of hidden region + sg1.setEndRes(16); + cig = new CigarArray(al, hc, sg1); + result = cig.getCigarstring(); + assertEquals(result, "2D9M1D"); + + // group ends 1 after start of hidden region + sg1.setEndRes(17); + cig = new CigarArray(al, hc, sg1); + result = cig.getCigarstring(); + assertEquals(result, "2D9M2D"); + + // group ends at end of hidden region + sg1.setEndRes(20); + cig = new CigarArray(al, hc, sg1); + result = cig.getCigarstring(); + assertEquals(result, "2D9M5D"); + + // group ends just after end of hidden region + sg1.setEndRes(21); + cig = new CigarArray(al, hc, sg1); + result = cig.getCigarstring(); + assertEquals(result, "2D9M5D1M"); + + // group ends 2 after end of hidden region + sg1.setEndRes(22); + cig = new CigarArray(al, hc, sg1); + result = cig.getCigarstring(); + assertEquals(result, "2D9M5D2M"); + } +}