Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.analysis

File SeqsetUtilsTest.java

 

Code metrics

0
24
4
1
115
75
4
0.17
6
4
1

Classes

Class Line # Actions
SeqsetUtilsTest 46 24 4
1.0100%
 

Contributing tests

This file is covered by 9 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.analysis;
22   
23    import jalview.datamodel.Alignment;
24    import jalview.datamodel.AlignmentI;
25    import jalview.datamodel.Sequence;
26    import jalview.datamodel.SequenceFeature;
27    import jalview.datamodel.SequenceI;
28    import jalview.gui.JvOptionPane;
29   
30    import static org.hamcrest.MatcherAssert.assertThat;
31    import static org.hamcrest.Matchers.equalTo;
32   
33    import java.util.BitSet;
34    import java.util.Hashtable;
35    import java.util.Map;
36   
37    import org.testng.Assert;
38    import org.testng.annotations.BeforeClass;
39    import org.testng.annotations.DataProvider;
40    import org.testng.annotations.Test;
41   
42    /**
43    * @author jprocter
44    *
45    */
 
46    public class SeqsetUtilsTest
47    {
48   
 
49  1 toggle @BeforeClass(alwaysRun = true)
50    public void setUpJvOptionPane()
51    {
52  1 JvOptionPane.setInteractiveMode(false);
53  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
54    }
55   
56    /**
57    * test for JAL-2046 bug - duplication of sequence features on reconstructed
58    * alignment
59    */
 
60  1 toggle @Test(groups = { "Functional" })
61    public void testSeqFeatureAddition()
62    {
63  1 SequenceI[] sqset = new SequenceI[] { new Sequence("Aseq1", "AREALSEQ"),
64    new Sequence("Aseq2", "AREALSEQ") };
65   
66  1 AlignmentI al = new Alignment(sqset);
67  1 al.setDataset(null);
68  1 AlignmentI ds = al.getDataset();
69  1 SequenceFeature sf1 = new SequenceFeature("f1", "foo", 2, 3, "far");
70  1 SequenceFeature sf2 = new SequenceFeature("f2", "foo", 2, 3, "far");
71  1 ds.getSequenceAt(0).addSequenceFeature(sf1);
72  1 Map<String, SeqsetUtils.SequenceInfo> unq = SeqsetUtils.uniquify(sqset, true);
73  1 SequenceI[] sqset2 = new SequenceI[] {
74    new Sequence(sqset[0].getName(), sqset[0].getSequenceAsString()),
75    new Sequence(sqset[1].getName(), sqset[1].getSequenceAsString()) };
76  1 Assert.assertSame(sqset[0].getSequenceFeatures().get(0), sf1);
77  1 Assert.assertTrue(sqset2[0].getSequenceFeatures().isEmpty());
78  1 ds.getSequenceAt(0).addSequenceFeature(sf2);
79  1 Assert.assertEquals(sqset[0].getSequenceFeatures().size(), 2);
80  1 SeqsetUtils.deuniquify(unq, sqset2);
81    // explicitly test that original sequence features still exist because they
82    // are on the shared dataset sequence
83  1 Assert.assertEquals(sqset[0].getSequenceFeatures().size(), 2);
84  1 Assert.assertEquals(sqset2[0].getSequenceFeatures().size(), 2);
85  1 Assert.assertSame(sqset[0].getSequenceFeatures().get(0),
86    sqset2[0].getSequenceFeatures().get(0));
87  1 Assert.assertSame(sqset[0].getSequenceFeatures().get(1),
88    sqset2[0].getSequenceFeatures().get(1));
89    }
90   
 
91  1 toggle @DataProvider
92    public Object[][] sequenceAndMask()
93    {
94  1 return new Object[][] {
95    { "AAAABBBBCCCCDDDD", 0xFFFFL, "AAAABBBBCCCCDDDD" },
96    { "AAAABBBBCCCCDDDD", 0x000FL, "AAAA" },
97    { "---A---B---C---D", 0x8888L, "ABCD" },
98    { "---A---B---C---D", 0x9999L, "-A-B-C-D" },
99    { "ABCDABCDABCDABCD", 0xC5A3L, "ABBDACCD" },
100    { "", 0xFFFFL, "" },
101    { "AAAABBBBCCCCDDDD", 0x0000L, "" },
102    { "AAABBBCCC", 0xFFFF, "AAABBBCCC" },
103    { "AAAABBBB", 0xD000L, "" },
104    { "AAAABBBB", 0xAA0AL, "AA" },
105    };
106    }
107   
 
108  10 toggle @Test(groups = {"Functional"}, dataProvider = "sequenceAndMask")
109    public void testFilterSequence(String sequence, long mask, String expected)
110    {
111  10 BitSet bitMask = BitSet.valueOf(new long[] {mask});
112  10 var result = SeqsetUtils.filterSequence(sequence.toCharArray(), bitMask);
113  10 assertThat(result, equalTo(expected.toCharArray()));
114    }
115    }