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.structure;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
26 import org.testng.Assert;
27 import org.testng.AssertJUnit;
28 import org.testng.annotations.BeforeClass;
29 import org.testng.annotations.Test;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.Annotation;
33 import jalview.datamodel.Sequence;
34 import jalview.datamodel.SequenceI;
35 import jalview.gui.AlignFrame;
36 import jalview.gui.JvOptionPane;
37 import jalview.io.DataSourceType;
38 import jalview.io.FileFormat;
39 import jalview.io.FileLoader;
40 import jalview.io.StructureFile;
45 @BeforeClass(alwaysRun = true)
46 public void setUpJvOptionPane()
48 JvOptionPane.setInteractiveMode(false);
49 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
55 * 1QCF|A/101-121 SFQKGDQMVVLEESGEWWKAR Ser 114 jumps to Gly 116 at position
56 * 115 in PDB Res Numbering secondary structure numbers in jmol seem to be in
57 * msd numbering, not pdb res numbering.
59 @Test(groups = { "Functional" }, enabled = false)
60 public void pdbEntryPositionMap() throws Exception
62 Assert.fail("This test intentionally left to fail");
63 for (int offset = 0; offset < 20; offset += 6)
65 // check we put the secondary structure in the right position
66 Sequence uprot = new Sequence("TheProtSeq",
67 "DAWEIPRESLKLEKKLGAGQFGEVWMATYNKHTKVAVKTMKPGSMSVEAFLAEANVMKTL");
68 uprot.setStart(offset + 258); // make it harder - create a fake
69 // relocation problem for jalview to
71 uprot.setEnd(uprot.getStart() + uprot.getLength() - 1);
72 // original numbers taken from
73 // http://www.ebi.ac.uk/pdbe-srv/view/entry/1qcf/secondary.html
74 // these are in numbering relative to the subsequence above
75 int coils[] = { 266, 275, 278, 287, 289, 298, 302, 316 },
77 { 303, 315 }, sheets[] = new int[] { 267, 268, 269, 270 };
79 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
80 StructureFile pmap = ssm.setMapping(true, new SequenceI[] { uprot },
82 { "A" }, "test/jalview/ext/jmol/1QCF.pdb",
83 DataSourceType.FILE, null, null);
84 assertTrue(pmap != null);
85 SequenceI protseq = pmap.getSeqsAsArray()[0];
86 AlignmentAnnotation pstra = protseq
87 .getAnnotation("Secondary Structure")[0];
89 pstra.restrict((pinds = protseq.findIndex(258) - 1),
90 pinde = (protseq.findIndex(317) - 1));
92 System.out.println("PDB Annot");
93 for (char c : protseq.getSubSequence(pinds, pinde).getSequence())
95 System.out.print(c + ", ");
97 System.out.println("\n" + pstra + "\n\nsubsequence\n");
98 for (char c : uprot.getSequence())
100 System.out.print(c + ", ");
102 System.out.println("");
103 for (AlignmentAnnotation ss : uprot
104 .getAnnotation("Secondary Structure"))
106 ss.adjustForAlignment();
107 System.out.println("Uniprot Annot\n" + ss);
108 assertTrue(ss.hasIcons);
110 for (int p : helices)
112 Annotation a = ss.annotations[op = (uprot.findIndex(offset + p)
114 assertTrue("Expected a helix at position " + p
115 + uprot.getCharAt(op) + " but got coil", a != null);
116 assertEquals("Expected a helix at position " + p,
117 a.secondaryStructure, expected);
122 Annotation a = ss.annotations[uprot.findIndex(offset + p) - 1];
123 assertTrue("Expected a strand at position " + p + " but got coil",
125 assertEquals("Expected a strand at position " + p,
126 a.secondaryStructure, expected);
131 Annotation a = ss.annotations[uprot.findIndex(offset + p) - 1];
132 assertTrue("Expected coil at position " + p + " but got "
133 + a.secondaryStructure, a == null);
139 @Test(groups = { "Functional" }, enabled = false)
140 public void testPDBentryMapping() throws Exception
142 Assert.fail("This test intentionally left to fail");
143 Sequence sq = new Sequence("1GAQ A subseq 126 to 219",
144 "EIVKGVCSNFLCDLQPGDNVQITGPVGKEMLMPKDPNATIIMLATGTGIAPFRSFLWKMFFEKHDDYKFNGLGWLFLGVPTSSSLLYKEEFGKM");
145 Sequence sq1 = new Sequence(sq);
147 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
148 // Associate the 1GAQ pdb file with the subsequence 'imported' from another
150 StructureFile pde = ssm.setMapping(true, new SequenceI[] { sq },
152 { "A" }, inFile = "examples/1gaq.txt", DataSourceType.FILE,
154 assertTrue("PDB File couldn't be found", pde != null);
155 StructureMapping[] mp = ssm.getMapping(inFile);
156 assertTrue("No mappings made.", mp != null && mp.length > 0);
157 int nsecStr = 0, nsTemp = 0;
158 // test for presence of transferred annotation on sequence
159 for (AlignmentAnnotation alan : sq.getAnnotation())
165 if (alan.graph == alan.LINE_GRAPH)
171 "Only one secondary structure should be transferred to associated sequence.",
174 "Only two line graphs should be transferred to associated sequence.",
176 // Now test the transfer function and compare annotated positions
177 for (StructureMapping origMap : mp)
179 if (origMap.getSequence() == sq)
181 assertEquals("Mapping was incomplete.", sq.getLength() - 1,
182 (origMap.getPDBResNum(sq.getEnd())
183 - origMap.getPDBResNum(sq.getStart())));
184 // sanity check - if this fails, mapping from first position in sequence
185 // we want to transfer to is not where we expect
186 assertEquals(1, origMap.getSeqPos(126));
187 SequenceI firstChain = pde.getSeqs().get(0);
188 // Compare the annotated positions on the PDB chain sequence with the
189 // annotation on the associated sequence
190 for (AlignmentAnnotation alan : firstChain.getAnnotation())
192 AlignmentAnnotation transfer = origMap.transfer(alan);
193 System.out.println("pdb:" + firstChain.getSequenceAsString());
194 System.out.println("ann:" + alan.toString());
195 System.out.println("pdb:" + sq.getSequenceAsString());
196 System.out.println("ann:" + transfer.toString());
198 for (int p = 0, pSize = firstChain.getLength(); p < pSize; p++)
200 // walk along the pdb chain's jalview sequence
203 .getSeqPos(rseqpos = firstChain.findPosition(p));
204 // only look at positions where there is a corresponding position in
210 // p is index into PDB residue entries
211 // rseqpos is pdb sequence position for position p
212 // fpos is sequence position for associated position for rseqpos
213 // tanpos is the column for the mapped sequence position
214 int tanpos = sq.findIndex(fpos) - 1;
215 if (tanpos < 0 || transfer.annotations.length <= tanpos)
217 // gone beyond mapping to the sequence
221 Annotation a = transfer.annotations[tanpos],
222 b = alan.annotations[p];
224 "Non-equivalent annotation element at " + p + "("
225 + rseqpos + ")" + " expected at " + fpos
226 + " (alIndex " + tanpos + ")",
227 a == null ? a : a.toString(),
228 b == null ? b : b.toString());
229 System.out.print("(" + a + "|" + b + ")");
238 * corner case for pdb mapping - revealed a problem with the AlignSeq->Mapping
242 @Test(groups = { "Functional" })
243 public void mapFer1From3W5V() throws Exception
245 AlignFrame seqf = new FileLoader(false).LoadFileWaitTillLoaded(
246 ">FER1_MAIZE/1-150 Ferredoxin-1, chloroplast precursor\nMATVLGSPRAPAFFFSSSSLRAAPAPTAVALPAAKVGIMGRSASSRRRLRAQATYNVKLITPEGEVELQVPD\nDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKE\nEELTGA",
247 DataSourceType.PASTE, FileFormat.Fasta);
248 SequenceI newseq = seqf.getViewport().getAlignment().getSequenceAt(0);
249 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
250 StructureFile pmap = ssm.setMapping(true, new SequenceI[] { newseq },
252 { null }, "examples/3W5V.pdb", DataSourceType.FILE, null, null);
255 AssertJUnit.fail("Couldn't make a mapping for 3W5V to FER1_MAIZE");
260 * compare reference annotation for imported pdb sequence to identical
261 * seuqence with transferred annotation from mapped pdb file
263 @Test(groups = { "Functional" })
264 public void compareTransferredToRefPDBAnnot() throws Exception
266 StructureImportSettings.setProcessSecondaryStructure(true);
267 StructureImportSettings.setVisibleChainAnnotation(true);
268 StructureImportSettings.setShowSeqFeatures(true);
269 AlignFrame ref = new FileLoader(false).LoadFileWaitTillLoaded(
270 "test/jalview/ext/jmol/1QCF.pdb", DataSourceType.FILE);
271 SequenceI refseq = ref.getViewport().getAlignment().getSequenceAt(0);
272 SequenceI newseq = new Sequence(refseq.getName() + "Copy",
273 refseq.getSequenceAsString());
274 // make it harder by shifting the copy vs the reference
275 newseq.setStart(refseq.getStart() + 25);
276 newseq.setEnd(refseq.getLength() + 25 + refseq.getStart());
277 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
278 ssm.setProcessSecondaryStructure(true);
279 ssm.setAddTempFacAnnot(true);
280 StructureFile pmap = ssm.setMapping(true, new SequenceI[] { newseq },
282 { null }, "test/jalview/ext/jmol/1QCF.pdb", DataSourceType.FILE,
284 assertTrue(pmap != null);
285 assertEquals("Original and copied sequence of different lengths.",
286 refseq.getLength(), newseq.getLength());
287 assertTrue(refseq.getAnnotation() != null
288 && refseq.getAnnotation().length > 0);
289 assertTrue(newseq.getAnnotation() != null
290 && newseq.getAnnotation().length > 0);
291 for (AlignmentAnnotation oannot : refseq.getAnnotation())
293 for (AlignmentAnnotation tannot : newseq.getAnnotation(oannot.label))
295 for (int p = 0, pSize = refseq.getLength(); p < pSize; p++)
297 Annotation orig = oannot.annotations[p],
298 tran = tannot.annotations[p];
299 assertTrue("Mismatch: coil and non coil site " + p,
300 orig == tran || orig != null && tran != null);
303 assertEquals("Mismatch in secondary structure at site " + p,
304 tran.secondaryStructure, orig.secondaryStructure);