1 package jalview.structure;
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertTrue;
6 import jalview.datamodel.AlignmentAnnotation;
7 import jalview.datamodel.Annotation;
8 import jalview.datamodel.Sequence;
9 import jalview.datamodel.SequenceI;
10 import jalview.gui.AlignFrame;
11 import jalview.io.FileLoader;
12 import jalview.io.FormatAdapter;
14 import org.testng.Assert;
15 import org.testng.AssertJUnit;
16 import org.testng.annotations.Test;
18 import MCview.PDBfile;
26 * 1QCF|A/101-121 SFQKGDQMVVLEESGEWWKAR Ser 114 jumps to Gly 116 at position
27 * 115 in PDB Res Numbering secondary structure numbers in jmol seem to be in
28 * msd numbering, not pdb res numbering.
30 @Test(groups = { "Functional" }, enabled = false)
31 public void pdbEntryPositionMap() throws Exception
33 Assert.fail("This test intentionally left to fail");
34 for (int offset = 0; offset < 20; offset += 6)
36 // check we put the secondary structure in the right position
37 Sequence uprot = new Sequence("TheProtSeq",
38 "DAWEIPRESLKLEKKLGAGQFGEVWMATYNKHTKVAVKTMKPGSMSVEAFLAEANVMKTL");
39 uprot.setStart(offset + 258); // make it harder - create a fake
40 // relocation problem for jalview to
42 uprot.setEnd(uprot.getStart() + uprot.getLength() - 1);
43 // original numbers taken from
44 // http://www.ebi.ac.uk/pdbe-srv/view/entry/1qcf/secondary.html
45 // these are in numbering relative to the subsequence above
46 int coils[] = { 266, 275, 278, 287, 289, 298, 302, 316 }, helices[] = new int[]
47 { 303, 315 }, sheets[] = new int[] { 267, 268, 269, 270 };
49 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
50 PDBfile pmap = ssm.setMapping(true, new SequenceI[] { uprot },
51 new String[] { "A" }, "test/jalview/ext/jmol/1QCF.pdb",
52 jalview.io.FormatAdapter.FILE);
53 assertTrue(pmap != null);
54 SequenceI protseq = pmap.getSeqsAsArray()[0];
55 AlignmentAnnotation pstra = protseq
56 .getAnnotation("Secondary Structure")[0];
58 pstra.restrict((pinds = protseq.findIndex(258) - 1),
59 pinde = (protseq.findIndex(317) - 1));
61 System.out.println("PDB Annot");
62 for (char c : protseq.getSubSequence(pinds, pinde).getSequence())
64 System.out.print(c + ", ");
66 System.out.println("\n" + pstra + "\n\nsubsequence\n");
67 for (char c : uprot.getSequence())
69 System.out.print(c + ", ");
71 System.out.println("");
72 for (AlignmentAnnotation ss : uprot
73 .getAnnotation("Secondary Structure"))
75 ss.adjustForAlignment();
76 System.out.println("Uniprot Annot\n" + ss);
77 assertTrue(ss.hasIcons);
81 Annotation a = ss.annotations[op = (uprot.findIndex(offset + p) - 1)];
83 "Expected a helix at position " + p + uprot.getCharAt(op)
84 + " but got coil", a != null);
85 assertEquals("Expected a helix at position " + p,
86 a.secondaryStructure, expected);
91 Annotation a = ss.annotations[uprot.findIndex(offset + p) - 1];
93 "Expected a strand at position " + p + " but got coil",
95 assertEquals("Expected a strand at position " + p,
96 a.secondaryStructure, expected);
101 Annotation a = ss.annotations[uprot.findIndex(offset + p) - 1];
102 assertTrue("Expected coil at position " + p + " but got "
103 + a.secondaryStructure, a == null);
109 @Test(groups = { "Functional" }, enabled = false)
110 public void testPDBentryMapping() throws Exception
112 Assert.fail("This test intentionally left to fail");
113 Sequence sq = new Sequence(
114 "1GAQ A subseq 126 to 219",
115 "EIVKGVCSNFLCDLQPGDNVQITGPVGKEMLMPKDPNATIIMLATGTGIAPFRSFLWKMFFEKHDDYKFNGLGWLFLGVPTSSSLLYKEEFGKM");
116 Sequence sq1 = new Sequence(sq);
118 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
119 // Associate the 1GAQ pdb file with the subsequence 'imported' from another
121 PDBfile pde = ssm.setMapping(true, new SequenceI[] { sq }, new String[]
122 { "A" }, inFile = "examples/1gaq.txt", jalview.io.FormatAdapter.FILE);
123 assertTrue("PDB File couldn't be found", pde != null);
124 StructureMapping[] mp = ssm.getMapping(inFile);
125 assertTrue("No mappings made.", mp != null && mp.length > 0);
126 int nsecStr = 0, nsTemp = 0;
127 // test for presence of transferred annotation on sequence
128 for (AlignmentAnnotation alan : sq.getAnnotation())
134 if (alan.graph == alan.LINE_GRAPH)
140 "Only one secondary structure should be transferred to associated sequence.",
143 "Only two line graphs should be transferred to associated sequence.",
145 // Now test the transfer function and compare annotated positions
146 for (StructureMapping origMap : mp)
148 if (origMap.getSequence() == sq)
150 assertEquals("Mapping was incomplete.", sq.getLength() - 1,
151 (origMap.getPDBResNum(sq.getEnd()) - origMap
152 .getPDBResNum(sq.getStart())));
153 // sanity check - if this fails, mapping from first position in sequence
154 // we want to transfer to is not where we expect
155 assertEquals(1, origMap.getSeqPos(126));
156 SequenceI firstChain = pde.getSeqs().get(0);
157 // Compare the annotated positions on the PDB chain sequence with the
158 // annotation on the associated sequence
159 for (AlignmentAnnotation alan : firstChain.getAnnotation())
161 AlignmentAnnotation transfer = origMap.transfer(alan);
162 System.out.println("pdb:" + firstChain.getSequenceAsString());
163 System.out.println("ann:" + alan.toString());
164 System.out.println("pdb:" + sq.getSequenceAsString());
165 System.out.println("ann:" + transfer.toString());
167 for (int p = 0, pSize = firstChain.getLength(); p < pSize; p++)
169 // walk along the pdb chain's jalview sequence
171 int fpos = origMap.getSeqPos(rseqpos = firstChain
173 // only look at positions where there is a corresponding position in
179 // p is index into PDB residue entries
180 // rseqpos is pdb sequence position for position p
181 // fpos is sequence position for associated position for rseqpos
182 // tanpos is the column for the mapped sequence position
183 int tanpos = sq.findIndex(fpos) - 1;
184 if (tanpos < 0 || transfer.annotations.length <= tanpos)
186 // gone beyond mapping to the sequence
190 Annotation a = transfer.annotations[tanpos], b = alan.annotations[p];
191 assertEquals("Non-equivalent annotation element at " + p + "("
192 + rseqpos + ")" + " expected at " + fpos + " (alIndex "
193 + tanpos + ")", a == null ? a : a.toString(),
194 b == null ? b : b.toString());
195 System.out.print("(" + a + "|" + b + ")");
204 * corner case for pdb mapping - revealed a problem with the AlignSeq->Mapping
208 @Test(groups = { "Functional" })
209 public void mapFer1From3W5V() throws Exception
211 AlignFrame seqf = new FileLoader(false)
212 .LoadFileWaitTillLoaded(
213 ">FER1_MAIZE/1-150 Ferredoxin-1, chloroplast precursor\nMATVLGSPRAPAFFFSSSSLRAAPAPTAVALPAAKVGIMGRSASSRRRLRAQATYNVKLITPEGEVELQVPD\nDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKE\nEELTGA",
214 FormatAdapter.PASTE, "FASTA");
215 SequenceI newseq = seqf.getViewport().getAlignment().getSequenceAt(0);
216 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
217 PDBfile pmap = ssm.setMapping(true, new SequenceI[] { newseq },
218 new String[] { null }, "examples/3W5V.pdb",
219 jalview.io.FormatAdapter.FILE);
222 AssertJUnit.fail("Couldn't make a mapping for 3W5V to FER1_MAIZE");
227 * compare reference annotation for imported pdb sequence to identical
228 * seuqence with transferred annotation from mapped pdb file
230 @Test(groups = { "Functional" })
231 public void compareTransferredToRefPDBAnnot() throws Exception
233 AlignFrame ref = new FileLoader(false)
234 .LoadFileWaitTillLoaded("test/jalview/ext/jmol/1QCF.pdb",
235 jalview.io.FormatAdapter.FILE);
236 SequenceI refseq = ref.getViewport().getAlignment().getSequenceAt(0);
237 SequenceI newseq = new Sequence(refseq.getName() + "Copy",
238 refseq.getSequenceAsString());
239 // make it harder by shifting the copy vs the reference
240 newseq.setStart(refseq.getStart() + 25);
241 newseq.setEnd(refseq.getLength() + 25 + refseq.getStart());
242 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
243 ssm.setProcessSecondaryStructure(true);
244 ssm.setAddTempFacAnnot(true);
245 PDBfile pmap = ssm.setMapping(true, new SequenceI[] { newseq },
246 new String[] { null }, "test/jalview/ext/jmol/1QCF.pdb",
247 jalview.io.FormatAdapter.FILE);
248 assertTrue(pmap != null);
249 assertEquals("Original and copied sequence of different lengths.",
250 refseq.getLength(), newseq.getLength());
251 assertTrue(refseq.getAnnotation() != null
252 && refseq.getAnnotation().length > 0);
253 assertTrue(newseq.getAnnotation() != null
254 && newseq.getAnnotation().length > 0);
255 for (AlignmentAnnotation oannot : refseq.getAnnotation())
257 for (AlignmentAnnotation tannot : newseq.getAnnotation(oannot.label))
259 for (int p = 0, pSize = refseq.getLength(); p < pSize; p++)
261 Annotation orig = oannot.annotations[p], tran = tannot.annotations[p];
262 assertTrue("Mismatch: coil and non coil site " + p, orig == tran
263 || orig != null && tran != null);
266 assertEquals("Mismatch in secondary structure at site " + p,
267 tran.secondaryStructure, orig.secondaryStructure);