package jalview.io.vamsas; import java.util.Vector; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Mapping; import jalview.datamodel.SequenceI; import jalview.io.VamsasAppDatastore; import uk.ac.vamsas.client.Vobject; import uk.ac.vamsas.objects.core.AlignmentSequence; import uk.ac.vamsas.objects.core.DataSet; import uk.ac.vamsas.objects.core.Local; import uk.ac.vamsas.objects.core.RangeType; import uk.ac.vamsas.objects.core.Seg; import uk.ac.vamsas.objects.core.Sequence; import uk.ac.vamsas.objects.core.SequenceMapping; import uk.ac.vamsas.objects.core.SequenceType; public class Sequencemapping extends Rangetype { public Sequencemapping(VamsasAppDatastore datastore, SequenceMapping sequenceMapping) { super(datastore); Object mjvmapping = getvObj2jv(sequenceMapping); if (mjvmapping==null) { add(sequenceMapping); } else { if (sequenceMapping.isUpdated()) { update((jalview.datamodel.Mapping) mjvmapping, sequenceMapping); } } } /** * create or update a vamsas sequence mapping corresponding to a jalview * Mapping between two dataset sequences * * @param datastore * @param mjvmapping * @param from * @param ds */ public Sequencemapping(VamsasAppDatastore datastore, jalview.datamodel.Mapping mjvmapping, uk.ac.vamsas.objects.core.SequenceType from, uk.ac.vamsas.objects.core.DataSet ds) { super(datastore); SequenceMapping sequenceMapping = (SequenceMapping) getjv2vObj(mjvmapping); if (sequenceMapping==null) { add(mjvmapping, from, ds); } else { if (from!=null && sequenceMapping.getLoc()!=from) { jalview.bin.Cache.log.warn("Probable IMPLEMENTATION ERROR: "+from+" doesn't match the local mapping sequence."); } if (ds!=null && sequenceMapping.getV_parent()!=ds) { jalview.bin.Cache.log.warn("Probable IMPLEMENTATION ERROR: "+ds+" doesn't match the parent of the bound sequence mapping object."); } if (sequenceMapping.isUpdated()) { conflict(mjvmapping, sequenceMapping); } else { update(mjvmapping, sequenceMapping); } } } private void conflict(Mapping mjvmapping, SequenceMapping sequenceMapping) { // TODO Auto-generated method stub } private void add(Mapping mjvmapping, uk.ac.vamsas.objects.core.SequenceType from, DataSet ds) { SequenceI jvto = mjvmapping.getTo(); while (jvto.getDatasetSequence()!=null) { jvto = jvto.getDatasetSequence(); } SequenceType to = (SequenceType) getjv2vObj(jvto); if (to==null) { jalview.bin.Cache.log.warn("NONFATAL - do a second update: Ignoring Forward Reference to seuqence not yet bound to vamsas seuqence object"); return; } SequenceMapping sequenceMapping = new SequenceMapping(); sequenceMapping.setLoc(from); sequenceMapping.setMap(to); boolean dnaToProt=false,sense=false; // ensure that we create a mapping with the correct sense if (((Sequence) sequenceMapping.getLoc()) .getDictionary() .equals(uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA)) { if (((Sequence) sequenceMapping.getMap()) .getDictionary() .equals(uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA)) { dnaToProt=true; sense=true; } } else { if (((Sequence) sequenceMapping.getMap()) .getDictionary() .equals(uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA)) { dnaToProt=true; sense=false; } } if (!dnaToProt) { jalview.bin.Cache.log.warn("Ignoring Mapping - don't support protein to protein mapping in vamsas document yet."); return; } if (ds==null) { // locate dataset for storage of SequenceMapping if (sense) { ds = (DataSet) ((uk.ac.vamsas.client.Vobject) sequenceMapping.getLoc()).getV_parent(); } else { ds = (DataSet) ((uk.ac.vamsas.client.Vobject) sequenceMapping.getMap()).getV_parent(); } } if (sense) { this.initMapType(sequenceMapping, mjvmapping.getMap(), true); } else { this.initMapType(sequenceMapping, mjvmapping.getMap().getInverse(), true); } ds.addSequenceMapping(sequenceMapping); sequenceMapping.setProvenance(this.dummyProvenance("user defined coding region translation")); // TODO: // correctly // construct // provenance // based // on // source // of // mapping bindjvvobj(mjvmapping, sequenceMapping); jalview.bin.Cache.log.debug("Successfully created mapping "+sequenceMapping.getVorbaId()); } private void update(jalview.datamodel.Mapping mjvmapping, SequenceMapping sequenceMapping) { jalview.bin.Cache.log.error("Not implemented: Jalview Update Mapping"); } /** * limitations: Currently, jalview only deals with mappings between dataset * sequences, and even then, only between those that map from DNA to Protein. * * @param sequenceMapping */ private void add(SequenceMapping sequenceMapping) { Object mobj; SequenceI from=null,to=null; boolean dnaToProt=false,sense=false; Sequence sdloc=null, sdmap=null; if (sequenceMapping.getLoc() instanceof AlignmentSequence) { sdloc = (Sequence) ((AlignmentSequence) sequenceMapping.getLoc()).getRefid(); } else { sdloc = ((Sequence) sequenceMapping.getLoc()); } if (sequenceMapping.getMap() instanceof AlignmentSequence) { sdmap = (Sequence) ((AlignmentSequence) sequenceMapping.getMap()).getRefid(); } else { sdmap = ((Sequence) sequenceMapping.getMap()); } if (sdloc==null || sdmap == null) { jalview.bin.Cache.log.info("Ignoring non sequence-sequence mapping"); return; } mobj = this.getvObj2jv((Vobject) sdloc); if (mobj instanceof SequenceI) { from = (SequenceI) mobj; } mobj = this.getvObj2jv((Vobject) sdmap); if (mobj instanceof SequenceI) { to = (SequenceI) mobj; } if (from == null || to == null) { jalview.bin.Cache.log.error("Probable Vamsas implementation error : unbound dataset sequences involved in a mapping are being parsed!"); return; } if (sdloc.getDictionary() .equals(uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA)) { if (sdmap.getDictionary() .equals(uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA)) { dnaToProt=true; sense=true; } // else { // } } else { if (sdmap.getDictionary() .equals(uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA)) { dnaToProt=true; sense=false; } } // create mapping storage object and make each dataset alignment reference // it. jalview.datamodel.AlignmentI dsLoc = (jalview.datamodel.AlignmentI) getvObj2jv(sdloc.getV_parent()); jalview.datamodel.AlignmentI dsMap = (jalview.datamodel.AlignmentI) getvObj2jv(sdmap.getV_parent()); AlignedCodonFrame afc = new AlignedCodonFrame(0); if (dsLoc!=null && dsLoc!=dsMap) { dsMap.addCodonFrame(afc); } if (dsMap!=null) { dsMap.addCodonFrame(afc); } // create and add the new mapping to (each) dataset's codonFrame jalview.util.MapList mapping = null; if (!sense) { mapping = this.parsemapType(sequenceMapping, 1, 3); // invert sense mapping = new jalview.util.MapList(mapping.getToRanges(), mapping.getFromRanges(), mapping.getToRatio(), mapping.getFromRatio()); afc.addMap(to, from, mapping); } else { mapping = this.parsemapType(sequenceMapping, 3, 1); // correct sense afc.addMap(from, to, mapping); } bindjvvobj(mapping, sequenceMapping); jalview.structure.StructureSelectionManager.getStructureSelectionManager().addMappings(new AlignedCodonFrame[] { afc }); } }