Changeset 654


Ignore:
Timestamp:
Apr 11, 2008, 5:40:25 PM (15 years ago)
Author:
mbayer
Message:

have made a number of changes relating to Affy support and fixed several bugs; Affy import now works too but we still haven't got inherited experimental factors showing for individual bioassays attached to an imported experiment

Location:
plugins/base2/uk.ac.ebi.tab2mage/branches/tab2mageimporter
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • plugins/base2/uk.ac.ebi.tab2mage/branches/tab2mageimporter/jsp/uk/ac/ebi/nugo/plugins/experiment.jsp

    r639 r654  
    186186      <tr class="noBorder">
    187187        <td style="border-style: none;"><select name="accession" onchange="arrayDesignOnChange()">
    188         <option selected="selected">Agilent potato POCI 1x44k</option>
     188        <option selected="selected">Agilent1</option>
    189189        </select></td>
    190190        <td style="border-style: none;">
  • plugins/base2/uk.ac.ebi.tab2mage/branches/tab2mageimporter/jsp/uk/ac/ebi/nugo/plugins/hybridizations.jsp

    r643 r654  
    158158    <td class="input">
    159159    <select name="platform">
    160     <option onclick="hideTwoChannelQuestions();">Affymetrix</option>
    161     <option onclick="showTwoChannelQuestions();" selected="selected" >Agilent</option>
     160    <option onclick="hideTwoChannelQuestions();" selected="selected" >Affymetrix</option>
     161    <option onclick="showTwoChannelQuestions();" >Agilent</option>
    162162    <option onclick="showTwoChannelQuestions();">AIDA</option>
    163163    <option onclick="showTwoChannelQuestions();">BZScan</option>
     
    178178  <tr>
    179179    <td class="boldText">Experimental organism:<font color="red"><b>&nbsp;*</b></font></td>
    180     <td class="input"><input type="text" size="50" name="organism" value="Mus musculus"/></td>
     180    <td class="input"><input type="text" size="50" name="organism" value="Homo sapiens"/></td>
    181181    <td>The full scientific name of the experimental organism used.</td>
    182182  </tr>
     
    185185  <tr>
    186186    <td class="boldText">Number of hybridizations:<font color="red"><b>&nbsp;*</b></font></td>
    187     <td class="input"><input type="text" size="3" name="numHybs" value="12"/></td>
     187    <td class="input"><input type="text" size="3" name="numHybs" value="32"/></td>
    188188    <td>The total number of hybridizations in the experiment. <b>Please note: for two-channel experiments there are two hybridizations per chip.</b>
    189189    </td>
     
    193193  <tr>
    194194    <td class="boldText">Experimental factors:<font color="red"><b>&nbsp;*</b></font> </td>
    195     <td class="input"><textarea rows="7" cols="35" name="expFactors" >Genotype(wild type,PGC-1 beta transgenic)</textarea></td>
     195    <td class="input"><textarea rows="7" cols="35" name="expFactors" ></textarea></td>
    196196    <td>Please list all experimental factors and value ranges using the following format (one per
    197197    line):<br>
     
    215215  <tr>
    216216    <td class="boldText">Target tissues:<font color="red"><b>&nbsp;*</b></font></td>
    217     <td class="input"><textarea rows="4" cols="32" name="tissues">heart</textarea></td>
     217    <td class="input"><textarea rows="4" cols="32" name="tissues">blood</textarea></td>
    218218    <td>List all target tissues -- one per line, in no particular order, each tissue once only.</td>
    219219  </tr>
     
    228228      <tr class="noBorder" >
    229229     
    230         <td style="vertical-align: middle;border-style: none;"><input type="text" name="path" size="35" value="/home/michab/E-MEXP-1340.raw.zip"></td>
     230        <td style="vertical-align: middle;border-style: none;"><input type="text" name="path" size="35" value=""></td>
    231231       
    232232        <td  style="vertical-align: middle;border-style: none;">
  • plugins/base2/uk.ac.ebi.tab2mage/branches/tab2mageimporter/src/uk/ac/ebi/nugo/common/ZipUnpacker.java

    r477 r654  
    44  Developed at the EBI , Cambridge.
    55  Author: Dominic Oyeniran: oyeniran@ebi.ac.uk
    6 */
     6 */
    77package uk.ac.ebi.nugo.common;
    88
     
    6060    Unpacks a zip file, checking that there is enough space to accommodate
    6161    the zip file once it is unpacked.
    62     */
     62   */
    6363  public void unpack(String dirName)
    6464  {
    6565    log.info("Begin to unpack the files");
     66   
     67    InputStream inStream =  null;
    6668    DbControl dc=null;
    6769    try
     
    6971      dc= sc.newDbControl();
    7072      if (file==null)
     73      {
     74        log.debug("file is null -- returning");
    7175        return;
    72       InputStream inStream =  file.getDownloadStream(0);
     76      }
     77      log.debug("getting input stream for file " + file.getName());
     78     
     79      int bytesAvailable = 0;
     80      while(inStream == null || bytesAvailable==0)
     81      {
     82        try
     83        {
     84          log.debug("trying to get input stream for file " + file.getName());
     85          inStream =file.getDownloadStream(0);
     86          log.debug("inStream = " + inStream);
     87          if(inStream != null)
     88          {
     89            bytesAvailable = inStream.available();
     90            log.debug("bytes available from this input stream = " + bytesAvailable);
     91          }
     92        }
     93        catch (Exception e)
     94        {
     95          e.printStackTrace();
     96        }
     97      }
     98     
     99      zipFileSize = getZipfileEntriesSize(inStream);
     100      log.info("size of zip file = " + zipFileSize);
    73101      //check if the logged in user has sufficient disk space. if yes go ahead with the unpacking
    74102      boolean hasSpace= checkUserQuota(inStream, dc);
    75103      if (hasSpace)
    76104      {
     105        log.debug("space is sufficient -- unpacking");
    77106        createSubDirectory( file, user, dirName);
    78107        // now call the method to unpack the zip files
     
    80109        FileUnpacker unpacker = zipFilePlugin.newInstance(net.sf.basedb.plugins.ZipFileUnpacker.class, null, dc.getSessionControl(), null, null);
    81110        numUnpackedFiles=unpacker.unpack(dc, unzippedFilesDirectory,file.getDownloadStream(0), false,null);
     111        log.debug("numUnpackedFiles = " + numUnpackedFiles);
    82112      }
    83113      else // if space is not enough
    84114      {
     115        log.debug("User do not have the required Disk Space. Please contact your BASE administrator or remove some files");
    85116        throw new BaseException("User do not have the required Disk Space. Please contact your BASE administrator or remove some files");
    86117      }
     
    90121    catch (Throwable exc)
    91122    {
     123      exc.printStackTrace();
    92124      dc.close();
    93125      log.info("File cannot be unpacked", exc);
     
    98130      if (dc!=null)
    99131        dc.close();
    100     }
    101   }
    102  
    103  
    104   /**
    105     Unpacks a zip file, checking that there is enough space to accommodate
    106     the zip file once it is unpacked.
    107       @throws NutribasePluginException
    108    */
    109   public void unpack()
    110   {
    111     log.info("Begin to unpack the files");
    112     DbControl dc=null;
    113     try
    114     {
    115       dc= sc.newDbControl();
    116       if (file==null)
    117         return;
    118       InputStream inStream =  file.getDownloadStream(0);
    119       //check if the logged in user has sufficient disk space. if yes go ahead with the unpacking
    120       boolean hasSpace= checkUserQuota(inStream, dc);
    121       if (hasSpace)
    122       {
    123         createSubDirectory( file, user);
    124         // now call the method to unpack the zip files
    125         PluginDefinition zipFilePlugin = PluginDefinition.getByClassName(dc, "net.sf.basedb.plugins.ZipFileUnpacker");
    126         FileUnpacker unpacker = zipFilePlugin.newInstance(net.sf.basedb.plugins.ZipFileUnpacker.class, null, dc.getSessionControl(), null, null);
    127         numUnpackedFiles=unpacker.unpack(dc, unzippedFilesDirectory,file.getDownloadStream(0), false,null);
    128       }
    129       else // if space is not enough
    130       {
    131         throw new BaseException("User do not have the required Disk Space. Please contact your BASE administrator or remove some files");
    132       }
    133       dc.commit();
    134       inStream.close();
    135     }
    136     catch (Throwable exc)
    137     {
    138       dc.close();
    139       log.info("File cannot be unpacked", exc);
    140       new BaseException(exc.getMessage());
    141     }
    142     finally
    143     {
    144       if (dc!=null)
    145         dc.close();
    146     }
    147   }
    148 
     132      if(inStream !=null)
     133        try
     134      {
     135          inStream.close();
     136      }
     137      catch (IOException e)
     138      {
     139        e.printStackTrace();
     140      }
     141    }
     142  }
     143 
     144 
    149145  /**
    150146    checks user quota
     
    156152  {
    157153    boolean hasDiskSpace= false; 
    158     zipFileSize = getZipfileEntriesSize(inStream);
    159154    //get the user's current disk usage and quota
    160155    Quota quota = user.getQuota();
     
    164159    log.info("the quota value of the user: " + user.getName()+ " is: "+quotaValue );
    165160    long currentDiskUsage = user.getDiskUsage(totalQuotaType, Location.PRIMARY);
    166       //check whether remaining disk space and zip file size are compatible
     161    //check whether remaining disk space and zip file size are compatible
    167162    long remainingSpace = quotaValue - currentDiskUsage;
    168163    log.info("the remaining space for user: " + user.getName()+ " is: "+remainingSpace );
     
    176171      hasDiskSpace=true;
    177172    }
     173    log.debug("hasDiskSpace = "+ hasDiskSpace);
    178174    return hasDiskSpace;
    179175  }
     
    184180      @return long - the total size of the zip file uncompressed, in bytes
    185181   
    186   */
     182  */
    187183  public static long getZipfileEntriesSize(InputStream fileInputStream)
    188184  {
    189185    long totalSize =0;
    190       try
    191       {
    192         ZipInputStream zipStream = new ZipInputStream(fileInputStream);     
    193         ZipEntry entry = zipStream.getNextEntry();
    194         while(entry!=null)
    195         {
    196           long size = entry.getSize();
    197           totalSize += size;
    198           entry = zipStream.getNextEntry();
    199         }
    200       }
    201       catch (IOException ioe)
    202       {
    203         throw new BaseException("zip file size could not be obtained " + ioe.getMessage());
    204       }
    205       return totalSize;
    206     }
     186    try
     187    {
     188      ZipInputStream zipStream = new ZipInputStream(fileInputStream);     
     189      ZipEntry entry = zipStream.getNextEntry();
     190      while(entry!=null)
     191      {
     192        long size = entry.getSize();
     193        log.debug("checking next zip file entry - size is " + size);
     194        totalSize += size;
     195        entry = zipStream.getNextEntry();
     196      }
     197    }
     198    catch (Exception e)
     199    {
     200      e.printStackTrace();
     201    }
     202    return totalSize;
     203  }
    207204  /**
    208205    create a sub-directory to contain the unzip files
     
    225222      Directory subDir = d.newSubDirectory();
    226223      subDir.setName(dirName);
    227         subDir.setDescription("Unzippped directory created at "+new Date());
     224      subDir.setDescription("Unzippped directory created at "+new Date());
    228225      if (subDir.isInDatabase())
    229226      {
     
    235232      }
    236233      dc.commit();
    237         setUnzippedFilesDirectory(subDir);
     234      setUnzippedFilesDirectory(subDir);
    238235    }
    239236    catch (Throwable ex)
     
    245242      if (dc!=null) dc.close();
    246243    }
    247            
    248    }
    249 
     244   
     245  }
     246 
    250247  /**
    251248    create a sub-directory to contain the unzip files
     
    267264      Directory subDir = d.newSubDirectory();
    268265      String fileName = zipFile.getName();
    269         String fileNameNoExt = fileName.substring(0, fileName.indexOf("."));
    270         subDir.setName(fileNameNoExt);
    271         subDir.setDescription("Unzippped directory created at "+new Date());
     266      String fileNameNoExt = fileName.substring(0, fileName.indexOf("."));
     267      subDir.setName(fileNameNoExt);
     268      subDir.setDescription("Unzippped directory created at "+new Date());
    272269      if (subDir.isInDatabase())
    273270      {
     
    279276      }
    280277      dc.commit();
    281         setUnzippedFilesDirectory(subDir);
     278      setUnzippedFilesDirectory(subDir);
    282279    }
    283280    catch (Throwable ex)
     
    290287      if (dc!=null) dc.close();
    291288    }
    292            
    293    }
    294 
     289   
     290  }
     291 
    295292  void setUnzippedFilesDirectory(Directory unzippedFilesDirectory)
    296293  {
    297294    this.unzippedFilesDirectory = unzippedFilesDirectory;
    298295  }
    299 
     296 
    300297  public Directory getUnzippedFilesDirectory()
    301298  {
  • plugins/base2/uk.ac.ebi.tab2mage/branches/tab2mageimporter/src/uk/ac/ebi/nugo/plugins/Tab2MageImporter.java

    r639 r654  
    205205
    206206    String message = null;
    207     if (item == null)
    208     {
    209       message = "The object is null";
    210 
    211     }
    212     else if (!(item instanceof Experiment))
    213     {
    214       message = "The object is not an Experiment: " + item;
    215     }
    216     else
    217     {   
    218       Experiment exp = (Experiment)item;
    219       RawDataType rawDataType = exp.getRawDataType();
    220       if (!Tab2MageHelper.supportedPlatforms(rawDataType.getId().toLowerCase()))
    221       {
    222         message = "This importer only supports Affymetrix, Agilent and Genepix Platforms. Your experiment's platform is :" + rawDataType.getId().toLowerCase();
    223       }
     207    try
     208    {
     209      if (item == null)
     210      {
     211        message = "The object is null";
     212
     213      }
     214      else if (!(item instanceof Experiment))
     215      {
     216        message = "The object is not an Experiment: " + item;
     217      }
     218      else
     219      {   
     220        Experiment exp = (Experiment)item;
     221        RawDataType rawDataType = exp.getRawDataType();
     222        if (!Tab2MageHelper.supportedPlatforms(rawDataType.getName().toLowerCase()))
     223        {
     224          message = "This importer only supports Affymetrix, Agilent and Genepix Platforms. Your experiment's platform is :" + rawDataType.getId().toLowerCase();
     225          System.out.println("platform not supported");
     226        }
     227      }
     228    }
     229    catch (Exception e)
     230    {
     231      e.printStackTrace();
    224232    }
    225233    return message;
     
    417425
    418426      // validate files supplied to platform
     427      System.out.println("raw data type = " + rdt.getName());
    419428      validPlatform=Tab2MageHelper.validatePlatform(dir, dc, rdt);
    420429      if (!validPlatform)
  • plugins/base2/uk.ac.ebi.tab2mage/branches/tab2mageimporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/Tab2MageDataImportFactory.java

    r558 r654  
    109109    String ext = Helper.getFileExtension(file);
    110110    // check if the file actually contains the extension we approved.
    111     if (!ExperimentPlatformsLibrary.fromExtension(ext).getPlatformName().equalsIgnoreCase(platform))
    112       throw new NutribasePluginException("data file [" + file.getName() + "] do not match platform [" + platform + "] specified");
     111    if (!platform.endsWith(ExperimentPlatformsLibrary.fromExtension(ext).getPlatformName()))
     112      throw new NutribasePluginException("data file [" + file.getName() + "] does not match platform [" + platform + "] specified");
    113113    this.file = file;
    114114  }
     
    122122  {
    123123    log.info("\n+++ Begin Data Import +++\n");
     124    log.debug("platform = " + platform);
    124125    DbControl dc = null;
    125126    boolean success = true;
     
    130131      checkFile(exampleFile);
    131132      log.debug("file check is successful");
    132       if (platform.equalsIgnoreCase("affymetrix"))
     133      if (platform.endsWith("affymetrix"))
    133134      {
    134135        if (dc == null)
     
    149150        dc.commit();
    150151      }
    151       else if (!platform.equalsIgnoreCase("affymetrix"))// 2. import 2-channel -- include checkpoints and rollback points
     152      else if (!platform.endsWith("affymetrix"))// 2. import 2-channel -- include checkpoints and rollback points
    152153      {
    153154        log.info(".......beginning [" + platform + "] data loading");
  • plugins/base2/uk.ac.ebi.tab2mage/branches/tab2mageimporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/Tab2MageHybWriter.java

    r471 r654  
    209209      catch(Throwable tr)
    210210      {
     211        tr.printStackTrace();
    211212        return done=false;
    212213      }
  • plugins/base2/uk.ac.ebi.tab2mage/branches/tab2mageimporter/src/uk/ac/ebi/nugo/plugins/util/tab2mage/Tab2MageHelper.java

    r558 r654  
    1616import net.sf.basedb.core.RawDataType;
    1717
     18import org.apache.log4j.Logger;
    1819import org.embl.cg.bloader.models.Tab2MAGEProtocol;
    1920
    2021import uk.ac.ebi.nugo.common.Helper;
    2122import uk.ac.ebi.nugo.common.NutribasePluginException;
     23import uk.ac.ebi.nugo.common.ZipUnpacker;
    2224import uk.ac.ebi.nugo.plugins.tab2mageimport.ExperimentPlatformsLibrary;
    2325import uk.ac.ebi.nugo.plugins.tab2mageimport.ImageLibrary;
    2426
    2527/**
    26   A plugin utils class for the tab2mage export and export. 
    27   [TODO] This class may be merged to other utils in the main base 2 source code
    28   @author Dominic Oyeniran
    29   @version 1.0
    30 */
    31 
    32 public class Tab2MageHelper 
     28 * A plugin utils class for the tab2mage export and export. [TODO] This class may be merged to other utils in the main base 2 source code
     29 *
     30 * @author Dominic Oyeniran
     31 * @version 1.0
     32 */
     33
     34public class Tab2MageHelper
    3335{
    34    /**
    35       validates the raw data file supplied  with experment platform i.e the raw data type
    36       @param dir, a base2 directory containing the raw files
    37       @param dc, database control for database access
    38       @param rdt, the raw data type for the experiment.
    39       @return validPlatform, true if file is validated and false if not
    40     */
    41    public static boolean validatePlatform(Directory dir, DbControl dc, RawDataType rdt)
    42    {
    43     boolean validPlatform =false;
    44      try
    45      {
    46        Directory directory = Directory.getByPath(dc, dir.getPath());
    47        ItemQuery<File> fileQuery = directory.getFiles();
    48        fileQuery.include(Include.MINE, Include.NOT_REMOVED, Include.IN_PROJECT);
    49         if (fileQuery.count(dc)==0)
    50          //dir.getSubDirectories();
    51          return validPlatform;
    52        ItemResultList<File> fileList = fileQuery.list(dc);
    53        System.out.println("The number of files in Dir : " + directory.getPath()+ " is : " +fileList.size());
    54        String agilent= ExperimentPlatformsLibrary.TXT.getPlatformName();
    55        for (File file: fileList)
    56        {
    57          // get the file extension
     36 
     37  protected static Logger log = Logger.getLogger(Tab2MageHelper.class);
     38 
     39  /**
     40   * validates the raw data file supplied with experment platform i.e the raw data type
     41   *
     42   * @param dir,
     43   *                a base2 directory containing the raw files
     44   * @param dc,
     45   *                database control for database access
     46   * @param rdt,
     47   *                the raw data type for the experiment.
     48   * @return validPlatform, true if file is validated and false if not
     49   */
     50  public static boolean validatePlatform(Directory dir, DbControl dc, RawDataType rdt)
     51  {
     52    boolean validPlatform = false;
     53    try
     54    {
     55      Directory directory = Directory.getByPath(dc, dir.getPath());
     56      ItemQuery<File> fileQuery = directory.getFiles();
     57      fileQuery.include(Include.MINE, Include.NOT_REMOVED, Include.IN_PROJECT);
     58      if (fileQuery.count(dc) == 0)
     59      {
     60        log.debug("no files found - return false");
     61        return validPlatform;
     62      }
     63      ItemResultList<File> fileList = fileQuery.list(dc);
     64      log.debug("The number of files in dir : " + directory.getPath() + " is : " + fileList.size());
     65      String agilent = ExperimentPlatformsLibrary.TXT.getPlatformName();
     66      for (File file : fileList)
     67      {
     68        // get the file extension
    5869        String ext = Helper.getFileExtension(file);
     70        log.debug("ext = " + ext);
    5971        /*
    60           We accept all files with .txt cos of the ambiquity caused by agilent raw data file (.txt) format.
    61           Tab2mage file also has a .txt extension
    62          */
    63        
     72         * We accept all files with .txt cos of the ambiquity caused by agilent raw data file (.txt) format. Tab2mage file also has a .txt extension
     73         */
     74
    6475        if (!ext.equalsIgnoreCase(ExperimentPlatformsLibrary.TXT.getFileExtension()))
    65         { 
    66           //System.out.println("++++ Now checking platform +++++++++++");
    67           ExperimentPlatformsLibrary platform = ExperimentPlatformsLibrary.fromExtension(ext);   
    68           if (platform!=null) // platform (raw data files provided) is supported
    69           {
    70             if (platform.getPlatformName().equalsIgnoreCase(rdt.getId())) //does the files match experiment platform?
     76        {
     77          log.debug("++++ Now checking platform +++++++++++");
     78          ExperimentPlatformsLibrary platform = ExperimentPlatformsLibrary.fromExtension(ext);
     79          if (platform != null) // platform (raw data files provided) is supported
     80          {
     81            if (platform.getPlatformName().equalsIgnoreCase(rdt.getName())) // does the files match experiment platform?
    7182            {
    72               validPlatform= true;
     83              log.debug("setting validPlatform to true");
     84              validPlatform = true;
    7385            }
    74           } else if (platform == null) //raw data files -platforms are not supported.
    75           {
    76             validPlatform= false;
    77           }
    78         }else if (ext.equalsIgnoreCase(ExperimentPlatformsLibrary.TXT.getFileExtension()) && agilent.equalsIgnoreCase(rdt.getId()) )
    79           validPlatform= true;
    80       }
     86          }
     87          else
     88            if (platform == null) // raw data files -platforms are not supported.
     89            {
     90              log.debug("platform object is null -- platform not supported");
     91              validPlatform = false;
     92            }
     93        }
     94        else
     95          if (ext.equalsIgnoreCase(ExperimentPlatformsLibrary.TXT.getFileExtension()) && agilent.equalsIgnoreCase(rdt.getName()))
     96          {
     97            log.debug("setting validPlatform to true");
     98            validPlatform = true;
     99          }
     100          else
     101          {
     102            log.debug("ignoring this file");
     103          }
     104      }
     105      log.debug("returning validPlatform = " + validPlatform);
    81106      return validPlatform;
    82      }
    83      catch (Throwable t)
    84      {
    85         return false;
    86      }
    87   }
    88    /**
    89       validates the image file supplied with experment platform i.e the raw data type
    90       @param imageFiles, the list of images. The List<file> must be checked to contain files
    91       and not null by the calling method.
    92       @param rdt, the raw data type for the experiment.
    93       @return valid, true if image file is validated and supported and false otherwise
    94     */
    95    public static boolean validateImages(List<File> imageFiles, RawDataType rdt)
    96    {
    97      boolean valid = false;
    98      for (File imageFile : imageFiles)
    99      {
    100        String ext = Helper.getFileExtension(imageFile);
    101        ImageLibrary image = ImageLibrary.fromExtension(ext);
    102        if (image == null)
    103        {
    104           valid= false;
    105        }
    106        else if (image!=null)
    107        {
    108          if (image.getSupportedPlatform().equalsIgnoreCase(rdt.getId()))
    109          {
    110            valid =true;
    111          }
    112        }
    113      }
    114      return valid;
    115    }
    116    /**
    117       retrieves all image files
    118       @param dir, directory containing the image files
    119       @param dc
    120       @return list of image files
    121     */
    122    public static List<File> getImageFiles(Directory dir, DbControl dc)
    123    {
    124      List<File> imageFiles = new ArrayList<File>();
    125      try
    126      {
    127        ItemQuery<File> fileQuery = dir.getFiles();
    128        if (fileQuery.count(dc)==0)
    129         return imageFiles;
    130        ItemResultList<File> fileList = fileQuery.list(dc);
    131        //System.out.println("The number of files in Dir : " + dir.getPath()+ " is : " +fileList.size());
    132        for (File file: fileList)
    133        {
    134          String ext = Helper.getFileExtension(file);
    135          // get all image files: these are files that have a.tiff and.dat extension
    136         if ( ext.equals(ImageLibrary.TIFF.getExtension()) || ext.equals(ImageLibrary.DAT.getExtension()))
     107    }
     108    catch (Throwable t)
     109    {
     110      t.printStackTrace();
     111      return false;
     112    }
     113  }
     114 
     115  /**
     116   * validates the image file supplied with experment platform i.e the raw data type
     117   *
     118   * @param imageFiles,
     119   *                the list of images. The List<file> must be checked to contain files and not null by the calling method.
     120   * @param rdt,
     121   *                the raw data type for the experiment.
     122   * @return valid, true if image file is validated and supported and false otherwise
     123   */
     124  public static boolean validateImages(List<File> imageFiles, RawDataType rdt)
     125  {
     126    boolean valid = false;
     127    for (File imageFile : imageFiles)
     128    {
     129      String ext = Helper.getFileExtension(imageFile);
     130      ImageLibrary image = ImageLibrary.fromExtension(ext);
     131      if (image == null)
     132      {
     133        valid = false;
     134      }
     135      else
     136        if (image != null)
     137        {
     138          if (image.getSupportedPlatform().equalsIgnoreCase(rdt.getId()))
     139          {
     140            valid = true;
     141          }
     142        }
     143    }
     144    return valid;
     145  }
     146 
     147  /**
     148   * retrieves all image files
     149   *
     150   * @param dir,
     151   *                directory containing the image files
     152   * @param dc
     153   * @return list of image files
     154   */
     155  public static List<File> getImageFiles(Directory dir, DbControl dc)
     156  {
     157    List<File> imageFiles = new ArrayList<File>();
     158    try
     159    {
     160      ItemQuery<File> fileQuery = dir.getFiles();
     161      if (fileQuery.count(dc) == 0)
     162        return imageFiles;
     163      ItemResultList<File> fileList = fileQuery.list(dc);
     164      // System.out.println("The number of files in Dir : " + dir.getPath()+ " is : " +fileList.size());
     165      for (File file : fileList)
     166      {
     167        String ext = Helper.getFileExtension(file);
     168        // get all image files: these are files that have a.tiff and.dat extension
     169        if (ext.equals(ImageLibrary.TIFF.getExtension()) || ext.equals(ImageLibrary.DAT.getExtension()))
    137170        {
    138171          imageFiles.add(file);
    139172        }
    140        }
    141      }
    142      catch (Throwable t)
    143      {
    144        throw new NutribasePluginException(t.getMessage());
    145      }
    146      return imageFiles;
    147    }
    148    /**
    149         gets all raw data files
    150        @param dir, directory containing the data files
    151        @param dc, the db control
    152        @param platform, the experiment platform
    153        @param tab2mageFileName, the tab2mage file name.
    154        @return list of raw data files matching the platform
    155     */
    156    public static List<File> getRawDataFiles(Directory dir, DbControl dc, String platform, String tab2mageFileName)
    157    {
    158      List<File> rawDataFiles = new ArrayList<File>();
    159      try
    160      {
    161        ItemQuery<File> fileQuery = dir.getFiles();
    162        if (fileQuery.count(dc)==0)
    163          return rawDataFiles;
    164        ItemResultList<File> fileList = fileQuery.list(dc);
    165        for (File file: fileList)
    166        {
    167          String ext = Helper.getFileExtension(file);
    168          // check if the ext is cel gpr or agilent and get the correct file.
    169          if (ext.equals(ExperimentPlatformsLibrary.GPR.getFileExtension()))
    170          {
    171            rawDataFiles.add(file);
    172          }
    173          else if (ext.equals(ExperimentPlatformsLibrary.TXT.getFileExtension()) &&
    174               platform.equalsIgnoreCase(ExperimentPlatformsLibrary.fromExtension(ext).getPlatformName()))
    175          { 
    176            if (!file.getName().equalsIgnoreCase(tab2mageFileName))
    177              rawDataFiles.add(file);
    178          }
    179          else if (ext.equals(ExperimentPlatformsLibrary.CEL.getFileExtension()))
    180          {
    181            rawDataFiles.add(file);
    182          }
    183        }
    184      }
    185      catch (Throwable t)
    186      {
     173      }
     174    }
     175    catch (Throwable t)
     176    {
    187177      throw new NutribasePluginException(t.getMessage());
    188      }
     178    }
     179    return imageFiles;
     180  }
     181 
     182  /**
     183   * gets all raw data files
     184   *
     185   * @param dir,
     186   *                directory containing the data files
     187   * @param dc,
     188   *                the db control
     189   * @param platform,
     190   *                the experiment platform
     191   * @param tab2mageFileName,
     192   *                the tab2mage file name.
     193   * @return list of raw data files matching the platform
     194   */
     195  public static List<File> getRawDataFiles(Directory dir, DbControl dc, String platform, String tab2mageFileName)
     196  {
     197    List<File> rawDataFiles = new ArrayList<File>();
     198    try
     199    {
     200      ItemQuery<File> fileQuery = dir.getFiles();
     201      if (fileQuery.count(dc) == 0)
     202        return rawDataFiles;
     203      ItemResultList<File> fileList = fileQuery.list(dc);
     204      for (File file : fileList)
     205      {
     206        String ext = Helper.getFileExtension(file);
     207        // check if the ext is cel gpr or agilent and get the correct file.
     208        if (ext.equals(ExperimentPlatformsLibrary.GPR.getFileExtension()))
     209        {
     210          rawDataFiles.add(file);
     211        }
     212        else
     213          if (ext.equals(ExperimentPlatformsLibrary.TXT.getFileExtension()) && platform.equalsIgnoreCase(ExperimentPlatformsLibrary.fromExtension(
     214                  ext).getPlatformName()))
     215          {
     216            if (!file.getName().equalsIgnoreCase(tab2mageFileName))
     217              rawDataFiles.add(file);
     218          }
     219          else
     220            if (ext.equals(ExperimentPlatformsLibrary.CEL.getFileExtension()))
     221            {
     222              rawDataFiles.add(file);
     223            }
     224      }
     225    }
     226    catch (Throwable t)
     227    {
     228      throw new NutribasePluginException(t.getMessage());
     229    }
    189230    return rawDataFiles;
    190    }
    191    /**
    192       checks if the protocol type in the <code> Tab2MAGEProtocol</code> object exists in BASE
    193       @param prot, the Tab2MAGEProtocol object that abstracts the tab2mage protocol section
    194       @param dc, the db control
    195       @return true if the protocol exist, false if not.
    196     */
    197    public static boolean checkIfProtocolTypesExist(Tab2MAGEProtocol prot, DbControl dc)
    198     {
    199       boolean found  = false;
    200       List<String> names = new ArrayList<String>();
    201       ItemResultList<ProtocolType> protocolTypes= ProtocolType.getQuery().list(dc);
    202       for (ProtocolType protocolType : protocolTypes)
    203       {
    204         names.add(protocolType.getName().toLowerCase().trim());
    205       }
    206       if (names.contains(prot.getType().toLowerCase()))
    207       {
    208         //System.out.printf("The protocol type:[ %s ] is found in the database\n", prot.getType().toString());
    209         found = true;
    210       }
    211       return found;
    212     }
    213    
    214    /**
    215       finds Ta2Mage Accession or Serial in the array Information Map
    216       @param arrayInformationMap, the map that contains the tab2mage file array acession and array serial information
    217       @param stringToFind, the string to match to a key in the  map
    218       @return, the value that matches the key : stringToFind
    219     */
    220    @SuppressWarnings("unchecked")
    221   public static String  findTab2MageAccessionOrSerial(HashMap arrayInformationMap, String stringToFind)
    222   {
    223     String value="";
     231  }
     232 
     233  /**
     234   * checks if the protocol type in the <code> Tab2MAGEProtocol</code> object exists in BASE
     235   *
     236   * @param prot,
     237   *                the Tab2MAGEProtocol object that abstracts the tab2mage protocol section
     238   * @param dc,
     239   *                the db control
     240   * @return true if the protocol exist, false if not.
     241   */
     242  public static boolean checkIfProtocolTypesExist(Tab2MAGEProtocol prot, DbControl dc)
     243  {
     244    boolean found = false;
     245    List<String> names = new ArrayList<String>();
     246    ItemResultList<ProtocolType> protocolTypes = ProtocolType.getQuery().list(dc);
     247    for (ProtocolType protocolType : protocolTypes)
     248    {
     249      names.add(protocolType.getName().toLowerCase().trim());
     250    }
     251    if (names.contains(prot.getType().toLowerCase()))
     252    {
     253      // System.out.printf("The protocol type:[ %s ] is found in the database\n", prot.getType().toString());
     254      found = true;
     255    }
     256    return found;
     257  }
     258 
     259  /**
     260   * finds Ta2Mage Accession or Serial in the array Information Map
     261   *
     262   * @param arrayInformationMap,
     263   *                the map that contains the tab2mage file array acession and array serial information
     264   * @param stringToFind,
     265   *                the string to match to a key in the map
     266   * @return, the value that matches the key : stringToFind
     267   */
     268  @SuppressWarnings("unchecked")
     269  public static String findTab2MageAccessionOrSerial(HashMap arrayInformationMap, String stringToFind)
     270  {
     271    String value = "";
    224272    HashMap<String, String> map = new HashMap<String, String>();
    225     map =arrayInformationMap;
    226     for(Map.Entry<String, String> entry: map.entrySet())
    227       {
    228         if (entry.getKey().equalsIgnoreCase(stringToFind))
    229         {
    230           value = entry.getValue();
    231         }
    232       }
     273    map = arrayInformationMap;
     274    for (Map.Entry<String, String> entry : map.entrySet())
     275    {
     276      if (entry.getKey().equalsIgnoreCase(stringToFind))
     277      {
     278        value = entry.getValue();
     279      }
     280    }
    233281    return value;
    234282  }
    235283 
    236284  /**
    237     checks that the experiment's raw data type is a supported platforms for thetab2mage importer
    238     @param rawDataType. the experiment raw data type type
    239       @return True if supported , false otherwise.
     285   * checks that the experiment's raw data type is a supported platforms for thetab2mage importer
     286   *
     287   * @param rawDataType.
     288   *                the experiment raw data type type
     289   * @return True if supported , false otherwise.
    240290   */
    241291  public static boolean supportedPlatforms(String rawDataType)
    242292  {
    243     boolean s= false;
    244     List<String> p= new ArrayList<String>();
    245     List<ExperimentPlatformsLibrary> platforms= Arrays.asList(ExperimentPlatformsLibrary.values());
     293    boolean s = false;
     294    List<String> p = new ArrayList<String>();
     295    List<ExperimentPlatformsLibrary> platforms = Arrays.asList(ExperimentPlatformsLibrary.values());
    246296    for (ExperimentPlatformsLibrary plat : platforms)
    247297    {
     
    249299    }
    250300    if (p.contains(rawDataType.toLowerCase()))
    251         s= true;
     301      s = true;
    252302   
    253303    return s;
    254304  }
    255305 
    256  
    257306}
Note: See TracChangeset for help on using the changeset viewer.