From: tcofoegbu Date: Wed, 27 Jul 2016 12:02:07 +0000 (+0100) Subject: JAL-1919 added codes for End-2-End scan for sequence consistency for PDB files parse... X-Git-Tag: Release_2_10_0~131 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=190af5d9e60121fdfba0dee0bcfb1c2fa037d72d;p=jalview.git JAL-1919 added codes for End-2-End scan for sequence consistency for PDB files parse with JmolParser vs. Jalview's PDBfile parser --- diff --git a/test/jalview/ext/jmol/JmolVsJalviewPDBParserEndToEndTest.java b/test/jalview/ext/jmol/JmolVsJalviewPDBParserEndToEndTest.java new file mode 100644 index 0000000..8a89830 --- /dev/null +++ b/test/jalview/ext/jmol/JmolVsJalviewPDBParserEndToEndTest.java @@ -0,0 +1,102 @@ +package jalview.ext.jmol; + +import jalview.datamodel.SequenceI; +import jalview.io.AppletFormatAdapter; + +import java.io.File; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; +import java.util.Vector; + +import MCview.PDBfile; + +/** + * This is not a unit test, rather it is a bulk End-to-End scan for sequences + * consistency for PDB files parsed with JmolParser vs. Jalview's PDBfile + * parser. The directory of PDB files to test must be provided in the launch + * args. + * + * @author tcnofoegbu + * + */ +public class JmolVsJalviewPDBParserEndToEndTest +{ + + public static void main(String[] args) + { + if (args == null || args[0] == null) + { + System.err + .println("You must provide a PDB directory in the launch argument"); + return; + } + + // args[0] must provide the directory of PDB files to run the test with + String testDir = args[0]; + System.out.println("PDB directory : " + testDir); + File pdbDir = new File(testDir); + String testFiles[] = pdbDir.list(); + testFileParser(testDir, testFiles); + } + + public static void testFileParser(String testDir, String[] testFiles) + { + Set failedFiles = new HashSet(); + int totalSeqScanned = 0, totalFail = 0; + for (String pdbStr : testFiles) + { + String testFile = testDir + "/" + pdbStr; + PDBfile mctest = null; + JmolParser jtest = null; + try + { + mctest = new PDBfile(false, false, false, testFile, + AppletFormatAdapter.FILE); + jtest = new JmolParser(false, false, false, testFile, + jalview.io.AppletFormatAdapter.FILE); + } catch (IOException e) + { + System.err.println("Exception thrown while parsing : " + pdbStr); + } + Vector seqs = jtest.getSeqs(); + Vector mcseqs = mctest.getSeqs(); + + for (SequenceI sq : seqs) + { + try + { + String testSeq = mcseqs.remove(0).getSequenceAsString(); + if (!sq.getSequenceAsString().equals(testSeq)) + { + ++totalFail; + System.err.println("Test Failed for " + pdbStr + ". Diff:"); + System.err.println(sq.getSequenceAsString()); + System.err.println(testSeq); + failedFiles.add(pdbStr); + } + ++totalSeqScanned; + } catch (Exception e) + { + e.printStackTrace(); + } + } + } + int count = 0; + + System.out.println("\n\nTotal sequence Scanned : " + totalSeqScanned); + System.out.println("Total sequence passed : " + + (totalSeqScanned - totalFail)); + System.out.println("Total sequence failed : " + totalFail); + System.out + .println("Success rate: " + + ((totalSeqScanned - totalFail) * 100) + / totalSeqScanned + "%"); + System.out.println("\nList of " + failedFiles.size() + + " file(s) with sequence diffs:"); + for (String problemFile : failedFiles) + { + System.out.println(++count + ". " + problemFile); + } + } +}