Changeset 248
- Timestamp:
- Mar 28, 2007, 6:29:17 PM (16 years ago)
- Location:
- trunk/se/lu/onk/BaseFile/src/basefile
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/se/lu/onk/BaseFile/src/basefile/BASEFileAssaySection.java
r247 r248 28 28 import java.util.List; 29 29 30 public class BASEFileAssaySection extends BASEFile Section30 public class BASEFileAssaySection extends BASEFileDataSection 31 31 { 32 32 private final ArrayList<String> data; 33 34 private final int height;35 36 private final int width;37 33 38 34 private final HashMap<Integer, Integer> idIndex = new HashMap<Integer, Integer>(); … … 40 36 public BASEFileAssaySection(BASEFileSection bfs) throws BASEFileException 41 37 { 42 if (!bfs.getType().equals("assays")) 38 super(bfs); 39 if (!bfs.isType("assays")) 43 40 { 44 41 throw new BASEFileException("Section must be of type 'assays' to create an assay section."); … … 49 46 this.width = width; 50 47 this.data = new ArrayList<String>(height*width); 51 }52 53 public final int getHeight()54 {55 return height;56 }57 58 public final int getWidth()59 {60 return width;61 48 } 62 49 … … 95 82 return this.findIntOpt("count"); 96 83 } 84 85 @Override 86 public int getDataLineLength() 87 { 88 return getColumns().size(); 89 } 97 90 98 91 } -
trunk/se/lu/onk/BaseFile/src/basefile/BASEFileReader.java
r247 r248 60 60 * @throws FileNotFoundException If the infile cant be found 61 61 */ 62 @Deprecated 62 63 public BASEFileReader(File in) throws FileNotFoundException 63 64 { … … 136 137 */ 137 138 public <R, S> BASEFileSpotSection<R, S> readSpotSection() 138 throws B adFormatException, IOException139 throws BASEFileException, IOException 139 140 { 140 141 while (section != null && !section.isType("spots")) … … 150 151 * @param <S> 151 152 * @return 152 * @throws BadFormatException153 153 * @throws IOException 154 154 * @throws BadSectionException … … 157 157 throws BASEFileException, IOException 158 158 { 159 section = readSection(false); 159 160 while (section != null && !section.isType("assays")) 160 161 { 161 162 section = readSection(false); 163 } 164 if (section == null) 165 { 166 throw new BASEFileException("Couldn't find assays section in file "+this.inFile.getAbsolutePath()); 162 167 } 163 168 return new BASEFileAssaySection(section); -
trunk/se/lu/onk/BaseFile/src/basefile/BASEFileSection.java
r185 r248 23 23 import java.util.ArrayList; 24 24 import java.util.Arrays; 25 import java.util.Collections; 25 26 import java.util.HashMap; 26 27 import java.util.List; 28 import java.util.Map; 27 29 28 30 /** … … 56 58 57 59 /** 60 * The type of this section. 61 */ 62 private String type; 63 64 private long pointer; 65 66 /** 58 67 * Creates a new BASEFileSection. 59 68 */ … … 61 70 { 62 71 startLine = -1; 72 pointer = -1; 63 73 dataStartLine = -1; 64 setHeader("section", ""); 74 type = ""; 75 } 76 77 public BASEFileSection(BASEFileSection bfs) throws BASEFileException 78 { 79 if (bfs == null) 80 { 81 throw new BASEFileException("Can't initiate an assay section with a null section."); 82 } 83 startLine = bfs.getStartLine(); 84 pointer = bfs.getStartPointer(); 85 dataStartLine = bfs.getDataStartLine(); 86 type = bfs.getType(); 87 setHeaders(bfs.getHeaders()); 65 88 } 66 89 … … 224 247 public final String setHeader(Object key, Object value) 225 248 { 226 return headers.put(key.toString(), value.toString()); 249 String ret = ""; 250 if ("section".equals(key)) 251 { 252 ret = this.getType(); 253 this.setType(value.toString()); 254 } 255 else 256 { 257 ret = headers.put(key.toString(), value.toString()); 258 } 259 return ret; 227 260 } 228 261 … … 281 314 return this.headers.get(key.toString()); 282 315 } 316 317 public final Map<String, String> getHeaders() 318 { 319 return Collections.unmodifiableMap(this.headers); 320 } 283 321 284 322 public final String removeHeader(Object key) … … 291 329 } 292 330 293 final boolean setHeaders( HashMap<String, String> headers)331 final boolean setHeaders(Map<String, String> headers) 294 332 { 295 333 if (headers == null) … … 300 338 for (String key : headers.keySet()) 301 339 { 302 this. headers.put(key, headers.get(key));340 this.setHeader(key, headers.get(key)); 303 341 } 304 342 return true; 305 343 } 344 345 public int getColIndex(String header, String col) throws BASEFileException 346 { 347 List<String> l = this.findFieldList(header); 348 if (l == null) throw new BASEFileException("Can't find header "+header); 349 int index = l.indexOf(col); 350 if (index == -1) throw new BASEFileException("Can't find column "+col+" in header "+header); 351 return index; 352 } 306 353 307 354 /** … … 312 359 public final String getType() 313 360 { 314 return headers.get("section"); 315 } 316 317 /** 318 * @param string 319 * @return 361 return type; 362 } 363 364 /** 365 * Checks the type of this section. 366 * 367 * @param string the type to test 368 * @return true if type matches string 320 369 */ 321 370 public final boolean isType(String string) … … 323 372 return getType().equals(string); 324 373 } 374 375 /** 376 * Sets the type of this section. 377 * 378 * @return the new type 379 */ 380 public final void setType(String type) 381 { 382 this.type = type; 383 } 325 384 326 385 public final int getDataStartLine() … … 329 388 } 330 389 390 @Deprecated 331 391 public final void setDataStartLine(int dataStartLine) 332 392 { … … 334 394 } 335 395 396 public final void setStartPointer(long pointer) 397 { 398 this.pointer = pointer; 399 } 400 336 401 public final int getStartLine() 337 402 { 338 403 return startLine; 339 404 } 405 406 public final long getStartPointer() 407 { 408 return pointer; 409 } 340 410 341 411 public final void setStartLine(int startLine) … … 347 417 { 348 418 this.headers.clear(); 349 setHeader("section", "");350 419 startLine = -1; 351 420 dataStartLine = -1; … … 359 428 for (String key : headers.keySet()) 360 429 { 361 if (!key.equals("section")) 362 { 363 ret += key + "\t" + headers.get(key) + "\n"; 364 } 430 ret += key + "\t" + headers.get(key) + "\n"; 365 431 } 366 432 ret += "%"; -
trunk/se/lu/onk/BaseFile/src/basefile/BASEFileSpotSection.java
r247 r248 26 26 import java.util.List; 27 27 28 public class BASEFileSpotSection<R, S> extends BASEFile Section28 public class BASEFileSpotSection<R, S> extends BASEFileDataSection 29 29 { 30 30 31 private final int height;32 private final int width;33 31 private final ArrayList<S> spotData; 34 32 private final ArrayList<R> reporterData; 35 36 public BASEFileSpotSection(BASEFileSection bfs) 33 34 public BASEFileSpotSection(BASEFileSection bfs) throws BASEFileException 37 35 { 38 this.height = bfs.findIntOpt("count"); 39 this.width = bfs.findStringOpts("assayFields").length * bfs.findStringOpts("assays").length + bfs.findStringOpts("columns").length - 1; 36 super(bfs); 37 if (!bfs.isType("spots")) 38 { 39 throw new BASEFileException("Section must be of type 'spots' to create an assay section."); 40 } 41 this.setHeight(bfs.findIntOpt("count")); 42 this.setWidth(bfs.findStringOpts("assayFields").length * bfs.findStringOpts("assays").length + bfs.findStringOpts("columns").length - 1); 40 43 this.spotData = new ArrayList<S>(height*width); 41 44 this.reporterData = new ArrayList<R>(height); … … 45 48 public BASEFileSpotSection(int height, int width) 46 49 { 50 this.setType("spots"); 47 51 this.height = height; 48 52 this.width = width; … … 54 58 public final void setDataMatrix(int height, int width) 55 59 { 56 60 this.height = height; 61 this.width = width; 62 this.spotData.ensureCapacity(height*width); 63 this.reporterData.ensureCapacity(height); 57 64 } 58 65 … … 97 104 i = reporterData.indexOf(reporter) + i; 98 105 return spotData.set(i, spot); 99 100 106 } 101 107 … … 111 117 } 112 118 119 public int getColumnsColIndex(String col) throws BASEFileException 120 { 121 return this.getColIndex("columns", col); 122 } 123 113 124 public List<Integer> getAssaysHeader() 114 125 { … … 116 127 } 117 128 129 public int getAssaysColIndex(String col) throws BASEFileException 130 { 131 return this.getColIndex("assays", col); 132 } 133 118 134 public List<String> getAssayFieldsHeader() 119 135 { 120 136 return this.findFieldList("assayFields"); 137 } 138 139 public int getAssayFieldsColIndex(String col) throws BASEFileException 140 { 141 return this.getColIndex("assayFields", col); 121 142 } 122 143 … … 128 149 public boolean isValid() 129 150 { 130 if (!isType("spots")) return false;131 151 if (getColumnHeader() == null) return false; 132 152 if (getAssayFieldsHeader() == null) return false; 133 153 if (getAssaysHeader() == null) return false; 134 154 return true; 135 }136 137 public final int getHeight()138 {139 return height;140 }141 142 public final int getWidth()143 {144 return width;145 155 } 146 156 … … 174 184 return reporterData.size(); 175 185 } 186 187 @Override 188 public int getDataLineLength() 189 { 190 int length = this.getColumnHeader().size() -1; 191 length += this.getAssayFieldsHeader().size() * this.getAssaysHeader().size(); 192 return length; 193 } 176 194 }
Note: See TracChangeset
for help on using the changeset viewer.