Changeset 3807


Ignore:
Timestamp:
Oct 5, 2007, 3:36:13 PM (16 years ago)
Author:
Nicklas Nordborg
Message:

References #721: Most things for attaching files to rw bioassays are now in place.

Location:
branches/filedb
Files:
1 added
25 edited

Legend:

Unmodified
Added
Removed
  • branches/filedb/config/dist/raw-data-types.xml

    r3675 r3807  
    649649    </intensity-formula>
    650650  </raw-data-type>
    651  
    652   <raw-data-type
    653     id="affymetrix"
    654     channels="1"
    655     name="Affymetrix"
    656     storage="file"
    657     >
    658   </raw-data-type>
    659  
     651
    660652  <raw-data-type
    661653    id="agilent"
  • branches/filedb/src/core/net/sf/basedb/core/Affymetrix.java

    r3804 r3807  
    2727import net.sf.basedb.core.data.ReporterData;
    2828import net.sf.basedb.core.filehandler.CdfFileHandler;
     29import net.sf.basedb.core.filehandler.CelFileHandler;
    2930import affymetrix.fusion.cdf.FusionCDFData;
    3031import affymetrix.fusion.cel.FusionCELData;
     
    162163      raw data type
    163164    @throws BaseException If there is another error
    164     @deprecated
     165    @deprecated Use {@link FileStoreUtil#setDataFile(DbControl, FileStoreEnabled, String, File)}
     166      instead with {@link DataFileType#AFFYMETRIX_CEL} as the file
     167      type
    165168  */
    166169  public static void setCelFile(RawBioAssay rawBioAssay, File file)
    167170    throws PermissionDeniedException, InvalidDataException, BaseException
    168171  {
    169     // Validate raw bioassay
    170172    if (rawBioAssay == null) throw new InvalidUseOfNullException("rawBioAssay");
    171     if (!rawBioAssay.getRawDataType().isAffymetrix())
    172     {
    173       throw new InvalidDataException("Raw data type for " + rawBioAssay.getName() +
    174         " is not an Affymetrix raw data type");
    175     }
    176173    rawBioAssay.checkPermission(Permission.WRITE);
    177  
     174
     175    if (!rawBioAssay.isPlatform(Platform.AFFYMETRIX))
     176    {
     177      throw new InvalidDataException("Raw bioassay isn't an Affymetrix chip: " + rawBioAssay.getName());
     178    }
    178179    DbControl dc = rawBioAssay.getDbControl();
    179     if (file != null)
    180     {
    181       // Validate array design
    182       ArrayDesign design = rawBioAssay.getArrayDesign();
    183       if (design == null)
    184       {
    185         throw new InvalidDataException("Raw bioassay " + rawBioAssay.getName() +
    186           " must have an array design to set CEL file");
    187       }
    188       if (!design.isPlatform(Platform.AFFYMETRIX))
    189       {
    190         throw new InvalidDataException("The array design " + design.getName() +
    191           " is not an Affymterix design");
    192       }
    193  
    194       // Verify that CEL chip type match CDF type
    195       FusionCELData cel = loadCelFile(file);
    196       File cdfFile = getCdfFile(design);
    197       FusionCDFData cdf = loadCdfFile(cdfFile);
    198       validateCelAndCdf(cel, cdf, cdfFile.getName());
    199      
    200       file.checkPermission(Permission.USE);
    201       AnyToAny ata = AnyToAny.getNewOrExisting(dc, rawBioAssay, CEL_LINK_NAME, file, true);
    202       if (!ata.isInDatabase()) dc.saveItem(ata);
    203      
    204       // Set headers
    205       setHeader(rawBioAssay, "Algorithm", cel.getAlg());
    206       for (int i = 0; i < cel.getNumberAlgorithmParameters(); ++i)
    207       {
    208         String name = cel.getAlgorithmParameterTag(i);
    209         setHeader(rawBioAssay, "Algorithm parameter: " + name, cel.getAlgorithmParameter(name));
    210       }
    211       setHeader(rawBioAssay, "Dat header", cel.getDatHeader());
    212       setHeader(rawBioAssay, "Chip type", cel.getChipType());
    213      
    214       // Set number of spots
    215       rawBioAssay.getData().setHasData(true);
    216       rawBioAssay.getData().setSpots(cel.getCells());
    217      
    218     }
    219     else
    220     {
    221       AnyToAny.unlinkFrom(dc, rawBioAssay, CEL_LINK_NAME);
    222       rawBioAssay.getData().setHasData(false);
    223       rawBioAssay.getData().setSpots(0);
    224     }
    225   }
    226  
    227   private static void setHeader(RawBioAssay rba, String name, String value)
    228   {
    229     if (name == null || value == null) return;
    230     rba.setHeader(name, value);
     180    FileStoreUtil.setDataFile(dc, rawBioAssay, DataFileType.AFFYMETRIX_CEL, file);
     181    if (file != null) rawBioAssay.getFileSet().validate(dc, true);
    231182  }
    232183 
     
    349300    @throws InvalidDataException If the file is not a CEL file
    350301    @since 2.4
     302    @deprecated Use {@link CdfFileHandler#loadCdfFile(File)} instead
    351303  */
    352304  public static FusionCELData loadCelFile(File celFile)
    353305    throws InvalidDataException
    354306  {
    355     if (celFile == null) throw new InvalidUseOfNullException("celFile");
    356     if (celFile.getLocation() != Location.PRIMARY)
    357     {
    358       throw new ItemNotFoundException("File data is not online for file '" +
    359           celFile.getName() + "'; location=" + celFile.getLocation());
    360     }
    361     FusionCELData cel = new FusionCELData();
    362     cel.setFileName(celFile.getName());
    363     cel.setInputStream(celFile.getDownloadStream(0));
    364     if (!cel.readHeader())
    365     {
    366       throw new InvalidDataException("Could not read CEL file '" +
    367           celFile.getPath()+"': " + cel.getError());
    368     }
    369     return cel;
     307    return new CelFileHandler().loadCelFile(celFile);
    370308  }
    371309 
  • branches/filedb/src/core/net/sf/basedb/core/Application.java

    r3783 r3807  
    468468        Keyring.init();
    469469        HibernateUtil.testTransactions();
     470        RawDataTypes.initPlatforms();
    470471 
    471472        // Adding a task that cleans the session control cache at regular intervale
  • branches/filedb/src/core/net/sf/basedb/core/ArrayDesign.java

    r3804 r3807  
    299299      write permission
    300300    @throws InvalidDataException If platform is null
     301    @since 2.5
    301302  */
    302303  public void setPlatform(Platform platform)
     
    316317    @throws PermissionDeniedException If the logged in user doesn't have
    317318      write permission
     319    @since 2.5
    318320  */
    319321  public void setVariant(PlatformVariant variant)
     
    337339    @return TRUE if either the variant of platform matches the
    338340      external ID
     341    @since 2.5
    339342  */
    340343  public boolean isPlatform(String externalId)
     
    353356    If the array design has a platform variant, the setting from the
    354357    variant is returned, otherwise the setting from the platform.
    355     @return TRUE if this array design use a file-only platform
     358    @return TRUE if this array design use a file-only variant / platform
     359    @since 2.5
    356360  */
    357361  public boolean isFileOnlyPlatform()
     
    709713  }
    710714 
     715  /**
     716    Set the number of features that are stored in files.
     717    @param numFeatures The number of features
     718    @since 2.5
     719  */
    711720  public void setNumFileFeatures(int numFeatures)
    712721  {
  • branches/filedb/src/core/net/sf/basedb/core/FileSet.java

    r3804 r3807  
    538538      boolean ignore = false;
    539539      boolean isValid = true;
     540      boolean invalidRelation = false;
    540541      String errorMessage = null;
    541542      if (handler.isValidator)
     
    547548        catch (Throwable t)
    548549        {
     550          invalidRelation = t instanceof InvalidRelationException;
    549551          ignore = t instanceof PermissionDeniedException;
    550552          errors.add(t);
    551553          isValid = false;
    552554          errorMessage = t.getMessage();
    553           if (!ignore) handler.resetMetadata(dc);
     555          if (!ignore && !invalidRelation) handler.resetMetadata(dc);
    554556        }
    555557      }
    556       if (extractMetadata && handler.isMetadataReader && isValid)
     558      if (extractMetadata && handler.isMetadataReader && (isValid || invalidRelation))
    557559      {
    558560        try
  • branches/filedb/src/core/net/sf/basedb/core/Platform.java

    r3801 r3807  
    378378    if (isFileOnly())
    379379    {
    380       // TODO - autogenerate a raw data type in a proper way
    381       rdt = new RawDataType(getExternalId(), getName(), getDescription(), getData().getChannels(),
    382         "file", null, null, null);
     380      rdt = RawDataTypes.getRawDataType("platform." + getExternalId());
    383381    }
    384382    else
  • branches/filedb/src/core/net/sf/basedb/core/PlatformVariant.java

    r3800 r3807  
    408408    if (isFileOnly())
    409409    {
    410       // TODO - autogenerate a raw data type
    411       rdt = new RawDataType(getExternalId(), getName(), getDescription(), getData().getChannels(),
    412           "file", null, null, null);
     410      rdt = RawDataTypes.getRawDataType("variant." + getExternalId());
    413411    }
    414412    else
  • branches/filedb/src/core/net/sf/basedb/core/RawBioAssay.java

    r3804 r3807  
    102102    throws BaseException
    103103  {
    104     Platform generic = Platform.getById(dc, SystemItems.getId(Platform.GENERIC));
     104    Platform generic = Platform.getByExternalId(dc,
     105      rawDataType.isAffymetrix() ? Platform.AFFYMETRIX : Platform.GENERIC);
    105106    return getNew(dc, generic, rawDataType);
    106107  }
     
    116117  }
    117118 
    118   /*
    119119  public static RawBioAssay getNew(DbControl dc, PlatformVariant variant, RawDataType rawDataType)
    120120  {
    121    
    122   }
    123   */
     121    RawBioAssay rba = dc.newItem(RawBioAssay.class);
     122    rba.setVariant(variant);
     123    RawDataType variantRdt = variant.getRawDataType();
     124    rba.setRawDataType(variantRdt != null ? variantRdt : rawDataType);
     125    rba.setName("New raw bioassay");
     126    return rba;
     127 
     128  }
    124129
    125130  /**
     
    349354  // -------------------------------------------
    350355
     356  /**
     357    Set the platform of the raw bioassay. This method will set the variant
     358    to null. Use {@link #setVariant(PlatformVariant)} if you want to
     359    set a specific variant.
     360    @param platform The new platform
     361    @throws PermissionDeniedException If the logged in user doesn't have
     362      write permission
     363    @throws InvalidDataException If platform is null
     364    @since 2.5
     365  */
    351366  public void setPlatform(Platform platform)
    352367  {
     
    357372  }
    358373 
     374  /**
     375    Set the platform and variant of the raw bioassay. This method will
     376    automatically set the platform to {@link PlatformVariant#getPlatform()}.
     377 
     378    @param variant The new platform variant, or null to remove
     379      the variant and keep the platform as it is
     380    @throws PermissionDeniedException If the logged in user doesn't have
     381      write permission
     382    @since 2.5
     383  */
    359384  public void setVariant(PlatformVariant variant)
    360385  {
     
    370395    }
    371396  }
     397 
     398  /**
     399    Check if the platform/variant of this raw bioassay has the
     400    given external ID.
     401    @param externalId The external ID to match
     402    @return TRUE if either the variant of platform matches the
     403      external ID
     404    @since 2.5
     405  */
     406  public boolean isPlatform(String externalId)
     407  {
     408    if (externalId == null) return false;
     409    if (externalId.equals(getData().getPlatform().getExternalId())) return true;
     410    if (getData().getVariant() != null)
     411    {
     412      if (externalId.equals(getData().getVariant().getExternalId())) return true;
     413    }
     414    return false;
     415  }
     416
     417  /**
     418    Check if this raw bioassay uses a file-only platform or variant.
     419    If the raw bioassay has a platform variant, the setting from the
     420    variant is returned, otherwise the setting from the platform.
     421    @return TRUE if this raw bioassay use a file-only variant / platform
     422    @since 2.5
     423  */
     424  public boolean isFileOnlyPlatform()
     425  {
     426    if (getData().getVariant() != null)
     427    {
     428      return getData().getVariant().isFileOnly();
     429    }
     430    else
     431    {
     432      return getData().getPlatform().isFileOnly();
     433    }
     434  }
    372435 
    373436  /**
     
    393456    checkPermission(Permission.WRITE);
    394457    if (rawDataType == null) throw new InvalidUseOfNullException("rawDataType");
    395     if (getData().getSpots() > 0)
     458    if (getData().getNumDbSpots() > 0)
    396459    {
    397460      throw new PermissionDeniedException("Not allowed to change the raw data type after raw data has been added");
     
    523586    checkPermission(Permission.WRITE);
    524587    if (arrayDesign != null) arrayDesign.checkPermission(Permission.USE);
    525     if (getData().getSpots() > 0)
     588    if (getData().getNumDbSpots() > 0)
    526589    {
    527590      throw new PermissionDeniedException("Not allowed to change the array design after raw data has been added");
     
    550613    checkPermission(Permission.WRITE);
    551614    if (arrayDesign != null) arrayDesign.checkPermission(Permission.USE);
    552     if (getData().getSpots() > 0 && arrayDesign != null)
    553     {
    554       // No need to validate if there is no change
    555       if (arrayDesign.getData().equals(getData().getArrayDesign())) return;
    556  
    557       if (getRawDataType().isAffymetrix())
    558       {
    559         // Verify CEL and CDF files
    560         Affymetrix.validateCelAndCdf(this, arrayDesign, false);
    561       }
    562       else if (getRawDataType().isStoredInDb())
    563       {
    564         validateFeatures(getDbControl(), arrayDesign, true, progress);
    565       }
     615   
     616    // No need to validate if there is no change
     617    if (arrayDesign == null && getData().getArrayDesign() == null) return;
     618    if (arrayDesign != null && arrayDesign.getData().equals(getData().getArrayDesign())) return;
     619   
     620    // Re-validate files
     621    if (hasFileSet()) getFileSet().validate(getDbControl(), true);
     622   
     623    // Re-validate data in database if we already have db data
     624    if (getData().getNumDbSpots() > 0 && arrayDesign != null)
     625    {
     626      validateFeatures(getDbControl(), arrayDesign, true, progress);
    566627    }
    567628    getData().setArrayDesign(arrayDesign == null ? null : arrayDesign.getData());
     
    581642    raw bioassay.
    582643    @return The number of spots
     644    @deprecated Use {@link #getNumDbSpots()} or {@link #getNumFileSpots()}
     645      instead. This method first checks the database and if not 0, it
     646      returns that value, otherwise it returns the number of file spots
    583647  */
    584648  public int getSpots()
    585649  {
    586     return getData().getSpots();
    587   }
     650    int dbSpots = getNumDbSpots();
     651    return dbSpots > 0 ? dbSpots : getNumFileSpots();
     652  }
     653 
     654  /**
     655    Get the number of spots on this raw bioassay that are
     656    stored in the database.
     657    @return The number of spots in the database
     658    @since 2.5
     659  */
     660  public int getNumDbSpots()
     661  {
     662    return getData().getNumDbSpots();
     663  }
     664 
     665  /**
     666    Get the number of spots on this raw bioassay that are
     667    stored inside files.
     668    @return The number of spots in files
     669    @since 2.5
     670  */
     671  public int getNumFileSpots()
     672  {
     673    return getData().getNumFileSpots();
     674  }
     675 
     676  /**
     677    Set the number of spots that are stored in files.
     678    @param numSpots The number of spots
     679    @since 2.5
     680  */
     681  public void setNumFileSpots(int numSpots)
     682  {
     683    checkPermission(Permission.WRITE);
     684    getData().setNumFileSpots(numSpots);
     685    getData().setHasData(numSpots > 0 || getNumDbSpots() > 0);
     686  }
     687 
    588688 
    589689  /**
     
    656756  {
    657757    checkPermission(Permission.WRITE);
    658     if (getData().getSpots() > 0)
    659     {
    660       throw new PermissionDeniedException("Not allowed to change the headers after raw data has been added");
    661     }
    662758    if (name == null) throw new InvalidUseOfNullException("header.name");
    663759    if (name.length() > MAX_HEADER_NAME_LENGTH)
     
    672768    getData().getHeaders().put(name, value);
    673769  }
     770 
     771  public void removeHeaders()
     772  {
     773    checkPermission(Permission.WRITE);
     774    getData().getHeaders().clear();
     775  }
     776
     777  public void removeHeader(String name)
     778  {
     779    checkPermission(Permission.WRITE);
     780    getData().getHeaders().remove(name);
     781  }
     782
    674783  /**
    675784    Get the names of all raw data headers. The set is sorted by name.
     
    819928  private void validateFeatures(DbControl dc, ArrayDesign design, boolean update, ProgressReporter progress)
    820929  {
    821     if (design.isAffyChip())
    822     {
    823       throw new InvalidDataException("The array design is an Affymetrix chip: " + design.getName());
    824     }
    825930    if (design.hasFeatures())
    826931    {
  • branches/filedb/src/core/net/sf/basedb/core/RawDataBatcher.java

    r3783 r3807  
    306306    throws BaseException
    307307  {
    308     rawBioAssayData.setSpots(rawBioAssayData.getSpots() + getTotalInsertCount());
     308    rawBioAssayData.setNumDbSpots(rawBioAssayData.getNumDbSpots() + getTotalInsertCount());
    309309    rawBioAssayData.setBytes(rawBioAssayData.getBytes() + bytes);
    310     rawBioAssayData.setHasData(rawBioAssayData.getSpots() > 0);
     310    rawBioAssayData.setHasData(rawBioAssayData.getNumDbSpots() > 0);
    311311    if (preloaded != null) preloaded.clear();
    312312  }
     
    441441      Statement s = HibernateUtil.getConnection(getDbControl().getHibernateSession()).createStatement();
    442442      s.executeUpdate(sql);
    443       rawBioAssayData.setSpots(0);
     443      rawBioAssayData.setNumDbSpots(0);
    444444      rawBioAssayData.setBytes(0);
    445       rawBioAssayData.setHasData(false);
     445      rawBioAssayData.setHasData(rawBioAssayData.getNumFileSpots() > 0);
    446446    }
    447447    catch (SQLException ex)
  • branches/filedb/src/core/net/sf/basedb/core/RawDataType.java

    r3783 r3807  
    2929import java.util.Collections;
    3030
     31import net.sf.basedb.core.data.PlatformData;
     32import net.sf.basedb.core.data.PlatformVariantData;
    3133import net.sf.basedb.core.data.RawData;
    3234
     
    4850{
    4951
    50   private final boolean isAffymetrix;
    5152  private final String id;
    5253  private final String name;
    5354  private final String description;
    54   private final String storage;
    55   private final boolean isStoredInDb;
     55  private final boolean fileOnly;
     56  private final boolean isAffymetrix;
    5657  private final int channels;
    57   private final String table;
    58   private final List<RawDataProperty> properties;
    59   private final Map<String, RawDataProperty> namedProperties;
    60   private final List<IntensityFormula> formulas;
    61   private final Map<String, IntensityFormula> namedFormulas;
    62  
    63   private final RealTable realTable;
     58  private String table;
     59  private RealTable realTable;
     60  private List<RawDataProperty> properties;
     61  private Map<String, RawDataProperty> namedProperties;
     62  private List<IntensityFormula> formulas;
     63  private Map<String, IntensityFormula> namedFormulas;
     64 
    6465
    6566  /**
     
    6768    See the getter methods for a description of the parameters
    6869  */
    69   RawDataType(String id, String name, String description, int channels, String storage,
     70  RawDataType(String id, String name, String description, int channels,
     71    String table, List<RawDataProperty> properties, List<IntensityFormula> formulas)
     72  {
     73    this(id, name, description, channels, false, false, table, properties, formulas);
     74  }
     75 
     76  RawDataType(PlatformData platform)
     77  {
     78    this("platform." + platform.getExternalId(), platform.getName(),
     79      platform.getDescription(), platform.getChannels(), true,
     80      Platform.AFFYMETRIX.equals(platform.getExternalId()),
     81      null, null, null);
     82  }
     83
     84  RawDataType(PlatformVariantData variant)
     85  {
     86    this("variant." + variant.getExternalId(), variant.getName(),
     87        variant.getDescription(), variant.getChannels(), true,
     88        Platform.AFFYMETRIX.equals(variant.getPlatform().getExternalId()),
     89        null, null, null);   
     90  }
     91 
     92  private RawDataType(String id, String name, String description, int channels,
     93    boolean fileOnly, boolean isAffymetrix,
    7094    String table, List<RawDataProperty> properties, List<IntensityFormula> formulas)
    7195  {
     
    7397    this.name = name;
    7498    this.description = description;
    75     this.storage = storage;
    7699    this.channels = channels;
    77     this.isStoredInDb = "database".equals(storage);
    78     this.table = isStoredInDb ? table : null;
    79     this.properties = properties == null ? null : Collections.unmodifiableList(properties);
    80     this.formulas = formulas;
    81     this.realTable = isStoredInDb ? new RealTable(table, "raw") : null;
     100    this.fileOnly = fileOnly;
     101    this.isAffymetrix = isAffymetrix;
    82102   
    83     // This is an ugly hack to support affymetrix data
    84     this.isAffymetrix = "affymetrix".equals(id);
    85    
    86     if (isStoredInDb && table == null)
     103    // For database raw data types
     104    if (!fileOnly)
    87105    {
    88       throw new InvalidDataException("No table specified for raw data type: " + id);
     106      if (table == null)
     107      {
     108        throw new InvalidDataException("No table specified for raw data type: " + id);
     109      }
     110      this.table = table;
     111      this.realTable = new RealTable(table, "raw");
     112     
     113      // Extended properties (=columns) of the table
     114      if (properties == null)
     115      {
     116        this.properties = null;
     117      }
     118      else
     119      {
     120        this.properties = Collections.unmodifiableList(properties);
     121        this.namedProperties = new HashMap<String, RawDataProperty>();
     122        for (RawDataProperty property : properties)
     123        {
     124          if (namedProperties.put(property.getName(), property) != null)
     125          {
     126            throw new BaseException("RawDataProperty[name="+property.getName()+"] is already defined for raw data type: "+name);
     127          }
     128        }
     129      }
     130     
     131      // Intensity formulas
     132      this.formulas = formulas;
     133      if (formulas != null)
     134      {
     135        this.namedFormulas = new HashMap<String, IntensityFormula>();
     136        for (IntensityFormula formula : formulas)
     137        {
     138          if (namedFormulas.put(formula.getName(), formula) != null)
     139          {
     140            throw new BaseException("IntensityFormula[name="+formula.getName()+"] is already defined for raw data type: "+name);
     141          }
     142        }
     143      }
    89144    }
    90    
    91     this.namedProperties = new HashMap<String, RawDataProperty>(
    92         properties == null ? 0 : properties.size());
    93     if (properties != null)
    94     {
    95       for (RawDataProperty property : properties)
    96       {
    97         if (namedProperties.put(property.getName(), property) != null)
    98         {
    99           throw new BaseException("RawDataProperty[name="+property.getName()+"] is already defined for raw data type: "+name);
    100         }
    101       }
    102     }
    103    
    104     this.namedFormulas = new HashMap<String, IntensityFormula>(
    105         formulas == null ? 0 : formulas.size());
    106     if (formulas != null)
    107     {
    108       for (IntensityFormula formula : formulas)
    109       {
    110         if (namedFormulas.put(formula.getName(), formula) != null)
    111         {
    112           throw new BaseException("IntensityFormula[name="+formula.getName()+"] is already defined for raw data type: "+name);
    113         }
    114       }
    115     }
    116   }
    117 
     145  }
     146 
    118147  /**
    119148    Get the id of this raw data type. This value is the same as the
     
    129158  /**
    130159    If this raw data type is the Affymetrix raw data type.
     160    @deprecated Use --- instead
    131161  */
    132162  public boolean isAffymetrix()
     
    177207
    178208  /**
    179     If the raw data of this raw data type is stored in the database
     209    If the raw data of this raw data type can be stored in the database
    180210    or not.
    181211    @see #getTableName()
     
    183213  public boolean isStoredInDb()
    184214  {
    185     return isStoredInDb;
     215    return !fileOnly;
    186216  }
    187217 
     
    213243 
    214244  /**
    215     Get a list of {@link RawDataProperty}s with definitions for the
     245    Get a list of {@link RawDataProperty}:s with definitions for the
    216246    extra properties that has been defined for this raw data type.
    217247
  • branches/filedb/src/core/net/sf/basedb/core/RawDataTypes.java

    r3679 r3807  
    2626package net.sf.basedb.core;
    2727
     28import net.sf.basedb.core.data.PlatformData;
     29import net.sf.basedb.core.data.PlatformVariantData;
    2830import net.sf.basedb.core.dbengine.DbEngine;
    2931import net.sf.basedb.util.Values;
    3032import net.sf.basedb.util.XMLUtil;
    3133
     34import java.util.HashMap;
    3235import java.util.HashSet;
    3336import java.util.List;
     
    6669  private static Map<String, RawDataType> rawDataTypes = null;
    6770
     71  private static Map<String, RawDataType> platformTypes = null;
     72 
    6873  /**
    6974    The DTD which is used to validate the XML file.
     
    8691  }
    8792 
     93  static synchronized void initPlatforms()
     94  {
     95    org.hibernate.Session session = null;
     96    org.hibernate.Transaction tx = null;
     97   
     98    try
     99    {
     100      platformTypes = new HashMap<String, RawDataType>();
     101      session = HibernateUtil.newSession();
     102      tx = HibernateUtil.newTransaction(session);
     103     
     104      org.hibernate.Query query = HibernateUtil.createQuery(session,
     105        "FROM PlatformData pfd WHERE pfd.fileOnly = true");
     106      for (PlatformData platform : HibernateUtil.loadList(PlatformData.class, query))
     107      {
     108        RawDataType rdt = new RawDataType(platform);
     109        platformTypes.put(rdt.getId(), rdt);
     110      }
     111     
     112      query = HibernateUtil.createQuery(session,
     113        "FROM PlatformVariantData pfv WHERE pfv.fileOnly = true");
     114      for (PlatformVariantData variant : HibernateUtil.loadList(PlatformVariantData.class, query))
     115      {
     116        RawDataType rdt = new RawDataType(variant);
     117        platformTypes.put(rdt.getId(), rdt);
     118      }
     119
     120    }
     121    finally
     122    {
     123      if (tx != null) HibernateUtil.commit(tx);
     124      if (session != null) HibernateUtil.close(session);
     125    }
     126  }
     127 
    88128  /**
    89129    Unload all settings.
     
    94134    if (rawDataTypes != null) rawDataTypes.clear();
    95135    rawDataTypes = null;
     136    if (platformTypes != null) platformTypes.clear();
     137    platformTypes = null;
    96138  }
    97139
     
    136178  public static RawDataType getRawDataType(String id)
    137179  {
    138     return id == null ? null : rawDataTypes.get(id);
     180    if (id == null) return null;
     181    if (id.startsWith("platform."))
     182    {
     183      return getPlatformRawDataType(id);
     184    }
     185    else if (id.startsWith("variant."))
     186    {
     187      return getVariantRawDataType(id);
     188    }
     189    else
     190    {
     191      return rawDataTypes.get(id);
     192    }
     193  }
     194 
     195 
     196  private static RawDataType getPlatformRawDataType(String id)
     197  {
     198    RawDataType rdt = platformTypes.get(id);
     199    if (rdt != null) return rdt;
     200   
     201    org.hibernate.Session session = null;
     202    org.hibernate.Transaction tx = null;
     203    try
     204    {
     205      org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session,
     206        "GET_PLATFORM_FOR_EXTERNAL_ID");
     207      query.setString("externalId", id.substring(9));
     208      PlatformData platform = HibernateUtil.loadData(PlatformData.class, query);
     209      if (platform == null || !platform.isFileOnly()) return null;
     210      rdt = new RawDataType(platform);
     211      platformTypes.put(id, rdt);
     212    }
     213    finally
     214    {
     215      if (tx != null) HibernateUtil.commit(tx);
     216      if (session != null) HibernateUtil.close(session);
     217    }
     218    return rdt;
     219  }
     220 
     221  private static RawDataType getVariantRawDataType(String id)
     222  {
     223    RawDataType rdt = platformTypes.get(id);
     224    if (rdt != null) return rdt;
     225   
     226    org.hibernate.Session session = null;
     227    org.hibernate.Transaction tx = null;
     228    try
     229    {
     230      org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session,
     231        "GET_PLATFORMVARIANT_FOR_EXTERNAL_ID");
     232      query.setString("externalId", id.substring(9));
     233      PlatformVariantData variant = HibernateUtil.loadData(PlatformVariantData.class, query);
     234      if (variant == null || !variant.isFileOnly()) return null;
     235      rdt = new RawDataType(variant);
     236      platformTypes.put(id, rdt);
     237    }
     238    finally
     239    {
     240      if (tx != null) HibernateUtil.commit(tx);
     241      if (session != null) HibernateUtil.close(session);
     242    }
     243    return rdt;
    139244  }
    140245
     
    182287        usedNames.add("table:" + table);
    183288      }
     289      else
     290      {
     291        throw new ConfigurationException("Attribute storage='" + storage +
     292          "' is no longer supported. Please remove declaration for <rawdatatype id='" + id +
     293          "'> from " + Application.getRawDataTypesFile());
     294      }
    184295      if (channels <= 0)
    185296      {
     
    189300      List<RawDataProperty> properties = loadProperties(el, channels);
    190301      List<IntensityFormula> formulas = loadIntensityFormulas(el, channels);
    191       RawDataType rdt = new RawDataType(id, name, description, channels, storage, table, properties, formulas);
     302      RawDataType rdt = new RawDataType(id, name, description, channels,
     303          table, properties, formulas);
    192304      rawDataTypes.put(id, rdt);
    193305    }
  • branches/filedb/src/core/net/sf/basedb/core/Update.java

    r3804 r3807  
    17631763      HibernateUtil.executeUpdate(query);
    17641764
     1765      // Change filter with 'spots' to 'numDbSpots'
     1766      query = HibernateUtil.getPredefinedSQLQuery(session,
     1767          "UPDATE_PROPERTY_FILTER");
     1768      /*
     1769        UPDATE PropertyFilters pf
     1770        SET pf.property = :newProperty
     1771        WHERE pf.property = :oldProperty
     1772       */
     1773      query.setString("oldProperty", "spots");
     1774      query.setString("newProperty", "numDbSpots");
     1775      HibernateUtil.executeUpdate(query);         
     1776     
    17651777      // Add READ permission to PLATFORM and DATAFILETYPE for all plug-ins
    17661778      // working with ARRAYDESIGN or RAWBIOASSAY
  • branches/filedb/src/core/net/sf/basedb/core/data/RawBioAssayData.java

    r3783 r3807  
    8383    Get the platform this raw bioassay uses.
    8484    @since 2.5
    85     @hibernate.many-to-one outer-join="false" update="false"
     85    @hibernate.many-to-one outer-join="false"
    8686    @hibernate.column name="`platform_id`" not-null="true"
    8787  */
     
    9999    Get the platform variant this raw bioassay uses, or null.
    100100    @since 2.5
    101     @hibernate.many-to-one outer-join="false" update="false"
     101    @hibernate.many-to-one outer-join="false"
    102102    @hibernate.column name="`variant_id`"
    103103  */
     
    212212  private int spots;
    213213  /**
    214     The number of data spots in this raw bio assay.
     214    The number of data spots in this raw bio assay, that
     215    are stored in the database.
    215216    @hibernate.property column="`spots`" type="int" not-null="true"
    216   */
    217   public int getSpots()
     217    @since 2.5
     218  */
     219  public int getNumDbSpots()
    218220  {
    219221    return spots;
    220222  }
    221   public void setSpots(int spots)
     223  public void setNumDbSpots(int spots)
    222224  {
    223225    this.spots = spots;
    224226  }
    225227
     228  private int fileSpots;
     229  /**
     230    The number of spots on this raw bioassay that are stored inside
     231    files.
     232    @hibernate.property column="`file_spots`" type="int" not-null="true"
     233    @since 2.5
     234  */
     235  public int getNumFileSpots()
     236  {
     237    return fileSpots;
     238  }
     239  public void setNumFileSpots(int fileSpots)
     240  {
     241    this.fileSpots = fileSpots;
     242  }
     243 
    226244  private long bytes;
    227245  /**
  • branches/filedb/src/core/net/sf/basedb/core/filehandler/AffymetrixFileHandler.java

    r3802 r3807  
    2525
    2626import affymetrix.fusion.cdf.FusionCDFData;
     27import affymetrix.fusion.cel.FusionCELData;
    2728import net.sf.basedb.core.File;
    2829import net.sf.basedb.core.FileStoreEnabled;
     
    9293  }
    9394 
     95  public FusionCELData loadCelFile(File celFile)
     96  {
     97    if (celFile == null) throw new InvalidUseOfNullException("celFile");
     98    if (celFile.getLocation() != Location.PRIMARY)
     99    {
     100      throw new ItemNotFoundException("File data is not online for file '" +
     101          celFile.getName() + "'; location=" + celFile.getLocation());
     102    }
     103    FusionCELData cel = new FusionCELData();
     104    cel.setFileName(celFile.getName());
     105    cel.setInputStream(celFile.getDownloadStream(0));
     106    if (!cel.readHeader())
     107    {
     108      throw new InvalidDataException("Could not read CEL file '" +
     109          celFile.getPath()+"': " + cel.getError());
     110    }
     111    return cel;
     112  }
    94113}
  • branches/filedb/src/core/net/sf/basedb/core/filehandler/CdfFileHandler.java

    r3802 r3807  
    6666    if (!isAffymetrix(design))
    6767    {
    68       throw new InvalidDataException("Array design '" + design +
     68      throw new InvalidDataException("Array design '" + design.getName() +
    6969        "' is not using the Affymetrix platform");
    7070    }
  • branches/filedb/src/core/net/sf/basedb/core/filehandler/CelFileHandler.java

    r3802 r3807  
    2424package net.sf.basedb.core.filehandler;
    2525
     26import affymetrix.fusion.cdf.FusionCDFData;
     27import affymetrix.fusion.cel.FusionCELData;
     28import net.sf.basedb.core.ArrayDesign;
     29import net.sf.basedb.core.DataFileType;
    2630import net.sf.basedb.core.DbControl;
     31import net.sf.basedb.core.File;
     32import net.sf.basedb.core.FileSetMember;
     33import net.sf.basedb.core.FileStoreUtil;
     34import net.sf.basedb.core.InvalidDataException;
     35import net.sf.basedb.core.InvalidRelationException;
     36import net.sf.basedb.core.Platform;
     37import net.sf.basedb.core.RawBioAssay;
     38import net.sf.basedb.core.StringUtil;
    2739
    2840/**
     
    3850  implements DataFileValidator, DataFileMetadataReader
    3951{
     52  private FusionCELData celData;
    4053
    4154  public CelFileHandler()
    4255  {}
    4356 
     57  /*
     58    From the DataFileValidator interface
     59    ----------------------------------------
     60  */
     61  /**
     62    Check that the raw bioassay is using the Affymetrix platform
     63    ({@link Platform#AFFYMETRIX}) and that the file selected
     64    as the CEL file really is a CEL file.
     65  */
    4466  public void validate(DbControl dc)
    4567  {
     68    RawBioAssay rba = (RawBioAssay)getItem();
     69    // Check platform
     70    if (!isAffymetrix(rba))
     71    {
     72      throw new InvalidDataException("Raw bioassay '" + rba.getName() +
     73        "' is not using the Affymetrix platform");
     74    }
     75   
     76    // Get the member for CEL file type
     77    FileSetMember celMember = getMember(DataFileType.AFFYMETRIX_CEL);
     78    if (celMember != null)
     79    {
     80      // Verify CEL file
     81      File celFile = celMember.getFile();
     82      celData = loadCelFile(celFile);
     83    }
     84   
     85    // The CEL file is valid, a failure below will result in InvalidRelationException
     86    try
     87    {
     88      ArrayDesign design = rba.getArrayDesign();
     89      if (design == null)
     90      {
     91        throw new InvalidDataException("Raw bioassay " + rba.getName() +
     92          " has no array design");
     93      }
     94      if (!design.isPlatform(Platform.AFFYMETRIX))
     95      {
     96        throw new InvalidDataException("The array design " + design.getName() +
     97          " is not an Affymterix design");
     98      }
     99 
     100      // Verify that CEL chip type match CDF type
     101      File cdfFile = FileStoreUtil.getDataFile(dc, design, DataFileType.AFFYMETRIX_CDF);
     102      FusionCDFData cdfData = loadCdfFile(cdfFile);
     103      validateCelAndCdf(celData, cdfData, cdfFile.getName());
     104    }
     105    catch (Throwable t)
     106    {
     107      throw new InvalidRelationException(t);
     108    }
    46109   
    47110  }
     111  // -------------------------------------------
    48112 
     113  /*
     114    From the DataFileMetadataReader interface
     115    ----------------------------------------
     116  */
    49117  public void extractMetadata(DbControl dc)
    50118  {
    51    
     119    if (celData == null)
     120    {
     121      FileSetMember celMember = getMember(DataFileType.AFFYMETRIX_CEL);
     122      if (celMember != null) celData = loadCelFile(celMember.getFile());
     123    }
     124    if (celData != null)
     125    {
     126      RawBioAssay rba = (RawBioAssay)getItem();
     127      setHeader(rba, "Algorithm", celData.getAlg());
     128      for (int i = 0; i < celData.getNumberAlgorithmParameters(); ++i)
     129      {
     130        String name = celData.getAlgorithmParameterTag(i);
     131        setHeader(rba, "Algorithm parameter: " + name,
     132            celData.getAlgorithmParameter(name));
     133      }
     134      setHeader(rba, "Dat header", celData.getDatHeader());
     135      setHeader(rba, "Chip type", celData.getChipType());
     136     
     137      // Set number of spots
     138      rba.setNumFileSpots(celData.getCells());
     139    }
    52140  }
    53141 
     142  /**
     143    Reset the number of file spots to 0, and remove all headers.
     144  */
    54145  public void resetMetadata(DbControl dc)
    55146  {
    56    
     147    RawBioAssay rba = (RawBioAssay)getItem();
     148    rba.setNumFileSpots(0);
     149    rba.removeHeaders();
     150  }
     151  // -------------------------------------------
     152
     153  private void setHeader(RawBioAssay rba, String name, String value)
     154  {
     155    if (name == null || value == null) return;
     156    value = StringUtil.trimString(value, RawBioAssay.MAX_HEADER_VALUE_LENGTH);
     157    rba.setHeader(name, value);
    57158  }
    58159
     160  private static void validateCelAndCdf(FusionCELData cel, FusionCDFData cdf, String cdfChipType)
     161    throws InvalidDataException
     162  {
     163    String celChipType = cel.getChipType();
     164    if (!cdfChipType.startsWith(celChipType))
     165    {
     166      throw new InvalidDataException("CEL chip type (" + celChipType +
     167        ") doesn't match CDF chip type (" + cdfChipType + ")");
     168    }
     169   
     170    if (cel.getRows() != cdf.getHeader().getRows() || cel.getCols() != cdf.getHeader().getRows())
     171    {
     172      throw new InvalidDataException("CEL size (rows=" + cel.getRows() + ", cols=" + cel.getCols() +
     173        ") doesn't match CDF size (rows=" +
     174        cdf.getHeader().getRows() + ", cols=" + cdf.getHeader().getCols()+")");
     175    }   
     176  }
     177
     178 
    59179}
  • branches/filedb/src/core/net/sf/basedb/core/filehandler/DataFileValidator.java

    r3802 r3807  
    2727import net.sf.basedb.core.DbControl;
    2828import net.sf.basedb.core.InvalidDataException;
     29import net.sf.basedb.core.InvalidRelationException;
    2930import net.sf.basedb.core.PermissionDeniedException;
    3031
     
    4950    or a subclass if the file is not a valid file. {@link PermissionDeniedException}:s
    5051    are ignored by the core and will not change the validation status.
     52    An exception of type {@link InvalidRelationException} is thrown
     53    the file itself is valid, but a related file that it depends on is not. The
     54    core will still mark the file as invalid and store the error message,
     55    but metadata extraction will still be performed.
    5156   
    5257    @param dc A DbControl object that can be used for database
     
    5459    @throws InvalidDataException If the validator detects an invalid
    5560      file
     61    @throws InvalidRelationException If the validator detects that the
     62      file is valid but another file that it depends on is not, metadata
     63      extract will still happen
    5664  */
    5765  public void validate(DbControl dc)
    58     throws InvalidDataException;
     66    throws InvalidDataException, InvalidRelationException;
    5967}
  • branches/filedb/www/common/datafiles/select_files.jsp

    r3802 r3807  
    180180
    181181    <form name="datafiles">
    182     <table class="form" cellspacing="2" border="0" cellpadding="0" width="100%">
    183182    <%
    184     if (deniedPlatform)
     183    if (fileTypes.size() == 0)
     184    {
     185      %>
     186      <div class="error">
     187        The <%=platform == null ? "" : "'" + HTML.encodeTags(platform.getName()) + "'" %>
     188        platform doesn't define any file types for <%=itemType.toString() %>
     189        items.
     190      </div>
     191      <%
     192    }
     193    else if (deniedPlatform)
    185194    {
    186195      %>
     
    188197      <%
    189198    }
    190     %>
    191     <%
    192     for (DataFileType dft : fileTypes)
    193     {
    194       PlatformFileType pft = platform == null ?
    195         null : platform.getFileType(dft, variant);
    196       boolean isRequired = pft == null ? false : pft.isRequired();
    197       FileSetMember member = fileSet == null || !fileSet.hasMember(dft) ?
    198         null : fileSet.getMember(dft);
    199       File file = null;
    200       boolean deniedFile = false;
    201       if (member != null)
     199    else
     200    {
     201      %>
     202      <table class="form" cellspacing="2" border="0" cellpadding="0" width="100%">
     203      <%
     204      for (DataFileType dft : fileTypes)
    202205      {
    203         try
     206        PlatformFileType pft = platform == null ?
     207          null : platform.getFileType(dft, variant);
     208        boolean isRequired = pft == null ? false : pft.isRequired();
     209        FileSetMember member = fileSet == null || !fileSet.hasMember(dft) ?
     210          null : fileSet.getMember(dft);
     211        File file = null;
     212        boolean deniedFile = false;
     213        if (member != null)
    204214        {
    205           file = member.getFile();
     215          try
     216          {
     217            file = member.getFile();
     218          }
     219          catch (PermissionDeniedException ex)
     220          {
     221            deniedFile = true;
     222          }
    206223        }
    207         catch (PermissionDeniedException ex)
     224       
     225        String path = "";
     226        if (file != null)
    208227        {
    209           deniedFile = true;
     228          path = file.getPath().toString();
    210229        }
    211       }
    212      
    213       String path = "";
    214       if (file != null)
    215       {
    216         path = file.getPath().toString();
    217       }
    218       else if (deniedFile || deniedPlatform)
    219       {
    220         path = "- denied -";
    221       }
    222       String inputName= "datafile."+dft.getId();
    223       recentFiles = (List<File>)cc.getRecent(dc, Item.FILE, dft.getExternalId());
    224       %>
    225       <tr>
    226         <td class="prompt"><%=HTML.encodeTags(dft.getName())%></td>
    227         <td>
    228           <table border="0" cellspacing="0" cellpadding="0">
    229           <tr>
    230             <td>     
    231               <input <%=isRequired ? requiredClazz : clazz%> type="text"
    232               name="<%=inputName%>" value="<%=HTML.encodeTags(path)%>"
    233               size="50" title="<%=HTML.encodeTags(dft.getDescription())%>"
    234               <%=deniedFile || deniedPlatform ? "disabled" : "" %>
    235               onchange="fileOnChange('<%=inputName%>')">&nbsp;
    236             </td>
    237             <td><base:button
    238                 title="Browse&hellip;"
    239                 onclick="<%="browseOnClick('"+inputName+"')"%>"
    240                 disabled="<%=deniedFile || deniedPlatform %>"
    241                 />
    242             </td>
    243           </tr>
    244           </table>
    245         </td>
    246       </tr>
    247       <tr>
    248         <td align="right"></td>
    249         <td>
    250         <%
    251         if (recentFiles != null && recentFiles.size() > 0)
     230        else if (deniedFile || deniedPlatform)
    252231        {
    253           %>
    254           <select name="recent.<%=inputName%>" onchange="recentOnChange('<%=inputName%>')">
    255           <option value="">- recently used -
     232          path = "- denied -";
     233        }
     234        String inputName= "datafile."+dft.getId();
     235        recentFiles = (List<File>)cc.getRecent(dc, Item.FILE, dft.getExternalId());
     236        %>
     237        <tr>
     238          <td class="prompt"><%=HTML.encodeTags(dft.getName())%></td>
     239          <td>
     240            <table border="0" cellspacing="0" cellpadding="0">
     241            <tr>
     242              <td>     
     243                <input <%=isRequired ? requiredClazz : clazz%> type="text"
     244                name="<%=inputName%>" value="<%=HTML.encodeTags(path)%>"
     245                size="50" title="<%=HTML.encodeTags(dft.getDescription())%>"
     246                <%=deniedFile || deniedPlatform ? "disabled" : "" %>
     247                onchange="fileOnChange('<%=inputName%>')">&nbsp;
     248              </td>
     249              <td><base:button
     250                  title="Browse&hellip;"
     251                  onclick="<%="browseOnClick('"+inputName+"')"%>"
     252                  disabled="<%=deniedFile || deniedPlatform %>"
     253                  />
     254              </td>
     255            </tr>
     256            </table>
     257          </td>
     258        </tr>
     259        <tr>
     260          <td align="right"></td>
     261          <td>
    256262          <%
    257           for (File recent : recentFiles)
     263          if (recentFiles != null && recentFiles.size() > 0)
    258264          {
    259265            %>
    260             <option value="<%=recent.getId()%>"><%=HTML.encodeTags(recent.getPath().toString())%>
     266            <select name="recent.<%=inputName%>" onchange="recentOnChange('<%=inputName%>')">
     267            <option value="">- recently used -
     268            <%
     269            for (File recent : recentFiles)
     270            {
     271              %>
     272              <option value="<%=recent.getId()%>"><%=HTML.encodeTags(recent.getPath().toString())%>
     273              <%
     274            }
     275            %>
     276            </select>
    261277            <%
    262278          }
    263279          %>
    264           </select>
    265           <%
    266         }
    267         %>
    268         </td>
     280          </td>
     281        </tr>
     282        <%
     283      }
     284      %>
     285      <tr>
     286        <td class="prompt">Validate</td>
     287        <td><input type="checkbox" value="1" name="datafiles.validate"></td>
    269288      </tr>
     289      <tr>
     290        <td class="prompt">Extract metadata</td>
     291        <td><input type="checkbox" value="1" name="datafiles.metadata"></td>
     292      </tr>
     293      </table>
    270294      <%
    271295    }
    272296    %>
    273     <tr>
    274       <td class="prompt">Validate</td>
    275       <td><input type="checkbox" value="1" name="datafiles.validate"></td>
    276     </tr>
    277     <tr>
    278       <td class="prompt">Extract metadata</td>
    279       <td><input type="checkbox" value="1" name="datafiles.metadata"></td>
    280     </tr>
    281     </table>
    282297
    283298    </form>
  • branches/filedb/www/include/scripts/platforms.js

    r3802 r3807  
    5454      }
    5555    }
    56   }
     56  }
     57 
     58  this.getPlatformById = function(id)
     59  {
     60    return allPlatforms['ID'+id];
     61  }
     62 
     63  this.populateList = function(list, platformId, variantId)
     64  {
     65    for (var p = 0; p < allPlatforms.length; p++)
     66    {
     67      var platform = allPlatforms[p];
     68      var option = new Option(platform.name, platform.id, false, platformId == platform.id && !variantId);
     69      list[list.length] = option;
     70      option.className = 'selectoptionheader';
     71      for (var v = 0; v < platform.variants.length; v++)
     72      {
     73        var variant = platform.variants[v];
     74        option = new Option(variant.name, platform.id + ':' + variant.id, false, platformId == platform.id && variantId == variant.id);
     75        option.className = 'selectoptionindent';
     76        list[list.length] = option;
     77      }
     78    }
     79  }
     80 
     81  this.getSelectedPlatform = function(list)
     82  {
     83    if (list.length == 0 || list.selectedIndex < 0) return null;
     84    var pv = list[list.selectedIndex].value.split(':');
     85    return this.getPlatformById(pv[0]);
     86  }
     87
     88  this.getSelectedVariant = function(list)
     89  {
     90    if (list.length == 0 || list.selectedIndex < 0) return null;
     91    var pv = list[list.selectedIndex].value.split(':');
     92    if (pv.length < 2) return null;
     93    var platform = this.getPlatformById(pv[0]);
     94    return platform.getVariantById(pv[1]);
     95  }
     96 
     97}
     98
     99var allPlatforms = new Array();
     100function Platform(id, externalId, name, fileOnly, rawDataType)
     101{
     102  this.id = id;
     103  this.externalId = externalId;
     104  this.name = name;
     105  this.fileOnly = fileOnly;
     106  this.rawDataType = rawDataType;
     107  this.variants = new Array();
     108 
     109  allPlatforms[allPlatforms.length] = this;
     110  allPlatforms['ID'+id] = this;
     111 
     112  this.getVariantById = function(id)
     113  {
     114    return this.variants['ID'+id];
     115  }
     116}
     117
     118function Variant(platform, id, externalId, name, fileOnly, rawDataType)
     119{
     120  this.platform = platform;
     121  this.id = id;
     122  this.externalId = externalId;
     123  this.name = name;
     124  this.fileOnly = fileOnly;
     125  this.rawDataType = rawDataType;
     126 
     127  platform.variants[platform.variants.length] = this;
     128  platform.variants['ID'+id] = this;
    57129}
    58130
    59131
    60132
     133
  • branches/filedb/www/lims/arraydesigns/edit_design.jsp

    r3802 r3807  
    3737  import="net.sf.basedb.core.Platform"
    3838  import="net.sf.basedb.core.PlatformVariant"
    39   import="net.sf.basedb.core.Affymetrix"
     39  import="net.sf.basedb.core.RawDataType"
    4040  import="net.sf.basedb.core.ItemQuery"
    4141  import="net.sf.basedb.core.ItemResultList"
     
    153153    function switchTab(tabControlId, tabId)
    154154    {
     155      var frm = document.forms['design'];
    155156      if (TabControl.setActiveTab(tabControlId, tabId))
    156157      {
     
    169170        else if (tabId == 'datafiles' && (platformChanged || !dataFilesLoaded))
    170171        {
    171           var platformId = getPlatform();
    172           var variantId = getVariant();
    173           Platforms.loadDataFilesFrame(frames.datafiles, '<%=ID%>', '<%=itemType.name()%>', <%=design == null ? 0 : design.getId()%>, platformId, variantId);
     172          var platform = Platforms.getSelectedPlatform(frm.platform);
     173          var variant = Platforms.getSelectedVariant(frm.platform);
     174          Platforms.loadDataFilesFrame(frames.datafiles, '<%=ID%>', '<%=itemType.name()%>', <%=design == null ? 0 : design.getId()%>, platform == null ? 0 : platform.id, variant == null ? 0 : variant.id);
    174175          dataFilesLoaded = true;
    175176          platformChanged = false;
     
    183184    }
    184185   
    185     function getPlatform()
    186     {
    187       var frm = document.forms['design'];
    188       if (frm.platform.length == 0) return 0;
    189       var pv = frm.platform[frm.platform.selectedIndex].value.split(':');
    190       return pv[0];
    191     }
    192    
    193     function getVariant()
    194     {
    195       var frm = document.forms['design'];
    196       if (frm.platform.length == 0) return 0;
    197       var pv = frm.platform[frm.platform.selectedIndex].value.split(':');
    198       return pv.length > 1 ? pv[1] : null;
    199     }
    200 
    201186    function platformOnChange()
    202187    {
     
    221206    function initPlatforms(platformId, variantId)
    222207    {
    223       var platforms = new Array();
    224       var variants = new Array();
    225208      <%
    226209      for (Platform p : platforms)
    227210      {
     211        RawDataType rdt = p.isFileOnly() ? null : p.getRawDataType();
    228212        %>
    229         platforms[platforms.length] = { name:'<%=p.getName()%>', id:<%=p.getId()%> };
    230         variants['platform.<%=p.getId()%>'] = new Array();
     213        var p<%=p.getId()%> = new Platform(<%=p.getId()%>, '<%=HTML.javaScriptEncode(p.getExternalId())%>', '<%=HTML.javaScriptEncode(p.getName())%>', <%=p.isFileOnly()%>, '<%=rdt == null ? "" : rdt.getId()%>');
    231214        <%
    232215      }
    233216      for (PlatformVariant v : variants)
    234217      {
     218        RawDataType rdt = v.isFileOnly() ? null : v.getRawDataType();
    235219        Platform p = v.getPlatform();
    236         String index = "platform." + p.getId();
    237220        %>
    238         variants['<%=index%>'][variants['<%=index%>'].length] = { name:'<%=v.getName()%>', id:<%=v.getId()%> };
     221        var v<%=v.getId()%> = new Variant(p<%=p.getId()%>, <%=v.getId()%>, '<%=HTML.javaScriptEncode(v.getExternalId())%>', '<%=HTML.javaScriptEncode(v.getName())%>', <%=v.isFileOnly()%>, '<%=rdt == null ? "" : rdt.getId()%>');
    239222        <%
    240223      }
    241224      %>
    242225      var frm = document.forms['design'];
    243       for (var p = 0; p < platforms.length; p++)
    244       {
    245         var platform = platforms[p];
    246         var index = 'platform.' + platform.id;
    247         var option = new Option(platform.name, platform.id, false, platformId == platform.id && !variantId);
    248         frm.platform[frm.platform.length] = option;
    249         option.className = 'selectoptionheader';
    250         for (var v = 0; v < variants[index].length; v++)
    251         {
    252           var variant = variants[index][v];
    253           option = new Option(variant.name, platform.id + ':' + variant.id, false, platformId == platform.id && variantId == variant.id);
    254           option.className = 'selectoptionindent';
    255           frm.platform[frm.platform.length] = option;
    256         }
    257       }
     226      Platforms.populateList(frm.platform, platformId, variantId);
    258227    }
    259228    </script>
     
    278247        <td class="prompt">Platform</td>
    279248        <td>
    280           <select name="platform" onchange="platformOnChange()" <%=deniedPlatform ? "disabled" : "" %>>
     249          <select name="platform" onchange="platformOnChange()" class="required"
     250            <%=deniedPlatform ? "disabled" : "" %>>
    281251          <%
    282252          if (deniedPlatform)
  • branches/filedb/www/lims/arraydesigns/list_designs.jsp

    r3801 r3807  
    252252        exportable="true"
    253253        show="always"
    254       />
    255       <tbl:columndef
    256         id="affyChip"
    257         property="affyChip"
    258         datatype="boolean"
    259         title="Affy chip"
    260         sortable="true"
    261         filterable="true"
    262         exportable="true"
    263       />
    264       <tbl:columndef
    265         id="cdfFile"
    266         title="CDF file"
    267254      />
    268255      <tbl:columndef
     
    549536                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
    550537                  /></tbl:cell>
    551                 <tbl:cell column="affyChip"><%=item.isAffyChip()%></tbl:cell>
    552                 <tbl:cell column="cdfFile">
    553                 <%
    554                 if (item.isAffyChip())
    555                 {
    556                   File cdfFile = null;
    557                   boolean readCdfFile = true;
    558                   try
    559                   {
    560                     cdfFile = Affymetrix.getCdfFile(item);
    561                   }
    562                   catch (PermissionDeniedException ex)
    563                   {
    564                     readCdfFile = false;
    565                   }
    566                   %>
    567                   <%=Base.getLinkedFile(ID, cdfFile, !readCdfFile, true, true, root)%>
    568                   <%
    569                 }
    570                 %>
    571                 </tbl:cell>
    572538                <tbl:cell column="hasFeatures"><%=item.hasFeatures() ? "yes" : "no"%></tbl:cell>
    573539                <tbl:cell column="numDbFeatures"><%=item.getNumDbFeatures()%></tbl:cell>
  • branches/filedb/www/views/rawbioassays/edit_rawbioassay.jsp

    r3679 r3807  
    3636  import="net.sf.basedb.core.Permission"
    3737  import="net.sf.basedb.core.RawBioAssay"
    38   import="net.sf.basedb.core.Affymetrix"
     38  import="net.sf.basedb.core.Platform"
     39  import="net.sf.basedb.core.PlatformVariant"
    3940  import="net.sf.basedb.core.Scan"
    4041  import="net.sf.basedb.core.Protocol"
     
    5253  import="net.sf.basedb.core.PermissionDeniedException"
    5354  import="net.sf.basedb.core.BaseException"
     55  import="net.sf.basedb.core.query.Orders"
     56  import="net.sf.basedb.core.query.Hql"
    5457  import="net.sf.basedb.clients.web.Base"
    5558  import="net.sf.basedb.clients.web.util.HTML"
     
    7477  RawBioAssay rawBioAssay = null;
    7578  String name = null;
    76   boolean readCurrentCelFile = true;
    77   File currentCelFile = null;
     79  boolean hasDbSpots = false;
     80
     81  boolean deniedPlatform = false;
     82  Platform currentPlatform = null;
     83  PlatformVariant currentVariant = null;
     84 
    7885  boolean readCurrentScan = true;
    7986  Scan currentScan = null;
     
    131138    title = "Create raw bioassay";
    132139    cc.removeObject("item");
     140   
     141    int currentPlatformId = Values.getInt(cc.getPropertyValue("platform"), 0);
     142    if (currentPlatformId == 0)
     143    {
     144      currentPlatformId = Values.getInt(cc.getRecent(Item.PLATFORM.name(), 0), 0);
     145    }
     146    if (currentPlatformId != 0) currentPlatform = Platform.getById(dc, currentPlatformId);
     147   
    133148    currentRawDataType = RawDataTypes.getRawDataType(cc.getPropertyValue("rawDataType"));
    134149    if (currentRawDataType == null)
     
    182197  {
    183198    rawBioAssay = RawBioAssay.getById(dc, itemId);
     199    rawBioAssay.checkPermission(Permission.WRITE);
     200    hasDbSpots = rawBioAssay.getNumDbSpots() > 0;
    184201    cc.setObject("item", rawBioAssay);
    185202    name = rawBioAssay.getName();
     
    187204    title = "Edit raw bioassay -- " + HTML.encodeTags(rawBioAssay.getName());
    188205   
    189     if (currentRawDataType.isAffymetrix())
    190     {
    191       try
    192       {
    193         currentCelFile = Affymetrix.getCelFile(rawBioAssay);
    194       }
    195       catch (PermissionDeniedException ex)
    196       {
    197         readCurrentCelFile = false;
    198       }
    199     }
    200    
    201206    try
    202207    {
     208      currentPlatform = rawBioAssay.getPlatform();
     209      currentVariant = rawBioAssay.getVariant();
     210    }
     211    catch (PermissionDeniedException ex)
     212    {
     213      deniedPlatform = true;
     214    }
     215   
     216    try
     217    {
    203218      currentScan = rawBioAssay.getScan();
    204219    }
     
    232247    }
    233248  }
    234   if (rawBioAssay != null) rawBioAssay.checkPermission(Permission.WRITE);
     249 
     250  ItemQuery<Platform> platformQuery = Platform.getQuery();
     251  platformQuery.order(Orders.asc(Hql.property("name")));
     252  platformQuery.setCacheResult(true);
     253  ItemResultList<Platform> platforms = platformQuery.list(dc);
     254
     255  ItemQuery<PlatformVariant> variantQuery = PlatformVariant.getQuery();
     256  variantQuery.order(Orders.asc(Hql.property("name")));
     257  variantQuery.setCacheResult(true);
     258  ItemResultList<PlatformVariant> variants = variantQuery.list(dc);
     259 
    235260  final String clazz = "class=\"text\"";
    236261  final String requiredClazz = "class=\"text required\"";
     
    238263
    239264  <base:page type="popup" title="<%=title%>">
    240   <base:head scripts="tabcontrol.js,annotations.js" styles="tabcontrol.css">
     265  <base:head scripts="tabcontrol.js,annotations.js,platforms.js" styles="tabcontrol.css">
    241266    <script language="JavaScript">
    242267    // Validate the "RawBioAssay" tab
     
    249274        frm.name.focus();
    250275        return false;
    251       }
    252       if (frm.rawdatatype)
    253       {
    254         var rawDataType = frm.rawdatatype[frm.rawdatatype.selectedIndex].value;
    255         if (isAffymetrix[rawDataType])
    256         {
    257           var celFileId = frm.celfile_id[frm.celfile_id.selectedIndex].value;
    258           var arrayDesignId = frm.arraydesign_id[frm.arraydesign_id.selectedIndex].value;
    259           if (celFileId != 0 && arrayDesignId == 0)
    260           {
    261             alert('You must select an array design if a CEL file is specified');
    262             return false;
    263           }
    264         }
    265276      }
    266277      return true;
     
    281292          Annotations.addInheritedAnnotationsToForm(frames.inheritedAnnotations, frm);
    282293        }
     294        if (dataFilesLoaded)
     295        {
     296          Platforms.addDataFilesToForm(frames.datafiles, frm);
     297        }
    283298        frm.submit();
    284299      }
     
    289304    var parentsChanged = false;
    290305    var protocolChanged = false;
     306    var dataFilesLoaded = false;
     307    var platformChanged = false;
    291308    function switchTab(tabControlId, tabId)
    292309    {
     310      var frm = document.forms['rawbioassay'];
    293311      if (TabControl.setActiveTab(tabControlId, tabId))
    294312      {
     
    306324          parentsChanged = false;
    307325        }
    308       }
    309     }
    310    
     326        else if (tabId == 'datafiles' && (platformChanged || !dataFilesLoaded))
     327        {
     328          var platform = Platforms.getSelectedPlatform(frm.platform);
     329          var variant = Platforms.getSelectedVariant(frm.platform);
     330          Platforms.loadDataFilesFrame(frames.datafiles, '<%=ID%>', '<%=itemType.name()%>', <%=rawBioAssay == null ? 0 : rawBioAssay.getId()%>, platform == null ? 0 : platform.id, variant == null ? 0 : variant.id);
     331          dataFilesLoaded = true;
     332          platformChanged = false;
     333        }
     334      }
     335    }
     336
     337    function platformOnChange()
     338    {
     339      var frm = document.forms['rawbioassay'];
     340      platformChanged = true;
     341      var platform = Platforms.getSelectedPlatform(frm.platform);
     342      var variant = Platforms.getSelectedVariant(frm.platform);
     343      var fileOnly = (variant != null && variant.fileOnly) ||
     344        (variant == null && platform.fileOnly);
     345      var rawDataType = variant == null ? platform.rawDataType : variant.rawDataType;
     346      if (frm.rawdatatype[frm.rawdatatype.length - 1].value == '')
     347      {
     348        frm.rawdatatype[frm.rawdatatype.length - 1] = null;
     349      }
     350      if (fileOnly)
     351      {
     352        frm.rawdatatype.disabled = true;
     353        Main.removeClass(frm.rawdatatype, 'required');
     354        frm.rawdatatype[frm.rawdatatype.length] = new Option('- file only -', '');
     355        frm.rawdatatype.selectedIndex = frm.rawdatatype.length - 1;
     356      }
     357      else if (rawDataType)
     358      {
     359        frm.rawdatatype.disabled = true;
     360        Main.removeClass(frm.rawdatatype, 'required');
     361        Forms.selectListOption(frm.rawdatatype, rawDataType);
     362      }
     363      else
     364      {
     365        frm.rawdatatype.disabled = false;
     366        Main.addClass(frm.rawdatatype, 'required');
     367      }
     368    }
     369
    311370    function getProtocolId()
    312371    {
     
    426485    {
    427486      var frm = document.forms['rawbioassay'];
    428       var url = '../../lims/arraydesigns/index.jsp?ID=<%=ID%>&mode=selectone&callback=setArrayDesignCallback';
     487      var url = '../../lims/arraydesigns/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setArrayDesignCallback';
    429488      if (frm.arraydesign_id.length > 1)
    430489      {
     
    432491        url += '&item_id='+id;
    433492      }
     493      var platform = Platforms.getSelectedPlatform(frm.platform);
     494      url += '&filter:INT:platform='+platform.id;
    434495      Main.openPopup(url, 'SelectArrayDesign', 1000, 700);
    435496    }
     
    448509    }
    449510   
    450     var isAffymetrix = new Array();
    451     <%
    452     for (RawDataType rdt : RawDataTypes.getRawDataTypes())
    453     {
    454       %>
    455       isAffymetrix['<%=rdt.getId()%>'] = <%=rdt.isAffymetrix() ? "true" : "false" %>;
    456       <%
    457     }
    458     %>
    459    
    460     function selectCelFileOnClick()
    461     {
    462       var frm = document.forms['rawbioassay'];
    463      
    464       if (frm.rawdatatype)
    465       {
    466         var rawDataType = frm.rawdatatype[frm.rawdatatype.selectedIndex].value;
    467         if (!isAffymetrix[rawDataType])
    468         {
    469           alert('CEL-files are only used for Affymetrix data types.');
    470           return;
    471         }
    472       }
    473 
    474       var url = '../../filemanager/index.jsp?ID=<%=ID%>&cmd=SelectOne&callback=setCelFileCallback';
    475       if (frm.celfile_id.length > 1)
    476       {
    477         var id = Math.abs(parseInt(frm.celfile_id[1].value));       
    478         url += '&item_id='+id;
    479       }
    480       url += '&filter:STRING:name=%25.cel';
    481       Main.openPopup(url, 'SelectFile', 1000, 700);
    482     }
    483     function setCelFileCallback(id, name)
    484     {
    485       var frm = document.forms['rawbioassay'];
    486       var list = frm.celfile_id;
    487       if (list.length < 2 || list[1].value == '0') // >
    488       {
    489         Forms.addListOption(list, 1, new Option());
    490       }
    491       list[1].value = id;
    492       list[1].text = name;
    493       list.selectedIndex = 1;
    494     }
    495 
    496     function rawDataTypeOnChange()
    497     {
    498       var frm = document.forms['rawbioassay'];
    499       if (frm.rawdatatype)
    500       {
    501         var rawDataType = frm.rawdatatype[frm.rawdatatype.selectedIndex].value;
    502         if (isAffymetrix[rawDataType])
    503         {
    504           frm.celfile_id.disabled = false;
    505         }
    506         else
    507         {
    508           frm.celfile_id.disabled = true;
    509         }
    510       }
    511     }
    512 
    513511    function init()
    514512    {
     
    523521      }
    524522      %>
    525       rawDataTypeOnChange();
     523      initPlatforms(<%=currentPlatform == null ? 0 : currentPlatform.getId()%>, <%=currentVariant == null ? 0 : currentVariant.getId()%>);
     524      platformOnChange();
     525    }
     526   
     527    function initPlatforms(platformId, variantId)
     528    {
     529      <%
     530      for (Platform p : platforms)
     531      {
     532        RawDataType rdt = p.isFileOnly() ? null : p.getRawDataType();
     533        %>
     534        var p<%=p.getId()%> = new Platform(<%=p.getId()%>, '<%=HTML.javaScriptEncode(p.getExternalId())%>', '<%=HTML.javaScriptEncode(p.getName())%>', <%=p.isFileOnly()%>, '<%=rdt == null ? "" : rdt.getId()%>');
     535        <%
     536      }
     537      for (PlatformVariant v : variants)
     538      {
     539        RawDataType rdt = v.isFileOnly() ? null : v.getRawDataType();
     540        Platform p = v.getPlatform();
     541        %>
     542        var v<%=v.getId()%> = new Variant(p<%=p.getId()%>, <%=v.getId()%>, '<%=HTML.javaScriptEncode(v.getExternalId())%>', '<%=HTML.javaScriptEncode(v.getName())%>', <%=v.isFileOnly()%>, '<%=rdt == null ? "" : rdt.getId()%>');
     543        <%
     544      }
     545      %>
     546      var frm = document.forms['rawbioassay'];
     547      Platforms.populateList(frm.platform, platformId, variantId);
    526548    }
    527549    </script>
     
    544566      </tr>
    545567      <tr>
    546         <td class="prompt">Raw data type</td>
     568        <td class="prompt">Platform</td>
    547569        <td>
     570          <select name="platform" onchange="platformOnChange()" class="required"
     571            <%=deniedPlatform || hasDbSpots ? "disabled" : "" %>>
    548572          <%
    549           if (rawBioAssay == null || !rawBioAssay.hasData())
     573          if (deniedPlatform)
    550574          {
    551575            %>
    552             <select name="rawdatatype" class="required" onchange="rawDataTypeOnChange()">
    553             <%
    554             for (RawDataType rdt : RawDataTypes.getRawDataTypes())
    555             {
    556               String selected = rdt.equals(currentRawDataType) ? "selected" : "";
    557               %>
    558               <option value="<%=rdt.getId()%>" <%=selected%>><%=HTML.encodeTags(rdt.getName())%>
    559               <%
    560             }
    561             %>
    562             </select>
    563             <%
    564           }
    565           else
    566           {
    567             %>
    568             <%=HTML.encodeTags(currentRawDataType.getName())%>
     576            <option value="-1">- denied -
    569577            <%
    570578          }
    571579          %>
    572        
     580          </select>
     581        </td>
     582      </tr>
     583      <tr>
     584        <td class="prompt">Raw data type</td>
     585        <td>
     586          <select name="rawdatatype" class="required"
     587            <%=hasDbSpots ? "disabled" : "" %>>
     588          <%
     589          for (RawDataType rdt : RawDataTypes.getRawDataTypes())
     590          {
     591            String selected = rdt.equals(currentRawDataType) ? "selected" : "";
     592            %>
     593            <option value="<%=rdt.getId()%>" <%=selected%>><%=HTML.encodeTags(rdt.getName())%>
     594            <%
     595          }
     596          %>
     597          </select>
    573598        </td>
    574599      </tr>
     
    577602        <td class="prompt">Array design</td>
    578603        <td>
    579           <%
    580           //if (rawBioAssay == null || !rawBioAssay.hasData())
    581           {
    582             %>
    583             <base:select
    584               id="arraydesign_id"
    585               clazz="selectionlist"
    586               required="false"
    587               current="<%=currentArrayDesign%>"
    588               denied="<%=!readCurrentArrayDesign%>"
    589               recent="<%=recentArrayDesigns%>"
    590               defaultitem="<%=defaultArrayDesign%>"
    591               newitem="<%=rawBioAssay == null%>"
    592               onselect="selectArrayDesignOnClick()"
    593               onchange="arrayDesignOnChange()"
    594             />
    595             <%
    596           }
    597           /*
    598           else
    599           {
    600             %>
    601             <%=readCurrentArrayDesign ?
    602               (currentArrayDesign != null ? HTML.encodeTags(currentArrayDesign.getName()) : "<i>- none -</i>")
    603               : "<i>- denied - </i>"%>
    604             <%
    605           }
    606           */
    607           %>
     604          <base:select
     605            id="arraydesign_id"
     606            clazz="selectionlist"
     607            required="false"
     608            current="<%=currentArrayDesign%>"
     609            denied="<%=!readCurrentArrayDesign%>"
     610            recent="<%=recentArrayDesigns%>"
     611            defaultitem="<%=defaultArrayDesign%>"
     612            newitem="<%=rawBioAssay == null%>"
     613            onselect="selectArrayDesignOnClick()"
     614            onchange="arrayDesignOnChange()"
     615          />
    608616        </td>
    609617      </tr>
    610       <%
    611       if (rawBioAssay == null || !rawBioAssay.hasData() || rawBioAssay.getRawDataType().isAffymetrix())
    612       {
    613         %>
    614         <tr id="celFile">
    615           <td class="prompt">CEL file</td>
    616           <td>
    617             <base:select
    618               id="celfile_id"
    619               clazz="selectionlist"
    620               required="false"
    621               current="<%=currentCelFile%>"
    622               denied="<%=!readCurrentCelFile%>"
    623               recent="<%=recentFiles%>"
    624               newitem="<%=rawBioAssay == null%>"
    625               onselect="selectCelFileOnClick()"
    626             />
    627           </td>
    628         </tr>
    629         <%
    630       }
    631       %>
    632618
    633619      <tr>
     
    691677      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
    692678    </t:tab>
     679   
     680    <t:tab id="datafiles" title="Data files" helpid="datafiles.edit">
     681      <iframe name="datafiles" id="idDatafiles" src="../../common/datafiles/wait.jsp"
     682        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
     683        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
     684    </t:tab>
    693685
    694686    <t:tab id="annotations" title="Annotations &amp; parameters"
  • branches/filedb/www/views/rawbioassays/index.jsp

    r3679 r3807  
    4343  import="net.sf.basedb.core.RawDataType"
    4444  import="net.sf.basedb.core.RawDataTypes"
     45  import="net.sf.basedb.core.Platform"
     46  import="net.sf.basedb.core.PlatformVariant"
    4547  import="net.sf.basedb.core.User"
    4648  import="net.sf.basedb.core.Path"
     
    7880<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
    7981<%!
    80   private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,rawDataType,spots,description");
     82  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,platform,variant,hasData,description");
    8183  private static final Item itemType = Item.RAWBIOASSAY;
    8284 
     
    214216    dc = sc.newDbControl();
    215217    RawBioAssay rba = (RawBioAssay)cc.getObject("item");
     218   
     219    Platform platform = null;
     220    PlatformVariant variant = null;
     221    if (request.getParameter("platform") != null)
     222    {
     223      String[] pv = request.getParameter("platform").split(":");
     224      int platformId = Values.getInt(pv[0], -1);
     225      int variantId = pv.length > 1 ? Values.getInt(pv[1], -1) : -1;
     226      if (platformId > 0) platform = Platform.getById(dc, platformId);
     227      if (variantId > 0) variant = PlatformVariant.getById(dc, variantId);
     228    }
     229   
    216230    RawDataType rdt = RawDataTypes.getRawDataType(Values.getStringOrNull(request.getParameter("rawdatatype")));
    217231    if (rdt != null) cc.setRecent("RawDataType", rdt.getId(), maxRecent);
     
    219233    if (rba == null)
    220234    {
    221       rba = RawBioAssay.getNew(dc, rdt);
     235      if (variant != null)
     236      {
     237        rba = RawBioAssay.getNew(dc, variant, rdt);
     238      }
     239      else
     240      {
     241        rba = RawBioAssay.getNew(dc, platform, rdt);
     242      }
    222243      message = "Raw bioassay created";
    223244      dc.saveItem(rba);
     
    225246    else
    226247    {
     248      dc.reattachItem(rba);
    227249      if (rdt != null) rba.setRawDataType(rdt);
    228       dc.reattachItem(rba);
     250      if (variant != null)
     251      {
     252        rba.setVariant(variant);
     253      }
     254      else if (platform != null)
     255      {
     256        rba.setPlatform(platform);
     257      }
    229258      message = "Raw bioassay updated";
    230259    }
     
    258287    {
    259288      ad = arrayDesignId == 0 ? null : ArrayDesign.getById(dc, arrayDesignId);
    260       if (rba.getSpots() > 0)
     289      if (rba.hasData())
    261290      {
    262291        if (rba.getRawDataType().isStoredInDb() && ad != null && ad.hasFeatures())
     
    280309      if (ad != null) cc.setRecent(ad, maxRecent);
    281310    }
    282     rdt = rba.getRawDataType();
    283     if (rdt.isAffymetrix())
    284     {
    285       int celFileId = Values.getInt(request.getParameter("celfile_id"), -1);
    286       if (celFileId >= 0) // < 0 = denied or unchanged
    287       {
    288         File celFile = celFileId == 0 ? null : File.getById(dc, celFileId);
    289         Affymetrix.setCelFile(rba, celFile);
    290       }
    291     }
    292 
     311
     312    // Data files tab
     313    boolean validate = Values.getBoolean(request.getParameter("datafiles.validate"));
     314    boolean metadata = Values.getBoolean(request.getParameter("datafiles.metadata"));
     315    Base.updateFiles(dc, rba, request, validate, metadata, cc, maxRecent);
     316   
    293317    // Annotations tab
    294318    Base.updateAnnotations(dc, rba, rba, request);
  • branches/filedb/www/views/rawbioassays/list_rawbioassays.jsp

    r3679 r3807  
    3232  import="net.sf.basedb.core.Item"
    3333  import="net.sf.basedb.core.RawBioAssay"
     34  import="net.sf.basedb.core.Platform"
    3435  import="net.sf.basedb.core.RawDataType"
    3536  import="net.sf.basedb.core.RawDataTypes"
     
    8990{
    9091  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
    91   final ItemQuery<RawBioAssay> query = Base.getConfiguredQuery(cc, true, RawBioAssay.getQuery(), mode);
    9292
    9393  // Query for experiments relatated to the current raw bioassay
     
    9898  experimentQuery.order(Orders.asc(Hql.property("name")));
    9999 
     100  // Get all platforms
     101  final ItemQuery<Platform> platformQuery = Platform.getQuery();
     102  platformQuery.order(Orders.asc(Hql.property("name")));
     103  platformQuery.setCacheResult(true);
     104  Enumeration<String, String> platforms = new Enumeration<String, String>();
     105  for (Platform p : platformQuery.list(dc))
     106  {
     107    platforms.add(Integer.toString(p.getId()), p.getName());
     108  }
     109 
    100110  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
    101111  annotationTypes = annotationTypeQuery.list(dc);
    102112  try
    103113  {
     114    final ItemQuery<RawBioAssay> query = Base.getConfiguredQuery(cc, true, RawBioAssay.getQuery(), mode);
    104115    rawBioAssays = query.iterate(dc);
    105116  }
    106117  catch (Throwable t)
    107118  {
     119    t.printStackTrace();
    108120    cc.setMessage(t.getMessage());
    109121  }
     
    250262        show="always"
    251263      />
    252       <%
     264      <tbl:columndef
     265        id="platform"
     266        property="platform"
     267        sortproperty="platform.name"
     268        exportproperty="platform.name"
     269        datatype="int"
     270        enumeration="<%=platforms%>"
     271        title="Platform"
     272        sortable="true"
     273        filterable="true"
     274        exportable="true"
     275      /> 
     276      <tbl:columndef
     277        id="variant"
     278        property="variant.name"
     279        datatype="string"
     280        title="Variant"
     281        sortable="true"
     282        filterable="true"
     283        exportable="true"
     284      />        <%
    253285      Enumeration<String, String> rawEnumeration = new Enumeration<String, String>();
    254286      for (RawDataType rdt : RawDataTypes.getRawDataTypes())
     
    277309      />
    278310      <tbl:columndef
    279         id="spots"
    280         property="spots"
     311        id="numDbSpots"
     312        property="numDbSpots"
    281313        datatype="int"
    282         title="Spots"
    283         sortable="true"
    284         filterable="true"
    285         exportable="true"
    286       />
    287       <tbl:columndef
    288         id="celFile"
    289         title="CEL file"
    290       />
     314        title="Db spots"
     315        sortable="true"
     316        filterable="true"
     317        exportable="true"
     318      />
     319      <tbl:columndef
     320        id="numFileSpots"
     321        property="numFileSpots"
     322        datatype="int"
     323        title="File spots"
     324        sortable="true"
     325        filterable="true"
     326        exportable="true"
     327      />     
    291328      <tbl:columndef
    292329        id="bytes"
     
    560597                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)"
    561598                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
    562                 <tbl:cell column="spots"><%=item.getSpots()%></tbl:cell>
     599                <tbl:cell column="numDbSpots"><%=item.getNumDbSpots()%></tbl:cell>
     600                <tbl:cell column="numFileSpots"><%=item.getNumFileSpots()%></tbl:cell>
    563601                <tbl:cell column="bytes"><%=Values.formatBytes(item.getBytes())%></tbl:cell>
    564                 <tbl:cell column="rawDataType"><%=HTML.encodeTags(rdt.getName())%></tbl:cell>
    565                 <tbl:cell column="celFile">
    566                 <%
    567                 if (rdt.isAffymetrix())
    568                 {
    569                   File celFile = null;
    570                   boolean readCelFile = true;
    571                   try
    572                   {
    573                     celFile = Affymetrix.getCelFile(item);
    574                   }
    575                   catch (PermissionDeniedException ex)
    576                   {
    577                     readCelFile = false;
    578                   }
    579                   %>
    580                   <%=Base.getLinkedFile(ID, celFile, !readCelFile, true, true, root)%>
    581                   <%
    582                 }
    583                 %>
    584                 </tbl:cell>
     602                <tbl:cell column="platform"
     603                  ><base:propertyvalue
     604                    item="<%=item%>"
     605                    property="platform"
     606                    enableEditLink="<%=mode.hasEditLink()%>"
     607                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
     608                  /></tbl:cell>
     609                <tbl:cell column="variant"
     610                  ><base:propertyvalue
     611                    item="<%=item%>"
     612                    property="variant"
     613                    enableEditLink="<%=mode.hasEditLink()%>"
     614                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
     615                  /></tbl:cell>               <tbl:cell column="rawDataType"><%=HTML.encodeTags(rdt.getName())%></tbl:cell>
    585616                <tbl:cell column="hasData"><%=item.hasData()%></tbl:cell>
    586617                <tbl:cell column="scan"
  • branches/filedb/www/views/rawbioassays/view_rawbioassay.jsp

    r3679 r3807  
    265265      </tr>
    266266      <tr>
     267        <td class="prompt">Platform</td>
     268        <td><base:propertyvalue item="<%=rawBioAssay%>" property="platform" /></td>
     269      </tr>
     270      <tr>
     271        <td class="prompt">Variant</td>
     272        <td><base:propertyvalue item="<%=rawBioAssay%>" property="variant" /></td>
     273      </tr>
     274      <tr>
    267275        <td class="prompt">Raw data type</td>
    268276        <td><%=HTML.encodeTags(rawDataType.getName())%></td>
    269277      </tr>
    270278      <tr>
    271         <td class="prompt">Has data</td>
    272         <td><%=rawBioAssay.hasData() ? "yes" : "no" %></td>
    273       </tr>
    274       <tr>
    275279        <td class="prompt">Spots</td>
    276         <td><%=rawBioAssay.getSpots()%></td>
    277       </tr>
    278       <%
    279       if (rawDataType.isAffymetrix())
    280       {
    281         boolean readCurrentCelFile = true;
    282         File currentCelFile = null;
    283         try
    284         {
    285           currentCelFile = Affymetrix.getCelFile(rawBioAssay);
    286         }
    287         catch (PermissionDeniedException ex)
    288         {
    289           readCurrentCelFile = false;
    290         }
    291         %>
    292         <tr>
    293           <td class="prompt">CEL file</td>
    294           <td><%=Base.getLinkedFile(ID, currentCelFile, !readCurrentCelFile, true, true, root)%></td>
    295         </tr>
    296         <%
    297       }
    298       %>
     280        <td><%=rawBioAssay.hasData() ? "yes (db: " + rawBioAssay.getNumDbSpots() +
     281            "; file: " + rawBioAssay.getNumFileSpots() + ")" : "no"%></td>
     282      </tr>
    299283      <tr>
    300284        <td class="prompt">Protocol</td>
     
    388372      </table>
    389373     
    390       <h4>Raw data headers</h4>
    391       <table class="form" cellspacing="0">
     374      <jsp:include page="../../common/datafiles/list_files.jsp">
     375        <jsp:param name="item_type" value="<%=itemType.name()%>" />
     376        <jsp:param name="item_id" value="<%=itemId%>" />
     377        <jsp:param name="ID" value="<%=ID%>" />
     378      </jsp:include>
     379     
    392380      <%
    393381      Set<String> names = rawBioAssay.getHeaderNames();
    394       boolean needsTr = true;
    395       if (names != null)
    396       {
    397         for (String name : names)
     382      %>
     383      <base:section
     384        id="headers"
     385        title="<%="Raw data headers (" + (names == null ? 0 : names.size()) + ")"%>"
     386        context="<%=cc%>"
     387        >
     388        <table class="form" cellspacing="0">
     389        <%
     390        boolean needsTr = true;
     391        if (names != null)
    398392        {
     393          for (String name : names)
     394          {
     395            %>
     396            <%=needsTr ? "<tr valign=\"top\">" : "" %>
     397              <td class="prompt"><%=HTML.encodeTags(name)%></td>
     398              <td><%=HTML.encodeTags(rawBioAssay.getHeader(name))%></td>
     399              <td>&nbsp;&nbsp;</td>
     400            <%=needsTr ? "" : "</tr>"%>
     401            <%
     402            needsTr = !needsTr;
     403          }
    399404          %>
    400           <%=needsTr ? "<tr valign=\"top\">" : "" %>
    401             <td class="prompt"><%=HTML.encodeTags(name)%></td>
    402             <td><%=HTML.encodeTags(rawBioAssay.getHeader(name))%></td>
    403             <td>&nbsp;&nbsp;</td>
    404405          <%=needsTr ? "" : "</tr>"%>
    405406          <%
    406           needsTr = !needsTr;
    407407        }
    408408        %>
    409         <%=needsTr ? "" : "</tr>"%>
    410         <%
    411       }
    412       %>
    413       </table>
     409        </table>
     410      </base:section>
    414411
    415412      <%
     
    429426      {
    430427        %>
    431         <h4 class="docked">Experiments</h4>
    432         <tbl:table
     428        <base:section
    433429          id="experiments"
    434           clazz="itemlist"
    435           columns="all"
     430          title="<%="Experiments (" + experiments.size() + ")"%>"
     431          context="<%=cc%>"
    436432          >
    437         <tbl:columndef
    438           id="name"
    439           title="Name"
    440         />
    441         <tbl:columndef
    442           id="description"
    443           title="Description"
    444         />
    445         <tbl:data>
    446           <tbl:columns>
    447           </tbl:columns>
    448           <tbl:rows>
    449           <%
    450           for (Experiment item : experiments)
    451           {
     433          <h4 class="docked">Experiments</h4>
     434          <tbl:table
     435            id="experiments"
     436            clazz="itemlist"
     437            columns="all"
     438            >
     439          <tbl:columndef
     440            id="name"
     441            title="Name"
     442          />
     443          <tbl:columndef
     444            id="description"
     445            title="Description"
     446          />
     447          <tbl:data>
     448            <tbl:columns>
     449            </tbl:columns>
     450            <tbl:rows>
     451            <%
     452            for (Experiment item : experiments)
     453            {
     454              %>
     455              <tbl:row>
     456                <tbl:cell column="name"><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
     457                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
     458              </tbl:row>
     459              <%
     460            }
    452461            %>
    453             <tbl:row>
    454               <tbl:cell column="name"><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
    455               <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
    456             </tbl:row>
    457             <%
    458           }
    459           %>
    460           </tbl:rows>
    461         </tbl:data>
    462         </tbl:table>
     462            </tbl:rows>
     463          </tbl:data>
     464          </tbl:table>
     465        </base:section>
    463466        <%
    464467      }     
     
    473476      {
    474477        %>
    475         <h4 class="docked">Shared to</h4>
     478        <base:section
     479          id="sharedTo"
     480          title="Shared to"
     481          context="<%=cc%>">
    476482        <tbl:table
    477483          id="itemsSharedTo"
     
    542548          </tbl:data>
    543549        </tbl:table>
     550        </base:section>
    544551        <%
    545552      }
Note: See TracChangeset for help on using the changeset viewer.