Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/biomage/BioSequence/SeqFeature.java


1   /***************************************************************************  
2    *                                                                         *
3    * C O P Y R I G H T   N O T I C E                                         * 
4    *  Copyright (c) 2001 by:                                                 *
5    *    * The MicroArray Gene Expression Database group (MGED)               *
6    *    * Rosetta Inpharmatics                                               *
7    *                                                                         *
8    *    All Rights Reserved.                                                 *
9    *                                                                         *
10   * Permission is hereby granted, free of charge, to any person             *
11   * obtaining a copy of this software and associated documentation files    *
12   * (the "Software"), to deal in the Software without restriction,          *
13   * including without limitation the rights to use, copy, modify, merge,    *
14   * publish, distribute, sublicense, and/or sell copies of the Software,    *
15   * and to permit persons to whom the Software is furnished to do so,       *
16   * subject to the following conditions:                                    *
17   *                                                                         *
18   * The above copyright notice and this permission notice shall be          *
19   * included in all copies or substantial portions of the Software.         *
20   *                                                                         *
21   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,         *
22   * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF      * 
23   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND                   *
24   * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS     *
25   * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN      *
26   * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN       *
27   * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE        *
28   * SOFTWARE.                                                               *
29   ***************************************************************************
30   *                                                                         *
31   * Created by the create_mage_java_classes java program based on the       * 
32   * information in the xmi file created from the MAGE-OM UML model,         *
33   * copyright European Bioinformatics Institute (EBI) for MGED and Rosetta  *
34   * Informatics.                                                            *
35   *                                                                         *
36   * The ideas and work are built on the previous work in perl of Jason      *
37   * Stewart, Open Informatics, and Robert M. Hubley, Institute for Systems  *
38   * Biology                                                                 *
39   *                                                                         *
40   * @author  Michael Miller, Rosetta Inpharmatics                           *
41   * @version Revision: 1.0                                                  *
42   * @date    Thu, Feb 21, 2002 10:46:35 AM                                  *
43   *                                                                         *
44   ***************************************************************************
45   */
46  
47  /**
48   *  org.biomage.BioSequence
49   *  
50   */
51  package org.biomage.BioSequence;
52  
53  /**
54   *  Import list for SeqFeature
55   *  
56   */
57  import java.io.Serializable;
58  import java.util.*;
59  import org.xml.sax.Attributes;
60  import java.io.Writer;
61  import java.io.IOException;
62  import org.biomage.Interface.HasRegions;
63  import org.biomage.Common.Describable;
64  
65  /**
66   *  Represents, in general, what would be a GenBank Feature Table 
67   *  annotation for a sequence.
68   *  
69   */
70  public
71  class SeqFeature
72      extends Describable
73      implements Serializable,
74          HasRegions
75  {
76      /**
77       *  Inner class for the enumeration values that the attribute basis 
78       *  can assume.
79       *  
80       */
81      public
82      class
83      Basis
84      {
85          int value = -1;
86          private HashMap nameToValue = new HashMap(5);
87  
88          final public int EXPERIMENTAL = 0;
89          final public int COMPUTATIONAL = 1;
90          final public int BOTH = 2;
91          final public int UNKNOWN = 3;
92          final public int NA = 4;
93  
94          Basis(){
95              nameToValue.put("EXPERIMENTAL",new Integer(0));
96              nameToValue.put("COMPUTATIONAL",new Integer(1));
97              nameToValue.put("BOTH",new Integer(2));
98              nameToValue.put("UNKNOWN",new Integer(3));
99              nameToValue.put("NA",new Integer(4));
100         }
101 
102         public int setValueByName(String name) {
103                 value = ((Integer)nameToValue.get(name)).intValue();
104                 return value;
105         }
106     }
107 
108     /**
109      *  How the evidence for a SeqFeature was determined.
110      *  
111      */
112      Basis basis = new Basis();
113 
114     /**
115      *  Association to classes that describe the location with the 
116      *  sequence of the SeqFeature.
117      *  
118      */
119     private Regions_list regions = new Regions_list();
120 
121     /**
122      *  Default constructor.
123      *  
124      */
125     public
126     SeqFeature()
127     {
128         super();
129     }
130 
131     /**
132      *  Attribute constructor.
133      *  
134      *  Looks up the attributes in the parameter and casts them from strings 
135      *  appropriately
136      *  @param atts: the attribute list.
137      *  
138      */
139     // TODO Work in progress (attribute constructor).
140     public
141     SeqFeature(Attributes atts)
142     {
143         super(atts);
144 
145         {
146             int nIndex = atts.getIndex("", "basis");
147             if (nIndex != -1)
148             {
149                 basis.setValueByName(atts.getValue(nIndex).toUpperCase());
150             }
151         }
152 
153     }
154 
155     /**
156      *  writeMAGEML
157      *  <p>
158      *  This method is responsible for assembling the attribute and 
159      *  association data into XML. It creates the object tag and then calls 
160      *  the writeAttributes and writeAssociation methods.
161      *  <p>
162      *  
163      */
164     public
165     void
166     writeMAGEML(Writer out)
167     throws IOException
168     {
169         out.write("<SeqFeature");
170         writeAttributes(out);
171         out.write(">");
172         writeAssociations(out);
173         out.write("</SeqFeature>");
174     }
175 
176     /**
177      *  writeAttributes
178      *  <p>
179      *  This method is responsible for assembling the attribute data into 
180      *  XML. It calls the super method to write out all attributes of this 
181      *  class and it's ancestors.
182      *  <p>
183      *  
184      */
185     public
186     void
187     writeAttributes(Writer out)
188     throws IOException
189     {
190         super.writeAttributes(out);
191         out.write(" basis=\"" + basis + "\"");
192     }
193 
194     /**
195      *  writeAssociations
196      *  <p>
197      *  This method is responsible for assembling the association data 
198      *  into XML. It calls the super method to write out all associations of 
199      *  this class's ancestors.
200      *  <p>
201      *  
202      */
203     public
204     void
205     writeAssociations(Writer out)
206     throws IOException
207     {
208         super.writeAssociations(out);
209         if ( regions.size() > 0 ){
210             out.write("<Regions_assnlist>");
211             for ( int i = 0; i < regions.size(); i++) {
212                 ((SeqFeatureLocation)regions.elementAt(i)).writeMAGEML(out);
213             }
214             out.write("</Regions_assnlist>");
215         }
216     }
217 
218     /**
219      *  Set method for basis
220      *  <p>
221      *  @param value to set
222      *  <p>
223      *  
224      */
225     public
226     void
227     setBasis(
228         Basis basis
229     )
230     {
231         this.basis = basis;
232     }
233 
234     /**
235      *  Get method for basis
236      *  <p>
237      *  @return value of the attribute
238      *  <p>
239      *  
240      */
241     public
242     Basis
243     getBasis()
244     {
245         return basis;
246     }
247 
248     /**
249      *  Set method for regions
250      *  <p>
251      *  @param value to set
252      *  <p>
253      *  
254      */
255     public
256     void
257     setRegions(
258         Regions_list regions
259     )
260     {
261         ((List)this.regions).addAll((List)regions);
262     }
263 
264     /**
265      *  Get method for regions
266      *  <p>
267      *  @return value of the attribute
268      *  <p>
269      *  
270      */
271     public
272     Regions_list
273     getRegions()
274     {
275         return regions;
276     }
277 
278     /**
279      *  Method to add SeqFeatureLocation to Regions_list
280      *  
281      */
282     public
283     void
284     addToRegions(
285         SeqFeatureLocation seqFeatureLocation
286     )
287     {
288         this.regions.add(seqFeatureLocation);
289     }
290 
291     /**
292      *  Method to add SeqFeatureLocation at position to Regions_list
293      *  
294      */
295     public
296     void
297     addToRegions(
298         int position,
299         SeqFeatureLocation seqFeatureLocation
300     )
301     {
302         this.regions.add(position, seqFeatureLocation);
303     }
304 
305     /**
306      *  Method to get SeqFeatureLocation from Regions_list
307      *  
308      */
309     public
310     SeqFeatureLocation
311     getFromRegions(
312         int position
313     )
314     {
315         return (SeqFeatureLocation) this.regions.get(position);
316     }
317 
318     /**
319      *  Method to remove by position from Regions_list
320      *  
321      */
322     public
323     void
324     removeElementAtFromRegions(
325         int position
326     )
327     {
328         this.regions.removeElementAt(position);
329     }
330 
331     /**
332      *  Method to remove first SeqFeatureLocation from Regions_list
333      *  
334      */
335     public
336     void
337     removeFromRegions(
338         SeqFeatureLocation seqFeatureLocation
339     )
340     {
341         this.regions.remove(seqFeatureLocation);
342     }
343 
344 }