Merge branch 'features/JAL-2326_JOptionPane-refactoring' into develop
[jalview.git] / test / jalview / io / IdentifyFileTest.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;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertTrue;
26
27 import jalview.gui.JvOptionPane;
28
29 import org.testng.Assert;
30 import org.testng.annotations.BeforeClass;
31 import org.testng.annotations.DataProvider;
32 import org.testng.annotations.Test;
33
34 public class IdentifyFileTest
35 {
36
37   @BeforeClass(alwaysRun = true)
38   public void setUpJvOptionPane()
39   {
40     JvOptionPane.setInteractiveMode(false);
41     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
42   }
43
44   @Test(groups = { "Functional" }, dataProvider = "identifyFiles")
45   public void testIdentify(String data, String expectedFileType)
46   {
47     String protocol = AppletFormatAdapter.FILE;
48     IdentifyFile ider = new IdentifyFile();
49     String actualFiletype = ider.identify(data, protocol);
50     Assert.assertEquals(actualFiletype, expectedFileType,
51             "File identification Failed!");
52   }
53
54   /**
55    * Additional tests for Jalview features file
56    */
57   @Test(groups = "Functional")
58   public void testIdentify_featureFile()
59   {
60     IdentifyFile ider = new IdentifyFile();
61
62     /*
63      * Jalview format with features only, no feature colours
64      */
65     String data = "Iron-sulfur (2Fe-2S)\tFER_CAPAA\t-1\t39\t39\tMETAL\n"
66             + "Iron-phosphorus (2Fe-P)\tID_NOT_SPECIFIED\t2\t86\t87\tMETALLIC\n";
67     assertEquals(IdentifyFile.FeaturesFile,
68             ider.identify(data, AppletFormatAdapter.PASTE));
69
70     /*
71      * Jalview feature colour followed by GFF format feature data
72      */
73     data = "METAL\tcc9900\n" + "GFF\n"
74             + "FER_CAPAA\tuniprot\tMETAL\t44\t45\t4.0\t.\t.\n";
75     assertEquals(IdentifyFile.FeaturesFile,
76             ider.identify(data, AppletFormatAdapter.PASTE));
77
78     /*
79      * Feature with '<' in the name (JAL-2098)
80      */
81     data = "kD < 3\tred\n" + "Low kD\tFER_CAPAA\t-1\t39\t39\tkD < 3\n";
82     assertEquals(IdentifyFile.FeaturesFile,
83             ider.identify(data, AppletFormatAdapter.PASTE));
84   }
85
86   @DataProvider(name = "identifyFiles")
87   public Object[][] IdentifyFileDP()
88   {
89     return new Object[][] {
90         { "examples/example.json", "JSON" },
91         { "examples/plantfdx.fa", "FASTA" },
92         { "examples/dna_interleaved.phy", "PHYLIP" },
93         { "examples/2GIS.pdb", "PDB" },
94         { "examples/rf00031_folded.stk", "STH" },
95         { "examples/testdata/test.rnaml", "RNAML" },
96         { "examples/testdata/test.aln", "CLUSTAL" },
97         { "examples/testdata/test.pfam", "PFAM" },
98         { "examples/testdata/test.msf", "MSF" },
99         { "examples/testdata/test.pir", "PIR" },
100         { "examples/testdata/test.html", "HTML" },
101         { "examples/testdata/test.pileup", "PileUp" },
102         { "examples/testdata/test.blc", "BLC" },
103         { "examples/exampleFeatures.txt", IdentifyFile.FeaturesFile },
104         { "examples/testdata/simpleGff3.gff", IdentifyFile.FeaturesFile },
105         { "examples/testdata/test.jvp", "Jalview" },
106         { "examples/testdata/test.cif", "mmCIF" },
107         {
108             "examples/testdata/cullpdb_pc25_res3.0_R0.3_d150729_chains9361.fasta.15316",
109             "FASTA" },
110
111     // { "examples/testdata/test.amsa", "AMSA" },
112     // { "examples/test.jnet", "JnetFile" },
113     };
114   }
115
116   @Test(groups = "Functional")
117   public void testLooksLikeFeatureData()
118   {
119     IdentifyFile id = new IdentifyFile();
120     assertFalse(id.looksLikeFeatureData(null));
121     assertFalse(id.looksLikeFeatureData(""));
122     // too few columns:
123     assertFalse(id.looksLikeFeatureData("1 \t 2 \t 3 \t 4 \t 5"));
124     // GFF format:
125     assertTrue(id
126             .looksLikeFeatureData("Seq1\tlocal\tHelix\t2456\t2462\tss"));
127     // Jalview format:
128     assertTrue(id.looksLikeFeatureData("Helix\tSeq1\t-1\t2456\t2462\tss"));
129     // non-numeric start column:
130     assertFalse(id.looksLikeFeatureData("Helix\tSeq1\t-1\t.\t2462\tss"));
131     // non-numeric start column:
132     assertFalse(id.looksLikeFeatureData("Helix\tSeq1\t-1\t2456\t.\tss"));
133   }
134 }