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.
31 { "Functional" }, enabled = false)
32 public void pdbEntryPositionMap() throws Exception
34 Assert.fail("This test intentionally left to fail");
35 for (int offset = 0; offset < 20; offset += 6)
37 // check we put the secondary structure in the right position
38 Sequence uprot = new Sequence("TheProtSeq",
39 "DAWEIPRESLKLEKKLGAGQFGEVWMATYNKHTKVAVKTMKPGSMSVEAFLAEANVMKTL");
40 uprot.setStart(offset + 258); // make it harder - create a fake
41 // relocation problem for jalview to
43 uprot.setEnd(uprot.getStart() + uprot.getLength() - 1);
44 // original numbers taken from
45 // http://www.ebi.ac.uk/pdbe-srv/view/entry/1qcf/secondary.html
46 // these are in numbering relative to the subsequence above
48 { 266, 275, 278, 287, 289, 298, 302, 316 }, helices[] = new int[]
49 { 303, 315 }, sheets[] = new int[]
50 { 267, 268, 269, 270 };
52 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
53 PDBfile pmap = ssm.setMapping(true, new SequenceI[]
54 { uprot }, new String[]
55 { "A" }, "test/jalview/ext/jmol/1QCF.pdb",
56 jalview.io.FormatAdapter.FILE);
57 assertTrue(pmap != null);
58 SequenceI protseq = pmap.getSeqsAsArray()[0];
59 AlignmentAnnotation pstra = protseq
60 .getAnnotation("Secondary Structure")[0];
62 pstra.restrict((pinds = protseq.findIndex(258) - 1),
63 pinde = (protseq.findIndex(317) - 1));
65 System.out.println("PDB Annot");
66 for (char c : protseq.getSubSequence(pinds, pinde).getSequence())
68 System.out.print(c + ", ");
70 System.out.println("\n" + pstra + "\n\nsubsequence\n");
71 for (char c : uprot.getSequence())
73 System.out.print(c + ", ");
75 System.out.println("");
76 for (AlignmentAnnotation ss : uprot
77 .getAnnotation("Secondary Structure"))
79 ss.adjustForAlignment();
80 System.out.println("Uniprot Annot\n" + ss);
81 assertTrue(ss.hasIcons);
85 Annotation a = ss.annotations[op = (uprot.findIndex(offset + p) - 1)];
87 "Expected a helix at position " + p + uprot.getCharAt(op)
88 + " but got coil", a != null);
89 assertEquals("Expected a helix at position " + p,
90 a.secondaryStructure, expected);
95 Annotation a = ss.annotations[uprot.findIndex(offset + p) - 1];
97 "Expected a strand at position " + p + " but got coil",
99 assertEquals("Expected a strand at position " + p,
100 a.secondaryStructure, expected);
105 Annotation a = ss.annotations[uprot.findIndex(offset + p) - 1];
106 assertTrue("Expected coil at position " + p + " but got "
107 + a.secondaryStructure, a == null);
114 { "Functional" }, enabled = false)
115 public void testPDBentryMapping() throws Exception
117 Assert.fail("This test intentionally left to fail");
118 Sequence sq = new Sequence(
119 "1GAQ A subseq 126 to 219",
120 "EIVKGVCSNFLCDLQPGDNVQITGPVGKEMLMPKDPNATIIMLATGTGIAPFRSFLWKMFFEKHDDYKFNGLGWLFLGVPTSSSLLYKEEFGKM");
121 Sequence sq1 = new Sequence(sq);
123 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
124 // Associate the 1GAQ pdb file with the subsequence 'imported' from another
126 PDBfile pde = ssm.setMapping(true, new SequenceI[]
128 { "A" }, inFile = "examples/1gaq.txt", jalview.io.FormatAdapter.FILE);
129 assertTrue("PDB File couldn't be found", pde != null);
130 StructureMapping[] mp = ssm.getMapping(inFile);
131 assertTrue("No mappings made.", mp != null && mp.length > 0);
132 int nsecStr = 0, nsTemp = 0;
133 // test for presence of transferred annotation on sequence
134 for (AlignmentAnnotation alan : sq.getAnnotation())
140 if (alan.graph == alan.LINE_GRAPH)
146 "Only one secondary structure should be transferred to associated sequence.",
149 "Only two line graphs should be transferred to associated sequence.",
151 // Now test the transfer function and compare annotated positions
152 for (StructureMapping origMap : mp)
154 if (origMap.getSequence() == sq)
156 assertEquals("Mapping was incomplete.", sq.getLength() - 1,
157 (origMap.getPDBResNum(sq.getEnd()) - origMap
158 .getPDBResNum(sq.getStart())));
159 // sanity check - if this fails, mapping from first position in sequence
160 // we want to transfer to is not where we expect
161 assertEquals(1, origMap.getSeqPos(126));
162 SequenceI firstChain = pde.getSeqs().get(0);
163 // Compare the annotated positions on the PDB chain sequence with the
164 // annotation on the associated sequence
165 for (AlignmentAnnotation alan : firstChain.getAnnotation())
167 AlignmentAnnotation transfer = origMap.transfer(alan);
168 System.out.println("pdb:" + firstChain.getSequenceAsString());
169 System.out.println("ann:" + alan.toString());
170 System.out.println("pdb:" + sq.getSequenceAsString());
171 System.out.println("ann:" + transfer.toString());
173 for (int p = 0, pSize = firstChain.getLength(); p < pSize; p++)
175 // walk along the pdb chain's jalview sequence
177 int fpos = origMap.getSeqPos(rseqpos = firstChain
179 // only look at positions where there is a corresponding position in
185 // p is index into PDB residue entries
186 // rseqpos is pdb sequence position for position p
187 // fpos is sequence position for associated position for rseqpos
188 // tanpos is the column for the mapped sequence position
189 int tanpos = sq.findIndex(fpos) - 1;
190 if (tanpos < 0 || transfer.annotations.length <= tanpos)
192 // gone beyond mapping to the sequence
196 Annotation a = transfer.annotations[tanpos], b = alan.annotations[p];
197 assertEquals("Non-equivalent annotation element at " + p + "("
198 + rseqpos + ")" + " expected at " + fpos + " (alIndex "
200 a == null ? a : a.toString(),
201 b == null ? b : b.toString());
202 System.out.print("(" + a + "|" + b + ")");
211 * corner case for pdb mapping - revealed a problem with the AlignSeq->Mapping
215 @Test(groups ={ "Functional" })
216 public void mapFer1From3W5V() throws Exception
218 AlignFrame seqf = new FileLoader(false)
219 .LoadFileWaitTillLoaded(
220 ">FER1_MAIZE/1-150 Ferredoxin-1, chloroplast precursor\nMATVLGSPRAPAFFFSSSSLRAAPAPTAVALPAAKVGIMGRSASSRRRLRAQATYNVKLITPEGEVELQVPD\nDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKE\nEELTGA",
221 FormatAdapter.PASTE, "FASTA");
222 SequenceI newseq = seqf.getViewport().getAlignment().getSequenceAt(0);
223 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
224 PDBfile pmap = ssm.setMapping(true, new SequenceI[]
225 { newseq }, new String[]
226 { null }, "examples/3W5V.pdb",
227 jalview.io.FormatAdapter.FILE);
230 AssertJUnit.fail("Couldn't make a mapping for 3W5V to FER1_MAIZE");
235 * compare reference annotation for imported pdb sequence to identical
236 * seuqence with transferred annotation from mapped pdb file
238 @Test(groups ={ "Functional" })
239 public void compareTransferredToRefPDBAnnot() throws Exception
241 AlignFrame ref = new FileLoader(false)
242 .LoadFileWaitTillLoaded("test/jalview/ext/jmol/1QCF.pdb",
243 jalview.io.FormatAdapter.FILE);
244 SequenceI refseq = ref.getViewport().getAlignment().getSequenceAt(0);
245 SequenceI newseq = new Sequence(refseq.getName() + "Copy",
246 refseq.getSequenceAsString());
247 // make it harder by shifting the copy vs the reference
248 newseq.setStart(refseq.getStart() + 25);
249 newseq.setEnd(refseq.getLength() + 25 + refseq.getStart());
250 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
251 ssm.setProcessSecondaryStructure(true);
252 ssm.setAddTempFacAnnot(true);
253 PDBfile pmap = ssm.setMapping(true, new SequenceI[]
254 { newseq }, new String[]
255 { null }, "test/jalview/ext/jmol/1QCF.pdb",
256 jalview.io.FormatAdapter.FILE);
257 assertTrue(pmap != null);
258 assertEquals("Original and copied sequence of different lengths.",
259 refseq.getLength(), newseq.getLength());
260 assertTrue(refseq.getAnnotation() != null
261 && refseq.getAnnotation().length > 0);
262 assertTrue(newseq.getAnnotation() != null
263 && newseq.getAnnotation().length > 0);
264 for (AlignmentAnnotation oannot : refseq.getAnnotation())
266 for (AlignmentAnnotation tannot : newseq.getAnnotation(oannot.label))
268 for (int p = 0, pSize = refseq.getLength(); p < pSize; p++)
270 Annotation orig = oannot.annotations[p], tran = tannot.annotations[p];
271 assertTrue("Mismatch: coil and non coil site " + p, orig == tran
272 || orig != null && tran != null);
275 assertEquals("Mismatch in secondary structure at site " + p,
276 tran.secondaryStructure, orig.secondaryStructure);