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.DBRefEntry;
25 import jalview.datamodel.SequenceI;
26 import jalview.io.VamsasAppDatastore;
28 import uk.ac.vamsas.objects.core.DataSet;
29 import uk.ac.vamsas.objects.core.DbRef;
30 import uk.ac.vamsas.objects.core.Map;
31 import uk.ac.vamsas.objects.core.Sequence;
33 public class Dbref extends Rangetype
35 jalview.datamodel.SequenceI sq = null;
37 uk.ac.vamsas.objects.core.Sequence sequence = null;
41 public Dbref(VamsasAppDatastore datastore, DBRefEntry dbentry,
42 jalview.datamodel.SequenceI sq2,
43 uk.ac.vamsas.objects.core.Sequence sequence2, DataSet dataset)
45 super(datastore, dbentry, DbRef.class);
46 // initialise object specific attributes
55 public Dbref(VamsasAppDatastore datastore, DbRef ref, Sequence vdseq,
58 super(datastore, ref, jalview.datamodel.DBRefEntry.class);
61 ds = (DataSet) vdseq.getV_parent();
65 public void updateToDoc()
67 DbRef dbref = (DbRef) this.vobj;
68 DBRefEntry jvobj = (DBRefEntry) this.jvobj;
69 dbref.setAccessionId(jvobj.getAccessionId());
70 dbref.setSource(jvobj.getSource());
71 dbref.setVersion(jvobj.getVersion());
72 if (jvobj.getMap() != null)
74 // Record mapping to external database coordinate system.
75 jalview.datamodel.Mapping mp = jvobj.getMap();
76 if (mp.getMap() != null)
79 if (dbref.getMapCount() == 0)
82 initMapType(vMap, mp.getMap(), true);
87 // we just update the data anyway.
88 vMap = dbref.getMap(0);
89 initMapType(vMap, mp.getMap(), true);
97 "Ignoring mapless DbRef.Map " + jvobj.getSrcAccString());
103 * ugly hack to try to get the embedded sequences within a database reference
104 * to be stored in the document's dataset.
108 private void updateMapTo(jalview.datamodel.Mapping mp)
111 "Performing updateMapTo remove this message when we know what we're doing.");
112 // TODO determine how sequences associated with database mappings are stored
114 if (mp != null && mp.getTo() != null)
116 if (mp.getTo().getDatasetSequence() == null)
118 // TODO: fix this hinky sh!t
119 DatastoreItem dssync = dsReg.getDatastoreItemFor(mp.getTo());
122 // sync the dataset sequence, if it hasn't been done already.
123 // TODO: ensure real dataset sequence corresponding to getTo is
125 dssync = new Datasetsequence(datastore, mp.getTo(),
126 (mp.getMappedWidth() == mp.getWidth())
127 ? sequence.getDictionary()
128 : ((mp.getMappedWidth() == 3)
129 ? uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA
130 : uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA),
134 // TODO: NOW add a mapping between new dataset sequence and sequence
135 // associated with the database reference
137 // dna mappings only...
138 // new jalview.io.vamsas.Sequencemapping(datastore, mp, sequence, ds);
145 log.debug("Ignoring non-dataset sequence mapping.");
149 public void updateFromDoc()
151 DbRef vobj = (DbRef) this.vobj;
152 DBRefEntry jvobj = (DBRefEntry) this.jvobj;
153 jvobj.setAccessionId(vobj.getAccessionId());
154 jvobj.setSource(vobj.getSource());
155 jvobj.setVersion(vobj.getVersion());
157 if (vobj.getMapCount() > 0)
159 // TODO: Jalview ignores all the other maps
160 if (vobj.getMapCount() > 1)
162 Console.debug("Ignoring additional mappings on DbRef: "
163 + jvobj.getSource() + ":" + jvobj.getAccessionId());
165 jalview.datamodel.Mapping mp = new jalview.datamodel.Mapping(
166 parsemapType(vobj.getMap(0)));
167 if (jvobj.getMap() == null || !mp.equals(jvobj.getMap()))
174 public void conflict()
176 DbRef vobj = (DbRef) this.vobj;
177 DBRefEntry jvobj = (DBRefEntry) this.jvobj;
178 Console.debug("Conflict in dbentry update for " + vobj.getAccessionId()
179 + vobj.getSource() + " " + vobj.getVorbaId());
180 // TODO Auto-generated method stub
184 public void addFromDocument()
186 DbRef vobj = (DbRef) this.vobj;
187 DBRefEntry jvobj = (DBRefEntry) this.jvobj;
189 sq.addDBRef(jvobj = new jalview.datamodel.DBRefEntry(
190 vobj.getSource().toString(), vobj.getVersion().toString(),
191 vobj.getAccessionId().toString()));
192 if (vobj.getMapCount() > 0)
194 // TODO: Jalview ignores all the other maps
195 if (vobj.getMapCount() > 1)
197 Console.debug("Ignoring additional mappings on DbRef: "
198 + jvobj.getSource() + ":" + jvobj.getAccessionId());
200 jalview.datamodel.Mapping mp = new jalview.datamodel.Mapping(
201 parsemapType(vobj.getMap(0)));
204 // TODO: jalview ignores links and properties because it doesn't know what
207 bindjvvobj(jvobj, vobj);
210 public void addToDocument()
212 DBRefEntry jvobj = (DBRefEntry) this.jvobj;
213 DbRef dbref = new DbRef();
214 bindjvvobj(jvobj, dbref);
215 dbref.setAccessionId(jvobj.getAccessionId());
216 dbref.setSource(jvobj.getSource());
217 dbref.setVersion(jvobj.getVersion());
218 sequence.addDbRef(dbref);
219 if (jvobj.getMap() != null)
221 jalview.datamodel.Mapping mp = jvobj.getMap();
222 if (mp.getMap() != null)
224 Map vMap = new Map();
225 initMapType(vMap, mp.getMap(), true);
232 "Ignoring mapless DbRef.Map " + jvobj.getSrcAccString());