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