2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.io.vamsas;
21 import java.util.Vector;
23 import jalview.datamodel.AlignedCodonFrame;
24 import jalview.datamodel.Mapping;
25 import jalview.datamodel.SequenceI;
26 import jalview.io.VamsasAppDatastore;
27 import uk.ac.vamsas.client.Vobject;
28 import uk.ac.vamsas.objects.core.AlignmentSequence;
29 import uk.ac.vamsas.objects.core.DataSet;
30 import uk.ac.vamsas.objects.core.Local;
31 import uk.ac.vamsas.objects.core.RangeType;
32 import uk.ac.vamsas.objects.core.Seg;
33 import uk.ac.vamsas.objects.core.Sequence;
34 import uk.ac.vamsas.objects.core.SequenceMapping;
35 import uk.ac.vamsas.objects.core.SequenceType;
37 public class Sequencemapping extends Rangetype
39 public Sequencemapping(VamsasAppDatastore datastore,
40 SequenceMapping sequenceMapping)
43 Object mjvmapping = getvObj2jv(sequenceMapping);
44 if (mjvmapping == null)
50 if (sequenceMapping.isUpdated())
52 update((jalview.util.MapList) mjvmapping, sequenceMapping);
58 * create or update a vamsas sequence mapping corresponding to a jalview
59 * Mapping between two dataset sequences
66 public Sequencemapping(VamsasAppDatastore datastore,
67 jalview.datamodel.Mapping mjvmapping,
68 uk.ac.vamsas.objects.core.SequenceType from,
69 uk.ac.vamsas.objects.core.DataSet ds)
72 SequenceMapping sequenceMapping = (SequenceMapping) getjv2vObj(mjvmapping);
73 if (sequenceMapping == null)
75 add(mjvmapping, from, ds);
79 if (from != null && sequenceMapping.getLoc() != from)
81 jalview.bin.Cache.log.warn("Probable IMPLEMENTATION ERROR: " + from
82 + " doesn't match the local mapping sequence.");
84 if (ds != null && sequenceMapping.is__stored_in_document()
85 && sequenceMapping.getV_parent() != ds)
88 .warn("Probable IMPLEMENTATION ERROR: "
90 + " doesn't match the parent of the bound sequence mapping object.");
92 if (sequenceMapping.isUpdated())
94 conflict(mjvmapping, sequenceMapping);
98 update(mjvmapping, sequenceMapping);
103 private void conflict(Mapping mjvmapping, SequenceMapping sequenceMapping)
105 System.err.println("Conflict in update of sequenceMapping "
106 + sequenceMapping.getVorbaId());
109 private void add(Mapping mjvmapping,
110 uk.ac.vamsas.objects.core.SequenceType from, DataSet ds)
112 SequenceI jvto = mjvmapping.getTo();
113 while (jvto.getDatasetSequence() != null)
115 jvto = jvto.getDatasetSequence();
117 SequenceType to = (SequenceType) getjv2vObj(jvto);
120 jalview.bin.Cache.log
121 .warn("NONFATAL - do a second update: Ignoring Forward Reference to seuqence not yet bound to vamsas seuqence object");
124 SequenceMapping sequenceMapping = new SequenceMapping();
125 sequenceMapping.setLoc(from);
126 sequenceMapping.setMap(to);
127 boolean dnaToProt = false, sense = false;
128 // ensure that we create a mapping with the correct sense
129 if (((Sequence) sequenceMapping.getLoc()).getDictionary().equals(
130 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA))
132 if (((Sequence) sequenceMapping.getMap()).getDictionary().equals(
133 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA))
141 if (((Sequence) sequenceMapping.getMap()).getDictionary().equals(
142 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA))
151 jalview.bin.Cache.log
152 .warn("Ignoring Mapping - don't support protein to protein mapping in vamsas document yet.");
157 // locate dataset for storage of SequenceMapping
160 ds = (DataSet) ((uk.ac.vamsas.client.Vobject) sequenceMapping
161 .getLoc()).getV_parent();
165 ds = (DataSet) ((uk.ac.vamsas.client.Vobject) sequenceMapping
166 .getMap()).getV_parent();
171 this.initMapType(sequenceMapping, mjvmapping.getMap(), true);
175 this.initMapType(sequenceMapping, mjvmapping.getMap().getInverse(),
178 ds.addSequenceMapping(sequenceMapping);
179 sequenceMapping.setProvenance(this
180 .dummyProvenance("user defined coding region translation")); // TODO:
189 bindjvvobj(mjvmapping, sequenceMapping);
191 jalview.bin.Cache.log.debug("Successfully created mapping "
192 + sequenceMapping.getVorbaId());
195 private void update(jalview.util.MapList mjvmapping,
196 SequenceMapping sequenceMapping)
198 jalview.bin.Cache.log
199 .error("Not implemented: Jalview Update Alcodon Mapping:TODO!");
202 private void update(jalview.datamodel.Mapping mjvmapping,
203 SequenceMapping sequenceMapping)
205 jalview.bin.Cache.log
206 .error("Not implemented: Jalview Update Sequence DBRef Mapping");
210 * limitations: Currently, jalview only deals with mappings between dataset
211 * sequences, and even then, only between those that map from DNA to Protein.
213 * @param sequenceMapping
215 private void add(SequenceMapping sequenceMapping)
218 SequenceI from = null, to = null;
219 boolean dnaToProt = false, sense = false;
220 Sequence sdloc = null, sdmap = null;
221 if (sequenceMapping.getLoc() instanceof AlignmentSequence)
223 sdloc = (Sequence) ((AlignmentSequence) sequenceMapping.getLoc())
228 sdloc = ((Sequence) sequenceMapping.getLoc());
230 if (sequenceMapping.getMap() instanceof AlignmentSequence)
232 sdmap = (Sequence) ((AlignmentSequence) sequenceMapping.getMap())
237 sdmap = ((Sequence) sequenceMapping.getMap());
239 if (sdloc == null || sdmap == null)
241 jalview.bin.Cache.log.info("Ignoring non sequence-sequence mapping");
244 mobj = this.getvObj2jv((Vobject) sdloc);
245 if (mobj instanceof SequenceI)
247 from = (SequenceI) mobj;
249 mobj = this.getvObj2jv((Vobject) sdmap);
250 if (mobj instanceof SequenceI)
252 to = (SequenceI) mobj;
254 if (from == null || to == null)
257 jalview.bin.Cache.log
258 .error("Probable Vamsas implementation error : unbound dataset sequences involved in a mapping are being parsed!");
262 if (sdloc.getDictionary().equals(
263 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA))
265 if (sdmap.getDictionary().equals(
266 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA))
277 if (sdmap.getDictionary().equals(
278 uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA))
284 // create mapping storage object and make each dataset alignment reference
286 jalview.datamodel.AlignmentI dsLoc = (jalview.datamodel.AlignmentI) getvObj2jv(sdloc
288 jalview.datamodel.AlignmentI dsMap = (jalview.datamodel.AlignmentI) getvObj2jv(sdmap
290 AlignedCodonFrame afc = new AlignedCodonFrame(0);
292 if (dsLoc != null && dsLoc != dsMap)
294 dsLoc.addCodonFrame(afc);
298 dsMap.addCodonFrame(afc);
300 // create and add the new mapping to (each) dataset's codonFrame
302 jalview.util.MapList mapping = null;
305 mapping = this.parsemapType(sequenceMapping, 1, 3); // invert sense
306 mapping = new jalview.util.MapList(mapping.getToRanges(), mapping
307 .getFromRanges(), mapping.getToRatio(), mapping
309 afc.addMap(to, from, mapping);
313 mapping = this.parsemapType(sequenceMapping, 3, 1); // correct sense
314 afc.addMap(from, to, mapping);
316 bindjvvobj(mapping, sequenceMapping);
317 jalview.structure.StructureSelectionManager
318 .getStructureSelectionManager().addMappings(
319 new AlignedCodonFrame[]
321 // Try to link up any conjugate database references in the two sequences
322 // matchConjugateDBRefs(from, to, mapping);
323 // Try to propagate any dbrefs across this mapping.
328 * Complete any 'to' references in jalview.datamodel.Mapping objects
329 * associated with conjugate DBRefEntry under given mapping
332 * sequence corresponding to from reference for sequence
335 * sequence correspondeing to to reference for sequence mapping
337 * maplist parsed in same sense as from and to
339 private void matchConjugateDBRefs(SequenceI from, SequenceI to,
340 jalview.util.MapList smap)
342 if (from.getDBRef() == null && to.getDBRef() == null)
344 if (jalview.bin.Cache.log.isDebugEnabled())
346 jalview.bin.Cache.log.debug("Not matching conjugate refs for "
347 + from.getName() + " and " + to.getName());
351 if (jalview.bin.Cache.log.isDebugEnabled())
353 jalview.bin.Cache.log.debug("Matching conjugate refs for "
354 + from.getName() + " and " + to.getName());
356 jalview.datamodel.DBRefEntry[] fdb = from.getDBRef();
357 jalview.datamodel.DBRefEntry[] tdb = new jalview.datamodel.DBRefEntry[to
359 int tdblen = to.getDBRef().length;
360 System.arraycopy(to.getDBRef(), 0, tdb, 0, tdblen);
361 Vector matched = new Vector();
362 jalview.util.MapList smapI = smap.getInverse();
363 for (int f = 0; f < fdb.length; f++)
365 jalview.datamodel.DBRefEntry fe = fdb[f];
366 jalview.datamodel.Mapping fmp = fe.getMap();
367 boolean fmpnnl = fmp != null;
368 // if (fmpnnl && fmp.getTo()!=null)
370 // jalview.bin.Cache.log.debug("Not overwriting existing To reference in
374 // smap from maps from fe.local to fe.map
375 boolean smapfromlocal2fe = (fmpnnl) ? smap.equals(fmp.getMap())
377 // smap from maps from fe.map to fe.local.
378 boolean smapfromfemap2local = (fmpnnl) ? smapI.equals(fmp.getMap())
380 for (int t = 0; t < tdblen; t++)
382 jalview.datamodel.DBRefEntry te = tdb[t];
385 if (fe.getSource().equals(te.getSource())
386 && fe.getAccessionId().equals(te.getAccessionId()))
388 jalview.datamodel.Mapping tmp = te.getMap();
389 boolean tmpnnl = tmp != null;
390 if (tmpnnl && tmp.getTo() != null)
394 // smap to maps from te.local to te.map
395 boolean smaptolocal2tm = (tmpnnl) ? smap.equals(tmp.getMap())
397 // smap to maps from te.map to te.local
398 boolean smaptotemap2local = (tmpnnl) ? smapI.equals(fmp
400 if (smapfromlocal2fe && smaptotemap2local)
402 // smap implies mapping from to to from
406 else if (smapfromfemap2local && smaptolocal2tm)