1 package jalview.io.vamsas;
\r
3 import java.util.Vector;
\r
5 import jalview.datamodel.AlignedCodonFrame;
\r
6 import jalview.datamodel.Mapping;
\r
7 import jalview.datamodel.SequenceI;
\r
8 import jalview.io.VamsasAppDatastore;
\r
9 import uk.ac.vamsas.client.Vobject;
\r
10 import uk.ac.vamsas.objects.core.AlignmentSequence;
\r
11 import uk.ac.vamsas.objects.core.DataSet;
\r
12 import uk.ac.vamsas.objects.core.Local;
\r
13 import uk.ac.vamsas.objects.core.RangeType;
\r
14 import uk.ac.vamsas.objects.core.Seg;
\r
15 import uk.ac.vamsas.objects.core.Sequence;
\r
16 import uk.ac.vamsas.objects.core.SequenceMapping;
\r
17 import uk.ac.vamsas.objects.core.SequenceType;
\r
19 public class Sequencemapping extends Rangetype
\r
21 public Sequencemapping(VamsasAppDatastore datastore, SequenceMapping sequenceMapping)
\r
24 Object mjvmapping = getvObj2jv(sequenceMapping);
\r
25 if (mjvmapping==null)
\r
27 add(sequenceMapping);
\r
29 if (sequenceMapping.isUpdated())
\r
31 update((jalview.datamodel.Mapping) mjvmapping, sequenceMapping);
\r
36 * create or update a vamsas sequence mapping corresponding to a jalview
\r
37 * Mapping between two dataset sequences
\r
44 public Sequencemapping(VamsasAppDatastore datastore, jalview.datamodel.Mapping mjvmapping, uk.ac.vamsas.objects.core.SequenceType from, uk.ac.vamsas.objects.core.DataSet ds)
\r
47 SequenceMapping sequenceMapping = (SequenceMapping) getjv2vObj(mjvmapping);
\r
48 if (sequenceMapping==null)
\r
50 add(mjvmapping, from, ds);
\r
52 if (from!=null && sequenceMapping.getLoc()!=from)
\r
54 jalview.bin.Cache.log.warn("Probable IMPLEMENTATION ERROR: "+from+" doesn't match the local mapping sequence.");
\r
56 if (ds!=null && sequenceMapping.getV_parent()!=ds)
\r
58 jalview.bin.Cache.log.warn("Probable IMPLEMENTATION ERROR: "+ds+" doesn't match the parent of the bound sequence mapping object.");
\r
60 if (sequenceMapping.isUpdated())
\r
62 conflict(mjvmapping, sequenceMapping);
\r
64 update(mjvmapping, sequenceMapping);
\r
68 private void conflict(Mapping mjvmapping, SequenceMapping sequenceMapping)
\r
70 // TODO Auto-generated method stub
\r
73 private void add(Mapping mjvmapping, uk.ac.vamsas.objects.core.SequenceType from, DataSet ds)
\r
75 SequenceI jvto = mjvmapping.getTo();
\r
76 while (jvto.getDatasetSequence()!=null)
\r
78 jvto = jvto.getDatasetSequence();
\r
80 SequenceType to = (SequenceType) getjv2vObj(jvto);
\r
83 jalview.bin.Cache.log.warn("NONFATAL - do a second update: Ignoring Forward Reference to seuqence not yet bound to vamsas seuqence object");
\r
86 SequenceMapping sequenceMapping = new SequenceMapping();
\r
87 sequenceMapping.setLoc(from);
\r
88 sequenceMapping.setMap(to);
\r
89 boolean dnaToProt=false,sense=false;
\r
90 // ensure that we create a mapping with the correct sense
\r
91 if (((Sequence) sequenceMapping.getLoc())
\r
93 .equals(uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA))
\r
95 if (((Sequence) sequenceMapping.getMap())
\r
97 .equals(uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA))
\r
103 if (((Sequence) sequenceMapping.getMap())
\r
105 .equals(uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA))
\r
114 jalview.bin.Cache.log.warn("Ignoring Mapping - don't support protein to protein mapping in vamsas document yet.");
\r
119 // locate dataset for storage of SequenceMapping
\r
122 ds = (DataSet) ((uk.ac.vamsas.client.Vobject) sequenceMapping.getLoc()).getV_parent();
\r
124 ds = (DataSet) ((uk.ac.vamsas.client.Vobject) sequenceMapping.getMap()).getV_parent();
\r
129 this.initMapType(sequenceMapping, mjvmapping.getMap(), true);
\r
131 this.initMapType(sequenceMapping, mjvmapping.getMap().getInverse(), true);
\r
133 ds.addSequenceMapping(sequenceMapping);
\r
134 sequenceMapping.setProvenance(this.dummyProvenance("user defined coding region translation")); // TODO:
\r
143 bindjvvobj(mjvmapping, sequenceMapping);
\r
145 jalview.bin.Cache.log.debug("Successfully created mapping "+sequenceMapping.getVorbaId());
\r
147 private void update(jalview.datamodel.Mapping mjvmapping, SequenceMapping sequenceMapping)
\r
149 jalview.bin.Cache.log.error("Not implemented: Jalview Update Mapping");
\r
152 * limitations: Currently, jalview only deals with mappings between dataset
\r
153 * sequences, and even then, only between those that map from DNA to Protein.
\r
155 * @param sequenceMapping
\r
157 private void add(SequenceMapping sequenceMapping)
\r
160 SequenceI from=null,to=null;
\r
161 boolean dnaToProt=false,sense=false;
\r
162 Sequence sdloc=null, sdmap=null;
\r
163 if (sequenceMapping.getLoc() instanceof AlignmentSequence)
\r
165 sdloc = (Sequence) ((AlignmentSequence) sequenceMapping.getLoc()).getRefid();
\r
167 sdloc = ((Sequence) sequenceMapping.getLoc());
\r
169 if (sequenceMapping.getMap() instanceof AlignmentSequence)
\r
171 sdmap = (Sequence) ((AlignmentSequence) sequenceMapping.getMap()).getRefid();
\r
173 sdmap = ((Sequence) sequenceMapping.getMap());
\r
175 if (sdloc==null || sdmap == null)
\r
177 jalview.bin.Cache.log.info("Ignoring non sequence-sequence mapping");
\r
180 mobj = this.getvObj2jv((Vobject) sdloc);
\r
181 if (mobj instanceof SequenceI)
\r
183 from = (SequenceI) mobj;
\r
185 mobj = this.getvObj2jv((Vobject) sdmap);
\r
186 if (mobj instanceof SequenceI)
\r
188 to = (SequenceI) mobj;
\r
190 if (from == null || to == null)
\r
193 jalview.bin.Cache.log.error("Probable Vamsas implementation error : unbound dataset sequences involved in a mapping are being parsed!");
\r
196 if (sdloc.getDictionary()
\r
197 .equals(uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA))
\r
199 if (sdmap.getDictionary()
\r
200 .equals(uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA))
\r
209 if (sdmap.getDictionary()
\r
210 .equals(uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA))
\r
216 // create mapping storage object and make each dataset alignment reference
\r
218 jalview.datamodel.AlignmentI dsLoc = (jalview.datamodel.AlignmentI) getvObj2jv(sdloc.getV_parent());
\r
219 jalview.datamodel.AlignmentI dsMap = (jalview.datamodel.AlignmentI) getvObj2jv(sdmap.getV_parent());
\r
220 AlignedCodonFrame afc = new AlignedCodonFrame(0);
\r
222 if (dsLoc!=null && dsLoc!=dsMap)
\r
224 dsMap.addCodonFrame(afc);
\r
228 dsMap.addCodonFrame(afc);
\r
230 // create and add the new mapping to (each) dataset's codonFrame
\r
232 jalview.util.MapList mapping = null;
\r
235 mapping = this.parsemapType(sequenceMapping, 1, 3); // invert sense
\r
236 mapping = new jalview.util.MapList(mapping.getToRanges(), mapping.getFromRanges(), mapping.getToRatio(), mapping.getFromRatio());
\r
237 afc.addMap(to, from, mapping);
\r
239 mapping = this.parsemapType(sequenceMapping, 3, 1); // correct sense
\r
240 afc.addMap(from, to, mapping);
\r
242 bindjvvobj(mapping, sequenceMapping);
\r
243 jalview.structure.StructureSelectionManager.getStructureSelectionManager().addMappings(new AlignedCodonFrame[] { afc });
\r