1 package jalview.structure;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
5 import static org.junit.Assert.fail;
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.junit.Assert;
15 import org.junit.Test;
17 import MCview.PDBfile;
25 * 1QCF|A/101-121 SFQKGDQMVVLEESGEWWKAR Ser 114 jumps to Gly 116 at position
26 * 115 in PDB Res Numbering secondary structure numbers in jmol seem to be in
27 * msd numbering, not pdb res numbering.
30 public void pdbEntryPositionMap() throws Exception
32 fail("This test intentionally left to fail");
33 for (int offset = 0; offset < 20; offset += 6)
35 // check we put the secondary structure in the right position
36 Sequence uprot = new Sequence("TheProtSeq",
37 "DAWEIPRESLKLEKKLGAGQFGEVWMATYNKHTKVAVKTMKPGSMSVEAFLAEANVMKTL");
38 uprot.setStart(offset + 258); // make it harder - create a fake
39 // relocation problem for jalview to
41 uprot.setEnd(uprot.getStart() + uprot.getLength() - 1);
42 // original numbers taken from
43 // http://www.ebi.ac.uk/pdbe-srv/view/entry/1qcf/secondary.html
44 // these are in numbering relative to the subsequence above
46 { 266, 275, 278, 287, 289, 298, 302, 316 }, helices[] = new int[]
47 { 303, 315 }, sheets[] = new int[]
48 { 267, 268, 269, 270 };
50 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
51 PDBfile pmap = ssm.setMapping(true, new SequenceI[]
52 { uprot }, new String[]
53 { "A" }, "test/jalview/ext/jmol/1QCF.pdb",
54 jalview.io.FormatAdapter.FILE);
55 assertTrue(pmap != null);
56 SequenceI protseq = pmap.getSeqsAsArray()[0];
57 AlignmentAnnotation pstra = protseq
58 .getAnnotation("Secondary Structure")[0];
60 pstra.restrict((pinds = protseq.findIndex(258) - 1),
61 pinde = (protseq.findIndex(317) - 1));
63 System.out.println("PDB Annot");
64 for (char c : protseq.getSubSequence(pinds, pinde).getSequence())
66 System.out.print(c + ", ");
68 System.out.println("\n" + pstra + "\n\nsubsequence\n");
69 for (char c : uprot.getSequence())
71 System.out.print(c + ", ");
73 System.out.println("");
74 for (AlignmentAnnotation ss : uprot
75 .getAnnotation("Secondary Structure"))
77 ss.adjustForAlignment();
78 System.out.println("Uniprot Annot\n" + ss);
79 assertTrue(ss.hasIcons);
83 Annotation a = ss.annotations[op = (uprot.findIndex(offset + p) - 1)];
85 "Expected a helix at position " + p + uprot.getCharAt(op)
86 + " but got coil", a != null);
87 assertEquals("Expected a helix at position " + p,
88 a.secondaryStructure, expected);
93 Annotation a = ss.annotations[uprot.findIndex(offset + p) - 1];
95 "Expected a strand at position " + p + " but got coil",
97 assertEquals("Expected a strand at position " + p,
98 a.secondaryStructure, expected);
103 Annotation a = ss.annotations[uprot.findIndex(offset + p) - 1];
104 assertTrue("Expected coil at position " + p + " but got "
105 + a.secondaryStructure, a == null);
112 public void testPDBentryMapping() throws Exception
114 fail("This test intentionally left to fail");
115 Sequence sq = new Sequence(
116 "1GAQ A subseq 126 to 219",
117 "EIVKGVCSNFLCDLQPGDNVQITGPVGKEMLMPKDPNATIIMLATGTGIAPFRSFLWKMFFEKHDDYKFNGLGWLFLGVPTSSSLLYKEEFGKM");
118 Sequence sq1 = new Sequence(sq);
120 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
121 // Associate the 1GAQ pdb file with the subsequence 'imported' from another
123 PDBfile pde = ssm.setMapping(true, new SequenceI[]
125 { "A" }, inFile = "examples/1gaq.txt", jalview.io.FormatAdapter.FILE);
126 assertTrue("PDB File couldn't be found", pde != null);
127 StructureMapping[] mp = ssm.getMapping(inFile);
128 assertTrue("No mappings made.", mp != null && mp.length > 0);
129 int nsecStr = 0, nsTemp = 0;
130 // test for presence of transferred annotation on sequence
131 for (AlignmentAnnotation alan : sq.getAnnotation())
137 if (alan.graph == alan.LINE_GRAPH)
143 "Only one secondary structure should be transferred to associated sequence.",
146 "Only two line graphs should be transferred to associated sequence.",
148 // Now test the transfer function and compare annotated positions
149 for (StructureMapping origMap : mp)
151 if (origMap.getSequence() == sq)
153 assertEquals("Mapping was incomplete.", sq.getLength() - 1,
154 (origMap.getPDBResNum(sq.getEnd()) - origMap
155 .getPDBResNum(sq.getStart())));
156 // sanity check - if this fails, mapping from first position in sequence
157 // we want to transfer to is not where we expect
158 assertEquals(1, origMap.getSeqPos(126));
159 SequenceI firstChain = pde.getSeqs().get(0);
160 // Compare the annotated positions on the PDB chain sequence with the
161 // annotation on the associated sequence
162 for (AlignmentAnnotation alan : firstChain.getAnnotation())
164 AlignmentAnnotation transfer = origMap.transfer(alan);
165 System.out.println("pdb:" + firstChain.getSequenceAsString());
166 System.out.println("ann:" + alan.toString());
167 System.out.println("pdb:" + sq.getSequenceAsString());
168 System.out.println("ann:" + transfer.toString());
170 for (int p = 0, pSize = firstChain.getLength(); p < pSize; p++)
172 // walk along the pdb chain's jalview sequence
174 int fpos = origMap.getSeqPos(rseqpos = firstChain
176 // only look at positions where there is a corresponding position in
182 // p is index into PDB residue entries
183 // rseqpos is pdb sequence position for position p
184 // fpos is sequence position for associated position for rseqpos
185 // tanpos is the column for the mapped sequence position
186 int tanpos = sq.findIndex(fpos) - 1;
187 if (tanpos < 0 || transfer.annotations.length <= tanpos)
189 // gone beyond mapping to the sequence
193 Annotation a = transfer.annotations[tanpos], b = alan.annotations[p];
194 assertEquals("Non-equivalent annotation element at " + p + "("
195 + rseqpos + ")" + " expected at " + fpos + " (alIndex "
197 a == null ? a : a.toString(),
198 b == null ? b : b.toString());
199 System.out.print("(" + a + "|" + b + ")");
208 * corner case for pdb mapping - revealed a problem with the AlignSeq->Mapping
213 public void mapFer1From3W5V() throws Exception
215 AlignFrame seqf = new FileLoader(false)
216 .LoadFileWaitTillLoaded(
217 ">FER1_MAIZE/1-150 Ferredoxin-1, chloroplast precursor\nMATVLGSPRAPAFFFSSSSLRAAPAPTAVALPAAKVGIMGRSASSRRRLRAQATYNVKLITPEGEVELQVPD\nDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKE\nEELTGA",
218 FormatAdapter.PASTE, "FASTA");
219 SequenceI newseq = seqf.getViewport().getAlignment().getSequenceAt(0);
220 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
221 PDBfile pmap = ssm.setMapping(true, new SequenceI[]
222 { newseq }, new String[]
223 { null }, "examples/3W5V.pdb",
224 jalview.io.FormatAdapter.FILE);
227 Assert.fail("Couldn't make a mapping for 3W5V to FER1_MAIZE");
232 * compare reference annotation for imported pdb sequence to identical
233 * seuqence with transferred annotation from mapped pdb file
236 public void compareTransferredToRefPDBAnnot() throws Exception
238 AlignFrame ref = new FileLoader(false)
239 .LoadFileWaitTillLoaded("test/jalview/ext/jmol/1QCF.pdb",
240 jalview.io.FormatAdapter.FILE);
241 SequenceI refseq = ref.getViewport().getAlignment().getSequenceAt(0);
242 SequenceI newseq = new Sequence(refseq.getName() + "Copy",
243 refseq.getSequenceAsString());
244 // make it harder by shifting the copy vs the reference
245 newseq.setStart(refseq.getStart() + 25);
246 newseq.setEnd(refseq.getLength() + 25 + refseq.getStart());
247 StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
248 ssm.setProcessSecondaryStructure(true);
249 ssm.setAddTempFacAnnot(true);
250 PDBfile pmap = ssm.setMapping(true, new SequenceI[]
251 { newseq }, new String[]
252 { null }, "test/jalview/ext/jmol/1QCF.pdb",
253 jalview.io.FormatAdapter.FILE);
254 assertTrue(pmap != null);
255 assertEquals("Original and copied sequence of different lengths.",
256 refseq.getLength(), newseq.getLength());
257 assertTrue(refseq.getAnnotation() != null
258 && refseq.getAnnotation().length > 0);
259 assertTrue(newseq.getAnnotation() != null
260 && newseq.getAnnotation().length > 0);
261 for (AlignmentAnnotation oannot : refseq.getAnnotation())
263 for (AlignmentAnnotation tannot : newseq.getAnnotation(oannot.label))
265 for (int p = 0, pSize = refseq.getLength(); p < pSize; p++)
267 Annotation orig = oannot.annotations[p], tran = tannot.annotations[p];
268 assertTrue("Mismatch: coil and non coil site " + p, orig == tran
269 || orig != null && tran != null);
272 assertEquals("Mismatch in secondary structure at site " + p,
273 tran.secondaryStructure, orig.secondaryStructure);