JAL-2750 renamed test to ScalePanelTest
[jalview.git] / test / jalview / io / gff / InterProScanHelperTest.java
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.io.gff;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertSame;
25 import static org.testng.AssertJUnit.assertTrue;
26 import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
27
28 import jalview.datamodel.AlignedCodonFrame;
29 import jalview.datamodel.Alignment;
30 import jalview.datamodel.AlignmentI;
31 import jalview.datamodel.Sequence;
32 import jalview.datamodel.SequenceDummy;
33 import jalview.datamodel.SequenceI;
34 import jalview.gui.JvOptionPane;
35
36 import java.io.IOException;
37 import java.util.ArrayList;
38 import java.util.List;
39 import java.util.Map;
40
41 import org.testng.annotations.BeforeClass;
42 import org.testng.annotations.Test;
43
44 public class InterProScanHelperTest
45 {
46
47   @BeforeClass(alwaysRun = true)
48   public void setUpJvOptionPane()
49   {
50     JvOptionPane.setInteractiveMode(false);
51     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
52   }
53
54   /**
55    * Test processing one InterProScan GFF line
56    * 
57    * @throws IOException
58    */
59   @Test(groups = "Functional")
60   public void testProcessProteinMatch() throws IOException
61   {
62     InterProScanHelper testee = new InterProScanHelper();
63     List<SequenceI> newseqs = new ArrayList<SequenceI>();
64     String[] gff = "Submitted\tPfam\tprotein_match\t5\t30\t0\t+\t.\tName=PF12838;Target=Submitted 5 30;signature_desc=4Fe-4S dicluster domain;ID=match$17_5_30"
65             .split("\\t");
66     SequenceI seq = new Sequence("Prot1", "PQRASTGKEEDVMIWCHQN");
67     seq.createDatasetSequence();
68     AlignmentI align = new Alignment(new SequenceI[] {});
69     Map<String, List<String>> set = Gff3Helper.parseNameValuePairs(gff[8]);
70
71     /*
72      * this should create a mapping from Prot1/5-30 to virtual sequence
73      * match$17_5_30 (added to newseqs) positions 1-26
74      */
75     testee.processProteinMatch(set, seq, gff, align, newseqs, false);
76     assertEquals(1, newseqs.size());
77     assertTrue(newseqs.get(0) instanceof SequenceDummy);
78     assertEquals("match$17_5_30", newseqs.get(0).getName());
79     assertEquals(1, align.getCodonFrames().size());
80     AlignedCodonFrame mapping = align.getCodonFrames().iterator().next();
81
82     /*
83      * 'dnaseqs' (map from) is here [Prot1]
84      * 'aaseqs' (map to) is here [match$17_5_30]
85      */
86     // TODO use more suitable naming in AlignedCodonFrame
87     assertEquals(1, mapping.getAaSeqs().length);
88     assertSame(seq.getDatasetSequence(), mapping.getdnaSeqs()[0]);
89     assertEquals(1, mapping.getdnaSeqs().length);
90     assertSame(newseqs.get(0), mapping.getAaSeqs()[0]);
91     assertEquals(1, mapping.getdnaToProt().length);
92     assertEquals(1, mapping.getdnaToProt()[0].getFromRanges().size());
93     assertArrayEquals(new int[] { 5, 30 }, mapping.getdnaToProt()[0]
94             .getFromRanges().get(0));
95     assertEquals(1, mapping.getdnaToProt()[0].getToRanges().size());
96     assertArrayEquals(new int[] { 1, 26 }, mapping.getdnaToProt()[0]
97             .getToRanges().get(0));
98   }
99
100 }