2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.io.vamsas;
23 import jalview.bin.Console;
24 import jalview.datamodel.AlignedCodonFrame;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.DBRefEntry;
27 import jalview.datamodel.Mapping;
28 import jalview.datamodel.SequenceI;
29 import jalview.gui.Desktop;
30 import jalview.io.VamsasAppDatastore;
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.Vector;
36 import uk.ac.vamsas.objects.core.AlignmentSequence;
37 import uk.ac.vamsas.objects.core.DataSet;
38 import uk.ac.vamsas.objects.core.Sequence;
39 import uk.ac.vamsas.objects.core.SequenceMapping;
40 import uk.ac.vamsas.objects.core.SequenceType;
43 * binds a vamsas sequence mapping object from the vamsas document to a maplist
44 * object associated with a mapping in the Jalview model. We use the maplist
45 * object because these are referred to both in the Mapping object associated
46 * with a jalview.datamodel.DBRefEntry and in the array of
47 * jalview.datamodel.AlCodonFrame objects that Jalview uses to propagate
48 * sequence mapping position highlighting across the views.
53 public class Sequencemapping extends Rangetype
55 public Sequencemapping(VamsasAppDatastore datastore,
56 SequenceMapping sequenceMapping)
58 super(datastore, sequenceMapping, jalview.util.MapList.class);
62 private SequenceType from;
66 private Mapping mjvmapping;
69 * create or update a vamsas sequence mapping corresponding to a jalview
70 * Mapping between two dataset sequences
77 public Sequencemapping(VamsasAppDatastore datastore,
78 jalview.datamodel.Mapping mjvmapping,
79 uk.ac.vamsas.objects.core.SequenceType from,
80 uk.ac.vamsas.objects.core.DataSet ds)
82 super(datastore, mjvmapping.getMap(), SequenceMapping.class);
85 this.mjvmapping = mjvmapping;
91 * local check that extant mapping context is valid
93 public void validate()
96 SequenceMapping sequenceMapping = (SequenceMapping) vobj;
97 if (sequenceMapping == null)
101 if (from != null && sequenceMapping.getLoc() != from)
103 Console.warn("Probable IMPLEMENTATION ERROR: " + from
104 + " doesn't match the local mapping sequence.");
106 if (ds != null && sequenceMapping.is__stored_in_document()
107 && sequenceMapping.getV_parent() != ds)
109 Console.warn("Probable IMPLEMENTATION ERROR: " + ds
110 + " doesn't match the parent of the bound sequence mapping object.");
114 public void addToDocument()
116 add(mjvmapping, from, ds);
119 public void addFromDocument()
121 add((SequenceMapping) vobj);
124 public void conflict()
126 conflict(mjvmapping, (SequenceMapping) vobj);
130 public void updateToDoc()
132 update(mjvmapping, (SequenceMapping) vobj);
135 public void updateFromDoc()
137 update((SequenceMapping) vobj, (jalview.datamodel.Mapping) jvobj);
140 private void conflict(Mapping mjvmapping, SequenceMapping sequenceMapping)
142 jalview.bin.Console.errPrintln("Conflict in update of sequenceMapping "
143 + sequenceMapping.getVorbaId());
146 private void add(Mapping mjvmapping,
147 uk.ac.vamsas.objects.core.SequenceType from, DataSet ds)
149 SequenceI jvto = mjvmapping.getTo();
150 while (jvto.getDatasetSequence() != null)
152 jvto = jvto.getDatasetSequence();
154 SequenceType to = (SequenceType) getjv2vObj(jvto);
158 "FIXME NONFATAL - do a second update: Ignoring Forward Reference to seuqence not yet bound to vamsas seuqence object");
161 SequenceMapping sequenceMapping = new SequenceMapping();
162 sequenceMapping.setLoc(from);
163 sequenceMapping.setMap(to);
164 boolean dnaToProt = false, sense = false;
165 // ensure that we create a mapping with the correct sense
166 if (((Sequence) sequenceMapping.getLoc()).getDictionary().equals(
167 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA))
169 if (((Sequence) sequenceMapping.getMap()).getDictionary().equals(
170 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA))
178 if (((Sequence) sequenceMapping.getMap()).getDictionary().equals(
179 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA))
189 "Ignoring Mapping - don't support protein to protein mapping in vamsas document yet.");
194 // locate dataset for storage of SequenceMapping
197 ds = (DataSet) ((uk.ac.vamsas.client.Vobject) sequenceMapping
198 .getLoc()).getV_parent();
202 ds = (DataSet) ((uk.ac.vamsas.client.Vobject) sequenceMapping
203 .getMap()).getV_parent();
208 this.initMapType(sequenceMapping, mjvmapping.getMap(), true);
212 this.initMapType(sequenceMapping, mjvmapping.getMap().getInverse(),
215 ds.addSequenceMapping(sequenceMapping);
216 sequenceMapping.setProvenance(
217 this.dummyProvenance("user defined coding region translation")); // TODO:
226 bindjvvobj(mjvmapping.getMap(), sequenceMapping);
229 "Successfully created mapping " + sequenceMapping.getVorbaId());
232 // private void update(jalview.util.MapList mjvmapping,
233 // SequenceMapping sequenceMapping)
235 Console.error("Not implemented: Jalview Update Alcodon Mapping:TODO!");
238 private void update(SequenceMapping sequenceMapping,
239 jalview.datamodel.Mapping mjvmapping)
241 Console.error("Not implemented: Update DBRef Mapping from Jalview");
244 private void update(jalview.datamodel.Mapping mjvmapping,
245 SequenceMapping sequenceMapping)
247 Console.error("Not implemented: Jalview Update Sequence DBRef Mapping");
251 * bind a SequenceMapping to a live AlCodonFrame element limitations:
252 * Currently, jalview only deals with mappings between dataset sequences, and
253 * even then, only between those that map from DNA to Protein.
255 * @param sequenceMapping
257 private void add(SequenceMapping sequenceMapping)
260 SequenceI from = null, to = null;
261 boolean dnaToProt = false, sense = false;
262 Sequence sdloc = null, sdmap = null;
263 if (sequenceMapping.getLoc() instanceof AlignmentSequence)
265 sdloc = (Sequence) ((AlignmentSequence) sequenceMapping.getLoc())
270 sdloc = ((Sequence) sequenceMapping.getLoc());
272 if (sequenceMapping.getMap() instanceof AlignmentSequence)
274 sdmap = (Sequence) ((AlignmentSequence) sequenceMapping.getMap())
279 sdmap = ((Sequence) sequenceMapping.getMap());
281 if (sdloc == null || sdmap == null)
283 Console.info("Ignoring non sequence-sequence mapping");
286 mobj = this.getvObj2jv(sdloc);
287 if (mobj instanceof SequenceI)
289 from = (SequenceI) mobj;
291 mobj = this.getvObj2jv(sdmap);
292 if (mobj instanceof SequenceI)
294 to = (SequenceI) mobj;
296 if (from == null || to == null)
300 "Probable Vamsas implementation error : unbound dataset sequences involved in a mapping are being parsed!");
304 if (sdloc.getDictionary().equals(
305 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA))
307 if (sdmap.getDictionary().equals(
308 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA))
319 if (sdmap.getDictionary().equals(
320 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA))
326 // create mapping storage object and make each dataset alignment reference
328 AlignmentI dsLoc = (AlignmentI) getvObj2jv(sdloc.getV_parent());
329 AlignmentI dsMap = (AlignmentI) getvObj2jv(sdmap.getV_parent());
330 AlignedCodonFrame acf = new AlignedCodonFrame();
332 if (dsLoc != null && dsLoc != dsMap)
334 dsLoc.addCodonFrame(acf);
338 dsMap.addCodonFrame(acf);
340 // create and add the new mapping to (each) dataset's codonFrame
342 jalview.util.MapList mapping = null;
347 mapping = this.parsemapType(sequenceMapping, 1, 3); // invert sense
348 mapping = new jalview.util.MapList(mapping.getToRanges(),
349 mapping.getFromRanges(), mapping.getToRatio(),
350 mapping.getFromRatio());
351 acf.addMap(to, from, mapping);
355 mapping = this.parsemapType(sequenceMapping, 3, 1); // correct sense
356 acf.addMap(from, to, mapping);
361 mapping = this.parsemapType(sequenceMapping, 1, 1); // correct sense
362 acf.addMap(from, to, mapping);
364 bindjvvobj(mapping, sequenceMapping);
365 jalview.structure.StructureSelectionManager
366 .getStructureSelectionManager(Desktop.instance)
367 .registerMapping(acf);
368 // Try to link up any conjugate database references in the two sequences
369 // matchConjugateDBRefs(from, to, mapping);
370 // Try to propagate any dbrefs across this mapping.
375 * Complete any 'to' references in jalview.datamodel.Mapping objects
376 * associated with conjugate DBRefEntry under given mapping
379 * sequence corresponding to from reference for sequence mapping
381 * sequence correspondeing to to reference for sequence mapping
383 * maplist parsed in same sense as from and to
385 private void matchConjugateDBRefs(SequenceI from, SequenceI to,
386 jalview.util.MapList smap)
388 if (from.getDBRefs() == null && to.getDBRefs() == null)
390 if (Console.isDebugEnabled())
392 Console.debug("Not matching conjugate refs for " + from.getName()
393 + " and " + to.getName());
397 if (Console.isDebugEnabled())
399 Console.debug("Matching conjugate refs for " + from.getName()
400 + " and " + to.getName());
402 List<DBRefEntry> fdb = from.getDBRefs();
403 List<DBRefEntry> tdb = new ArrayList<DBRefEntry>(to.getDBRefs());
404 int tdblen = to.getDBRefs().size();
409 // System.arraycopy(to.getDBRefs(), 0, tdb, 0, tdblen);
414 Vector matched = new Vector();
415 jalview.util.MapList smapI = smap.getInverse();
416 for (int f = 0, fn = fdb.size(); f < fn; f++)
418 jalview.datamodel.DBRefEntry fe = fdb.get(f);
419 jalview.datamodel.Mapping fmp = fe.getMap();
420 boolean fmpnnl = (fmp != null);
421 // if (fmpnnl && fmp.getTo()!=null)
423 // Cache.debug("Not overwriting existing To reference in
427 // smap from maps from fe.local to fe.map
428 boolean smapfromlocal2fe = (fmpnnl) ? smap.equals(fmp.getMap())
430 // smap from maps from fe.map to fe.local.
431 boolean smapfromfemap2local = (fmpnnl) ? smapI.equals(fmp.getMap())
433 for (int t = 0; t < tdblen; t++)
435 jalview.datamodel.DBRefEntry te = tdb.get(t);
438 if (fe.getSource().equals(te.getSource())
439 && fe.getAccessionId().equals(te.getAccessionId()))
441 jalview.datamodel.Mapping tmp = te.getMap();
442 boolean tmpnnl = tmp != null;
443 if (tmpnnl && tmp.getTo() != null)
447 // smap to maps from te.local to te.map
448 boolean smaptolocal2tm = (tmpnnl) ? smap.equals(tmp.getMap())
450 // smap to maps from te.map to te.local
451 boolean smaptotemap2local = (tmpnnl)
452 ? smapI.equals(fmp.getMap())
454 if (smapfromlocal2fe && smaptotemap2local)
456 // smap implies mapping from to to from
460 else if (smapfromfemap2local && smaptolocal2tm)