b6c31929a6c3d7b326891731a7e0484556a949a8
[jalview.git] / src / jalview / datamodel / DBRefEntry.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer
3  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.datamodel;
20
21 public class DBRefEntry
22 {
23   String source="", version="", accessionId="";
24   /**
25    * maps from associated sequence to the database sequence's coordinate system
26    */
27   Mapping map=null;
28   public DBRefEntry() {
29       
30   }
31   public DBRefEntry(String source, String version, String accessionId)
32   {
33     this(source, version, accessionId, null);
34   }
35   /**
36    * 
37    * @param source canonical source (uppercase only)
38    * @param version (source dependent version string)
39    * @param accessionId (source dependent accession number string)
40    * @param map (mapping from local sequence numbering to source accession numbering)
41    */
42   public DBRefEntry(String source, String version, String accessionId, Mapping map) {
43     this.source = source.toUpperCase();
44     this.version = version;
45     this.accessionId = accessionId;
46     this.map = map;
47   }
48   public DBRefEntry(DBRefEntry entry)
49   {
50     this((entry.source==null ? "" : new String(entry.source)), 
51             (entry.version==null ? "" : new String(entry.version)),
52             (entry.accessionId==null ? "" : new String(entry.accessionId)),
53             (entry.map==null ? null : new Mapping(entry.map)));
54   }
55   public boolean equals(DBRefEntry entry) {
56       if (entry==this)
57           return true;
58       if (entry==null)
59           return false;
60       if (equalRef(entry)
61               &&
62           ((map==null && entry.map==null) || (map!=null && entry.map!=null && map.equals(entry.map)))) {
63               return true;
64           }
65       return false;
66   }
67   /**
68    * test for similar DBRef attributes, except for the map object.
69    * @param entry 
70    * @return true if source, accession and version are equal with those of entry
71    */
72   public boolean equalRef(DBRefEntry entry)
73   {
74     if (entry==null)
75     {
76       return false;
77     }
78     if (entry==this)
79       return true;
80     if ((source!=null && entry.source!=null && source.equalsIgnoreCase(entry.source))
81             &&
82             (accessionId!=null && entry.accessionId!=null && accessionId.equalsIgnoreCase(entry.accessionId))
83             &&
84             (version!=null && entry.version!=null && version.equalsIgnoreCase(entry.version))
85             )
86     {
87       return true;
88     }
89     return false;
90   }
91   public String getSource()
92   {
93     return source;
94   }
95
96   public String getVersion()
97   {
98     return version;
99   }
100
101   public String getAccessionId()
102   {
103     return accessionId;
104   }
105 /**
106  * @param accessionId the accessionId to set
107  */
108 public void setAccessionId(String accessionId) {
109     this.accessionId = accessionId;
110 }
111 /**
112  * @param source the source to set
113  */
114 public void setSource(String source) {
115     this.source = source;
116 }
117 /**
118  * @param version the version to set
119  */
120 public void setVersion(String version) {
121     this.version = version;
122 }
123 /**
124  * @return the map
125  */
126 public Mapping getMap() {
127     return map;
128 }
129 /**
130  * @param map the map to set
131  */
132 public void setMap(Mapping map) {
133     this.map = map;
134 }
135 public boolean hasMap()
136 {
137   return map!=null;
138 }
139 /**
140  * 
141  * @return source+":"+accessionId
142  */
143 public String getSrcAccString()
144 {
145   return ((source!=null) ? source : "")
146     + ":" + ((accessionId!=null) ? accessionId : "");
147 }
148 }