{
char sequenceChar = sequence.getCharAt(column);
int pos = sequence.findPosition(column);
- setStatusMessage(sequence, seqIndex, sequenceChar, pos);
+ setStatusMessage(sequence.getName(), seqIndex, sequenceChar, pos);
return pos;
}
* Sequence 6 ID: O.niloticus.3 Nucleotide: Uracil (2)
* </pre>
*
- * @param sequence
+ * @param seqName
* @param seqIndex
* sequence position in the alignment (1..)
* @param sequenceChar
* @param residuePos
* the sequence residue position (if not over a gap)
*/
- protected void setStatusMessage(SequenceI sequence, int seqIndex,
+ protected void setStatusMessage(String seqName, int seqIndex,
char sequenceChar, int residuePos)
{
StringBuilder text = new StringBuilder(32);
*/
String seqno = seqIndex == -1 ? "" : " " + (seqIndex + 1);
text.append("Sequence").append(seqno).append(" ID: ")
- .append(sequence.getName());
+ .append(seqName);
String residue = null;
{
return;
}
- SequenceI ds = al.getSequenceAt(sequenceIndex).getDatasetSequence();
+ SequenceI alignedSeq = al.getSequenceAt(sequenceIndex);
+ SequenceI ds = alignedSeq.getDatasetSequence();
for (SearchResultMatchI m : results.getResults())
{
SequenceI seq = m.getSequence();
if (seq == ds)
{
int start = m.getStart();
- setStatusMessage(seq, sequenceIndex, seq.getCharAt(start - 1),
- start);
+ setStatusMessage(alignedSeq.getName(), sequenceIndex,
+ seq.getCharAt(start - 1), start);
return;
}
}
import static org.testng.AssertJUnit.assertSame;
import static org.testng.AssertJUnit.assertTrue;
-import jalview.gui.JvOptionPane;
-
import java.util.BitSet;
import org.junit.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import jalview.gui.JvOptionPane;
+
public class SearchResultsTest
{
sr.addResult(seq1, 3, 6);
assertEquals(2, sr.getSize());
}
+
+ /**
+ * Test for method that checks if search results matches a sequence region
+ */
+ @Test(groups = { "Functional" })
+ public void testInvolvesSequence()
+ {
+ SequenceI dataset = new Sequence("genome", "ATGGCCCTTTAAGCAACATTT");
+ // first 'exon':
+ SequenceI cds1 = new Sequence("cds1/1-12", "ATGGCCCTTTAA");
+ cds1.setDatasetSequence(dataset);
+ // overlapping second 'exon':
+ SequenceI cds2 = new Sequence("cds2/7-18", "CTTTAAGCAACA");
+ cds2.setDatasetSequence(dataset);
+ // unrelated sequence
+ SequenceI cds3 = new Sequence("cds3", "ATGGCCCTTTAAGCAACA");
+
+ SearchResults sr = new SearchResults();
+ assertFalse(sr.involvesSequence(cds1));
+
+ /*
+ * cds1 and cds2 share the same dataset sequence, but
+ * only cds1 overlaps match 4:6 (fixes bug JAL-3613)
+ */
+ sr.addResult(dataset, 4, 6);
+ assertTrue(sr.involvesSequence(cds1));
+ assertFalse(sr.involvesSequence(cds2));
+ assertFalse(sr.involvesSequence(cds3));
+
+ /*
+ * search results overlap cds2 only
+ */
+ sr = new SearchResults();
+ sr.addResult(dataset, 18, 18);
+ assertFalse(sr.involvesSequence(cds1));
+ assertTrue(sr.involvesSequence(cds2));
+
+ /*
+ * add a search result overlapping cds1
+ */
+ sr.addResult(dataset, 1, 1);
+ assertTrue(sr.involvesSequence(cds1));
+ assertTrue(sr.involvesSequence(cds2));
+
+ /*
+ * single search result overlapping both
+ */
+ sr = new SearchResults();
+ sr.addResult(dataset, 10, 12);
+ assertTrue(sr.involvesSequence(cds1));
+ assertTrue(sr.involvesSequence(cds2));
+
+ /*
+ * search results matching aligned sequence
+ */
+ sr = new SearchResults();
+ sr.addResult(cds1, 10, 12);
+ assertTrue(sr.involvesSequence(cds1));
+ assertFalse(sr.involvesSequence(cds2));
+ sr.addResult(cds2, 1, 3); // no start-end overlap
+ assertFalse(sr.involvesSequence(cds2));
+ sr.addResult(cds2, 7, 9); // start-end overlap
+ assertTrue(sr.involvesSequence(cds2));
+ }
}