*/
package jalview.io;
+import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
+import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.api.ViewStyleI;
import jalview.bin.Cache;
import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.HiddenSequences;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
import jalview.gui.Jalview2XML;
import jalview.schemes.AnnotationColourGradient;
import jalview.schemes.ColourSchemeI;
+import jalview.viewmodel.AlignmentViewport;
import java.io.File;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.testng.Assert;
public static void tearDownAfterClass() throws Exception
{
jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
-
}
- public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
+ int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
{
int numdsann = 0;
for (SequenceI sq : avp.getAlignment().getDataset().getSequences())
*
* @throws Exception
*/
- @Test(groups = { "Functional" }, enabled = false)
+ @Test(groups = { "Functional" }, enabled = true)
public void testStoreAndRecoverExpandedviews() throws Exception
{
AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
}
/**
- * based on above test store and recovery of expanded views.
+ * Test save and reload of a project with a different representative sequence
+ * in each view.
*
* @throws Exception
*/
public void testStoreAndRecoverReferenceSeqSettings() throws Exception
{
Desktop.instance.closeAll_actionPerformed(null);
- String afid = "";
- {
- AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
- "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
- assertTrue("Didn't read in the example file correctly.", af != null);
- afid = af.getViewport().getSequenceSetId();
- }
- Map<String, SequenceI> refs = new HashMap<String, SequenceI>();
+ AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
+ "examples/exampleFile_2_7.jar", FormatAdapter.FILE);
+ assertTrue("Didn't read in the example file correctly.", af != null);
+ String afid = af.getViewport().getSequenceSetId();
+
+ /*
+ * remember representative and hidden sequences marked
+ * on each panel
+ */
+ Map<String, SequenceI> refseqs = new HashMap<String, SequenceI>();
+ Map<String, List<String>> hiddenSeqNames = new HashMap<String, List<String>>();
+
+ /*
+ * mark sequence 2, 3, 4.. in panels 1, 2, 3...
+ * as reference sequence for itself and the preceding sequence
+ */
int n = 1;
for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
{
- // mark representative
- SequenceI rep = ap.getAlignment().getSequenceAt(
- n++ % ap.getAlignment().getHeight());
- refs.put(ap.getViewName(), rep);
+ AlignViewportI av = ap.getAlignViewport();
+ AlignmentI alignment = ap.getAlignment();
+ int repIndex = n % alignment.getHeight();
+ SequenceI rep = alignment.getSequenceAt(repIndex);
+ refseqs.put(ap.getViewName(), rep);
+ List<String> hiddenNames = new ArrayList<String>();
+ hiddenSeqNames.put(ap.getViewName(), hiddenNames);
+
+ /*
+ * hide rep sequence and the one before it
+ */
+ SequenceI seqToHide = alignment.getSequenceAt(repIndex);
+ SequenceGroup sg = new SequenceGroup();
+ sg.addSequence(seqToHide, false);
+ SequenceI precedingSeq = alignment.getSequenceAt(repIndex - 1);
+ sg.addSequence(precedingSeq, false);
+ av.setSelectionGroup(sg);
+ ((AlignmentViewport) av).hideSequences(seqToHide, true);
+
+ /*
+ * record names of hidden sequences
+ */
+ HiddenSequences hs = alignment.getHiddenSequences();
+ for (SequenceI seq : hs.hiddenSequences)
+ {
+ if (seq != null)
+ {
+ hiddenNames.add(seq.getName());
+ }
+ }
// code from mark/unmark sequence as reference in jalview.gui.PopupMenu
- // todo refactor the to an alignment view controller
- ap.getAlignViewport().setDisplayReferenceSeq(true);
- ap.getAlignViewport().setColourByReferenceSeq(true);
- ap.getAlignViewport().getAlignment().setSeqrep(rep);
+ // todo refactor this to an alignment view controller
+ av.setDisplayReferenceSeq(true);
+ av.setColourByReferenceSeq(true);
+ av.getAlignment().setSeqrep(rep);
+
+ n++;
}
File tfile = File.createTempFile("testStoreAndRecoverReferenceSeq",
".jvp");
try
{
new Jalview2XML(false).saveState(tfile);
- } catch (Error e)
- {
- Assert.fail("Didn't save the expanded view state", e);
- } catch (Exception e)
+ } catch (Throwable e)
{
Assert.fail("Didn't save the expanded view state", e);
}
{
Assert.assertEquals(Desktop.getAlignFrames().length, 0);
}
- {
- AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
+
+ af = new FileLoader().LoadFileWaitTillLoaded(
tfile.getAbsolutePath(), FormatAdapter.FILE);
- afid = af.getViewport().getSequenceSetId();
- }
+ afid = af.getViewport().getSequenceSetId();
+
for (AlignmentViewPanel ap : Desktop.getAlignmentPanels(afid))
{
// check representative
- SequenceI rep = ap.getAlignment().getSeqrep();
+ AlignmentI alignment = ap.getAlignment();
+ SequenceI rep = alignment.getSeqrep();
Assert.assertNotNull(rep,
"Couldn't restore sequence representative from project");
// can't use a strong equals here, because by definition, the sequence IDs
// will be different.
// could set vamsas session save/restore flag to preserve IDs across
// load/saves.
- Assert.assertEquals(refs.get(ap.getViewName()).toString(),
+ Assert.assertEquals(refseqs.get(ap.getViewName()).toString(),
rep.toString(),
"Representative wasn't the same when recovered.");
Assert.assertTrue(ap.getAlignViewport().isDisplayReferenceSeq(),
"Display reference sequence view setting not set.");
Assert.assertTrue(ap.getAlignViewport().isColourByReferenceSeq(),
"Colour By Reference Seq view setting not set.");
+
+ /*
+ * verify hidden sequences in restored panel
+ */
+ List<String> hidden = hiddenSeqNames.get(ap.getViewName());
+ HiddenSequences hs = alignment.getHiddenSequences();
+ assertEquals(
+ "wrong number of restored hidden sequences in "
+ + ap.getViewName(),
+ hidden.size(), hs.getSize());
}
}