0ad2df7b6aab0fd84162f59fac62cc14430bc6a1
[jalview.git] / src / org / biojava / dasobert / feature / AbstractFeatureTrack.java
1 /*
2  *                  BioJava development code
3  *
4  * This code may be freely distributed and modified under the
5  * terms of the GNU Lesser General Public Licence.  This should
6  * be distributed with the code.  If you do not have a copy,
7  * see:
8  *
9  *      http://www.gnu.org/copyleft/lesser.html
10  *
11  * Copyright for this code is held jointly by the individual
12  * authors.  These should be listed in @author doc comments.
13  *
14  * For more information on the BioJava project and its aims,
15  * or to join the biojava-l mailing list, visit the home page
16  * at:
17  *
18  *      http://www.biojava.org/
19  * 
20  * Created on Feb 9, 2005
21  *
22  */
23 package org.biojava.dasobert.feature;
24
25 import java.util.ArrayList;
26 import java.util.Iterator;
27 import java.util.List;
28
29 /**
30  * An Abstract class representing a Feature as being diplayed in the
31  * SeqFeaturePanel A feature corresponds to everything that is visible in a
32  * "line" and can contain one or multiple Segments.
33  * 
34  * 
35  * @author Andreas Prlic
36  * 
37  */
38 public abstract class AbstractFeatureTrack implements FeatureTrack,
39         Cloneable
40 {
41
42   String name;
43
44   String method;
45
46   String type;
47
48   List segments;
49
50   String note;
51
52   String link;
53
54   String source;
55
56   String score;
57
58   String orientation;
59
60   String typeID;
61
62   String typeCategory;
63
64   public AbstractFeatureTrack()
65   {
66     source = "Unknown";
67     method = "Unknown";
68     type = "Unknown";
69     note = "";
70     link = "";
71     score = "";
72     orientation = null;
73     segments = new ArrayList();
74
75   }
76
77   public abstract Object clone();
78
79   public String toString()
80   {
81     String str = "Feature: method: " + method + " type: " + type;
82     if (name != null)
83       str += " name: " + name;
84
85     if ((note != null) && (!note.equals("null")))
86     {
87       if (note.length() > 40)
88         str += "note: " + note.substring(0, 39) + "...";
89       else
90         str += " note: " + note;
91     }
92     str += " # segments: " + segments.size();
93     return str;
94   }
95
96   /**
97    * returns true if the specified sequence position is within the range of this
98    * Feature
99    * 
100    * @param seqPosition
101    *                the position to check
102    * @return true if the position is within the ranges of the segments of this
103    *         feature
104    */
105   public boolean overlaps(int seqPosition)
106   {
107     List segments = getSegments();
108     Iterator iter = segments.iterator();
109
110     while (iter.hasNext())
111     {
112
113       Segment seg = (Segment) iter.next();
114       if (seg.overlaps(seqPosition))
115         return true;
116     }
117
118     return false;
119   }
120
121   public void setSource(String s)
122   {
123     source = s;
124   }
125
126   public String getSource()
127   {
128     return source;
129   };
130
131   public void setName(String nam)
132   {
133     name = nam;
134   }
135
136   public String getName()
137   {
138     return name;
139   }
140
141   public void setMethod(String methd)
142   {
143     method = methd;
144   }
145
146   public String getMethod()
147   {
148     return method;
149   }
150
151   public void setType(String typ)
152   {
153     type = typ;
154   }
155
156   public String getType()
157   {
158     return type;
159   }
160
161   public void setNote(String nte)
162   {
163     if (nte != null)
164       note = nte;
165   }
166
167   public String getNote()
168   {
169     return note;
170   }
171
172   public void setLink(String lnk)
173   {
174     link = lnk;
175   }
176
177   public String getLink()
178   {
179     return link;
180   }
181
182   public void setScore(String s)
183   {
184     score = s;
185   }
186
187   public String getScore()
188   {
189     return score;
190   }
191
192   /** add a segment to this feature */
193   public void addSegment(int start, int end, String name)
194   {
195     Segment s = new SegmentImpl();
196     s.setStart(start);
197     s.setEnd(end);
198     s.setName(name);
199     s.setParent(this);
200     segments.add(s);
201   }
202
203   public void addSegment(Segment s)
204   {
205     s.setParent(this);
206     segments.add(s);
207   }
208
209   public List getSegments()
210   {
211     return segments;
212   }
213
214   public String getOrientation()
215   {
216     return orientation;
217   }
218
219   public void setOrientation(String orientation)
220   {
221     this.orientation = orientation;
222   }
223
224   /**
225    * test if two features are equivalent important: only comares type,method and
226    * source. The individual segments are not compared!
227    * 
228    */
229   public boolean equals(FeatureTrack feat)
230   {
231     // if ( note == null) {
232     // if (( feat.getNote() == null ) ||
233     // ( feat.getNote().equals(""))) {
234     // } else if ( this.note.equals(feat.getNote())){
235     // return true;
236     // }
237     if (this.type.equals(feat.getType()))
238     {
239       if (this.method.equals(feat.getMethod()))
240       {
241         if (this.source.equals(feat.getSource()))
242         {
243           if (this.note.equals(feat.getNote()))
244           {
245             return true;
246           }
247         }
248       }
249     }
250     return false;
251
252   }
253
254   public String getTypeCategory()
255   {
256     // TODO Auto-generated method stub
257     return typeCategory;
258   }
259
260   public String getTypeID()
261   {
262     // TODO Auto-generated method stub
263     return typeID;
264   }
265
266   public void setTypeCategory(String typeCategory)
267   {
268     this.typeCategory = typeCategory;
269
270   }
271
272   public void setTypeID(String typeID)
273   {
274     this.typeID = typeID;
275
276   }
277
278 }