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.
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
26 import jalview.bin.Cache;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.SequenceFeature;
29 import jalview.datamodel.SequenceI;
30 import jalview.gui.JvOptionPane;
31 import jalview.structure.StructureImportSettings;
32 import jalview.structure.StructureImportSettings.StructureParser;
33 import jalview.ws.seqfetcher.DbSourceProxy;
35 import java.util.Arrays;
36 import java.util.List;
38 import org.testng.Assert;
39 import org.testng.annotations.BeforeClass;
40 import org.testng.annotations.BeforeMethod;
41 import org.testng.annotations.Test;
43 public class PDBSequenceFetcherTest
46 @BeforeClass(alwaysRun = true)
47 public void setUpJvOptionPane()
49 JvOptionPane.setInteractiveMode(false);
50 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
55 @BeforeMethod(alwaysRun = true)
56 public void setUp() throws Exception
58 Cache.loadProperties("test/jalview/io/testProps.jvprops");
59 // ensure 'add annotation from structure' is selected
60 Cache.applicationProperties.setProperty("STRUCT_FROM_PDB",
61 Boolean.TRUE.toString());
62 Cache.applicationProperties.setProperty("ADD_SS_ANN",
63 Boolean.TRUE.toString());
65 sf = new SequenceFetcher();
69 * Test that RNA structure can be added by a call to the RNAML service.
71 * Note this test depends on http://arn-ibmc.in2p3.fr/api/compute/2d which is
72 * not always reliable.
76 @Test(groups = { "Network" }, enabled = true)
77 public void testRnaSeqRetrieve() throws Exception
79 Cache.applicationProperties.setProperty("PDB_DOWNLOAD_FORMAT", "PDB");
80 List<DbSourceProxy> sps = sf.getSourceProxy("PDB");
81 AlignmentI response = sps.get(0).getSequenceRecords("2GIS");
82 assertTrue(response != null);
83 assertTrue(response.getHeight() == 1);
84 for (SequenceI sq : response.getSequences())
86 assertTrue("No annotation transfered to sequence.",
87 sq.getAnnotation().length > 0);
88 assertTrue("No PDBEntry on sequence.",
89 sq.getAllPDBEntries().size() > 0);
91 "No RNA annotation on sequence, possibly http://arn-ibmc.in2p3.fr/api/compute/2d not available?",
96 @Test(groups = { "Network" }, enabled = true)
97 public void testPdbSeqRetrieve() throws Exception
99 StructureImportSettings.setDefaultStructureFileFormat("PDB");
100 StructureImportSettings
101 .setDefaultPDBFileParser(StructureParser.JALVIEW_PARSER);
103 testRetrieveProteinSeqFromPDB();
106 @Test(groups = { "Network" }, enabled = true)
107 public void testmmCifSeqRetrieve() throws Exception
109 StructureImportSettings.setDefaultStructureFileFormat("mmCIF");
110 testRetrieveProteinSeqFromPDB();
113 private class TestRetrieveObject
119 public TestRetrieveObject(String id, int expectedHeight)
123 this.expectedHeight = expectedHeight;
128 private List<TestRetrieveObject> toRetrieve = Arrays.asList(
129 new TestRetrieveObject("1QIP", 4),
130 new TestRetrieveObject("4IM2", 1));
132 private void testRetrieveProteinSeqFromPDB() throws Exception
134 List<DbSourceProxy> sps = sf.getSourceProxy("PDB");
135 StringBuilder errors = new StringBuilder();
136 for (TestRetrieveObject str : toRetrieve)
138 AlignmentI response = sps.get(0).getSequenceRecords(str.id);
139 assertTrue("No aligment for " + str.id, response != null);
140 assertEquals(response.getHeight(), str.expectedHeight,
141 "Number of chains for " + str.id);
142 for (SequenceI sq : response.getSequences())
144 assertTrue("No annotation transfered to sequence " + sq.getName(),
145 sq.getAnnotation().length > 0);
146 assertTrue("No PDBEntry on sequence " + sq.getName(),
147 sq.getAllPDBEntries().size() > 0);
148 // FIXME: should test that all residues extracted as sequences from
149 // chains in structure have a mapping to data in the structure
150 List<SequenceFeature> prev = null;
152 for (int col = 1; col <= sq.getLength(); col++)
154 List<SequenceFeature> sf = sq.findFeatures(col, col, "RESNUM");
159 "Expected one feature at column (position): "
161 + " (" + sq.findPosition(col - 1) + ")"
167 errors.append("Last Feature was at position " + lastp + ": "
168 + prev.get(0).toString());
175 lastp = sq.findPosition(col - 1);
180 if (errors.length() > 0)
182 Assert.fail(errors.toString());