Class |
Line # |
Actions |
|||
---|---|---|---|---|---|
Dbref | 33 | 73 | 25 |
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.bin.Console; | |
24 | import jalview.datamodel.DBRefEntry; | |
25 | import jalview.datamodel.SequenceI; | |
26 | import jalview.io.VamsasAppDatastore; | |
27 | ||
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; | |
32 | ||
33 | public class Dbref extends Rangetype | |
34 | { | |
35 | jalview.datamodel.SequenceI sq = null; | |
36 | ||
37 | uk.ac.vamsas.objects.core.Sequence sequence = null; | |
38 | ||
39 | DataSet ds; | |
40 | ||
41 | 0 | public Dbref(VamsasAppDatastore datastore, DBRefEntry dbentry, |
42 | jalview.datamodel.SequenceI sq2, | |
43 | uk.ac.vamsas.objects.core.Sequence sequence2, DataSet dataset) | |
44 | { | |
45 | 0 | super(datastore, dbentry, DbRef.class); |
46 | // initialise object specific attributes | |
47 | 0 | sq = sq2; |
48 | 0 | sequence = sequence2; |
49 | 0 | this.jvobj = dbentry; |
50 | 0 | ds = dataset; |
51 | // call the accessors | |
52 | 0 | doSync(); |
53 | } | |
54 | ||
55 | 0 | public Dbref(VamsasAppDatastore datastore, DbRef ref, Sequence vdseq, |
56 | SequenceI dsseq) | |
57 | { | |
58 | 0 | super(datastore, ref, jalview.datamodel.DBRefEntry.class); |
59 | 0 | sequence = vdseq; |
60 | 0 | sq = dsseq; |
61 | 0 | ds = (DataSet) vdseq.getV_parent(); |
62 | 0 | doJvUpdate(); |
63 | } | |
64 | ||
65 | 0 | public void updateToDoc() |
66 | { | |
67 | 0 | DbRef dbref = (DbRef) this.vobj; |
68 | 0 | DBRefEntry jvobj = (DBRefEntry) this.jvobj; |
69 | 0 | dbref.setAccessionId(jvobj.getAccessionId()); |
70 | 0 | dbref.setSource(jvobj.getSource()); |
71 | 0 | dbref.setVersion(jvobj.getVersion()); |
72 | 0 | if (jvobj.getMap() != null) |
73 | { | |
74 | // Record mapping to external database coordinate system. | |
75 | 0 | jalview.datamodel.Mapping mp = jvobj.getMap(); |
76 | 0 | if (mp.getMap() != null) |
77 | { | |
78 | 0 | Map vMap = null; |
79 | 0 | if (dbref.getMapCount() == 0) |
80 | { | |
81 | 0 | vMap = new Map(); |
82 | 0 | initMapType(vMap, mp.getMap(), true); |
83 | 0 | dbref.addMap(vMap); |
84 | } | |
85 | else | |
86 | { | |
87 | // we just update the data anyway. | |
88 | 0 | vMap = dbref.getMap(0); |
89 | 0 | initMapType(vMap, mp.getMap(), true); |
90 | } | |
91 | 0 | updateMapTo(mp); |
92 | } | |
93 | } | |
94 | else | |
95 | { | |
96 | 0 | Console.debug( |
97 | "Ignoring mapless DbRef.Map " + jvobj.getSrcAccString()); | |
98 | } | |
99 | ||
100 | } | |
101 | ||
102 | /** | |
103 | * ugly hack to try to get the embedded sequences within a database reference | |
104 | * to be stored in the document's dataset. | |
105 | * | |
106 | * @param mp | |
107 | */ | |
108 | 0 | private void updateMapTo(jalview.datamodel.Mapping mp) |
109 | { | |
110 | 0 | log.info( |
111 | "Performing updateMapTo remove this message when we know what we're doing."); | |
112 | // TODO determine how sequences associated with database mappings are stored | |
113 | // in the document | |
114 | 0 | if (mp != null && mp.getTo() != null) |
115 | { | |
116 | 0 | if (mp.getTo().getDatasetSequence() == null) |
117 | { | |
118 | // TODO: fix this hinky sh!t | |
119 | 0 | DatastoreItem dssync = dsReg.getDatastoreItemFor(mp.getTo()); |
120 | 0 | if (dssync == null) |
121 | { | |
122 | // sync the dataset sequence, if it hasn't been done already. | |
123 | // TODO: ensure real dataset sequence corresponding to getTo is | |
124 | // recovered | |
125 | 0 | dssync = new Datasetsequence(datastore, mp.getTo(), |
126 | 0 | (mp.getMappedWidth() == mp.getWidth()) |
127 | ? sequence.getDictionary() | |
128 | 0 | : ((mp.getMappedWidth() == 3) |
129 | ? uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_NA | |
130 | : uk.ac.vamsas.objects.utils.SymbolDictionary.STANDARD_AA), | |
131 | ds); | |
132 | } | |
133 | // | |
134 | // TODO: NOW add a mapping between new dataset sequence and sequence | |
135 | // associated with the database reference | |
136 | ||
137 | // dna mappings only... | |
138 | // new jalview.io.vamsas.Sequencemapping(datastore, mp, sequence, ds); | |
139 | ||
140 | } | |
141 | ||
142 | } | |
143 | else | |
144 | { | |
145 | 0 | log.debug("Ignoring non-dataset sequence mapping."); |
146 | } | |
147 | } | |
148 | ||
149 | 0 | public void updateFromDoc() |
150 | { | |
151 | 0 | DbRef vobj = (DbRef) this.vobj; |
152 | 0 | DBRefEntry jvobj = (DBRefEntry) this.jvobj; |
153 | 0 | jvobj.setAccessionId(vobj.getAccessionId()); |
154 | 0 | jvobj.setSource(vobj.getSource()); |
155 | 0 | jvobj.setVersion(vobj.getVersion()); |
156 | // add new dbref | |
157 | 0 | if (vobj.getMapCount() > 0) |
158 | { | |
159 | // TODO: Jalview ignores all the other maps | |
160 | 0 | if (vobj.getMapCount() > 1) |
161 | { | |
162 | 0 | Console.debug("Ignoring additional mappings on DbRef: " |
163 | + jvobj.getSource() + ":" + jvobj.getAccessionId()); | |
164 | } | |
165 | 0 | jalview.datamodel.Mapping mp = new jalview.datamodel.Mapping( |
166 | parsemapType(vobj.getMap(0))); | |
167 | 0 | if (jvobj.getMap() == null || !mp.equals(jvobj.getMap())) |
168 | { | |
169 | 0 | jvobj.setMap(mp); |
170 | } | |
171 | } | |
172 | } | |
173 | ||
174 | 0 | public void conflict() |
175 | { | |
176 | 0 | DbRef vobj = (DbRef) this.vobj; |
177 | 0 | DBRefEntry jvobj = (DBRefEntry) this.jvobj; |
178 | 0 | Console.debug("Conflict in dbentry update for " + vobj.getAccessionId() |
179 | + vobj.getSource() + " " + vobj.getVorbaId()); | |
180 | // TODO Auto-generated method stub | |
181 | ||
182 | } | |
183 | ||
184 | 0 | public void addFromDocument() |
185 | { | |
186 | 0 | DbRef vobj = (DbRef) this.vobj; |
187 | 0 | DBRefEntry jvobj = (DBRefEntry) this.jvobj; |
188 | // add new dbref | |
189 | 0 | sq.addDBRef(jvobj = new jalview.datamodel.DBRefEntry( |
190 | vobj.getSource().toString(), vobj.getVersion().toString(), | |
191 | vobj.getAccessionId().toString())); | |
192 | 0 | if (vobj.getMapCount() > 0) |
193 | { | |
194 | // TODO: Jalview ignores all the other maps | |
195 | 0 | if (vobj.getMapCount() > 1) |
196 | { | |
197 | 0 | Console.debug("Ignoring additional mappings on DbRef: " |
198 | + jvobj.getSource() + ":" + jvobj.getAccessionId()); | |
199 | } | |
200 | 0 | jalview.datamodel.Mapping mp = new jalview.datamodel.Mapping( |
201 | parsemapType(vobj.getMap(0))); | |
202 | 0 | jvobj.setMap(mp); |
203 | } | |
204 | // TODO: jalview ignores links and properties because it doesn't know what | |
205 | // to do with them. | |
206 | ||
207 | 0 | bindjvvobj(jvobj, vobj); |
208 | } | |
209 | ||
210 | 0 | public void addToDocument() |
211 | { | |
212 | 0 | DBRefEntry jvobj = (DBRefEntry) this.jvobj; |
213 | 0 | DbRef dbref = new DbRef(); |
214 | 0 | bindjvvobj(jvobj, dbref); |
215 | 0 | dbref.setAccessionId(jvobj.getAccessionId()); |
216 | 0 | dbref.setSource(jvobj.getSource()); |
217 | 0 | dbref.setVersion(jvobj.getVersion()); |
218 | 0 | sequence.addDbRef(dbref); |
219 | 0 | if (jvobj.getMap() != null) |
220 | { | |
221 | 0 | jalview.datamodel.Mapping mp = jvobj.getMap(); |
222 | 0 | if (mp.getMap() != null) |
223 | { | |
224 | 0 | Map vMap = new Map(); |
225 | 0 | initMapType(vMap, mp.getMap(), true); |
226 | 0 | dbref.addMap(vMap); |
227 | 0 | updateMapTo(mp); |
228 | } | |
229 | else | |
230 | { | |
231 | 0 | Console.debug( |
232 | "Ignoring mapless DbRef.Map " + jvobj.getSrcAccString()); | |
233 | } | |
234 | } | |
235 | } | |
236 | ||
237 | } |