Clover icon

Coverage Report

  1. Project Clover database Wed Nov 13 2024 18:27:33 GMT
  2. Package jalview.io.vamsas

File Datasetsequence.java

 

Coverage histogram

../../../img/srcFileCovDistChart0.png
59% of files have more coverage

Code metrics

28
87
11
1
284
190
34
0.39
7.91
11
3.09

Classes

Class Line # Actions
Datasetsequence 42 87 34
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.io.vamsas;
22   
23    import jalview.datamodel.DBRefEntry;
24    import jalview.datamodel.SequenceFeature;
25    import jalview.datamodel.SequenceI;
26    import jalview.io.VamsasAppDatastore;
27   
28    import java.util.List;
29   
30    import uk.ac.vamsas.objects.core.DataSet;
31    import uk.ac.vamsas.objects.core.DbRef;
32    import uk.ac.vamsas.objects.core.Sequence;
33   
34    /**
35    * synchronize a vamsas dataset sequence with a jalview dataset sequence. This
36    * class deals with all sequence features and database references associated
37    * with the jalview sequence.
38    *
39    * @author JimP
40    *
41    */
 
42    public class Datasetsequence extends DatastoreItem
43    {
44    String dict;
45   
46    private DataSet dataset;
47   
48    // private AlignmentI jvdset;
49   
 
50  0 toggle public Datasetsequence(VamsasAppDatastore vamsasAppDatastore,
51    SequenceI sq, String theDict, DataSet theDataset)
52    {
53  0 super(vamsasAppDatastore, sq, uk.ac.vamsas.objects.core.Sequence.class);
54  0 this.dataset = theDataset;
55    // this.jvdset = jvdset;
56  0 this.dict = theDict;
57  0 doSync();
58    }
59   
 
60  0 toggle public Datasetsequence(VamsasAppDatastore vamsasAppDatastore,
61    Sequence vdseq)
62    {
63  0 super(vamsasAppDatastore, vdseq, SequenceI.class);
64  0 doJvUpdate();
65    }
66   
 
67  0 toggle @Override
68    public void addFromDocument()
69    {
70  0 Sequence vseq = (Sequence) vobj;
71  0 SequenceI dsseq = new jalview.datamodel.Sequence(vseq.getName(),
72    vseq.getSequence(), (int) vseq.getStart(), (int) vseq.getEnd());
73  0 dsseq.setDescription(vseq.getDescription());
74  0 bindjvvobj(dsseq, vseq);
75  0 dsseq.setVamsasId(vseq.getVorbaId().getId());
76  0 jvobj = dsseq;
77  0 modified = true;
78    }
79   
 
80  0 toggle @Override
81    public void updateFromDoc()
82    {
83  0 Sequence sq = (Sequence) vobj;
84  0 SequenceI sequence = (SequenceI) jvobj;
85  0 if (!sequence.getSequenceAsString().equals(sq.getSequence()))
86    {
87  0 log.warn(
88    "Potential Client Error ! - mismatch of dataset sequence: and jalview internal dataset sequence.");
89    }
90    else
91    {
92    // verify and update principal attributes.
93  0 if (sequence.getDescription() != null
94    && (sequence.getDescription() == null || !sequence
95    .getDescription().equals(sq.getDescription())))
96    {
97  0 sequence.setDescription(sq.getDescription());
98  0 modified = true;
99    }
100  0 if (sequence.getSequence() == null
101    || !sequence.getSequenceAsString().equals(sq.getSequence()))
102    {
103  0 if (sequence.getStart() != sq.getStart()
104    || sequence.getEnd() != sq.getEnd())
105    {
106    // update modified sequence.
107  0 sequence.setSequence(sq.getSequence());
108  0 sequence.setStart((int) sq.getStart());
109  0 sequence.setEnd((int) sq.getEnd());
110  0 modified = true;
111    }
112    }
113  0 if (!sequence.getName().equals(sq.getName()))
114    {
115  0 sequence.setName(sq.getName());
116  0 modified = true;
117    }
118  0 modified |= updateJvDbRefs();
119    // updateJvFeatures();
120    }
121    }
122   
123    /*
124    * private void updateJvFeatures() { Sequence vsq = (Sequence) vobj;
125    *
126    * // add or update any new features/references on dataset sequence if
127    * (vsq.getgetSequenceFeatures() != null) { int sfSize =
128    * sq.getSequenceFeatures().length;
129    *
130    * for (int sf = 0; sf < sfSize; sf++) { new
131    * jalview.io.vamsas.Sequencefeature(datastore,
132    * (jalview.datamodel.SequenceFeature) sq .getSequenceFeatures()[sf], dataset,
133    * (Sequence) vobj); } } }
134    */
 
135  0 toggle private boolean updateSqFeatures()
136    {
137  0 boolean changed = false;
138  0 SequenceI sq = (SequenceI) jvobj;
139   
140    // add or update any new features/references on dataset sequence
141  0 List<SequenceFeature> sfs = sq.getSequenceFeatures();
142  0 for (SequenceFeature sf : sfs)
143    {
144  0 changed |= new jalview.io.vamsas.Sequencefeature(datastore, sf,
145    dataset, (Sequence) vobj).docWasUpdated();
146    }
147   
148  0 return changed;
149    }
150   
 
151  0 toggle @Override
152    public void addToDocument()
153    {
154  0 SequenceI sq = (SequenceI) jvobj;
155  0 Sequence sequence = new Sequence();
156  0 bindjvvobj(sq, sequence);
157  0 sq.setVamsasId(sequence.getVorbaId().getId());
158  0 sequence.setSequence(sq.getSequenceAsString());
159  0 sequence.setDictionary(dict);
160  0 sequence.setName(sq.getName());
161  0 sequence.setStart(sq.getStart());
162  0 sequence.setEnd(sq.getEnd());
163  0 sequence.setDescription(sq.getDescription());
164  0 dataset.addSequence(sequence);
165  0 vobj = sequence;
166  0 updateSqFeatures();
167  0 updateDbRefs();// sq,(Sequence) vobj, dataset);
168    }
169   
170    /**
171    * sync database references from jv to document
172    *
173    * @return true if document was modified
174    */
 
175  0 toggle private boolean updateDbRefs()
176    {
177  0 boolean modifiedthedoc = false;
178  0 SequenceI sq = (SequenceI) jvobj;
179   
180  0 if (sq.getDatasetSequence() == null && sq.getDBRefs() != null)
181    {
182    // only sync database references for dataset sequences
183  0 List<DBRefEntry> entries = sq.getDBRefs();
184    // jalview.datamodel.DBRefEntry dbentry;
185  0 for (int db = 0, dn = entries.size(); db < dn; db++)
186    {
187  0 modifiedthedoc |= new jalview.io.vamsas.Dbref(datastore,
188    // dbentry =
189    entries.get(db), sq, (Sequence) vobj, dataset)
190    .docWasUpdated();
191   
192    }
193   
194    }
195  0 return modifiedthedoc;
196    }
197   
198    /**
199    * sync database references from document to jv sequence
200    *
201    * @return true if local sequence refs were modified
202    */
 
203  0 toggle private boolean updateJvDbRefs()
204    {
205  0 boolean modifiedtheseq = false;
206  0 SequenceI sq = (SequenceI) jvobj;
207  0 Sequence vsq = (Sequence) vobj;
208  0 if (vsq.getDbRefCount() > 0)
209    {
210    // only sync database references for dataset sequences
211  0 DbRef[] entries = vsq.getDbRef();
212    // DbRef dbentry;
213  0 for (int db = 0; db < entries.length; db++)
214    {
215  0 modifiedtheseq |= new jalview.io.vamsas.Dbref(datastore,
216    // dbentry =
217    entries[db], vsq, sq).jvWasUpdated();
218    }
219    }
220  0 return modifiedtheseq;
221    }
222   
 
223  0 toggle @Override
224    public void conflict()
225    {
226  0 log.warn(
227    "Conflict in dataset sequence update to document. Overwriting document");
228    // TODO: could try to import from document data to jalview first. and then
229  0 updateToDoc();
230    }
231   
232    boolean modified = false;
233   
 
234  0 toggle @Override
235    public void updateToDoc()
236    {
237  0 SequenceI sq = (SequenceI) jvobj;
238  0 Sequence sequence = (Sequence) vobj;
239    // verify and update principal attributes.
240  0 if (sequence.getDescription() != null
241    && (sequence.getDescription() == null || !sequence
242    .getDescription().equals(sq.getDescription())))
243    {
244  0 sequence.setDescription(sq.getDescription());
245  0 modified = true;
246    }
247  0 if (sequence.getSequence() == null
248    || !sequence.getSequence().equals(sq.getSequenceAsString()))
249    {
250  0 if (sequence.getStart() != sq.getStart()
251    || sequence.getEnd() != sq.getEnd())
252    {
253    // update modified sequence.
254  0 sequence.setSequence(sq.getSequenceAsString());
255  0 sequence.setStart(sq.getStart());
256  0 sequence.setEnd(sq.getEnd());
257  0 modified = true;
258    }
259    }
260  0 if (!dict.equals(sequence.getDictionary()))
261    {
262  0 sequence.setDictionary(dict);
263  0 modified = true;
264    }
265  0 if (!sequence.getName().equals(sq.getName()))
266    {
267  0 sequence.setName(sq.getName());
268  0 modified = true;
269    }
270  0 modified |= updateDbRefs();
271  0 modified |= updateSqFeatures();
272    }
273   
274    /**
275    * (probably could just do vobj.isModified(), but..)
276    *
277    * @return true if document's dataset sequence was modified
278    */
 
279  0 toggle public boolean getModified()
280    {
281  0 return modified;
282    }
283   
284    }