From 39f35c9fc1fb8270d93ba06aa83f3dfbd18dd4a2 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 11 Aug 2020 14:31:52 +0100 Subject: [PATCH] JAL-3705 unit test and "fix" borrowing unused schema attribute --- src/jalview/project/Jalview2XML.java | 100 ++++++++++++++++---------------- test/jalview/io/CrossRef2xmlTests.java | 90 +++++++++++++++++++++++----- 2 files changed, 126 insertions(+), 64 deletions(-) diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index ccd9ab0..1851be7 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -2547,63 +2547,61 @@ public class Jalview2XML private Mapping createVamsasMapping(jalview.datamodel.Mapping jmp, SequenceI parentseq, SequenceI jds, boolean recurse) { - Mapping mp = null; - if (jmp.getMap() != null) + if (jmp.getMap() == null) { - mp = new Mapping(); + return null; + } + Mapping mp = new Mapping(); + + if (jmp.getMappedFromId() != null) + { + mp.setMappingType(jmp.getMappedFromId()); + } + + jalview.util.MapList mlst = jmp.getMap(); + List r = mlst.getFromRanges(); + for (int[] range : r) + { + MapListFrom mfrom = new MapListFrom(); + mfrom.setStart(range[0]); + mfrom.setEnd(range[1]); + mp.getMapListFrom().add(mfrom); + } + r = mlst.getToRanges(); + for (int[] range : r) + { + MapListTo mto = new MapListTo(); + mto.setStart(range[0]); + mto.setEnd(range[1]); + mp.getMapListTo().add(mto); + } + mp.setMapFromUnit(BigInteger.valueOf(mlst.getFromRatio())); + mp.setMapToUnit(BigInteger.valueOf(mlst.getToRatio())); + if (jmp.getTo() != null) + { + // check/create ID for the sequence referenced by getTo() - jalview.util.MapList mlst = jmp.getMap(); - List r = mlst.getFromRanges(); - for (int[] range : r) + String jmpid = ""; + SequenceI ps = null; + if (parentseq != jmp.getTo() + && parentseq.getDatasetSequence() != jmp.getTo()) { - MapListFrom mfrom = new MapListFrom(); - mfrom.setStart(range[0]); - mfrom.setEnd(range[1]); - // mp.addMapListFrom(mfrom); - mp.getMapListFrom().add(mfrom); + // chaining dbref rather than a handshaking one + jmpid = seqHash(ps = jmp.getTo()); } - r = mlst.getToRanges(); - for (int[] range : r) + else { - MapListTo mto = new MapListTo(); - mto.setStart(range[0]); - mto.setEnd(range[1]); - // mp.addMapListTo(mto); - mp.getMapListTo().add(mto); + jmpid = seqHash(ps = parentseq); } - mp.setMapFromUnit(BigInteger.valueOf(mlst.getFromRatio())); - mp.setMapToUnit(BigInteger.valueOf(mlst.getToRatio())); - if (jmp.getTo() != null) + mp.setDseqFor(jmpid); + if (!seqRefIds.containsKey(jmpid)) { - // MappingChoice mpc = new MappingChoice(); - - // check/create ID for the sequence referenced by getTo() - - String jmpid = ""; - SequenceI ps = null; - if (parentseq != jmp.getTo() - && parentseq.getDatasetSequence() != jmp.getTo()) - { - // chaining dbref rather than a handshaking one - jmpid = seqHash(ps = jmp.getTo()); - } - else - { - jmpid = seqHash(ps = parentseq); - } - // mpc.setDseqFor(jmpid); - mp.setDseqFor(jmpid); - if (!seqRefIds.containsKey(jmpid)) - { - jalview.bin.Cache.log.debug("creatign new DseqFor ID"); - seqRefIds.put(jmpid, ps); - } - else - { - jalview.bin.Cache.log.debug("reusing DseqFor ID"); - } - - // mp.setMappingChoice(mpc); + jalview.bin.Cache.log.debug("creatign new DseqFor ID"); + seqRefIds.put(jmpid, ps); + } + else + { + jalview.bin.Cache.log.debug("reusing DseqFor ID"); } } return mp; @@ -5637,6 +5635,8 @@ public class Jalview2XML fto, m.getMapFromUnit().intValue(), m.getMapToUnit().intValue()); + jmap.setMappedFromId(m.getMappingType()); + /* * (optional) choice of dseqFor or Sequence */ diff --git a/test/jalview/io/CrossRef2xmlTests.java b/test/jalview/io/CrossRef2xmlTests.java index 3ca6ed8..a336d6d 100644 --- a/test/jalview/io/CrossRef2xmlTests.java +++ b/test/jalview/io/CrossRef2xmlTests.java @@ -24,20 +24,6 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; -import jalview.analysis.CrossRef; -import jalview.api.AlignmentViewPanel; -import jalview.datamodel.AlignedCodonFrame; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.AlignmentTest; -import jalview.datamodel.SequenceI; -import jalview.gui.AlignFrame; -import jalview.gui.CrossRefAction; -import jalview.gui.Desktop; -import jalview.gui.JvOptionPane; -import jalview.gui.SequenceFetcher; -import jalview.project.Jalview2XML; -import jalview.util.DBRefUtils; - import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -51,6 +37,20 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import jalview.analysis.CrossRef; +import jalview.api.AlignmentViewPanel; +import jalview.datamodel.AlignedCodonFrame; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.AlignmentTest; +import jalview.datamodel.DBRefEntry; +import jalview.datamodel.SequenceI; +import jalview.gui.AlignFrame; +import jalview.gui.CrossRefAction; +import jalview.gui.Desktop; +import jalview.gui.JvOptionPane; +import jalview.gui.SequenceFetcher; +import jalview.project.Jalview2XML; +import jalview.util.DBRefUtils; import junit.extensions.PA; @Test(singleThreaded = true) @@ -678,4 +678,66 @@ public class CrossRef2xmlTests extends Jalview2xmlBase "stringify mismatch for " + xrefpath); } } + + /** + * Test for JAL-3705, that verifies fetching an EMBL entry, saving to project, + * reloading, and showing cross-references + */ + @Test(groups = { "Operational" }, enabled = true) + public void testRestoreGeneXrefsFromProject() throws Exception + { + /* + * fetch EMBL:J03321 and verify a couple of its UNIPROT xrefs, which should + * have the EMBL proteinId as Mapping.mappedFromId + */ + SequenceFetcher sf = new SequenceFetcher(Desktop.instance, "EMBL", + "J03321"); + sf.run(); + AlignFrame[] afs = Desktop.getAlignFrames(); + assertEquals(afs.length, 1); + SequenceI seq = afs[0].getViewport().getAlignment().getSequenceAt(0); + assertEquals(seq.getName(), "EMBL|J03321"); + int found = 0; + for (DBRefEntry dbref : seq.getDBRefs()) + { + if ("UNIPROT".equals(dbref.getSource())) + { + found++; + if ("P10559".equals(dbref.getAccessionId())) + { + assertEquals(dbref.getMap().getMappedFromId(), "AAA91573.1"); + } + else if ("P10560".equals(dbref.getAccessionId())) + { + assertEquals(dbref.getMap().getMappedFromId(), "AAA91574.1"); + } + } + } + final int expectedUniprotXrefs = 8; // this might change in future! + assertEquals(found, expectedUniprotXrefs); + + /* + * save to project, close all, reload project, Get Cross-References | UNIPROT + * - should use the restored mappedFromId for the CDS sequence ids + */ + File tfile = File.createTempFile("testRestoreGeneXrefsFromProject", + ".jvp"); + new Jalview2XML(false).saveState(tfile); + Desktop.instance.closeAll_actionPerformed(null); + new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), + DataSourceType.FILE); + afs = Desktop.getAlignFrames(); + assertEquals(afs.length, 1); + seq = afs[0].getViewport().getAlignment().getSequenceAt(0); + assertEquals(seq.getName(), "EMBL|J03321"); + CrossRefAction.getHandlerFor(new SequenceI[] {seq}, true, "UNIPROT", afs[0]).run(); + AlignFrame[] afs2 = Desktop.getAlignFrames(); + assertEquals(afs2.length, 3); // gene sequence, plus split frame + List cds = afs2[1].getViewport().getAlignment().getSequences(); + assertEquals(cds.size(), expectedUniprotXrefs); + assertEquals(cds.get(0).getName(), "CDS|AAA91567.1"); + assertEquals(cds.get(7).getName(), "CDS|AAA91574.1"); + + Desktop.instance.closeAll_actionPerformed(null); + } } -- 1.7.10.2