From 8d4567f28f3fce1e763beefeed625b35b3d6e8fe Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 29 Oct 2014 10:47:13 +0000 Subject: [PATCH] JAL-1264 JAL-674 test to exercise the AlignmentAnnotation.remap method via the jalview.structure.StructureMapping.transfer method --- test/jalview/structure/Mapping.java | 103 +++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 test/jalview/structure/Mapping.java diff --git a/test/jalview/structure/Mapping.java b/test/jalview/structure/Mapping.java new file mode 100644 index 0000000..cd7fafe --- /dev/null +++ b/test/jalview/structure/Mapping.java @@ -0,0 +1,103 @@ +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(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); + boolean hasSecStr=false,hasTemp=false; + 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()) + { + if (alan.hasIcons) + { + hasSecStr = true; + } + if (alan.graph == alan.LINE_GRAPH) + { + hasTemp = true; + } + + 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 + ")"); + } + + } + } + } + assertTrue("No secondary structure transferred to associated sequence.",hasSecStr); + assertTrue("No temperature factor transferred to associated sequence.",hasTemp); + } + +} -- 1.7.10.2