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.datamodel;
23 import jalview.api.DBRefEntryI;
25 import java.util.Arrays;
27 public class DBRefEntry implements DBRefEntryI
29 String source = "", version = "", accessionId = "";
32 * maps from associated sequence to the database sequence's coordinate system
41 public DBRefEntry(String source, String version, String accessionId)
43 this(source, version, accessionId, null);
49 * canonical source (uppercase only)
51 * (source dependent version string)
53 * (source dependent accession number string)
55 * (mapping from local sequence numbering to source accession
58 public DBRefEntry(String source, String version, String accessionId,
61 this.source = source.toUpperCase();
62 this.version = version;
63 this.accessionId = accessionId;
67 public DBRefEntry(DBRefEntryI entry)
69 this((entry.getSource() == null ? "" : new String(entry.getSource())),
70 (entry.getVersion() == null ? "" : new String(
72 (entry.getAccessionId() == null ? "" : new String(
73 entry.getAccessionId())),
74 (entry.getMap() == null ? null : new Mapping(entry.getMap())));
78 public boolean equals(Object o)
80 // TODO should also override hashCode to ensure equal objects have equal
82 if (o == null || !(o instanceof DBRefEntry))
86 DBRefEntry entry = (DBRefEntry) o;
92 && ((map == null && entry.map == null) || (map != null
93 && entry.map != null && map.equals(entry.map))))
101 * Answers true if this object is either equivalent to, or can be 'improved'
102 * by, the given entry. Specifically, answers true if
104 * <li>source and accession are identical (ignoring case)</li>
105 * <li>version is identical (ignoring case), or this version is of the format
106 * "someSource:0", in which case the version for the other entry replaces it</li>
107 * <li>mappings are not compared but if this entry has no mapping, replace
108 * with that for the other entry</li>
115 public boolean updateFrom(DBRefEntryI other)
127 * source must either match or be both null
129 String otherSource = other.getSource();
130 if ((source == null && otherSource != null)
131 || (source != null && otherSource == null)
132 || (source != null && !source.equalsIgnoreCase(otherSource)))
138 * accession id must either match or be both null
140 String otherAccession = other.getAccessionId();
141 if ((accessionId == null && otherAccession != null)
142 || (accessionId != null && otherAccession == null)
143 || (accessionId != null && !accessionId
144 .equalsIgnoreCase(otherAccession)))
150 * if my version is null, "0" or "source:0" then replace with other version,
151 * otherwise the versions have to match
153 String otherVersion = other.getVersion();
155 if ((version == null || version.equals("0") || version.endsWith(":0"))
156 && otherVersion != null)
158 setVersion(otherVersion);
163 && (otherVersion == null || !version
164 .equalsIgnoreCase(otherVersion)))
171 * if I have no mapping, take that of the other dbref
175 setMap(other.getMap());
181 * test for similar DBRef attributes, except for the map object.
184 * @return true if source, accession and version are equal with those of entry
187 public boolean equalRef(DBRefEntryI entry)
189 // TODO is this method and equals() not needed?
199 && (source != null && entry.getSource() != null && source
200 .equalsIgnoreCase(entry.getSource()))
201 && (accessionId != null && entry.getAccessionId() != null && accessionId
202 .equalsIgnoreCase(entry.getAccessionId()))
203 && (version != null && entry.getVersion() != null && version
204 .equalsIgnoreCase(entry.getVersion())))
212 public String getSource()
218 public String getVersion()
224 public String getAccessionId()
230 public void setAccessionId(String accessionId)
232 this.accessionId = accessionId;
236 public void setSource(String source)
238 this.source = source;
242 public void setVersion(String version)
244 this.version = version;
248 public Mapping getMap()
257 public void setMap(Mapping map)
262 public boolean hasMap()
269 * @return source+":"+accessionId
271 public String getSrcAccString()
273 return ((source != null) ? source : "") + ":"
274 + ((accessionId != null) ? accessionId : "");
278 public String toString()
280 return getSrcAccString();
284 public boolean isPrimary()
287 * if a map is present, unless it is 1:1 and has no SequenceI mate, it cannot be a primary reference.
291 if (map.getTo() != null)
295 if (map.getMap().getFromRatio() != map.getMap().getToRatio()
296 || map.getMap().getFromRatio() != 1)
300 // check map is really 1:1, no shifts allowed.
301 if (map.getMap().getFromHighest() != map.getMap().getToHighest()
302 && map.getMap().getFromLowest() != map.getMap().getToLowest()
304 map.getMap().getFromRanges().toArray(new int[0][]),
305 map.getMap().getToRanges().toArray(new int[0][])))
312 // no version string implies the reference has not been verified at all.
315 // tricky - this test really needs to search the sequence's set of dbrefs to
316 // see if there is a primary reference that derived this reference.
317 String ucv = version.toUpperCase();
318 for (String primsrc : Arrays.asList(DBRefSource.allSources()))
320 if (ucv.startsWith(primsrc.toUpperCase()))
322 // by convention, many secondary references inherit the primary
324 // source string as a prefix for any version information from the
325 // secondary reference.