updated jalview version of dasobert 1.53e client and added Das Sequence Source discov...
[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 /** An Abstract class representing a Feature as being diplayed in the SeqFeaturePanel 
30  *  A feature corresponds to everything that is visible in a "line" and can contain one or multiple Segments.
31  * 
32  * 
33  * @author Andreas Prlic
34  *
35  */
36 public abstract class AbstractFeatureTrack implements FeatureTrack,Cloneable {
37
38         String name;
39         String method;
40         String type;
41         List  segments ;
42         String note;
43         String link;
44         String source;
45         String score;
46         String orientation;
47         String typeID;
48         String typeCategory;
49
50         public AbstractFeatureTrack() {
51                 source = "Unknown";
52                 method = "Unknown";
53                 type   = "Unknown";
54                 note   = "";
55                 link   = "";
56                 score  = "";
57                 orientation = null;
58                 segments = new ArrayList();
59
60         }
61
62         public abstract Object clone();
63
64
65         public String toString() {
66                 String str = "Feature: method: " + method +" type: " + type ;
67                 if ( name != null)
68                         str += " name: " + name;
69                 
70                 if (( note != null) && (! note.equals("null")))
71                 {
72                         if (note.length() > 40)
73                                 str += "note: " +note.substring(0,39) + "...";
74                         else
75                                 str += " note: "+note;
76                 }
77                 str += " # segments: " + segments.size() ;
78                 return str ;
79         }
80
81
82         /** returns true if the specified sequence position is within the range of this Feature
83          * 
84          * @param seqPosition the position to check
85          * @return true if the position is within the ranges of the segments of this feature
86          */
87         public boolean overlaps(int seqPosition){
88                 List segments = getSegments();
89                 Iterator iter =segments.iterator();
90
91                 while (iter.hasNext()){
92
93                         Segment seg = (Segment) iter.next();
94                         if ( seg.overlaps(seqPosition) )
95                                 return true;                                     
96                 }
97
98                 return false;
99         }
100
101         public void setSource(String s) { source = s;}
102         public String getSource() { return source; };
103
104
105         public void setName(String nam) { name = nam; }
106         public String getName() { return name; }
107
108         public void setMethod(String methd) { method = methd ; }
109         public String getMethod() { return method ; }
110
111         public void setType(String typ) { type = typ ; }
112         public String getType() { return type ; }
113
114         public void setNote(String nte) { 
115                 if (nte != null)
116                         note = nte; 
117                 }
118         public String getNote() { return note ; }
119
120         public void setLink(String lnk) { link = lnk;}
121         public String getLink() { return link;}
122
123         public void setScore(String s){ score = s;}
124         public String getScore() { return score;}
125
126         /** add a segment to this feature */
127         public void addSegment(int start, int end, String name) {
128                 Segment s = new SegmentImpl() ;
129                 s.setStart(start);
130                 s.setEnd(end) ;
131                 s.setName(name);
132                 s.setParent(this);
133                 segments.add(s);
134         }
135
136         public void addSegment( Segment s ){
137                 s.setParent(this);
138                 segments.add(s);
139         }
140
141         public List getSegments() {
142                 return segments ;
143         }
144
145
146         public String getOrientation() {
147                 return orientation;
148         }
149
150         public void setOrientation(String orientation) {
151                 this.orientation = orientation;
152         }
153
154         /** test if two features are equivalent 
155          * important: only comares type,method and source.
156          * The individual segments are not compared!
157          * 
158          * */
159         public  boolean equals(FeatureTrack feat) {
160 //              if ( note == null) {
161                 //  if (( feat.getNote() == null ) || 
162                 // ( feat.getNote().equals(""))) {
163                 //} else if ( this.note.equals(feat.getNote())){
164                 //  return true;
165                 //}
166                 if ( this.type.equals(feat.getType())){
167                         if ( this.method.equals(feat.getMethod())){
168                                 if ( this.source.equals(feat.getSource())){                                                                             
169                                         if (this.note.equals(feat.getNote())){
170                                                 return true;
171                                         }
172                                 }
173                         }
174                 }
175                 return false;
176
177         }
178         public String getTypeCategory() {
179                 // TODO Auto-generated method stub
180                 return typeCategory;
181         }
182
183         public String getTypeID() {
184                 // TODO Auto-generated method stub
185                 return typeID;
186         }
187
188         public void setTypeCategory(String typeCategory) {
189                 this.typeCategory = typeCategory;
190                 
191         }
192
193         public void setTypeID(String typeID) {
194                 this.typeID = typeID;
195                 
196         }
197         
198
199
200 }