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.datamodel.DBRefEntry;
24 import jalview.datamodel.SequenceI;
25 import jalview.io.VamsasAppDatastore;
27 import uk.ac.vamsas.objects.core.DataSet;
28 import uk.ac.vamsas.objects.core.DbRef;
29 import uk.ac.vamsas.objects.core.Sequence;
32 * synchronize a vamsas dataset sequence with a jalview dataset sequence. This
33 * class deals with all sequence features and database references associated
34 * with the jalview sequence.
39 public class Datasetsequence extends DatastoreItem
43 private DataSet dataset;
45 // private AlignmentI jvdset;
47 public Datasetsequence(VamsasAppDatastore vamsasAppDatastore,
48 SequenceI sq, String dict, DataSet dataset)
50 super(vamsasAppDatastore, sq, uk.ac.vamsas.objects.core.Sequence.class);
51 this.dataset = dataset;
52 // this.jvdset = jvdset;
57 public Datasetsequence(VamsasAppDatastore vamsasAppDatastore,
60 super(vamsasAppDatastore, vdseq, SequenceI.class);
64 public void addFromDocument()
66 Sequence vseq = (Sequence) vobj;
67 SequenceI dsseq = new jalview.datamodel.Sequence(vseq.getName(),
68 vseq.getSequence(), (int) vseq.getStart(), (int) vseq.getEnd());
69 dsseq.setDescription(vseq.getDescription());
70 bindjvvobj(dsseq, vseq);
71 dsseq.setVamsasId(vseq.getVorbaId().getId());
76 public void updateFromDoc()
78 Sequence sq = (Sequence) vobj;
79 SequenceI sequence = (SequenceI) jvobj;
80 if (!sequence.getSequenceAsString().equals(sq.getSequence()))
82 log.warn("Potential Client Error ! - mismatch of dataset sequence: and jalview internal dataset sequence.");
86 // verify and update principal attributes.
87 if (sequence.getDescription() != null
88 && (sequence.getDescription() == null || !sequence
89 .getDescription().equals(sq.getDescription())))
91 sequence.setDescription(sq.getDescription());
94 if (sequence.getSequence() == null
95 || !sequence.getSequenceAsString().equals(sq.getSequence()))
97 if (sequence.getStart() != sq.getStart()
98 || sequence.getEnd() != sq.getEnd())
100 // update modified sequence.
101 sequence.setSequence(sq.getSequence());
102 sequence.setStart((int) sq.getStart());
103 sequence.setEnd((int) sq.getEnd());
107 if (!sequence.getName().equals(sq.getName()))
109 sequence.setName(sq.getName());
112 modified |= updateJvDbRefs();
113 // updateJvFeatures();
118 * private void updateJvFeatures() { Sequence vsq = (Sequence) vobj;
120 * // add or update any new features/references on dataset sequence if
121 * (vsq.getgetSequenceFeatures() != null) { int sfSize =
122 * sq.getSequenceFeatures().length;
124 * for (int sf = 0; sf < sfSize; sf++) { new
125 * jalview.io.vamsas.Sequencefeature(datastore,
126 * (jalview.datamodel.SequenceFeature) sq .getSequenceFeatures()[sf], dataset,
127 * (Sequence) vobj); } } }
129 private boolean updateSqFeatures()
131 boolean modified = false;
132 SequenceI sq = (SequenceI) jvobj;
134 // add or update any new features/references on dataset sequence
135 if (sq.getSequenceFeatures() != null)
137 int sfSize = sq.getSequenceFeatures().length;
139 for (int sf = 0; sf < sfSize; sf++)
141 modified |= new Sequencefeature(datastore,
142 sq.getSequenceFeatures()[sf], dataset,
143 (Sequence) vobj).docWasUpdated();
149 public void addToDocument()
151 SequenceI sq = (SequenceI) jvobj;
152 Sequence sequence = new Sequence();
153 bindjvvobj(sq, sequence);
154 sq.setVamsasId(sequence.getVorbaId().getId());
155 sequence.setSequence(sq.getSequenceAsString());
156 sequence.setDictionary(dict);
157 sequence.setName(sq.getName());
158 sequence.setStart(sq.getStart());
159 sequence.setEnd(sq.getEnd());
160 sequence.setDescription(sq.getDescription());
161 dataset.addSequence(sequence);
164 updateDbRefs();// sq,(Sequence) vobj, dataset);
168 * sync database references from jv to document
170 * @return true if document was modified
172 private boolean updateDbRefs()
174 boolean modifiedthedoc = false;
175 SequenceI sq = (SequenceI) jvobj;
177 if (sq.getDatasetSequence() == null && sq.getDBRef() != null)
179 // only sync database references for dataset sequences
180 DBRefEntry[] entries = sq.getDBRef();
181 // jalview.datamodel.DBRefEntry dbentry;
182 for (int db = 0; db < entries.length; db++)
184 modifiedthedoc |= new Dbref(datastore,
186 entries[db], sq, (Sequence) vobj, dataset).docWasUpdated();
191 return modifiedthedoc;
195 * sync database references from document to jv sequence
197 * @return true if local sequence refs were modified
199 private boolean updateJvDbRefs()
201 boolean modifiedtheseq = false;
202 SequenceI sq = (SequenceI) jvobj;
203 Sequence vsq = (Sequence) vobj;
204 if (vsq.getDbRefCount() > 0)
206 // only sync database references for dataset sequences
207 DbRef[] entries = vsq.getDbRef();
209 for (int db = 0; db < entries.length; db++)
211 modifiedtheseq |= new Dbref(datastore,
213 entries[db], vsq, sq).jvWasUpdated();
216 return modifiedtheseq;
219 public void conflict()
221 log.warn("Conflict in dataset sequence update to document. Overwriting document");
222 // TODO: could try to import from document data to jalview first. and then
226 boolean modified = false;
228 public void updateToDoc()
230 SequenceI sq = (SequenceI) jvobj;
231 Sequence sequence = (Sequence) vobj;
232 // verify and update principal attributes.
233 if (sequence.getDescription() != null
234 && (sequence.getDescription() == null || !sequence
235 .getDescription().equals(sq.getDescription())))
237 sequence.setDescription(sq.getDescription());
240 if (sequence.getSequence() == null
241 || !sequence.getSequence().equals(sq.getSequenceAsString()))
243 if (sequence.getStart() != sq.getStart()
244 || sequence.getEnd() != sq.getEnd())
246 // update modified sequence.
247 sequence.setSequence(sq.getSequenceAsString());
248 sequence.setStart(sq.getStart());
249 sequence.setEnd(sq.getEnd());
253 if (!dict.equals(sequence.getDictionary()))
255 sequence.setDictionary(dict);
258 if (!sequence.getName().equals(sq.getName()))
260 sequence.setName(sq.getName());
263 modified |= updateDbRefs();
264 modified |= updateSqFeatures();
268 * (probably could just do vobj.isModified(), but..)
270 * @return true if document's dataset sequence was modified
272 public boolean getModified()