/* * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.io; import static org.testng.AssertJUnit.assertNotNull; import static org.testng.AssertJUnit.assertTrue; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.DynamicData; import jalview.datamodel.PDBEntry; import jalview.datamodel.PDBEntry.Type; import jalview.datamodel.SequenceI; import jalview.gui.JvOptionPane; import jalview.io.AnnotationFile.ViewDef; import jalview.structure.StructureSelectionManager; import java.io.File; import java.util.Hashtable; import java.util.List; import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class AnnotationFileIOTest { private StructureSelectionManager ssm = null; private AlignmentI al = null; @BeforeClass(alwaysRun = true) public void setUpJvOptionPane() { JvOptionPane.setInteractiveMode(false); JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); } static String TestFiles[][] = { { "Test example annotation import/export", "examples/uniref50.fa", "examples/testdata/example_annot_file.jva" }, { "Test multiple combine annotation statements import/export", "examples/uniref50.fa", "examples/testdata/test_combine_annot.jva" }, { "Test multiple combine annotation statements with sequence_ref import/export", "examples/uniref50.fa", "examples/testdata/uniref50_iupred.jva" }, { "Test group only annotation file parsing results in parser indicating annotation was parsed", "examples/uniref50.fa", "examples/testdata/test_grpannot.jva" }, { "Test hiding/showing of insertions on sequence_ref", "examples/uniref50.fa", "examples/testdata/uniref50_seqref.jva" } }; @Test(groups = { "Functional" }) public void exampleAnnotationFileIO() throws Exception { for (String[] testPair : TestFiles) { testAnnotationFileIO(testPair[0], new File(testPair[1]), new File( testPair[2])); } } AlignmentI readAlignmentFile(File f) { System.out.println("Reading file: " + f); String ff = f.getPath(); try { FormatAdapter rf = new FormatAdapter(); AlignmentI al = rf.readFile(ff, DataSourceType.FILE, new IdentifyFile().identify(ff, DataSourceType.FILE)); // make sure dataset is initialised ? not sure about this for (int i = 0; i < al.getSequencesArray().length; ++i) { al.getSequenceAt(i).createDatasetSequence(); } assertNotNull("Couldn't read supplied alignment data.", al); return al; } catch (Exception e) { e.printStackTrace(); } Assert.fail("Couln't read the alignment in file '" + f.toString() + "'"); return null; } /** * test alignment data in given file can be imported, exported and reimported * with no dataloss * * @param f * - source datafile (IdentifyFile.identify() should work with it) * @param ioformat * - label for IO class used to write and read back in the data from * f */ void testAnnotationFileIO(String testname, File f, File annotFile) { System.out.println("Test: " + testname + "\nReading annotation file '" + annotFile + "' onto : " + f); String af = annotFile.getPath(); try { AlignmentI al = readAlignmentFile(f); ColumnSelection cs = new ColumnSelection(); assertTrue( "Test " + testname + "\nAlignment was not annotated - annotation file not imported.", new AnnotationFile().readAnnotationFile(al, cs, af, DataSourceType.FILE)); AnnotationFile aff = new AnnotationFile(); ViewDef v = aff.new ViewDef(null, al.getHiddenSequences(), cs, new Hashtable()); String anfileout = new AnnotationFile().printAnnotations( al.getAlignmentAnnotation(), al.getGroups(), al.getProperties(), null, al, v); assertTrue( "Test " + testname + "\nAlignment annotation file was not regenerated. Null string", anfileout != null); assertTrue( "Test " + testname + "\nAlignment annotation file was not regenerated. Empty string", anfileout.length() > "JALVIEW_ANNOTATION".length()); System.out.println("Output annotation file:\n" + anfileout + "\n< phyreDD = AnnotationFile .generatePhyreDynamicDataList(structModelHeader, structModelData); expectedPDBEntry.setProperty("DYNAMIC_DATA_PHYRE2", phyreDD); Assert.assertEquals(actualPDBEntry, expectedPDBEntry); } @Test( groups = { "Functional" }, dataProvider = "phyre2ModelMappingDataProvider") void testPhyre2ModelRegistration(String phyre2ModelFile, String expectedPhyre2FastaMappingFile) { String actualFastaMappingFile = ssm .getPhyre2FastaFileFor(phyre2ModelFile); Assert.assertNotNull(actualFastaMappingFile); Assert.assertEquals(actualFastaMappingFile, expectedPhyre2FastaMappingFile); } @Test(groups = { "Functional" }, dataProvider = "FilePathProvider") void testResolveAbsolutePath(String caseDescription, String suppliedPath, String baseURI, String expectedURI) { System.out.println(">>>> Testing Case - " + caseDescription); String actualURI = AnnotationFile.resolveAbsolutePath(suppliedPath, baseURI); Assert.assertEquals(actualURI, expectedURI); } @DataProvider(name = "phyre2ModelPDBEntryDataProvider") public static Object[][] phyre2ModelPDBEntryDataProvider() { String[] structModelHeader = new String[] { "QUERY_SEQ", "TEMPLATE_SEQ", "MODEL_FILE", "MAPPING_FILE", "Confidence", "% I.D", "Aligned Range", "Other Information"}; String baseDir = "examples/testdata/phyre2results/56da5616b4559c93/"; return new Object[][] { { structModelHeader, baseDir, "FER_CAPAN_1-144\tc4n58A_\tc4n58A_.1.pdb\tc4n58A_.1.fasta\t1\t54\t48-143\tPDB Header: Hyrolase
Chain: " + "A
PDB Molecule: Pectocin m2
PDB Title: Crystal structure of pectocin m2 at 1.86 amgtroms" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td1a70a_\td1a70a_.2.pdb\td1a70a_.2.fasta\t1\t71\t48-144\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td1offa_\td1offa_.3.pdb\td1offa_.3.fasta\t1\t73\t48-142\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td1frra_\td1frra_.4.pdb\td1frra_.4.fasta\t0.999\t62\t49-142\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td1pfda_\td1pfda_.5.pdb\td1pfda_.5.fasta\t0.999\t70\t48-143\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td1frda_\td1frda_.6.pdb\td1frda_.6.fasta\t0.999\t50\t48-143\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td1fxia_\td1fxia_.7.pdb\td1fxia_.7.fasta\t0.999\t62\t48-142\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td1gaqb_\td1gaqb_.8.pdb\td1gaqb_.8.fasta\t0.999\t71\t48-144\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td1iuea_\td1iuea_.9.pdb\td1iuea_.9.fasta\t0.999\t48\t48-142\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td1awda_\td1awda_.10.pdb\td1awda_.10.fasta\t0.999\t68\t50-142\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td1wria_\td1wria_.11.pdb\td1wria_.11.fasta\t0.999\t59\t49-142\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td1czpa_\td1czpa_.12.pdb\td1czpa_.12.fasta\t0.999\t64\t48-142\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td2cjoa_\td2cjoa_.13.pdb\td2cjoa_.13.fasta\t0.999\t63\t48-142\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td4fxca_\td4fxca_.14.pdb\td4fxca_.14.fasta\t0.999\t64\t48-142\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\tc4itkA_\tc4itkA_.15.pdb\tc4itkA_.15.fasta\t0.999\t57\t50-142\tPDB Header: Electron transport
" + "Chain: A
PDB Molecule: Apoferredoxin
PDB Title: The structure of c.reinhardtii ferredoxin 2" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\tc1krhA_\tc1krhA_.16.pdb\tc1krhA_.16.fasta\t0.999\t25\t48-142\tPDB Header: Oxidoreductase
Chain: " + "A
PDB Molecule: Benzoate 1,2-deoxygenase reductase
PDB Title: X-ray structure of benzoate " + "deoxygenate reductase" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td1krha3\td1krha3.17.pdb\td1krha3.17.fasta\t0.999\t24\t48-143\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin domains from multi domain proteins" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\td1jq4a_\td1jq4a_.18.pdb\td1jq4a_.18.fasta\t0.999\t29\t47-138\tFold: Beta-Grasp (ubiquitin-like)
" + "Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin domains from multi domain proteins" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\tc4wqmA_\tc4wqmA_.19.pdb\tc4wqmA_.19.fasta\t0.999\t28\t49-144\tPDB header: Oxidoreductase
Chain: " + "A
PDB Molecule: Toluene-4-monooxygenase electron transfer component
PDB Title: Structure of the " + "toluene 4-monooxygenase nah oxidoreductase t4mof,2 k270s k271s variant" }, { structModelHeader, baseDir, "FER_CAPAN_1-144\tc2piaA_\tc2piaA_.20.pdb\tc2piaA_.20.fasta\t0.999\t22\t1-136\tPDB header: Reductase
Chain: " + "A
PDB Molecule: Phthalate deoxygenase reductase
PDB Title: Phthalate deoxygenate reductase: a" + " modular structure for2 electron transfer from pyridine nucleotides to [2fe-2s]" } }; } @DataProvider(name = "phyre2ModelMappingDataProvider") public static Object[][] phyre2ModelMappingDataProvider() { return new Object[][] { { "examples/testdata/phyre2results/56da5616b4559c93/c4n58A_.1.pdb", "examples/testdata/phyre2results/56da5616b4559c93/c4n58A_.1.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d1a70a_.2.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d1a70a_.2.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d1offa_.3.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d1offa_.3.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d1frra_.4.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d1frra_.4.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d1pfda_.5.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d1pfda_.5.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d1frda_.6.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d1frda_.6.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d1fxia_.7.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d1fxia_.7.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d1gaqb_.8.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d1gaqb_.8.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d1iuea_.9.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d1iuea_.9.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d1awda_.10.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d1awda_.10.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d1wria_.11.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d1wria_.11.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d1czpa_.12.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d1czpa_.12.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d2cjoa_.13.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d2cjoa_.13.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d4fxca_.14.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d4fxca_.14.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/c4itkA_.15.pdb", "examples/testdata/phyre2results/56da5616b4559c93/c4itkA_.15.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/c1krhA_.16.pdb", "examples/testdata/phyre2results/56da5616b4559c93/c1krhA_.16.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d1krha3.17.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d1krha3.17.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/d1jq4a_.18.pdb", "examples/testdata/phyre2results/56da5616b4559c93/d1jq4a_.18.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/c4wqmA_.19.pdb", "examples/testdata/phyre2results/56da5616b4559c93/c4wqmA_.19.fasta" }, { "examples/testdata/phyre2results/56da5616b4559c93/c2piaA_.20.pdb", "examples/testdata/phyre2results/56da5616b4559c93/c2piaA_.20.fasta" } }; } @DataProvider(name = "phyre2InfoHTMLTableDataProvider") public static Object[][] phyre2InfoHTMLTableDataProvider() { return new Object[][] { { "STRUCTMODEL Annotation with no headear information provided", null, new String[] { "FER_CAPAN_1-144", "d1a70a_ d1a70a_.2.pdb", "d1a70a_.2.fasta", }, "" }, { "STRUCTMODEL Annotation with complete compulsary data and headear information provided", new String[] { "HEADER_STRUCT_MODEL", "QUERY_SEQ", "TEMPLATE_SEQ", "MODEL_FILE", "MAPPING_FILE" }, new String[] { "FER_CAPAN_1-144", "d1a70a_ d1a70a_.2.pdb", "d1a70a_.2.fasta", }, "
Phyre2 Template Info
" }, { "STRUCTMODEL Annotation with complete compulsary data and headear information provided", new String[] { "HEADER_STRUCT_MODEL", "QUERY_SEQ", "TEMPLATE_SEQ", "MODEL_FILE", "MAPPING_FILE", "Confidence", "% I.D", "Aligned Range", "Other Information", "Coverage" }, new String[] { "FER_CAPAN_1-144", "d1a70a_ d1a70a_.2.pdb", "d1a70a_.2.fasta", "1", "71", "48-144", "Fold: Beta-Grasp (ubiquitin-like)
Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, "
Phyre2 Template Info
MAPPING_FILE71
Confidence48-144
% I.DFold: Beta-Grasp (ubiquitin-like)
Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related
" } }; } @DataProvider(name = "StructModelHtmlDataProvider") public static Object[][] IsGenerateStructInfoHtmlDataProvider() { return new Object[][] { { "STRUCTMODEL Annotation with no headear or data provided", null, null, false }, { "STRUCTMODEL Annotation with headear information and no data column provided", new String[] { "HEADER_STRUCT_MODEL", "QUERY_SEQ" }, null, false }, { "STRUCTMODEL Annotation with no headear information provided", null, new String[] { "FER_CAPAN_1-144", "d1a70a_ d1a70a_.2.pdb", "d1a70a_.2.fasta", }, false }, { "STRUCTMODEL Annotation with only two headear information and two data column provided", new String[] { "HEADER_STRUCT_MODEL", "QUERY_SEQ" }, new String[] { "FER_CAPAN_1-144", "d1a70a_" }, false }, { "STRUCTMODEL Annotation with complete compulsary data and headear information provided", new String[] { "HEADER_STRUCT_MODEL", "QUERY_SEQ", "TEMPLATE_SEQ", "MODEL_FILE", "MAPPING_FILE" }, new String[] { "FER_CAPAN_1-144", "d1a70a_", "d1a70a_.2.pdb", "d1a70a_.2.fasta", }, true }, { "STRUCTMODEL Annotation with complete compulsary data and headear information provided", new String[] { "HEADER_STRUCT_MODEL", "QUERY_SEQ", "TEMPLATE_SEQ", "MODEL_FILE", "MAPPING_FILE", "Confidence", "% I.D", "Aligned Range", "Other Information", "Coverage" }, new String[] { "FER_CAPAN_1-144", "d1a70a_", "d1a70a_.2.pdb", "d1a70a_.2.fasta", "1", "71", "48-144", "Fold: Beta-Grasp (ubiquitin-like)
Superfamily: 2Fe-2S ferredoxin-like
Family: 2Fe-2S ferredoxin-related" }, true } }; } @DataProvider(name = "FilePathProvider") public static Object[][] filePathProvider() { return new Object[][] { { "relative local file path resolution", "c4n58A_.1.pdb", "", "c4n58A_.1.pdb" }, { "relative local file path resolution", "c4n58A_.1.pdb", "/examples/testdata/phyre2results/", "/examples/testdata/phyre2results/c4n58A_.1.pdb" }, { "relative URL path resolution", "c4n58A_.1.pdb", "http://www.jalview.org/builds/develop/examples/testdata/phyre2results/", "http://www.jalview.org/builds/develop/examples/testdata/phyre2results/c4n58A_.1.pdb" }, { "Absolute local file path resolution", "/examples/testdata/phyre2results_xx/c4n58A_.1.pdb", "/examples/testdata/phyre2results/", "/examples/testdata/phyre2results_xx/c4n58A_.1.pdb" }, { "Absolute URL path resolution", "http://www.jalview.org/builds/develop/another_directory/c4n58A_.1.pdb", "http://www.jalview.org/builds/develop/examples/testdata/phyre2results/", "http://www.jalview.org/builds/develop/another_directory/c4n58A_.1.pdb" } }; } }