package jalview.structure; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import org.junit.Test; import MCview.PDBfile; public class Mapping { @Test public void testPDBentryMapping() throws Exception { Sequence sq = new Sequence( "1GAQ A subseq 126 to 219", "EIVKGVCSNFLCDLQPGDNVQITGPVGKEMLMPKDPNATIIMLATGTGIAPFRSFLWKMFFEKHDDYKFNGLGWLFLGVPTSSSLLYKEEFGKM"); Sequence sq1 = new Sequence(sq); String inFile; StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager(); // Associate the 1GAQ pdb file with the subsequence 'imported' from another // source PDBfile pde = ssm.setMapping(true, new SequenceI[] { sq }, new String[] { "A" }, inFile = "examples/1gaq.txt", jalview.io.FormatAdapter.FILE); assertTrue("PDB File couldn't be found", pde != null); StructureMapping[] mp = ssm.getMapping(inFile); assertTrue("No mappings made.", mp != null && mp.length > 0); int nsecStr = 0, nsTemp = 0; // test for presence of transferred annotation on sequence for (AlignmentAnnotation alan : sq.getAnnotation()) { if (alan.hasIcons) { nsecStr++; } if (alan.graph == alan.LINE_GRAPH) { nsTemp++; } } assertEquals( "Only one secondary structure should be transferred to associated sequence.", 1, nsecStr); assertEquals( "Only two line graphs should be transferred to associated sequence.", 2, nsTemp); // Now test the transfer function and compare annotated positions for (StructureMapping origMap:mp) { if (origMap.getSequence()==sq) { assertEquals("Mapping was incomplete.", sq.getLength() - 1, (origMap.getPDBResNum(sq.getEnd()) - origMap .getPDBResNum(sq.getStart()))); // sanity check - if this fails, mapping from first position in sequence // we want to transfer to is not where we expect assertEquals(1, origMap.getSeqPos(126)); SequenceI firstChain = pde.getSeqs().get(0); // Compare the annotated positions on the PDB chain sequence with the // annotation on the associated sequence for (AlignmentAnnotation alan : firstChain.getAnnotation()) { AlignmentAnnotation transfer = origMap.transfer(alan); System.out.println("pdb:" + firstChain.getSequenceAsString()); System.out.println("ann:" + alan.toString()); System.out.println("pdb:" + sq.getSequenceAsString()); System.out.println("ann:" + transfer.toString()); for (int p = 0, pSize = firstChain.getLength() - 1; p < pSize; p++) { // walk along the pdb chain's jalview sequence int rseqpos; int fpos = origMap.getSeqPos(rseqpos = firstChain .findPosition(p)); // only look at positions where there is a corresponding position in // mapping if (fpos < 1) { continue; } // p is index into PDB residue entries // rseqpos is pdb sequence position for position p // fpos is sequence position for associated position for rseqpos int tanpos = sq.findIndex(fpos); if (transfer.annotations.length <= tanpos) { // gone beyond mapping to the sequence break; } Annotation a = transfer.annotations[sq.findIndex(fpos)], b = alan.annotations[p]; assertEquals("Non-equivalent annotation element at " + p + "(" + rseqpos + ")" + " expected at " + fpos + " (alIndex " + sq.findIndex(fpos) + ")", a == null ? a : a.toString(), b == null ? b : b.toString()); System.out.print("(" + a + "|" + b + ")"); } } } } } }