7491da2a59d5578b578ae1153f9d25586806c763
[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(new String(entry.source), new String(entry.version), new String(entry.accessionId), new Mapping(entry.map));
51   }
52   public boolean equals(DBRefEntry entry) {
53       if (entry==this)
54           return true;
55       if (entry==null)
56           return false;
57       if (equalRef(entry)
58               &&
59           ((map==null && entry.map==null) || (map!=null && entry.map!=null && map.equals(entry.map)))) {
60               return true;
61           }
62       return false;
63   }
64   /**
65    * test for similar DBRef attributes, except for the map object.
66    * @param entry 
67    * @return true if source, accession and version are equal with those of entry
68    */
69   public boolean equalRef(DBRefEntry entry)
70   {
71     if (entry==null)
72     {
73       return false;
74     }
75     if (entry==this)
76       return true;
77     if ((source!=null && entry.source!=null && source.equalsIgnoreCase(entry.source))
78             &&
79             (accessionId!=null && entry.accessionId!=null && accessionId.equalsIgnoreCase(entry.accessionId))
80             &&
81             (version!=null && entry.version!=null && version.equalsIgnoreCase(entry.version))
82             )
83     {
84       return true;
85     }
86     return false;
87   }
88   public String getSource()
89   {
90     return source;
91   }
92
93   public String getVersion()
94   {
95     return version;
96   }
97
98   public String getAccessionId()
99   {
100     return accessionId;
101   }
102 /**
103  * @param accessionId the accessionId to set
104  */
105 public void setAccessionId(String accessionId) {
106     this.accessionId = accessionId;
107 }
108 /**
109  * @param source the source to set
110  */
111 public void setSource(String source) {
112     this.source = source;
113 }
114 /**
115  * @param version the version to set
116  */
117 public void setVersion(String version) {
118     this.version = version;
119 }
120 /**
121  * @return the map
122  */
123 public Mapping getMap() {
124     return map;
125 }
126 /**
127  * @param map the map to set
128  */
129 public void setMap(Mapping map) {
130     this.map = map;
131 }
132 public boolean hasMap()
133 {
134   return map!=null;
135 }
136 /**
137  * 
138  * @return source+":"+accessionId
139  */
140 public String getSrcAccString()
141 {
142   return ((source!=null) ? source : "")
143     + ":" + ((accessionId!=null) ? accessionId : "");
144 }
145 }