JAL-653 test for 'groups file' and mixed Jalview/GFF
[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.assertTrue;
25
26 import org.testng.Assert;
27 import org.testng.annotations.DataProvider;
28 import org.testng.annotations.Test;
29
30 public class IdentifyFileTest
31 {
32
33   @Test(groups = { "Functional" }, dataProvider = "identifyFiles")
34   public void testIdentify(String data, String expectedFileType)
35   {
36     String protocol = AppletFormatAdapter.FILE;
37     IdentifyFile ider = new IdentifyFile();
38     String actualFiletype = ider.identify(data, protocol);
39     Assert.assertEquals(actualFiletype, expectedFileType,
40             "File identification Failed!");
41   }
42
43   /**
44    * Additional tests for (a) Jalview features file with no colour
45    * specifications (old style 'groups' file) and (b) Jalview features file with
46    * embedded GFF
47    */
48   @Test(groups = "Functional")
49   public void testIdentify_featureFile()
50   {
51     IdentifyFile ider = new IdentifyFile();
52
53     // Jalview format with features only, no feature colours
54     String data = "Iron-sulfur (2Fe-2S)\tFER_CAPAA\t-1\t39\t39\tMETAL\n"
55             + "Iron-phosphorus (2Fe-P)\tID_NOT_SPECIFIED\t2\t86\t87\tMETALLIC\n";
56     Assert.assertEquals(IdentifyFile.FeaturesFile, ider.identify(data, AppletFormatAdapter.PASTE));
57
58     // Jalview feature colour followed by GFF format feature data
59     data = "METAL\tcc9900\n" + "GFF\n"
60             + "FER_CAPAA\tuniprot\tMETAL\t44\t45\t4.0\t.\t.\n";
61     Assert.assertEquals(IdentifyFile.FeaturesFile,
62             ider.identify(data, AppletFormatAdapter.PASTE));
63   }
64
65   @DataProvider(name = "identifyFiles")
66   public Object[][] IdentifyFileDP()
67   {
68     return new Object[][] {
69         { "examples/example.json", "JSON" },
70         { "examples/plantfdx.fa", "FASTA" },
71         { "examples/dna_interleaved.phy", "PHYLIP" },
72         { "examples/2GIS.pdb", "PDB" },
73         { "examples/rf00031_folded.stk", "STH" },
74         { "examples/testdata/test.rnaml", "RNAML" },
75         { "examples/testdata/test.aln", "CLUSTAL" },
76         { "examples/testdata/test.pfam", "PFAM" },
77         { "examples/testdata/test.msf", "MSF" },
78         { "examples/testdata/test.pir", "PIR" },
79         { "examples/testdata/test.html", "HTML" },
80         { "examples/testdata/test.pileup", "PileUp" },
81         { "examples/testdata/test.blc", "BLC" },
82         { "examples/exampleFeatures.txt", IdentifyFile.FeaturesFile },
83         { "examples/testdata/simplegff3.gff", IdentifyFile.FeaturesFile },
84         { "examples/testdata/test.jvp", "Jalview" },
85         {
86             "examples/testdata/cullpdb_pc25_res3.0_R0.3_d150729_chains9361.fasta.15316",
87             "FASTA" },
88
89     // { "examples/testdata/test.amsa", "AMSA" },
90     // { "examples/test.jnet", "JnetFile" },
91     };
92   }
93
94   @Test(groups = "Functional")
95   public void testLooksLikeFeatureData()
96   {
97     IdentifyFile id = new IdentifyFile();
98     assertFalse(id.looksLikeFeatureData(null));
99     assertFalse(id.looksLikeFeatureData(""));
100     // too few columns:
101     assertFalse(id.looksLikeFeatureData("1 \t 2 \t 3 \t 4 \t 5"));
102     // GFF format:
103     assertTrue(id
104             .looksLikeFeatureData("Seq1\tlocal\tHelix\t2456\t2462\tss"));
105     // Jalview format:
106     assertTrue(id.looksLikeFeatureData("Helix\tSeq1\t-1\t2456\t2462\tss"));
107     // non-numeric start column:
108     assertFalse(id.looksLikeFeatureData("Helix\tSeq1\t-1\t.\t2462\tss"));
109     // non-numeric start column:
110     assertFalse(id.looksLikeFeatureData("Helix\tSeq1\t-1\t2456\t.\tss"));
111   }
112 }