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<int[]> 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<int[]> 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;
fto, m.getMapFromUnit().intValue(),
m.getMapToUnit().intValue());
+ jmap.setMappedFromId(m.getMappingType());
+
/*
* (optional) choice of dseqFor or Sequence
*/
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;
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)
"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<SequenceI> 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);
+ }
}