2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.ext.jmol;
23 import jalview.datamodel.SequenceI;
24 import jalview.gui.JvOptionPane;
25 import jalview.io.DataSourceType;
28 import java.io.IOException;
29 import java.util.HashSet;
31 import java.util.Vector;
33 import org.testng.annotations.BeforeClass;
35 import MCview.PDBfile;
38 * This is not a unit test, rather it is a bulk End-to-End scan for sequences
39 * consistency for PDB files parsed with JmolParser vs. Jalview's PDBfile
40 * parser. The directory of PDB files to test must be provided in the launch
46 public class JmolVsJalviewPDBParserEndToEndTest
49 @BeforeClass(alwaysRun = true)
50 public void setUpJvOptionPane()
52 JvOptionPane.setInteractiveMode(false);
53 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
56 public static void main(String[] args)
58 if (args == null || args[0] == null)
61 .println("You must provide a PDB directory in the launch argument");
65 // args[0] must provide the directory of PDB files to run the test with
66 String testDir = args[0];
67 System.out.println("PDB directory : " + testDir);
68 File pdbDir = new File(testDir);
69 String testFiles[] = pdbDir.list();
70 testFileParser(testDir, testFiles);
73 public static void testFileParser(String testDir, String[] testFiles)
75 Set<String> failedFiles = new HashSet<String>();
76 int totalSeqScanned = 0, totalFail = 0;
77 for (String pdbStr : testFiles)
79 String testFile = testDir + "/" + pdbStr;
80 PDBfile mctest = null;
81 JmolParser jtest = null;
84 mctest = new PDBfile(false, false, false, testFile, DataSourceType.FILE);
85 jtest = new JmolParser(testFile, DataSourceType.FILE);
86 } catch (IOException e)
88 System.err.println("Exception thrown while parsing : " + pdbStr);
90 Vector<SequenceI> seqs = jtest.getSeqs();
91 Vector<SequenceI> mcseqs = mctest.getSeqs();
93 for (SequenceI sq : seqs)
97 String testSeq = mcseqs.remove(0).getSequenceAsString();
98 if (!sq.getSequenceAsString().equals(testSeq))
101 System.err.println("Test Failed for " + pdbStr + ". Diff:");
102 System.err.println(sq.getSequenceAsString());
103 System.err.println(testSeq);
104 failedFiles.add(pdbStr);
107 } catch (Exception e)
115 System.out.println("\n\nTotal sequence Scanned : " + totalSeqScanned);
116 System.out.println("Total sequence passed : "
117 + (totalSeqScanned - totalFail));
118 System.out.println("Total sequence failed : " + totalFail);
120 .println("Success rate: "
121 + ((totalSeqScanned - totalFail) * 100)
122 / totalSeqScanned + "%");
123 System.out.println("\nList of " + failedFiles.size()
124 + " file(s) with sequence diffs:");
125 for (String problemFile : failedFiles)
127 System.out.println(++count + ". " + problemFile);