Changeset 554


Ignore:
Timestamp:
Jan 25, 2008, 4:38:19 PM (13 years ago)
Author:
Martin Svensson
Message:

References #89 Illumina items are now created by the installation plug-in but there are still some checks and testings that need to be done befor this plug-in is finished.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/net/sf/basedb/illumina/src/net/sf/basedb/illumina/install/Install.java

    r551 r554  
    2424*/
    2525package net.sf.basedb.illumina.install;
    26 
    27 import java.util.ArrayList;
    28 import java.util.Arrays;
    29 import java.util.Collection;
    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;
    35 import java.util.Set;
    3626
    3727import net.sf.basedb.core.BaseException;
     
    4232import net.sf.basedb.core.Item;
    4333import net.sf.basedb.core.ItemAlreadyExistsException;
     34import net.sf.basedb.core.ItemNotFoundException;
    4435import net.sf.basedb.core.Permission;
    4536import net.sf.basedb.core.Platform;
     
    6152import net.sf.basedb.core.plugin.Request;
    6253import net.sf.basedb.core.plugin.Response;
     54
     55import java.util.ArrayList;
     56import java.util.Arrays;
     57import java.util.Collection;
     58import java.util.Collections;
     59import java.util.EnumSet;
     60import java.util.HashSet;
     61import java.util.Iterator;
     62import java.util.List;
     63import java.util.Set;
    6364
    6465/**
     
    202203        if (installExp2) expressionTypes.add(2);
    203204       
    204         installIlluminaItems(installSnp, expressionTypes, alreadyExistingItem.equals(SKIP_OPTION));
     205        installIlluminaItems(installSnp, expressionTypes, alreadyExistingItem.equals(SKIP_OPTION), progress);
    205206      }
    206207      catch(Throwable ex)
     
    296297    @throws ItemAlreadyExistsException If ignoreInstalledItems = FALSE and one of the
    297298   */
    298   public void installIlluminaItems(boolean installSNP, HashSet<Integer> expressionTypes, boolean ignoreExistingItems)
     299  public void installIlluminaItems(boolean installSNP, HashSet<Integer> expressionTypes, boolean ignoreExistingItems, ProgressReporter progress)
    299300    throws ItemAlreadyExistsException
    300301  {
     
    319320      dc = sc.newDbControl();
    320321 
    321       List<DataFileType> dataFileTypes = new ArrayList<DataFileType>();
    322       dataFileTypes.add(createDataFileType(dc, bgxFileTypeId, "BGX file", Item.ARRAYDESIGN, BGX_FILEYTPE_EXTENSION, ignoreExistingItems));
     322      List<DataFileType> expressionDataFileTypes = new ArrayList<DataFileType>();
     323      DataFileType dft = createDataFileType(dc, bgxFileTypeId, "BGX file", Item.ARRAYDESIGN, BGX_FILEYTPE_EXTENSION, ignoreExistingItems);
     324      dft.setDescription("Illumina BGX file");
     325      expressionDataFileTypes.add(dft);
    323326
    324327      for (int i = 1; i <= largestNumOfStrips; i++ )
    325328      {
    326         String name = "Scandata filetype" + i;       
    327         dataFileTypes.add(createDataFileType(dc, scandataFileTypePrefix + i, name, Item.RAWBIOASSAY, SCANDATA_FILETYPE_EXTENSION, ignoreExistingItems));
     329        String name = "Scandata filetype" + i; 
     330        dft = createDataFileType(dc, scandataFileTypePrefix + i, name, Item.RAWBIOASSAY, SCANDATA_FILETYPE_EXTENSION, ignoreExistingItems);
     331        dft.setDescription("Illumina scandata file");
     332        expressionDataFileTypes.add(dft);
    328333      }
    329334      //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      
     335     
     336      dc.commit();
     337     
     338      dc = sc.newDbControl();
     339      Platform illuminaPlatform = createPlatform(dc, illuminaPlatformExternalId, "Illumina", ignoreExistingItems);
     340           
     341      List<PlatformVariant> platformVariants = new ArrayList<PlatformVariant>();     
     342      String namePrefix = "Illumina expression";
     343      for (int type : expressionTypes)
     344      {
     345        PlatformVariant pfv = createPlatformVariant(dc, expExternalIdPrefix + type, namePrefix + type,
     346            illuminaPlatform, RawDataTypes.getRawDataType("illumina.scandata"), ignoreExistingItems);
     347        pfv.setDescription("Platform variant to use with Illumina expression containing " + type + " strip(s)/array");
     348        pfv.addFileType(DataFileType.getByExternalId(dc, bgxFileTypeId), true);
     349        for (int i = 1; i <= type; i++)
     350        {
     351          pfv.addFileType(DataFileType.getByExternalId(dc, scandataFileTypePrefix+i), true);
     352        }
     353        platformVariants.add(pfv);       
     354      }
     355      if (installSNP)
     356      {
     357        PlatformVariant pfv = createPlatformVariant(dc, snpVariantExternalId, "Illumina SNP", illuminaPlatform, 2, ignoreExistingItems);
     358        pfv.setDescription("Platform variant to be used with Illumina SNP data.");
     359        //TODO Add data file types to the SNP variant.
     360        platformVariants.add(pfv);       
     361      }     
    354362      dc.commit();
    355363    }
     
    393401    try
    394402    {
     403      dft = DataFileType.getByExternalId(dc, externalId);
     404      String message = null;
     405      if (!ignoreExistingItem)
     406      {
     407        throw new ItemAlreadyExistsException(dft.getExternalId());
     408      }
     409      dft = DataFileType.getByExternalId(dc, externalId);
     410      if (!dft.getExtension().equals(extension)) message = dft.getName() + " has invalid extension";
     411      if (dft.getItemType().equals(itemType)) message = dft.getName() + " has invalid item type";
     412      if (message != null) throw new ItemAlreadyExistsException(message);
     413     
     414    }
     415    catch (ItemNotFoundException infe)
     416    {
    395417      dft = DataFileType.getNew(dc, externalId, itemType);
    396418      dc.saveItem(dft);
     
    398420      dft.setExtension(extension);
    399421    }
    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     }
    413422    return dft;
    414423  }
     
    419428    try
    420429    {
     430      platform = Platform.getByExternalId(dc, externalId);
     431      if (!ignoreExistingItem)
     432      {
     433        throw new ItemAlreadyExistsException(platform.getExternalId());
     434      }
     435      //TODO Check that existing platform can be used with the rest of the items.
     436    }
     437    catch (ItemNotFoundException infex)
     438    {
    421439      platform = Platform.getNew(dc, externalId, null);
    422       //TODO More property to set?
    423440      dc.saveItem(platform);
    424441      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       }
    437442    }
    438443    return platform;
     
    442447    Creates variants associated with a raw data type
    443448   */
    444   private PlatformVariant createPlatformVariant(DbControl dc, String extId,
     449  private PlatformVariant createPlatformVariant(DbControl dc, String externalId, String name,
    445450      Platform illuminaPlatform, RawDataType rawDataType, boolean ignoreExistingItem)
    446451  {
     
    448453    try
    449454    {
    450       variant = PlatformVariant.getNew(dc, illuminaPlatform, extId, rawDataType);
    451       dc.saveItem(variant);     
    452     }
    453     catch (ItemAlreadyExistsException iex)
    454     {
     455      variant = PlatformVariant.getByExternalId(dc, externalId);
    455456      if (!ignoreExistingItem)
    456457      {
    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;
     458        throw new ItemAlreadyExistsException(variant.getExternalId());
     459      }
     460      String message = null;
     461      if (variant.isFileOnly()) message = "Platform variant " + variant.getExternalId() + " already exists but is file-only";
     462      if (!variant.getRawDataType().equals(rawDataType)) message = "Platform variant " + variant.getExternalId() + " already exists but has not " + rawDataType.getName() + " as raw data type";
     463      if (!variant.getPlatform().equals(illuminaPlatform)) message = "Platform variant " + variant.getExternalId() + " already exists for another platform.";
     464      if (message != null) throw new ItemAlreadyExistsException(message);
     465     
     466    }
     467    catch (ItemNotFoundException infex)
     468    {
     469      variant = PlatformVariant.getNew(dc, illuminaPlatform, externalId, rawDataType);
     470      dc.saveItem(variant);
     471      variant.setName(name);
     472    }
     473    return variant;
    471474  }
    472475
     
    474477    Creates file-only platform variants
    475478   */
    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;
     479  private PlatformVariant createPlatformVariant(DbControl dc, String externalId,
     480      String name, Platform platform, int channels, boolean ignoreExistingItems)
     481  {
     482    PlatformVariant variant = null;
     483    try
     484    {
     485      variant = PlatformVariant.getByExternalId(dc, externalId);
     486      if (!ignoreExistingItems)
     487      {
     488        throw new ItemAlreadyExistsException(variant.getExternalId());
     489      }
     490      String message = null;
     491      if (!variant.isFileOnly()) message = "Platform variant " + variant.getName() + " exists but is not file-only";
     492      if (!variant.getPlatform().equals(platform)) message = "Platform variant " + variant.getName() + " exists but has not platform: " + platform;
     493      if (variant.getRawDataType().getChannels() != channels) message = "Platform variant " + variant.getName() + " exists but not for " + channels + " data"; 
     494      if (message != null) throw new InvalidDataException (message);
     495    }
     496    catch (ItemNotFoundException infex)
     497    {
     498      variant = PlatformVariant.getNew(dc, platform, externalId, channels);
     499      dc.saveItem(variant);
     500      variant.setName(name);
     501    }
     502    return variant;
    482503  }
    483504}
Note: See TracChangeset for help on using the changeset viewer.