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 jalview.util.UrlConstants.DB_ACCESSION;
24 import static jalview.util.UrlConstants.SEQUENCE_ID;
25 import static org.testng.AssertJUnit.assertEquals;
26 import static org.testng.AssertJUnit.assertFalse;
27 import static org.testng.AssertJUnit.assertNotNull;
28 import static org.testng.AssertJUnit.assertNull;
29 import static org.testng.AssertJUnit.assertTrue;
31 import java.awt.Component;
32 import java.awt.Container;
33 import java.io.IOException;
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.Iterator;
37 import java.util.List;
39 import javax.swing.JMenu;
40 import javax.swing.JMenuItem;
41 import javax.swing.JPopupMenu;
42 import javax.swing.JSeparator;
44 import org.testng.annotations.BeforeClass;
45 import org.testng.annotations.BeforeMethod;
46 import org.testng.annotations.Test;
48 import jalview.bin.Cache;
49 import jalview.datamodel.AlignmentAnnotation;
50 import jalview.datamodel.AlignmentI;
51 import jalview.datamodel.Annotation;
52 import jalview.datamodel.ColumnSelection;
53 import jalview.datamodel.DBRefEntry;
54 import jalview.datamodel.DBRefSource;
55 import jalview.datamodel.HiddenColumns;
56 import jalview.datamodel.Sequence;
57 import jalview.datamodel.SequenceFeature;
58 import jalview.datamodel.SequenceGroup;
59 import jalview.datamodel.SequenceI;
60 import jalview.io.DataSourceType;
61 import jalview.io.FileFormat;
62 import jalview.io.FormatAdapter;
63 import jalview.urls.api.UrlProviderFactoryI;
64 import jalview.urls.desktop.DesktopUrlProviderFactory;
65 import jalview.util.MessageManager;
66 import jalview.util.UrlConstants;
68 public class PopupMenuTest
71 @BeforeClass(alwaysRun = true)
72 public void setUpJvOptionPane()
74 JvOptionPane.setInteractiveMode(false);
75 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
78 // 4 sequences x 13 positions
79 final static String TEST_DATA = ">FER_CAPAA Ferredoxin\n"
81 + ">FER_CAPAN Ferredoxin, chloroplast precursor\n"
83 + ">FER1_SOLLC Ferredoxin-1, chloroplast precursor\n"
84 + "TIETHKEEELTA-\n" + ">Q93XJ9_SOLTU Ferredoxin I precursor\n"
89 AlignmentPanel parentPanel;
91 PopupMenu testee = null;
93 @BeforeMethod(alwaysRun = true)
94 public void setUp() throws IOException
96 Cache.loadProperties("test/jalview/io/testProps.jvprops");
99 String inMenuString = ("EMBL-EBI Search | http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$"
103 + "UNIPROT | http://www.uniprot.org/uniprot/$" + DB_ACCESSION + "$")
105 + ("INTERPRO | http://www.ebi.ac.uk/interpro/entry/$"
106 + DB_ACCESSION + "$")
109 // Gene3D entry tests for case (in)sensitivity
110 ("Gene3D | http://gene3d.biochem.ucl.ac.uk/Gene3D/search?sterm=$"
111 + DB_ACCESSION + "$&mode=protein");
113 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(
114 UrlConstants.DEFAULT_LABEL, inMenuString, "");
115 Preferences.sequenceUrlLinks = factory.createUrlProvider();
117 alignment = new FormatAdapter().readFile(TEST_DATA,
118 DataSourceType.PASTE, FileFormat.Fasta);
119 AlignFrame af = new AlignFrame(alignment, 700, 500);
120 parentPanel = new AlignmentPanel(af, af.getViewport());
121 testee = new PopupMenu(parentPanel, alignment.getSequenceAt(0), null);
123 for (SequenceI seq : alignment.getSequences())
125 final AlignmentAnnotation annotation = new AlignmentAnnotation(
126 "label" + i, "desc" + i, i);
127 annotation.setCalcId("calcId" + i);
128 seq.addAlignmentAnnotation(annotation);
129 annotation.setSequenceRef(seq);
133 @Test(groups = { "Functional" })
134 public void testConfigureReferenceAnnotationsMenu_noSequenceSelected()
136 JMenuItem menu = new JMenuItem();
137 List<SequenceI> seqs = new ArrayList<>();
138 testee.configureReferenceAnnotationsMenu(menu, seqs);
139 assertFalse(menu.isEnabled());
141 menu.setEnabled(true);
142 testee.configureReferenceAnnotationsMenu(menu, null);
143 assertFalse(menu.isEnabled());
147 * Test building the 'add reference annotations' menu for the case where there
148 * are no reference annotations to add to the alignment. The menu item should
151 @Test(groups = { "Functional" })
152 public void testConfigureReferenceAnnotationsMenu_noReferenceAnnotations()
154 JMenuItem menu = new JMenuItem();
157 * Initial state is that sequences have annotations, and have dataset
158 * sequences, but the dataset sequences have no annotations. Hence nothing
161 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
163 testee.configureReferenceAnnotationsMenu(menu, seqs);
164 assertFalse(menu.isEnabled());
168 * Test building the 'add reference annotations' menu for the case where all
169 * reference annotations are already on the alignment. The menu item should be
172 @Test(groups = { "Functional" })
173 public void testConfigureReferenceAnnotationsMenu_alreadyAdded()
175 JMenuItem menu = new JMenuItem();
176 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
178 // make up new annotations and add to dataset sequences, sequences and
180 attachReferenceAnnotations(seqs, true, true);
182 testee.configureReferenceAnnotationsMenu(menu, seqs);
183 assertFalse(menu.isEnabled());
187 * Test building the 'add reference annotations' menu for the case where
188 * several reference annotations are on the dataset but not on the sequences.
189 * The menu item should be enabled, and acquire a tooltip which lists the
190 * annotation sources (calcIds) and type (labels).
192 @Test(groups = { "Functional" })
193 public void testConfigureReferenceAnnotationsMenu()
195 JMenuItem menu = new JMenuItem();
196 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
198 // make up new annotations and add to dataset sequences
199 attachReferenceAnnotations(seqs, false, false);
201 testee.configureReferenceAnnotationsMenu(menu, seqs);
202 assertTrue(menu.isEnabled());
203 String s = MessageManager.getString("label.add_annotations_for");
204 String expected = "<html><style> div.ttip {width:350px;white-space:pre-wrap;padding:2px;overflow-wrap:break-word;}</style>"
205 + "<div class=\"ttip\">" + s
206 + "<br/>Jmol/secondary structure<br/>PDB/Temp </div></html>";
207 assertEquals(expected, menu.getToolTipText());
211 * Test building the 'add reference annotations' menu for the case where
212 * several reference annotations are on the dataset and the sequences but not
213 * on the alignment. The menu item should be enabled, and acquire a tooltip
214 * which lists the annotation sources (calcIds) and type (labels).
216 @Test(groups = { "Functional" })
217 public void testConfigureReferenceAnnotationsMenu_notOnAlignment()
219 JMenuItem menu = new JMenuItem();
220 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
222 // make up new annotations and add to dataset sequences and sequences
223 attachReferenceAnnotations(seqs, true, false);
225 testee.configureReferenceAnnotationsMenu(menu, seqs);
226 assertTrue(menu.isEnabled());
227 String s = MessageManager.getString("label.add_annotations_for");
228 String expected = "<html><style> div.ttip {width:350px;white-space:pre-wrap;padding:2px;overflow-wrap:break-word;}</style>"
229 + "<div class=\"ttip\">" + s
230 + "<br/>Jmol/secondary structure<br/>PDB/Temp </div></html>";
231 assertEquals(expected, menu.getToolTipText());
235 * Generate annotations and add to dataset sequences and (optionally)
236 * sequences and/or alignment
239 * @param addToSequence
240 * @param addToAlignment
242 private void attachReferenceAnnotations(List<SequenceI> seqs,
243 boolean addToSequence, boolean addToAlignment)
245 // PDB.secondary structure on Sequence0
246 AlignmentAnnotation annotation = new AlignmentAnnotation(
247 "secondary structure", "", 0);
248 annotation.setCalcId("PDB");
249 seqs.get(0).getDatasetSequence().addAlignmentAnnotation(annotation);
252 seqs.get(0).addAlignmentAnnotation(annotation);
256 this.alignment.addAnnotation(annotation);
259 // PDB.Temp on Sequence1
260 annotation = new AlignmentAnnotation("Temp", "", 0);
261 annotation.setCalcId("PDB");
262 seqs.get(1).getDatasetSequence().addAlignmentAnnotation(annotation);
265 seqs.get(1).addAlignmentAnnotation(annotation);
269 this.alignment.addAnnotation(annotation);
272 // JMOL.secondary structure on Sequence0
273 annotation = new AlignmentAnnotation("secondary structure", "", 0);
274 annotation.setCalcId("Jmol");
275 seqs.get(0).getDatasetSequence().addAlignmentAnnotation(annotation);
278 seqs.get(0).addAlignmentAnnotation(annotation);
282 this.alignment.addAnnotation(annotation);
287 * Test building the 'add reference annotations' menu for the case where there
288 * are two alignment views:
290 * <li>in one view, reference annotations have been added (are on the
291 * datasets, sequences and alignment)</li>
292 * <li>in the current view, reference annotations are on the dataset and
293 * sequence, but not the alignment</li>
295 * The menu item should be enabled, and acquire a tooltip which lists the
296 * annotation sources (calcIds) and type (labels).
298 @Test(groups = { "Functional" })
299 public void testConfigureReferenceAnnotationsMenu_twoViews()
304 * Test for building menu options including 'show' and 'hide' annotation
307 @Test(groups = { "Functional" })
308 public void testBuildAnnotationTypesMenus()
310 JMenu showMenu = new JMenu();
311 JMenu hideMenu = new JMenu();
312 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
314 // make up new annotations and add to sequences and to the alignment
316 // PDB.secondary structure on Sequence0
317 AlignmentAnnotation annotation = new AlignmentAnnotation(
318 "secondary structure", "", new Annotation[] {});
319 annotation.setCalcId("PDB");
320 annotation.visible = true;
321 seqs.get(0).addAlignmentAnnotation(annotation);
322 parentPanel.getAlignment().addAnnotation(annotation);
324 // JMOL.secondary structure on Sequence0 - hidden
325 annotation = new AlignmentAnnotation("secondary structure", "",
326 new Annotation[] {});
327 annotation.setCalcId("JMOL");
328 annotation.visible = false;
329 seqs.get(0).addAlignmentAnnotation(annotation);
330 parentPanel.getAlignment().addAnnotation(annotation);
332 // Jpred.SSP on Sequence0 - hidden
333 annotation = new AlignmentAnnotation("SSP", "", new Annotation[] {});
334 annotation.setCalcId("JPred");
335 annotation.visible = false;
336 seqs.get(0).addAlignmentAnnotation(annotation);
337 parentPanel.getAlignment().addAnnotation(annotation);
339 // PDB.Temp on Sequence1
340 annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
341 annotation.setCalcId("PDB");
342 annotation.visible = true;
343 seqs.get(1).addAlignmentAnnotation(annotation);
344 parentPanel.getAlignment().addAnnotation(annotation);
347 * Expect menu options to show "secondary structure" and "SSP", and to hide
348 * "secondary structure" and "Temp". Tooltip should be calcId.
350 testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
352 assertTrue(showMenu.isEnabled());
353 assertTrue(hideMenu.isEnabled());
355 Component[] showOptions = showMenu.getMenuComponents();
356 Component[] hideOptions = hideMenu.getMenuComponents();
358 assertEquals(4, showOptions.length); // includes 'All' and separator
359 assertEquals(4, hideOptions.length);
360 String all = MessageManager.getString("label.all");
361 assertEquals(all, ((JMenuItem) showOptions[0]).getText());
362 assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
363 assertEquals(JSeparator.HORIZONTAL,
364 ((JSeparator) showOptions[1]).getOrientation());
365 assertEquals("secondary structure",
366 ((JMenuItem) showOptions[2]).getText());
367 assertEquals("JMOL", ((JMenuItem) showOptions[2]).getToolTipText());
368 assertEquals("SSP", ((JMenuItem) showOptions[3]).getText());
369 assertEquals("JPred", ((JMenuItem) showOptions[3]).getToolTipText());
371 assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
372 assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
373 assertEquals(JSeparator.HORIZONTAL,
374 ((JSeparator) hideOptions[1]).getOrientation());
375 assertEquals("secondary structure",
376 ((JMenuItem) hideOptions[2]).getText());
377 assertEquals("PDB", ((JMenuItem) hideOptions[2]).getToolTipText());
378 assertEquals("Temp", ((JMenuItem) hideOptions[3]).getText());
379 assertEquals("PDB", ((JMenuItem) hideOptions[3]).getToolTipText());
383 * Test for building menu options with only 'hide' annotation types enabled.
385 @Test(groups = { "Functional" })
386 public void testBuildAnnotationTypesMenus_showDisabled()
388 JMenu showMenu = new JMenu();
389 JMenu hideMenu = new JMenu();
390 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
392 // make up new annotations and add to sequences and to the alignment
394 // PDB.secondary structure on Sequence0
395 AlignmentAnnotation annotation = new AlignmentAnnotation(
396 "secondary structure", "", new Annotation[] {});
397 annotation.setCalcId("PDB");
398 annotation.visible = true;
399 seqs.get(0).addAlignmentAnnotation(annotation);
400 parentPanel.getAlignment().addAnnotation(annotation);
402 // PDB.Temp on Sequence1
403 annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
404 annotation.setCalcId("PDB");
405 annotation.visible = true;
406 seqs.get(1).addAlignmentAnnotation(annotation);
407 parentPanel.getAlignment().addAnnotation(annotation);
410 * Expect menu options to hide "secondary structure" and "Temp". Tooltip
411 * should be calcId. 'Show' menu should be disabled.
413 testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
415 assertFalse(showMenu.isEnabled());
416 assertTrue(hideMenu.isEnabled());
418 Component[] showOptions = showMenu.getMenuComponents();
419 Component[] hideOptions = hideMenu.getMenuComponents();
421 assertEquals(2, showOptions.length); // includes 'All' and separator
422 assertEquals(4, hideOptions.length);
423 String all = MessageManager.getString("label.all");
424 assertEquals(all, ((JMenuItem) showOptions[0]).getText());
425 assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
426 assertEquals(JSeparator.HORIZONTAL,
427 ((JSeparator) showOptions[1]).getOrientation());
429 assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
430 assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
431 assertEquals(JSeparator.HORIZONTAL,
432 ((JSeparator) hideOptions[1]).getOrientation());
433 assertEquals("secondary structure",
434 ((JMenuItem) hideOptions[2]).getText());
435 assertEquals("PDB", ((JMenuItem) hideOptions[2]).getToolTipText());
436 assertEquals("Temp", ((JMenuItem) hideOptions[3]).getText());
437 assertEquals("PDB", ((JMenuItem) hideOptions[3]).getToolTipText());
441 * Test for building menu options with only 'show' annotation types enabled.
443 @Test(groups = { "Functional" })
444 public void testBuildAnnotationTypesMenus_hideDisabled()
446 JMenu showMenu = new JMenu();
447 JMenu hideMenu = new JMenu();
448 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
450 // make up new annotations and add to sequences and to the alignment
452 // PDB.secondary structure on Sequence0
453 AlignmentAnnotation annotation = new AlignmentAnnotation(
454 "secondary structure", "", new Annotation[] {});
455 annotation.setCalcId("PDB");
456 annotation.visible = false;
457 seqs.get(0).addAlignmentAnnotation(annotation);
458 parentPanel.getAlignment().addAnnotation(annotation);
460 // PDB.Temp on Sequence1
461 annotation = new AlignmentAnnotation("Temp", "", new Annotation[] {});
462 annotation.setCalcId("PDB2");
463 annotation.visible = false;
464 seqs.get(1).addAlignmentAnnotation(annotation);
465 parentPanel.getAlignment().addAnnotation(annotation);
468 * Expect menu options to show "secondary structure" and "Temp". Tooltip
469 * should be calcId. 'hide' menu should be disabled.
471 testee.buildAnnotationTypesMenus(showMenu, hideMenu, seqs);
473 assertTrue(showMenu.isEnabled());
474 assertFalse(hideMenu.isEnabled());
476 Component[] showOptions = showMenu.getMenuComponents();
477 Component[] hideOptions = hideMenu.getMenuComponents();
479 assertEquals(4, showOptions.length); // includes 'All' and separator
480 assertEquals(2, hideOptions.length);
481 String all = MessageManager.getString("label.all");
482 assertEquals(all, ((JMenuItem) showOptions[0]).getText());
483 assertTrue(showOptions[1] instanceof JPopupMenu.Separator);
484 assertEquals(JSeparator.HORIZONTAL,
485 ((JSeparator) showOptions[1]).getOrientation());
486 assertEquals("secondary structure",
487 ((JMenuItem) showOptions[2]).getText());
488 assertEquals("PDB", ((JMenuItem) showOptions[2]).getToolTipText());
489 assertEquals("Temp", ((JMenuItem) showOptions[3]).getText());
490 assertEquals("PDB2", ((JMenuItem) showOptions[3]).getToolTipText());
492 assertEquals(all, ((JMenuItem) hideOptions[0]).getText());
493 assertTrue(hideOptions[1] instanceof JPopupMenu.Separator);
494 assertEquals(JSeparator.HORIZONTAL,
495 ((JSeparator) hideOptions[1]).getOrientation());
499 * Test for adding sequence id, dbref and feature links
501 @Test(groups = { "Functional" })
502 public void testBuildLinkMenu()
504 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
505 final SequenceI seq0 = seqs.get(0);
506 final SequenceI seq1 = seqs.get(1);
507 final List<SequenceFeature> noFeatures = Collections
508 .<SequenceFeature> emptyList();
509 final String linkText = MessageManager.getString("action.link");
511 seq0.addDBRef(new DBRefEntry(DBRefSource.UNIPROT, "1", "P83527"));
512 seq0.addDBRef(new DBRefEntry("INTERPRO", "1", "IPR001041"));
513 seq0.addDBRef(new DBRefEntry("INTERPRO", "1", "IPR012675"));
514 seq0.addDBRef(new DBRefEntry("INTERPRO", "1", "IPR006058"));
515 seq1.addDBRef(new DBRefEntry(DBRefSource.UNIPROT, "1", "Q9ZTS2"));
516 seq1.addDBRef(new DBRefEntry("GENE3D", "1", "3.10.20.30"));
519 * check the Link Menu for the first sequence
521 JMenu linkMenu = PopupMenu.buildLinkMenu(seq0, noFeatures);
522 assertEquals(linkText, linkMenu.getText());
523 Component[] linkItems = linkMenu.getMenuComponents();
526 * menu items are ordered: SEQUENCE_ID search first, then dbrefs in order
527 * of database name (and within that by order of dbref addition)
529 assertEquals(5, linkItems.length);
530 assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
531 assertEquals("INTERPRO|IPR001041",
532 ((JMenuItem) linkItems[1]).getText());
533 assertEquals("INTERPRO|IPR012675",
534 ((JMenuItem) linkItems[2]).getText());
535 assertEquals("INTERPRO|IPR006058",
536 ((JMenuItem) linkItems[3]).getText());
537 assertEquals("UNIPROT|P83527", ((JMenuItem) linkItems[4]).getText());
540 * check the Link Menu for the second sequence
541 * note dbref GENE3D is matched to link Gene3D, the latter is displayed
543 linkMenu = PopupMenu.buildLinkMenu(seq1, noFeatures);
544 linkItems = linkMenu.getMenuComponents();
545 assertEquals(3, linkItems.length);
546 assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
547 assertEquals("Gene3D|3.10.20.30", ((JMenuItem) linkItems[1]).getText());
548 assertEquals("UNIPROT|Q9ZTS2", ((JMenuItem) linkItems[2]).getText());
551 * if there are no valid links the Links submenu is still shown, but
552 * reduced to the EMBL-EBI lookup only (inserted by
553 * CustomUrlProvider.choosePrimaryUrl())
555 String unmatched = "NOMATCH|http://www.uniprot.org/uniprot/$"
556 + DB_ACCESSION + "$";
557 UrlProviderFactoryI factory = new DesktopUrlProviderFactory(null,
559 Preferences.sequenceUrlLinks = factory.createUrlProvider();
561 linkMenu = PopupMenu.buildLinkMenu(seq1, noFeatures);
562 linkItems = linkMenu.getMenuComponents();
563 assertEquals(1, linkItems.length);
564 assertEquals("EMBL-EBI Search", ((JMenuItem) linkItems[0]).getText());
567 * if sequence is null, only feature links are shown (alignment popup submenu)
569 linkMenu = PopupMenu.buildLinkMenu(null, noFeatures);
570 linkItems = linkMenu.getMenuComponents();
571 assertEquals(0, linkItems.length);
573 List<SequenceFeature> features = new ArrayList<>();
574 SequenceFeature sf = new SequenceFeature("type", "desc", 1, 20, null);
576 linkMenu = PopupMenu.buildLinkMenu(null, features);
577 linkItems = linkMenu.getMenuComponents();
578 assertEquals(0, linkItems.length); // feature has no links
580 sf.addLink("Pfam family|http://pfam.xfam.org/family/PF00111");
581 linkMenu = PopupMenu.buildLinkMenu(null, features);
582 linkItems = linkMenu.getMenuComponents();
583 assertEquals(1, linkItems.length);
584 JMenuItem item = (JMenuItem) linkItems[0];
585 assertEquals("Pfam family", item.getText());
586 // ? no way to verify URL, compiled into link's actionListener
589 @Test(groups = { "Functional" })
590 public void testHideInsertions()
592 // get sequences from the alignment
593 List<SequenceI> seqs = parentPanel.getAlignment().getSequences();
595 // add our own seqs to avoid problems with changes to existing sequences
596 // (gap at end of sequences varies depending on how tests are run!)
597 Sequence seqGap1 = new Sequence("GappySeq",
598 "AAAA----AA-AAAAAAA---AAA-----------AAAAAAAAAA--");
599 seqGap1.createDatasetSequence();
601 Sequence seqGap2 = new Sequence("LessGappySeq",
602 "AAAAAA-AAAAA---AAA--AAAAA--AAAAAAA-AAAAAA");
603 seqGap2.createDatasetSequence();
605 Sequence seqGap3 = new Sequence("AnotherGapSeq",
606 "AAAAAA-AAAAAA--AAAAAA-AAAAAAAAAAA---AAAAAAAA");
607 seqGap3.createDatasetSequence();
609 Sequence seqGap4 = new Sequence("NoGaps",
610 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
611 seqGap4.createDatasetSequence();
614 ColumnSelection sel = new ColumnSelection();
615 parentPanel.av.getAlignment().getHiddenColumns()
616 .revealAllHiddenColumns(sel);
618 // get the Popup Menu for 7th sequence - no insertions
619 testee = new PopupMenu(parentPanel, seqs.get(7), null);
620 testee.hideInsertions_actionPerformed(null);
622 HiddenColumns hidden = parentPanel.av.getAlignment().getHiddenColumns();
623 Iterator<int[]> it = hidden.iterator();
624 assertFalse(it.hasNext());
626 // get the Popup Menu for GappySeq - this time we have insertions
627 testee = new PopupMenu(parentPanel, seqs.get(4), null);
628 testee.hideInsertions_actionPerformed(null);
629 hidden = parentPanel.av.getAlignment().getHiddenColumns();
630 it = hidden.iterator();
632 assertTrue(it.hasNext());
633 int[] region = it.next();
634 assertEquals(region[0], 4);
635 assertEquals(region[1], 7);
637 assertTrue(it.hasNext());
639 assertEquals(region[0], 10);
640 assertEquals(region[1], 10);
642 assertTrue(it.hasNext());
644 assertEquals(region[0], 18);
645 assertEquals(region[1], 20);
647 assertTrue(it.hasNext());
649 assertEquals(region[0], 24);
650 assertEquals(region[1], 34);
652 assertTrue(it.hasNext());
654 assertEquals(region[0], 45);
655 assertEquals(region[1], 46);
657 assertFalse(it.hasNext());
659 sel = new ColumnSelection();
660 hidden.revealAllHiddenColumns(sel);
662 // make a sequence group and hide insertions within the group
663 SequenceGroup sg = new SequenceGroup();
666 sg.addSequence(seqGap2, false);
667 sg.addSequence(seqGap3, false);
668 parentPanel.av.setSelectionGroup(sg);
670 // hide columns outside and within selection
671 // only hidden columns outside the collection will be retained (unless also
672 // gaps in the selection)
673 hidden.hideColumns(1, 10);
674 hidden.hideColumns(31, 40);
676 // get the Popup Menu for LessGappySeq in the sequence group
677 testee = new PopupMenu(parentPanel, seqs.get(5), null);
678 testee.hideInsertions_actionPerformed(null);
679 hidden = parentPanel.av.getAlignment().getHiddenColumns();
680 it = hidden.iterator();
682 assertTrue(it.hasNext());
684 assertEquals(region[0], 1);
685 assertEquals(region[1], 7);
687 assertTrue(it.hasNext());
689 assertEquals(region[0], 13);
690 assertEquals(region[1], 14);
692 assertTrue(it.hasNext());
694 assertEquals(region[0], 34);
695 assertEquals(region[1], 34);
698 @Test(groups = { "Functional" })
699 public void testAddFeatureDetails()
701 String menuText = MessageManager.getString("label.feature_details");
704 * with no features, sub-menu should not be created
706 List<SequenceFeature> features = new ArrayList<>();
707 SequenceI seq = this.alignment.getSequenceAt(0); // FER_CAPAA/1-12
708 testee.addFeatureDetails(features, seq, 10);
709 JMenu menu = findMenu(testee, menuText);
713 * add some features; the menu item text is wrapped in html, and includes
714 * feature type, position, description, group (if not null)
716 SequenceFeature sf1 = new SequenceFeature("helix", "curly", 2, 6, null);
717 SequenceFeature sf2 = new SequenceFeature("chain", "straight", 1, 1,
721 testee.addFeatureDetails(features, seq, 10);
722 menu = findMenu(testee, menuText);
724 assertEquals(2, menu.getItemCount());
725 JMenuItem item = menu.getItem(0);
726 assertEquals("<html>helix 2-6 curly</html>", item.getText());
727 item = menu.getItem(1);
728 assertEquals("<html>chain 1 straight (uniprot)</html>", item.getText());
731 * long feature descriptions are truncated to 40 characters
734 "this is a quite extraordinarily long description");
735 testee.remove(menu); // don't create the sub-menu twice
736 testee.addFeatureDetails(features, seq, 10);
737 menu = findMenu(testee, menuText);
738 item = menu.getItem(0);
740 "<html>helix 2-6 this is a quite extraordinarily long des...</html>",
745 * Returns the first component which is a JMenu with the given text
751 private JMenu findMenu(Container c, String text)
753 for (int i = 0; i < c.getComponentCount(); i++)
755 Component comp = c.getComponent(i);
756 if ((comp instanceof JMenu) && ((JMenu) comp).getText().equals(text))
764 @Test(groups = { "Functional" })
765 public void testAddFeatureDetails_linkedFeatures()
767 // todo tests that verify menu items for complement features