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.
23 import static org.junit.Assert.assertNotEquals;
24 import static org.testng.Assert.assertEquals;
25 import static org.testng.Assert.assertFalse;
26 import static org.testng.Assert.assertNotNull;
27 import static org.testng.Assert.assertNotSame;
28 import static org.testng.Assert.assertSame;
29 import static org.testng.Assert.assertTrue;
31 import jalview.api.FeatureColourI;
32 import jalview.bin.Cache;
33 import jalview.bin.Jalview;
34 import jalview.datamodel.Alignment;
35 import jalview.datamodel.AlignmentI;
36 import jalview.datamodel.AlignmentView;
37 import jalview.datamodel.HiddenColumns;
38 import jalview.datamodel.Sequence;
39 import jalview.datamodel.SequenceFeature;
40 import jalview.datamodel.SequenceGroup;
41 import jalview.datamodel.SequenceI;
42 import jalview.io.DataSourceType;
43 import jalview.io.FileLoader;
44 import jalview.project.Jalview2xmlTests;
45 import jalview.renderer.ResidueShaderI;
46 import jalview.schemes.BuriedColourScheme;
47 import jalview.schemes.FeatureColour;
48 import jalview.schemes.HelixColourScheme;
49 import jalview.schemes.JalviewColourScheme;
50 import jalview.schemes.StrandColourScheme;
51 import jalview.schemes.TurnColourScheme;
52 import jalview.util.MessageManager;
54 import java.awt.Color;
55 import java.util.Arrays;
56 import java.util.Iterator;
58 import org.testng.annotations.AfterMethod;
59 import org.testng.annotations.BeforeClass;
60 import org.testng.annotations.BeforeMethod;
61 import org.testng.annotations.Test;
63 public class SplitFrameTest
65 AlignFrame dnaAf, proteinAf;
67 SplitFrame testSplitFrame;
69 @BeforeClass(alwaysRun = true)
70 public static void setUpBeforeClass() throws Exception
74 * use read-only test properties file
76 Cache.loadProperties("test/jalview/io/testProps.jvprops");
77 Jalview.main(new String[] { "-nonews" });
80 @AfterMethod(alwaysRun = true)
81 public void tearDown()
83 Desktop.instance.closeAll_actionPerformed(null);
87 * configure (read-only) properties for test to ensure Consensus is computed
88 * for colour Above PID testing
90 @BeforeMethod(alwaysRun = true)
93 Cache.loadProperties("test/jalview/io/testProps.jvprops");
94 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
95 Boolean.TRUE.toString());
96 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
97 "examples/testdata/MN908947.jvp", DataSourceType.FILE);
100 * wait for Consensus thread to complete
104 while (af.getViewport().getConsensusSeq() == null)
109 } catch (InterruptedException e)
114 testSplitFrame = (SplitFrame) af.getSplitViewContainer();
115 proteinAf=af.getViewport().getAlignment().isNucleotide() ? testSplitFrame.getComplementAlignFrame(af) : af;
116 dnaAf=testSplitFrame.getComplementAlignFrame(proteinAf);
119 public static void setUpJvOptionPane()
121 JvOptionPane.setInteractiveMode(false);
122 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
125 @Test(groups= {"Functional"})
126 public void testAlignAsSplitFrame()
130 * If alignment was requested from one half of a SplitFrame, show in a
131 * SplitFrame with the other pane similarly aligned.
133 AlignFrame requestedBy = proteinAf;
134 AlignmentI wholeProteinAl = proteinAf.getViewport().getAlignment();
135 SequenceI[] sel = wholeProteinAl.getSequencesArray();
136 // Select 3 sequences, from columns 3-7 inclusive
137 SequenceGroup selRegion = new SequenceGroup(
138 Arrays.asList(sel[0], sel[1], sel[3]));
139 selRegion.setStartRes(3);
140 selRegion.setEndRes(7);
141 proteinAf.getViewport().setSelectionGroup(selRegion);
142 proteinAf.getViewport().sendSelection();
143 assertNotNull(dnaAf.getViewport().getSelectionGroup());
144 AlignmentView inputView = proteinAf.gatherSequencesForAlignment();
145 assertEquals(inputView.getSequences().length, 3);
146 assertEquals(inputView.getWidth(), 5);
147 assertNotNull(inputView.getComplementView());
149 Object alAndHidden[] = inputView.getAlignmentAndHiddenColumns(
150 proteinAf.getViewport().getGapCharacter());
151 AlignmentI result = new Alignment((SequenceI[]) alAndHidden[0]);
152 result.setHiddenColumns((HiddenColumns) alAndHidden[1]);
153 // check we are referring to the expected alignment
155 requestedBy.getSplitViewContainer().getComplement(requestedBy),
156 dnaAf.getCurrentView().getAlignment());
157 // and that datasets are consistent (if not, there's a problem elsewhere in
158 // splitframe construction
159 AlignmentI complementDs = requestedBy.getSplitViewContainer()
160 .getComplement(requestedBy).getDataset();
161 assertTrue(complementDs == dnaAf
162 .getViewport().getAlignment().getDataset());
163 assertTrue(complementDs == proteinAf.getViewport().getAlignment()
166 char gc = requestedBy.getSplitViewContainer().getComplement(requestedBy)
169 AlignmentI complement = inputView.getComplementView()
170 .getVisibleAlignment(gc);
171 String complementTitle = requestedBy.getSplitViewContainer()
172 .getComplementTitle(requestedBy);
173 // becomes null if the alignment window was closed before the alignment
175 AlignmentI copyComplement = new Alignment(complement);
176 // todo should this be done by copy constructor?
177 copyComplement.setGapCharacter(complement.getGapCharacter());
178 // share the same dataset (and the mappings it holds)
179 copyComplement.setDataset(complementDs);
180 copyComplement.alignAs(result);
181 // check shape is as expected
182 assertEquals(copyComplement.getWidth(), result.getWidth() * 3);
183 assertEquals(copyComplement.getHeight(), result.getHeight());
184 // specific bug with this set - see same CDS for all distinct products
186 !copyComplement.getSequenceAt(0).getSequenceAsString().equals(
187 copyComplement.getSequenceAt(1).getSequenceAsString()),
188 "Didn't reconstruct CDS correctly");
189 // now get the result again, do some edits and reconstruct again
190 alAndHidden = inputView.getAlignmentAndHiddenColumns(
191 proteinAf.getViewport().getGapCharacter());
192 AlignmentI newresult = new Alignment((SequenceI[]) alAndHidden[0]);
193 newresult.setHiddenColumns((HiddenColumns) alAndHidden[1]);
194 newresult.setDataset(complementDs);
195 newresult.getSequenceAt(0).insertCharAt(3, 3, '-');
196 newresult.getSequenceAt(1).insertCharAt(0, 3, '-');
198 AlignmentI newcomplement = inputView.getComplementView()
199 .getVisibleAlignment('-');
200 newcomplement.alignAs(newresult);
201 assertEquals(newcomplement.getWidth(), newresult.getWidth() * 3);
202 assertEquals(newcomplement.getHeight(), newresult.getHeight());
203 // if reconstruction worked, the first sequence should not equal the first
204 // sequence in the original CDS 'alignAs'
205 for (int sq = 0; sq < 3; sq++)
207 // check same CDS in same position
208 assertTrue(newcomplement.getSequenceAt(sq)
209 .getDatasetSequence() == newcomplement.getSequenceAt(sq)
210 .getDatasetSequence());
211 // verify that sequence strings are different
212 assertTrue(!newcomplement.getSequenceAt(sq).getSequenceAsString()
213 .equals(copyComplement.getSequenceAt(sq)
214 .getSequenceAsString()));
216 // JAL-3748 bug manifests as duplicated CDS sequence content, so need to
217 // also check each CDS is distinct.
219 !newcomplement.getSequenceAt(0).getSequenceAsString().equals(
220 newcomplement.getSequenceAt(1).getSequenceAsString()),
221 "Didn't reconstruct CDS correctly");