import static org.testng.Assert.assertSame;
import static org.testng.Assert.assertTrue;
+import jalview.api.AlignViewportI;
import jalview.api.FinderI;
import jalview.bin.Cache;
import jalview.datamodel.Alignment;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
import jalview.gui.JvOptionPane;
import jalview.io.DataSourceType;
import jalview.io.FileLoader;
import java.util.List;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
private AlignmentI al;
+ private AlignViewportI av;
+
@BeforeClass(groups = "Functional")
public void setUp()
{
+ "seq3 --bcdEFH\n" + "seq4 aa---aMMMMMaaa\n";
af = new FileLoader().LoadFileWaitTillLoaded(seqData,
DataSourceType.PASTE);
- al = af.getViewport().getAlignment();
+ av = af.getViewport();
+ al = av.getAlignment();
+ }
+
+ @AfterMethod
+ public void tearDownAfterTest()
+ {
+ av.setSelectionGroup(null);
}
/**
/*
* find next match only
*/
- Finder f = new Finder(al);
- f.findNext("E.H", null, false, false); // 'E, any character, H'
+ Finder f = new Finder(av);
+ f.findNext("E.H", false, false); // 'E, any character, H'
// should match seq2 efH only
SearchResultsI sr = f.getSearchResults();
assertEquals(sr.getSize(), 1);
assertEquals(matches.get(0).getStart(), 5);
assertEquals(matches.get(0).getEnd(), 7);
- f = new Finder(al);
- f.findAll("E.H", null, false, false); // 'E, any character, H'
+ f = new Finder(av);
+ f.findAll("E.H", false, false); // 'E, any character, H'
// should match seq2 efH and seq3 EFH
sr = f.getSearchResults();
assertEquals(sr.getSize(), 2);
@Test(groups = "Functional")
public void testFind_residueNumber()
{
- Finder f = new Finder(al);
+ Finder f = new Finder(av);
/*
* find first match should return seq1 residue 9
*/
- f.findNext("9", null, false, false);
+ f.findNext("9", false, false);
SearchResultsI sr = f.getSearchResults();
assertEquals(sr.getSize(), 1);
List<SearchResultMatchI> matches = sr.getResults();
/*
* find all matches should return seq1 and seq4 (others are too short)
*/
- f = new Finder(al);
- f.findAll("9", null, false, false);
+ f = new Finder(av);
+ f.findAll("9", false, false);
sr = f.getSearchResults();
assertEquals(sr.getSize(), 2);
matches = sr.getResults();
/*
* parsing of search string as integer is strict
*/
- f = new Finder(al);
- f.findNext(" 9", null, false, false);
+ f = new Finder(av);
+ f.findNext(" 9", false, false);
assertTrue(f.getSearchResults().isEmpty());
}
* start at second sequence; colIndex of -1
* means sequence id / description is searched
*/
- Finder f = new Finder(al);
+ Finder f = new Finder(av);
PA.setValue(f, "sequenceIndex", 1);
PA.setValue(f, "columnIndex", -1);
- f.findNext("e", null, false, false); // matches id
+ f.findNext("e", false, false); // matches id
assertTrue(f.getSearchResults().isEmpty());
assertEquals(f.getIdMatches().size(), 1);
// colIndex is now 0 - for use in next find next
// searching A--BCDefHI
assertEquals(PA.getValue(f, "columnIndex"), 0);
- f = new Finder(al);
+ f = new Finder(av);
PA.setValue(f, "sequenceIndex", 1);
PA.setValue(f, "columnIndex", 0);
- f.findNext("e", null, false, false); // matches in sequence
+ f.findNext("e", false, false); // matches in sequence
assertTrue(f.getIdMatches().isEmpty());
assertEquals(f.getSearchResults().getSize(), 1);
List<SearchResultMatchI> matches = f.getSearchResults().getResults();
assertEquals(PA.getValue(f, "columnIndex"), 7);
// find next from end of sequence - finds next sequence id
- f = new Finder(al);
+ f = new Finder(av);
PA.setValue(f, "sequenceIndex", 1);
PA.setValue(f, "columnIndex", 7);
- f.findNext("e", null, false, false);
+ f.findNext("e", false, false);
assertEquals(f.getIdMatches().size(), 1);
assertSame(f.getIdMatches().get(0), al.getSequenceAt(2));
assertTrue(f.getSearchResults().isEmpty());
al2.getSequenceAt(0).setDescription("BRAF");
al2.getSequenceAt(1).setDescription("braf");
+ AlignViewportI av2 = new AlignViewport(al2);
+
/*
* find first match only
*/
- Finder f = new Finder(al2);
- f.findNext("rAF", null, false, true);
+ Finder f = new Finder(av2);
+ f.findNext("rAF", false, true);
assertEquals(f.getIdMatches().size(), 1);
assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
assertTrue(f.getSearchResults().isEmpty());
/*
* find all matches
*/
- f = new Finder(al2);
- f.findAll("rAF", null, false, true);
+ f = new Finder(av2);
+ f.findAll("rAF", false, true);
assertEquals(f.getIdMatches().size(), 2);
assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
assertSame(f.getIdMatches().get(1), al2.getSequenceAt(1));
/*
* case sensitive
*/
- f = new Finder(al2);
- f.findAll("RAF", null, true, true);
+ f = new Finder(av2);
+ f.findAll("RAF", true, true);
assertEquals(f.getIdMatches().size(), 1);
assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
assertTrue(f.getSearchResults().isEmpty());
al2.getSequenceAt(0).setDescription("the efh sequence");
al2.getSequenceAt(0).setName("mouseEFHkinase");
al2.getSequenceAt(1).setName("humanEFHkinase");
- f = new Finder(al2);
+ f = new Finder(av2);
/*
* sequence matches should have no duplicates
*/
- f.findAll("EFH", null, false, true);
+ f.findAll("EFH", false, true);
assertEquals(f.getIdMatches().size(), 2);
assertSame(f.getIdMatches().get(0), al2.getSequenceAt(0));
assertSame(f.getIdMatches().get(1), al2.getSequenceAt(1));
@Test(groups = "Functional")
public void testFindAll_sequenceIds()
{
- Finder f = new Finder(al);
+ Finder f = new Finder(av);
/*
* case insensitive; seq1 occurs twice in sequence id but
* only one match should be returned
*/
- f.findAll("SEQ1", null, false, false);
+ f.findAll("SEQ1", false, false);
assertEquals(f.getIdMatches().size(), 1);
assertSame(f.getIdMatches().get(0), al.getSequenceAt(0));
SearchResultsI searchResults = f.getSearchResults();
/*
* case sensitive
*/
- f = new Finder(al);
- f.findAll("SEQ1", null, true, false);
+ f = new Finder(av);
+ f.findAll("SEQ1", true, false);
searchResults = f.getSearchResults();
assertTrue(searchResults.isEmpty());
* match both sequence id and sequence
*/
AlignmentI al2 = new Alignment(al);
+ AlignViewportI av2 = new AlignViewport(al2);
al2.addSequence(new Sequence("aBz", "xyzabZpqrAbZ"));
- f = new Finder(al2);
- f.findAll("ABZ", null, false, false);
+ f = new Finder(av2);
+ f.findAll("ABZ", false, false);
assertEquals(f.getIdMatches().size(), 1);
assertSame(f.getIdMatches().get(0), al2.getSequenceAt(4));
searchResults = f.getSearchResults();
/*
* efh should be matched in seq2 only
*/
- FinderI f = new Finder(al);
- f.findNext("EfH", null, false, false);
+ FinderI f = new Finder(av);
+ f.findNext("EfH", false, false);
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
SearchResultMatchI match = searchResults.getResults().get(0);
/*
* I should be found in seq1 (twice) and seq2 (once)
*/
- f = new Finder(al);
- f.findNext("I", null, false, false); // find next: seq1/16
+ f = new Finder(av);
+ f.findNext("I", false, false); // find next: seq1/16
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
assertEquals(match.getStart(), 16);
assertEquals(match.getEnd(), 16);
- f.findNext("I", null, false, false); // find next: seq1/18
+ f.findNext("I", false, false); // find next: seq1/18
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
assertEquals(match.getStart(), 18);
assertEquals(match.getEnd(), 18);
- f.findNext("I", null, false, false); // find next: seq2/8
+ f.findNext("I", false, false); // find next: seq2/8
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
assertEquals(match.getStart(), 8);
assertEquals(match.getEnd(), 8);
- f.findNext("I", null, false, false);
+ f.findNext("I", false, false);
assertTrue(f.getSearchResults().isEmpty());
/*
* find should reset to start of alignment after a failed search
*/
- f.findNext("I", null, false, false); // find next: seq1/16
+ f.findNext("I", false, false); // find next: seq1/16
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
@Test(groups = "Functional")
public void testFind_maximalResultOnly()
{
- Finder f = new Finder(al);
- f.findAll("M+", null, false, false);
+ Finder f = new Finder(av);
+ f.findAll("M+", false, false);
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
SearchResultMatchI match = searchResults.getResults().get(0);
@Test(groups = "Functional")
public void testFind_findAll()
{
- Finder f = new Finder(al);
- f.findAll("EfH", null, false, false);
+ Finder f = new Finder(av);
+ f.findAll("EfH", false, false);
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 2);
SearchResultMatchI match = searchResults.getResults().get(0);
/*
* find all I should find 2 positions in seq1, 1 in seq2
*/
- f.findAll("I", null, false, false);
+ f.findAll("I", false, false);
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 3);
match = searchResults.getResults().get(0);
@Test(groups = "Functional")
public void testFind_findAllCaseSensitive()
{
- Finder f = new Finder(al);
+ Finder f = new Finder(av);
/*
* BC should match seq1/9-10 and seq2/2-3
*/
- f.findAll("BC", null, true, false);
+ f.findAll("BC", true, false);
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 2);
SearchResultMatchI match = searchResults.getResults().get(0);
/*
* bc should match seq3/1-2
*/
- f = new Finder(al);
- f.findAll("bc", null, true, false);
+ f = new Finder(av);
+ f.findAll("bc", true, false);
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
assertEquals(match.getStart(), 1);
assertEquals(match.getEnd(), 2);
- f.findAll("bC", null, true, false);
+ f.findAll("bC", true, false);
assertTrue(f.getSearchResults().isEmpty());
}
sg.setEndRes(5);
sg.addSequence(al.getSequenceAt(1), false);
sg.addSequence(al.getSequenceAt(2), false);
+ av.setSelectionGroup(sg);
- FinderI f = new Finder(al);
- f.findNext("b", sg, false, false);
+ FinderI f = new Finder(av);
+ f.findNext("b", false, false);
assertTrue(f.getIdMatches().isEmpty());
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
/*
* a second Find should not return the 'b' in seq3 as outside the selection
*/
- f.findNext("b", sg, false, false);
+ f.findNext("b", false, false);
assertTrue(f.getSearchResults().isEmpty());
assertTrue(f.getIdMatches().isEmpty());
- f = new Finder(al);
- f.findNext("d", sg, false, false);
+ f = new Finder(av);
+ f.findNext("d", false, false);
assertTrue(f.getIdMatches().isEmpty());
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
assertSame(match.getSequence(), al.getSequenceAt(1));
assertEquals(match.getStart(), 4);
assertEquals(match.getEnd(), 4);
- f.findNext("d", sg, false, false);
+ f.findNext("d", false, false);
assertTrue(f.getIdMatches().isEmpty());
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
sg.setEndRes(5);
sg.addSequence(al.getSequenceAt(1), false);
sg.addSequence(al.getSequenceAt(2), false);
+ av.setSelectionGroup(sg);
/*
* search for 'e' should match two sequence ids and one residue
*/
- Finder f = new Finder(al);
- f.findAll("e", sg, false, false);
+ Finder f = new Finder(av);
+ f.findAll("e", false, false);
assertEquals(f.getIdMatches().size(), 2);
assertSame(f.getIdMatches().get(0), al.getSequenceAt(1));
assertSame(f.getIdMatches().get(1), al.getSequenceAt(2));
/*
* search for 'Q' should match two sequence ids only
*/
- f = new Finder(al);
- f.findAll("Q", sg, false, false);
+ f = new Finder(av);
+ f.findAll("Q", false, false);
assertEquals(f.getIdMatches().size(), 2);
assertSame(f.getIdMatches().get(0), al.getSequenceAt(1));
assertSame(f.getIdMatches().get(1), al.getSequenceAt(2));
sg.addSequence(al.getSequenceAt(1), false);
sg.addSequence(al.getSequenceAt(2), false);
sg.addSequence(al.getSequenceAt(3), false);
-
+ av.setSelectionGroup(sg);
+
/*
* search for 'I' should match two sequence positions
*/
- Finder f = new Finder(al);
- f.findAll("I", sg, false, false);
+ Finder f = new Finder(av);
+ f.findAll("I", false, false);
assertTrue(f.getIdMatches().isEmpty());
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 2);
* find all search for D should ignore hidden positions in seq1 and seq3,
* find the visible D in seq2
*/
- Finder f = new Finder(al);
- f.findAll("D", null, false, false);
+ Finder f = new Finder(av);
+ f.findAll("D", false, false);
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
SearchResultMatchI match = searchResults.getResults().get(0);
* find all 'aaa' should find end of seq4 only
*/
hc.hideColumns(2, 5);
- f = new Finder(al);
- f.findAll("aaa", null, false, false);
+ f = new Finder(av);
+ f.findAll("aaa", false, false);
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
/*
* find all 'BE' should not match across hidden columns in seq1
*/
- f.findAll("BE", null, false, false);
+ f.findAll("BE", false, false);
assertTrue(f.getSearchResults().isEmpty());
/*
*/
hc.revealAllHiddenColumns(new ColumnSelection());
hc.hideColumns(8, 13);
- f = new Finder(al);
- f.findNext("H", null, false, false);
+ f = new Finder(av);
+ f.findNext("H", false, false);
searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 1);
match = searchResults.getResults().get(0);
sg.addSequence(al.getSequenceAt(2), false);
sg.setStartRes(0);
sg.setEndRes(13);
+ av.setSelectionGroup(sg);
/*
* find all search for A or H
* should match seq2/1, seq2/7, not seq3/6
*/
- Finder f = new Finder(al);
- f.findAll("[AH]", sg, false, false);
+ Finder f = new Finder(av);
+ f.findAll("[AH]", false, false);
SearchResultsI searchResults = f.getSearchResults();
assertEquals(searchResults.getSize(), 2);
SearchResultMatchI match = searchResults.getResults().get(0);