Source code: org/biomage/BioAssay/Image.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:12 AM *
43 * *
44 ***************************************************************************
45 */
46
47 /**
48 * org.biomage.BioAssay
49 *
50 */
51 package org.biomage.BioAssay;
52
53 /**
54 * Import list for Image
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.HasChannels;
63 import org.biomage.Interface.HasFormat;
64 import org.biomage.Common.Identifiable;
65 import org.biomage.Description.OntologyEntry;
66
67 /**
68 * An image is created by an imageAcquisition event, typically by
69 * scanning the hybridized array (the PhysicalBioAssay).
70 *
71 */
72 public
73 class Image
74 extends Identifiable
75 implements Serializable,
76 HasChannels,
77 HasFormat
78 {
79 /**
80 * The file location in which an image may be found.
81 *
82 */
83 String URI;
84
85 /**
86 * The channels captured in this image.
87 *
88 */
89 private Channels_list channels = new Channels_list();
90
91 /**
92 * The file format of the image typically a TIF or a JPEG.
93 *
94 */
95 private OntologyEntry format;
96
97
98 /**
99 * Default constructor.
100 *
101 */
102 public
103 Image()
104 {
105 super();
106 }
107
108 /**
109 * Attribute constructor.
110 *
111 * Looks up the attributes in the parameter and casts them from strings
112 * appropriately
113 * @param atts: the attribute list.
114 *
115 */
116 // TODO Work in progress (attribute constructor).
117 public
118 Image(Attributes atts)
119 {
120 super(atts);
121
122 {
123 int nIndex = atts.getIndex("", "URI");
124 if (nIndex != -1)
125 {
126 URI = atts.getValue(nIndex);
127 }
128 }
129
130 }
131
132 /**
133 * writeMAGEML
134 * <p>
135 * This method is responsible for assembling the attribute and
136 * association data into XML. It creates the object tag and then calls
137 * the writeAttributes and writeAssociation methods.
138 * <p>
139 *
140 */
141 public
142 void
143 writeMAGEML(Writer out)
144 throws IOException
145 {
146 out.write("<Image");
147 writeAttributes(out);
148 out.write(">");
149 writeAssociations(out);
150 out.write("</Image>");
151 }
152
153 /**
154 * writeAttributes
155 * <p>
156 * This method is responsible for assembling the attribute data into
157 * XML. It calls the super method to write out all attributes of this
158 * class and it's ancestors.
159 * <p>
160 *
161 */
162 public
163 void
164 writeAttributes(Writer out)
165 throws IOException
166 {
167 super.writeAttributes(out);
168 if ( URI != null ) {
169 out.write(" URI=\"" + URI + "\"");
170 }
171 }
172
173 /**
174 * writeAssociations
175 * <p>
176 * This method is responsible for assembling the association data
177 * into XML. It calls the super method to write out all associations of
178 * this class's ancestors.
179 * <p>
180 *
181 */
182 public
183 void
184 writeAssociations(Writer out)
185 throws IOException
186 {
187 super.writeAssociations(out);
188 if ( channels.size() > 0 ){
189 out.write("<Channels_assnreflist>");
190 for ( int i = 0; i < channels.size(); i++) {
191 out.write("<Channel_ref identifier=\"" + ((Channel)channels.elementAt(i)).getIdentifier() + "\"/>");
192 }
193 out.write("</Channels_assnreflist>");
194 }
195 if ( format != null ){
196 out.write("<Format_assn>");
197 format.writeMAGEML(out);
198 out.write("</Format_assn>");
199 }
200 }
201
202 /**
203 * Set method for URI
204 * <p>
205 * @param value to set
206 * <p>
207 *
208 */
209 public
210 void
211 setURI(
212 String URI
213 )
214 {
215 this.URI = URI;
216 }
217
218 /**
219 * Get method for URI
220 * <p>
221 * @return value of the attribute
222 * <p>
223 *
224 */
225 public
226 String
227 getURI()
228 {
229 return URI;
230 }
231
232 /**
233 * Set method for channels
234 * <p>
235 * @param value to set
236 * <p>
237 *
238 */
239 public
240 void
241 setChannels(
242 Channels_list channels
243 )
244 {
245 ((List)this.channels).addAll((List)channels);
246 }
247
248 /**
249 * Get method for channels
250 * <p>
251 * @return value of the attribute
252 * <p>
253 *
254 */
255 public
256 Channels_list
257 getChannels()
258 {
259 return channels;
260 }
261
262 /**
263 * Method to add Channel to Channels_list
264 *
265 */
266 public
267 void
268 addToChannels(
269 Channel channel
270 )
271 {
272 this.channels.add(channel);
273 }
274
275 /**
276 * Method to add Channel at position to Channels_list
277 *
278 */
279 public
280 void
281 addToChannels(
282 int position,
283 Channel channel
284 )
285 {
286 this.channels.add(position, channel);
287 }
288
289 /**
290 * Method to get Channel from Channels_list
291 *
292 */
293 public
294 Channel
295 getFromChannels(
296 int position
297 )
298 {
299 return (Channel) this.channels.get(position);
300 }
301
302 /**
303 * Method to remove by position from Channels_list
304 *
305 */
306 public
307 void
308 removeElementAtFromChannels(
309 int position
310 )
311 {
312 this.channels.removeElementAt(position);
313 }
314
315 /**
316 * Method to remove first Channel from Channels_list
317 *
318 */
319 public
320 void
321 removeFromChannels(
322 Channel channel
323 )
324 {
325 this.channels.remove(channel);
326 }
327
328 /**
329 * Set method for format
330 * <p>
331 * @param value to set
332 * <p>
333 *
334 */
335 public
336 void
337 setFormat(
338 OntologyEntry format
339 )
340 {
341 this.format = format;
342 }
343
344 /**
345 * Get method for format
346 * <p>
347 * @return value of the attribute
348 * <p>
349 *
350 */
351 public
352 OntologyEntry
353 getFormat()
354 {
355 return format;
356 }
357
358 }