Changeset 551
- Timestamp:
- Jan 24, 2008, 4:52:09 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/net/sf/basedb/illumina/src/net/sf/basedb/illumina/install/Install.java
r546 r551 25 25 package net.sf.basedb.illumina.install; 26 26 27 import java.util.ArrayList; 28 import java.util.Arrays; 29 import java.util.Collection; 27 30 import java.util.Collections; 31 import java.util.EnumSet; 32 import java.util.HashSet; 33 import java.util.Iterator; 34 import java.util.List; 28 35 import java.util.Set; 29 36 30 37 import net.sf.basedb.core.BaseException; 38 import net.sf.basedb.core.BooleanParameterType; 39 import net.sf.basedb.core.DataFileType; 40 import net.sf.basedb.core.DbControl; 41 import net.sf.basedb.core.InvalidDataException; 31 42 import net.sf.basedb.core.Item; 43 import net.sf.basedb.core.ItemAlreadyExistsException; 44 import net.sf.basedb.core.Permission; 45 import net.sf.basedb.core.Platform; 46 import net.sf.basedb.core.PlatformVariant; 32 47 import net.sf.basedb.core.PluginDefinition; 48 import net.sf.basedb.core.PluginParameter; 33 49 import net.sf.basedb.core.ProgressReporter; 50 import net.sf.basedb.core.RawDataType; 51 import net.sf.basedb.core.RawDataTypes; 34 52 import net.sf.basedb.core.RequestInformation; 53 import net.sf.basedb.core.StringParameterType; 35 54 import net.sf.basedb.core.plugin.About; 36 55 import net.sf.basedb.core.plugin.AboutImpl; … … 38 57 import net.sf.basedb.core.plugin.GuiContext; 39 58 import net.sf.basedb.core.plugin.InteractivePlugin; 59 import net.sf.basedb.core.plugin.Permissions; 40 60 import net.sf.basedb.core.plugin.Plugin; 41 61 import net.sf.basedb.core.plugin.Request; … … 48 68 49 69 <ul> 50 <li>Create the <code>Illumina</code> platform with two 51 variants <code>Expression</code> and <code>Snip</code> 70 <li>Create the <code>Illumina</code> platform with three 71 variants <code>Expression1</code>, <code>Expression2</code> 72 and <code>SNP</code>. 52 73 53 74 <li>Register the following data file types: 54 55 <li>Add raw data types 75 <ul> 76 <li>BGX 77 <li>ScanData 78 <li>SNP-files...?? 56 79 57 80 <li>Add reporter annotations … … 64 87 implements InteractivePlugin 65 88 { 66 67 89 private static final About about = new AboutImpl( 68 90 "Illumina plug-ins installer", … … 80 102 private static final Set<GuiContext> guiContexts = 81 103 Collections.singleton(new GuiContext(Item.PLUGINDEFINITION, GuiContext.Type.ITEM)); 82 104 105 private RequestInformation configureJob = null; 106 107 private static final Set<Permissions> permissions = new HashSet<Permissions>(); 108 109 private static final PluginParameter<Boolean> installSnpVariantParameter = new PluginParameter<Boolean> 110 ( 111 "installSnp", 112 "Install SNP variant", 113 "The SNP variant of Illumina should be installed?", 114 new BooleanParameterType(true, true) 115 ); 116 private static final PluginParameter<Boolean> installExp1VariantParameter = new PluginParameter<Boolean> 117 ( 118 "installExp1", 119 "Install Expression1 variant", 120 "The Expression1 variant of Illumina should be installed?", 121 new BooleanParameterType(true, true) 122 ); 123 private static final PluginParameter<Boolean> installExp2VariantParameter = new PluginParameter<Boolean> 124 ( 125 "installExp2", 126 "Install Expression2 variant", 127 "The Expression2 variant of Illumina should be installed?", 128 new BooleanParameterType(true, true) 129 ); 130 131 public static final String SKIP_OPTION = "skip"; 132 public static final String ABORT_OPTION = "abort"; 133 134 private static final String BGX_FILEYTPE_EXTENSION = "bgx"; 135 private static final String SCANDATA_FILETYPE_EXTENSION = ""; 136 private static final String SNP_FILETYPE_EXTENSION = ""; 137 138 private static final PluginParameter<String> alreadyInstalledErrorParameter = new PluginParameter<String>( 139 "alreadyInstalledError", 140 "Platform or any of the selected variants is already installed", 141 "How to situations where the platform or any of the selected variants " + 142 "already exists in the database." + 143 "If not specified, default value will be used.\n\n" + 144 "abort = Abort the installation, nothing will be created.\n" + 145 "skip = Installation of the already existing item will be skipped " + 146 "and the installation tries to proceed with rest of the items.", 147 new StringParameterType(255, SKIP_OPTION, true, 1, 0, 0, 148 Arrays.asList( new String[] { ABORT_OPTION, SKIP_OPTION})) 149 ); 83 150 84 151 public Install() … … 94 161 } 95 162 @Override 163 public Collection<Permissions> getPermissions() 164 { 165 if (permissions.size() == 0) 166 { 167 permissions.add(new Permissions(Item.PLATFORM, null, EnumSet.of(Permission.CREATE))); 168 permissions.add(new Permissions(Item.PLATFORM, null, EnumSet.of(Permission.WRITE))); 169 permissions.add(new Permissions(Item.PLATFORMVARIANT, null, EnumSet.of(Permission.CREATE))); 170 permissions.add(new Permissions(Item.DATAFILETYPE, null, EnumSet.of(Permission.CREATE))); 171 } 172 return permissions; 173 } 174 @Override 96 175 public boolean supportsConfigurations() 97 176 { … … 110 189 { 111 190 String command = request.getCommand(); 112 response.setDone("Nothing has been done! Only testing"); 191 if (command.equals(Request.COMMAND_EXECUTE)) 192 { 193 try 194 { 195 boolean installSnp = (Boolean)job.getValue("installSnp"); 196 boolean installExp1 = (Boolean)job.getValue("installExp1"); 197 boolean installExp2 = (Boolean)job.getValue("installExp2"); 198 String alreadyExistingItem = (String)job.getValue("alreadyInstalledError"); 199 200 HashSet<Integer> expressionTypes = new HashSet<Integer>(); 201 if (installExp1) expressionTypes.add(1); 202 if (installExp2) expressionTypes.add(2); 203 204 installIlluminaItems(installSnp, expressionTypes, alreadyExistingItem.equals(SKIP_OPTION)); 205 } 206 catch(Throwable ex) 207 { 208 response.setError(ex.getMessage(), Arrays.asList(ex)); 209 return; 210 } 211 response.setDone("Illumina items were installed successfully"); 212 } 213 else 214 { 215 response.setError("Unknown command: " + command, null); 216 } 113 217 } 114 218 // ------------------------------------------- … … 141 245 public void configure(GuiContext context, Request request, Response response) 142 246 { 143 response.setDone("Nothing really. Just testing"); 247 String command = request.getCommand(); 248 if (command.equals(Request.COMMAND_CONFIGURE_JOB)) 249 { 250 List<Throwable> errors = validateRequestParameters( 251 getConfigureJobParameters().getParameters(), 252 request); 253 254 if (errors != null) 255 { 256 response.setError(errors.size() + " invalid parameters were found in the request", errors); 257 return; 258 } 259 storeValue(job, request, alreadyInstalledErrorParameter); 260 storeValue(job, request, installExp1VariantParameter); 261 storeValue(job, request, installExp2VariantParameter); 262 storeValue(job, request, installSnpVariantParameter); 263 264 response.setDone("The job configuration is complete."); 265 } 266 else 267 { 268 response.setError("Unknown command: " + command, null); 269 } 144 270 } 145 271 … … 155 281 } 156 282 // ------------------------------------------- 283 284 /** 285 Creates items that are required when working with the Illumina platform in BASE. 286 The items get the following external ids: 287 <ul> 288 289 This method gives options on which platform variants to create and how already 290 existing items should be handled. 291 @param installSNP TRUE if the SNP variant should be created, FALSE otherwise 292 @param expressionTypes A set of numbers. A expression variant will be created for each object in the set 293 and the number itself represent the number of strip(s) in an array of the variant to create. 294 @param ignoreExistingItems TRUE if items already existing should be ignored and the rest should be installed. 295 FALSE if NO items should be created when there is one or more already existing in BASE. 296 @throws ItemAlreadyExistsException If ignoreInstalledItems = FALSE and one of the 297 */ 298 public void installIlluminaItems(boolean installSNP, HashSet<Integer> expressionTypes, boolean ignoreExistingItems) 299 throws ItemAlreadyExistsException 300 { 301 DbControl dc = null; 302 int largestNumOfStrips = 0; 303 //external ids. 304 String illuminaPlatformExternalId = "illumina"; 305 String snpVariantExternalId = "illumina.snp"; 306 String expExternalIdPrefix = "illumina.exp"; 307 String scandataFileTypePrefix = "illlumina.scandata."; 308 String bgxFileTypeId = "illumina.bgx"; 309 310 Iterator<Integer> expressionTypeIterator = expressionTypes.iterator(); 311 while(expressionTypeIterator.hasNext()) 312 { 313 int next = expressionTypeIterator.next(); 314 largestNumOfStrips = largestNumOfStrips < next ? next : largestNumOfStrips; 315 } 316 317 try 318 { 319 dc = sc.newDbControl(); 320 321 List<DataFileType> dataFileTypes = new ArrayList<DataFileType>(); 322 dataFileTypes.add(createDataFileType(dc, bgxFileTypeId, "BGX file", Item.ARRAYDESIGN, BGX_FILEYTPE_EXTENSION, ignoreExistingItems)); 323 324 for (int i = 1; i <= largestNumOfStrips; i++ ) 325 { 326 String name = "Scandata filetype" + i; 327 dataFileTypes.add(createDataFileType(dc, scandataFileTypePrefix + i, name, Item.RAWBIOASSAY, SCANDATA_FILETYPE_EXTENSION, ignoreExistingItems)); 328 } 329 //TODO Create data file type for SNP filer. 330 331 // 332 // Platform illuminaPlatform = createPlatform(dc, illuminaPlatformExternalId, "Illumina", ignoreExistingItems); 333 // 334 // List<PlatformVariant> platformVariants = new ArrayList<PlatformVariant>(); 335 // String namePrefix = "Illumina expression"; 336 // for (int type : expressionTypes) 337 // { 338 // PlatformVariant pfv = createPlatformVariant(dc, expExternalIdPrefix + type, 339 // illuminaPlatform, RawDataTypes.getRawDataType("illumina.scandata"), ignoreExistingItems); 340 // pfv.setName(namePrefix + type); 341 // pfv.setDescription("Platform variant to use with Illumina expression"); 342 // //TODO Add data file types to the expression variants. 343 // platformVariants.add(pfv); 344 // } 345 // if (installSNP) 346 // { 347 // PlatformVariant pfv = createPlatformVariant(dc, snpVariantExternalId, "Illumina SNP", illuminaPlatform, 2, ignoreExistingItems); 348 // pfv.setName("Illumina SNP"); 349 // pfv.setDescription("Platform variant to be used for Illumina SNP data."); 350 // //TODO Add data file types to the SNP variant. 351 // platformVariants.add(pfv); 352 // } 353 354 dc.commit(); 355 } 356 finally 357 { 358 if (dc != null) 359 { 360 dc.close(); 361 } 362 } 363 } 157 364 158 365 private RequestInformation getConfigureJobParameters() 159 366 { 160 return new RequestInformation 161 ( 162 Request.COMMAND_CONFIGURE_JOB, 163 "Select Installation options", 164 about.getDescription(), 165 null 166 ); 167 168 } 169 367 if (configureJob == null) 368 { 369 List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>(); 370 parameters.add(installSnpVariantParameter); 371 parameters.add(installExp1VariantParameter); 372 parameters.add(installExp2VariantParameter); 373 parameters.add(alreadyInstalledErrorParameter); 374 375 configureJob = new RequestInformation 376 ( 377 Request.COMMAND_CONFIGURE_JOB, 378 "Select installation options", 379 "Set which parts to install and " + 380 "how to act if items already exists.", 381 parameters 382 ); 383 } 384 return configureJob; 385 } 386 387 private DataFileType createDataFileType(DbControl dc, String externalId, String name, 388 Item itemType, String extension, boolean ignoreExistingItem) 389 throws ItemAlreadyExistsException 390 { 391 392 DataFileType dft = null; 393 try 394 { 395 dft = DataFileType.getNew(dc, externalId, itemType); 396 dc.saveItem(dft); 397 dft.setName(name); 398 dft.setExtension(extension); 399 } 400 catch (ItemAlreadyExistsException iex) 401 { 402 if (!ignoreExistingItem) 403 { 404 throw iex; 405 } 406 else 407 { 408 dft = DataFileType.getByExternalId(dc, externalId); 409 if (dft.getExtension() != extension) throw new InvalidDataException(dft.getName() + " has invalid extension"); 410 if (dft.getItemType() != itemType) throw new InvalidDataException(dft.getName() + " has invalid item type"); 411 } 412 } 413 return dft; 414 } 415 416 private Platform createPlatform(DbControl dc, String externalId, String name, boolean ignoreExistingItem) 417 { 418 Platform platform = null; 419 try 420 { 421 platform = Platform.getNew(dc, externalId, null); 422 //TODO More property to set? 423 dc.saveItem(platform); 424 platform.setName(name); 425 } 426 catch (ItemAlreadyExistsException iex) 427 { 428 if (!ignoreExistingItem) 429 { 430 throw iex; 431 } 432 else 433 { 434 platform = Platform.getByExternalId(dc, externalId); 435 //TODO Check that existing platform can be used with the rest of the items. 436 } 437 } 438 return platform; 439 } 440 441 /* 442 Creates variants associated with a raw data type 443 */ 444 private PlatformVariant createPlatformVariant(DbControl dc, String extId, 445 Platform illuminaPlatform, RawDataType rawDataType, boolean ignoreExistingItem) 446 { 447 PlatformVariant variant = null; 448 try 449 { 450 variant = PlatformVariant.getNew(dc, illuminaPlatform, extId, rawDataType); 451 dc.saveItem(variant); 452 } 453 catch (ItemAlreadyExistsException iex) 454 { 455 if (!ignoreExistingItem) 456 { 457 throw iex; 458 } 459 else 460 { 461 variant = PlatformVariant.getByExternalId(dc, extId); 462 if (variant.isFileOnly()) 463 throw new InvalidDataException ("Platform variant " + variant.getName() + " exists but is not file-only"); 464 if (!variant.getRawDataType().equals(rawDataType)) 465 throw new InvalidDataException ("Platform variant " + variant.getName() + " exists but has not raw data type: " + rawDataType); 466 if (!variant.getPlatform().equals(illuminaPlatform)) 467 throw new InvalidDataException ("Platform variant " + variant.getName() + " exists but has not platform: " + illuminaPlatform); 468 } 469 } 470 return null; 471 } 472 473 /* 474 Creates file-only platform variants 475 */ 476 private PlatformVariant createPlatformVariant(DbControl dc, 477 String snpVariantExternalId, String name, Platform illuminaPlatform, 478 int channels, boolean ignoreExistingItems) 479 { 480 // TODO Auto-generated method stub 481 return null; 482 } 170 483 } 171 172 173
Note: See TracChangeset
for help on using the changeset viewer.