Changeset 486


Ignore:
Timestamp:
Nov 23, 2007, 3:50:59 PM (16 years ago)
Author:
mbayer
Message:

first commit of this branch

  • have added JSP page for custom input.html to take parameters that allows the plugin to configure an entire experiment itself
  • have modified the plugin class to take the parameters and print them out -- normal input disabled right now
  • build file modified slightly -- new targets included etc
Location:
branches/uk_ac_ebi_Tab2MageImporter
Files:
8 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/uk_ac_ebi_Tab2MageImporter/build.xml

    r473 r486  
    11<?xml version="1.0" encoding="UTF-8"?>
    2 <project name="EBIPlugin"  default="build.plugin" basedir="."  >
     2<project name="EBIPlugin" default="copyToServer" basedir=".">
    33
    44  <!-- variables used -->
     
    88  <property name="util.src.plugins" location="${src.plugins}/uk/ac/ebi/nugo/common/" />
    99  <property name="core.src.plugins" location="${src.plugins}/uk/ac/ebi/nugo/plugins" />
    10    
    11   <property name="javac.arg" value="-Xlint:unchecked"
    12       description="Extra arguments sent to Java compiler" />
     10
    1311  <property name="plugin.name" value="Tab2MageImporter" />
    1412  <property name="utils.name" value="ebi-plugins-utils" />
     13  <property name="jspDir" location="jsp" />
    1514 
     15  <!-- tomcat -->
     16  <!-- property name="tomcat.home" value="${env.CATALINA_HOME}" / -->
     17  <property name="tomcat.home" value="C:\tomcat\apache-tomcat-6.0.13"/>
     18  <property name="tomcat.shutdownscript" value="${tomcat.home}/bin/shutdown.bat" />
     19  <property name="tomcat.startupscript" value="${tomcat.home}/bin/startup.bat" />
     20 
     21
    1622  <!-- set up classpath for compiling -->
    1723  <path id="nugo.plugin.compile.classpath">
    1824    <fileset dir="${lib.plugins}">
    19       <include name="**/*.jar"/>
     25      <include name="**/*.jar" />
    2026    </fileset>
    2127  </path>
    22    
    23   <target
    24     name="build.plugin"
    25     depends= "utils,plugin.compile"
    26     description="Compile the plugin"
    27   />
    28    
    29   <target name="utils"
    30     depends="clean"
    31     description="compile the common ebi -plugin util classes"
    32     >
    33     <javac
    34       encoding="ISO-8859-1"
    35       srcdir="${util.src.plugins}"
    36       destdir="${bin.plugins}"
    37       classpathref="nugo.plugin.compile.classpath"
    38       debug="true"
    39       deprecation="true"
    40       >
    41       <compilerarg value="${javac.arg}" />
     28
     29  <target name="build.plugin" depends="utils,plugin.compile" description="Compile the plugin" />
     30
     31  <target name="utils" depends="clean" description="compile the common ebi -plugin util classes">
     32    <javac encoding="ISO-8859-1" srcdir="${util.src.plugins}" destdir="${bin.plugins}" classpathref="nugo.plugin.compile.classpath" debug="true" deprecation="true">
    4233    </javac>
    43     <jar
    44       basedir="${bin.plugins}"
    45       jarfile="${lib.plugins}\ebi-plugins-utils.jar"
    46     />
    47     <jar
    48       basedir="${bin.plugins}"
    49       jarfile="${utils.name}.jar"
    50     />
     34    <jar basedir="${bin.plugins}" jarfile="${lib.plugins}\ebi-plugins-utils.jar" />
     35    <jar basedir="${bin.plugins}" jarfile="${utils.name}.jar" />
    5136    <delete includeemptydirs="true">
    52       <fileset dir="${bin.plugins}" includes="**/*"/>
     37      <fileset dir="${bin.plugins}" includes="**/*" />
    5338    </delete>
    5439  </target>
    55  
    56   <target
    57       name="plugin.compile"
    58       depends="clean"
    59       description="compile the ta2mage importer plugin source code, without dependencies and put in a jar file"
    60       >
    61       <javac
    62         encoding="ISO-8859-1"
    63         srcdir="${core.src.plugins}"
    64         destdir="${bin.plugins}"
    65         classpathref="nugo.plugin.compile.classpath"
    66         debug="true"
    67         deprecation="true"
    68         >
    69         <compilerarg value="${javac.arg}" />
    70       </javac>
    71       <jar
    72         basedir="${bin.plugins}"
    73         jarfile="${plugin.name}.jar"
    74         manifest="MANIFEST.MF"
    75    
    76       />
    77       <delete includeemptydirs="true">
    78         <fileset dir="${bin.plugins}" includes="**/*"/>
    79       </delete>
     40
     41  <target name="plugin.compile" depends="clean" description="compile the ta2mage importer plugin source code, without dependencies and put in a jar file">
     42    <javac source="1.5" target="1.5" encoding="ISO-8859-1" srcdir="${core.src.plugins}" destdir="${bin.plugins}" classpathref="nugo.plugin.compile.classpath" debug="true" deprecation="true">
     43    </javac>
     44    <jar basedir="${bin.plugins}" jarfile="${plugin.name}.jar" manifest="MANIFEST.MF" />
     45    <delete includeemptydirs="true">
     46      <fileset dir="${bin.plugins}" includes="**/*" />
     47    </delete>
    8048  </target>
    81  
    82   <target
    83       name="all"
    84       depends="clean"
    85       description="compile all the ta2mage importer plugin source code with dependencies and put in a jar file"
    86       >
    87       <javac
    88         encoding="ISO-8859-1"
    89         srcdir="${src.plugins}"
    90         destdir="${bin.plugins}"
    91         classpathref="nugo.plugin.compile.classpath"
    92         debug="true"
    93         deprecation="true"
    94         >
    95         <compilerarg value="${javac.arg}" />
    96       </javac>
    97       <jar
    98         basedir="${bin.plugins}"
    99         jarfile="${plugin.name}.jar"
    100         manifest="MANIFEST.MF"
    101       />
     49
     50  <target name="all" depends="clean" description="compile all the ta2mage importer plugin source code with dependencies and put in a jar file">
     51    <javac source="1.5" target="1.5" encoding="ISO-8859-1" srcdir="${src.plugins}" destdir="${bin.plugins}" classpathref="nugo.plugin.compile.classpath" debug="true" deprecation="true">
     52    </javac>
     53    <jar basedir="${bin.plugins}" jarfile="${plugin.name}.jar" manifest="MANIFEST.MF" />
    10254  </target>
    103  
    104   <target
    105       name="clean"
    106       depends=""
    107       description="clean/clear the bin folder"
    108       >
    109       <delete includeemptydirs="true">
    110         <fileset dir="${bin.plugins}" includes="**/*"/>
    111       </delete>
     55
     56  <target name="clean" depends="" description="clean/clear the bin folder">
     57    <delete includeemptydirs="true">
     58      <fileset dir="${bin.plugins}" includes="**/*" />
     59    </delete>
    11260  </target>
    113  
    114 </project>
     61
     62
     63  <target name="copyJSPs">
     64    <copy todir="C:\tomcat\apache-tomcat-6.0.13\webapps\base\plugins\" verbose="true">
     65      <fileset dir="${jspDir}" />
     66    </copy>
     67  </target>
     68
     69
     70  <target name="copyToServer" depends="build.plugin,copyJSPs">
     71    <copy file="${plugin.name}.jar" todir="C:\tomcat\apache-tomcat-6.0.13\webapps\base\WEB-INF\lib" verbose="true" />
     72    <!-- now restart tomcat to reload the application -->
     73    <echo message="tomcat home = "/>
     74    <echo message="${tomcat.home}"/>
     75    <echo message="shutting down tomcat" />
     76    <exec executable="${tomcat.shutdownscript}" spawn="yes" />
     77    <echo message="starting up tomcat" />
     78    <exec executable="${tomcat.startupscript}" spawn="yes" />
     79  </target>
     80
     81
     82
     83</project>
  • branches/uk_ac_ebi_Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/Tab2MageImporter.java

    r482 r486  
    11/*
    2   This file is for NutriBASE - Nutrigenomics BioArray Software Environment.
    3   A customisation of the BASE SOFTWARE.
    4   Developed at the EBI , Cambridge.
     2 This file is for NutriBASE - Nutrigenomics BioArray Software Environment.
     3 A customisation of the BASE SOFTWARE.
     4 Developed at the EBI , Cambridge.
    55 */
    66package uk.ac.ebi.nugo.plugins;
     
    88import java.io.IOException;
    99import java.io.InputStream;
    10 import java.util.ArrayList;
    1110import java.util.Arrays;
    1211import java.util.Collections;
     12import java.util.LinkedList;
    1313import java.util.List;
    14 import java.util.Map;
    1514import java.util.Set;
    1615import java.util.zip.ZipEntry;
     
    2423import net.sf.basedb.core.File;
    2524import net.sf.basedb.core.FileParameterType;
     25import net.sf.basedb.core.IntegerParameterType;
    2626import net.sf.basedb.core.Item;
    27 import net.sf.basedb.core.ItemParameterType;
    28 import net.sf.basedb.core.Path;
    29 import net.sf.basedb.core.PathParameterType;
     27import net.sf.basedb.core.Job;
     28import net.sf.basedb.core.PluginConfigurationRequest;
    3029import net.sf.basedb.core.PluginParameter;
    3130import net.sf.basedb.core.ProgressReporter;
     
    3332import net.sf.basedb.core.RequestInformation;
    3433import net.sf.basedb.core.StringParameterType;
    35 import net.sf.basedb.core.User;
    3634import net.sf.basedb.core.plugin.About;
    3735import net.sf.basedb.core.plugin.AboutImpl;
     
    4341import net.sf.basedb.core.plugin.Request;
    4442import net.sf.basedb.core.plugin.Response;
    45 import uk.ac.ebi.nugo.common.Helper;
    46 import uk.ac.ebi.nugo.common.ZipUnpacker;
    47 import uk.ac.ebi.nugo.plugins.tab2mageimport.ValidationConstants;
    48 import uk.ac.ebi.nugo.plugins.tab2mageimport.io.AnnotationTypesWriter;
    49 import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Tab2MageDataImportFactory;
    50 import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Tab2MageExperimentWriter;
    51 import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Tab2MageWriterFactory;
    52 import uk.ac.ebi.nugo.plugins.tab2mageimport.mail.Tab2MageEMessaging;
    53 import uk.ac.ebi.nugo.plugins.tab2mageimport.validation.Tab2MageValidationFactory;
    5443import uk.ac.ebi.nugo.plugins.util.tab2mage.Tab2MageHelper;
    5544
    5645/**
    57   A plugin that imports an experiment in tab2mage specification for upload into Base2/Nutribase.
    58   @author Dominic Oyeniran
    59   @version 1.0
    60   @base.modified $Date$
    61 */
    62 public class Tab2MageImporter
    63   extends AbstractPlugin implements InteractivePlugin, AutoDetectingImporter
     46 * A plugin that imports an experiment in tab2mage specification for upload into Base2/Nutribase.
     47 *
     48 * @author Dominic Oyeniran
     49 * @version 1.0
     50 * @base.modified $Date$
     51 */
     52public class Tab2MageImporter extends AbstractPlugin implements InteractivePlugin, AutoDetectingImporter
    6453{
    6554  //
    6655  private RequestInformation configureJob;
    67   //  the gui experiment type parameter
     56  // the gui experiment type parameter
    6857  private PluginParameter<Experiment> experimentParameter;
    69  
     58
    7059  // the gui zip file parameter
    7160  private PluginParameter<File> fileParameter;
    72  
     61
    7362  // the gui tab2mage file name parameter
    7463  private PluginParameter<String> tab2mageFileNameParameter;
    75  
    76   //  the gui email server parameter
     64
     65  // the gui email server parameter
    7766  private PluginParameter<String> emailHostParameter;
    78  
     67
    7968  // validation file parameter
    8069  private PluginParameter<String> statusPathParameter;
    81  
     70
    8271  // boolean overwrite parameter type
    83   private BooleanParameterType overwriteType= new BooleanParameterType(false, false);
    84  
     72  private BooleanParameterType overwriteType = new BooleanParameterType(false, false);
     73
    8574  // overwrite parameter
    8675  private PluginParameter<Boolean> overWriteParameter;
    87  
     76
    8877  // directory parameter
    8978  private PluginParameter<String> directoryParameter;
    9079
    91   //  validation mode parameter
     80  // validation mode parameter
    9281  private PluginParameter<Boolean> validationParameter;
    93  
    94   private static final About about =
    95     new AboutImpl
    96     (       
    97         "Tab2Mage Importer",
    98         "This plugin is used to import raw data files and an experiment in the tab2mage format specfication. The tab2mage specification " +
    99         "is provided by the microarray informatics team at the EBI, Cambridge. The imported experiment can later be " +
    100         "exported by the corresponding tab2mage export plugin.",
    101         "1.0",
    102         "@Copyright 2007, The EBI NutriBase development team",
    103         "Dominic Oyeniran",
    104         "oyeniran@ebi.ac.uk",
    105         "http://www.ebi.ac.uk/~oyeniran"
    106     );
    107  
    108   private static final GuiContext experimentItemGuiContext = new GuiContext (Item.EXPERIMENT,GuiContext.Type.ITEM);
    109  
    110   private static final Set<GuiContext> guiContexts=Collections.singleton(experimentItemGuiContext);
    111  
     82
     83  // parameters from custom input page (input.jsp)
     84  PluginParameter zipFile;
     85  PluginParameter platform;
     86  PluginParameter organism;
     87  PluginParameter numDesigns;
     88  PluginParameter dyeSwap;
     89  PluginParameter refSample;
     90  PluginParameter numTreatments;
     91  PluginParameter expFactors;
     92  PluginParameter numReplicates;
     93  PluginParameter tissues;
     94  PluginParameter pooling;
     95
     96
     97  private static final About about = new AboutImpl("Tab2Mage Importer", "This plugin is used to import raw data files and an experiment in the tab2mage format specfication. The tab2mage specification " + "is provided by the microarray informatics team at the EBI, Cambridge. The imported experiment can later be " + "exported by the corresponding tab2mage export plugin.", "1.0", "@Copyright 2007, The EBI NutriBase development team", "Dominic Oyeniran", "oyeniran@ebi.ac.uk", "http://www.ebi.ac.uk/~oyeniran");
     98
     99  private static final GuiContext experimentItemGuiContext = new GuiContext(Item.EXPERIMENT, GuiContext.Type.ITEM);
     100
     101  private static final Set<GuiContext> guiContexts = Collections.singleton(experimentItemGuiContext);
     102
    112103  /**
    113    
    114     creates a new tab2mage importer
     104   *
     105   * creates a new tab2mage importer
    115106   */
    116107  public Tab2MageImporter()
    117   {}
    118  
    119   private RequestInformation getConfigureJobParameters()
    120   {
    121     if (configureJob == null)
    122     {
    123       fileParameter = new PluginParameter<File>(
    124           "file",
    125           "Zip File",
    126           "Please specify the zip file containing tab2mage files and raw data files only", 
    127           new FileParameterType(null, true, 1));
    128      
    129       directoryParameter = new PluginParameter<String>(
    130            "directory",
    131            "Unzipped Files Directory",
    132            "Please specify a name for the directory to store unzipped files.",
    133            new StringParameterType(255, null, true));
    134      
    135       tab2mageFileNameParameter = new PluginParameter<String>(
    136           "tab2mageFileName",
    137           "Tab2Mage FileName with Extension",
    138           "Please specify the name of the tab2mage file with extension e.g.tab2mage.txt. This must be same as the name of the tab2mage file contained in the zip file supplied",
    139           new StringParameterType(255, null, true));
    140      
    141       emailHostParameter = new PluginParameter<String>(
    142            "emailHost",
    143            "Email Server Name",
    144            "Please specify your email server name e.g. smtp.companydomain.com. If you could not receive an email please check the release note for guidance",
    145            new StringParameterType(255, null, false));
    146      
    147       experimentParameter = new PluginParameter<Experiment>(
    148           "experiment",
    149           "Experiment",
    150           "The experiment to import to", 
    151           new ItemParameterType<Experiment>(Experiment.class, null,true,1,null));
    152      
    153       validationParameter = new PluginParameter<Boolean>(
    154            "validation",
    155            "Run Validation Only",
    156            "Set parameter to TRUE to run the plugin in VALIDATION MODE ONLY.",
    157            overwriteType);
    158        
    159       statusPathParameter = new PluginParameter<String>(
    160           "statusPath",
    161           "Save Validation Report As",
    162           "Please specify the file name where the plugin should store causes for failure and errors during validation",
    163           new PathParameterType(Path.Type.FILE, Helper.getUserDefaultDirectory(sc)+"/validationreport.txt", true));
    164      
    165       overWriteParameter = new PluginParameter<Boolean>(
    166            "overwrite",
    167            "Overwrite",
    168            "Overwrite existing file?",
    169            new BooleanParameterType(true, false));
    170        
    171       List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>();
    172      
    173       parameters.add(fileParameter);
    174       parameters.add(directoryParameter );
    175       parameters.add(tab2mageFileNameParameter);
    176       parameters.add(experimentParameter);
    177       parameters.add(validationParameter);
    178       parameters.add(statusPathParameter);
    179       parameters.add(overWriteParameter);
    180       parameters.add(emailHostParameter);
    181            
    182       configureJob = new RequestInformation
    183       (
    184           Request.COMMAND_CONFIGURE_JOB,
    185           "Tab2Mage importer options",
    186           "Set the zip file path and the parameters required to import raw data files and tab2mage experiment meta data." +
    187           "To run in Validation Mode, Please set 'Run Validation' parameter to TRUE. ",
    188           parameters
    189       );
    190     }
    191     return configureJob;
    192   }
    193  
    194   public void configure(GuiContext context, Request request, Response response)
    195   {
    196     String command = request.getCommand();   
     108  {
     109  }
     110
     111  public void configure(GuiContext context, Request request, Response response)
     112  {
     113    System.out.println("configure()");
     114    String command = request.getCommand();
     115    System.out.println("command = " + command);
     116
    197117    try
    198118    {
    199       if (command.equals(Request.COMMAND_CONFIGURE_JOB))
     119      if (command.equals(Request.COMMAND_CONFIGURE_PLUGIN))
    200120      {
    201         List<Throwable> errors = validateRequestParameters (getConfigureJobParameters().getParameters(), request);
    202         if (errors != null)
    203         {
    204           response.setError(errors.size() + " invalid parameters were found in the request",errors);
    205           return;
    206         }
     121
     122      }
     123      else if (command.equals(Request.COMMAND_CONFIGURE_JOB))
     124      {
     125        //validation
     126//        List<Throwable> errors = validateRequestParameters (getConfigureJobParameters().getParameters(), request);
     127//        if (errors != null)
     128//        {
     129//        response.setError(errors.size() + " invalid parameters were found in the request",errors);
     130//        return;
     131
     132        //store the parameter values in the database
     133        storeValue(job, request, zipFile);
     134        storeValue(job, request, platform);
     135        storeValue(job, request, organism);
     136        storeValue(job, request, numDesigns);
     137        storeValue(job, request, dyeSwap);
     138        storeValue(job, request, refSample);
     139        storeValue(job, request, numTreatments);
     140        storeValue(job, request, expFactors);
     141        storeValue(job, request, numReplicates);
     142        storeValue(job, request, tissues);
     143        storeValue(job, request, pooling);
     144
     145        // set the response as done
     146        response.setDone("Job configuration complete", Job.ExecutionTime.SHORT);
     147
     148        //print out current values
     149        PluginConfigurationRequest pcRequest = (PluginConfigurationRequest) sc.getSessionSetting("plugin.configure.request");
     150        String zipFile = (String)pcRequest.getCurrentParameterValue("zipFile");
     151        String platform = (String) pcRequest.getCurrentParameterValue("platform");
     152        String organism = (String) pcRequest.getCurrentParameterValue("organism");
     153        String numDesigns = (String) pcRequest.getCurrentParameterValue("numDesigns");
     154        String dyeSwap = (String) pcRequest.getCurrentParameterValue("dyeSwap");
     155        String refSample = (String) pcRequest.getCurrentParameterValue("refSample");
     156        String numTreatments = (String) pcRequest.getCurrentParameterValue("numTreatments");
     157        String expFactors = (String) pcRequest.getCurrentParameterValue("expFactors");
     158        String numReplicates = (String) pcRequest.getCurrentParameterValue("numReplicates");
     159        String tissues = (String) pcRequest.getCurrentParameterValue("tissues");
     160        String pooling = (String) pcRequest.getCurrentParameterValue("pooling");
     161
     162        System.out.println("zipFile = " + zipFile);
     163        System.out.println("platform = " + platform);
     164        System.out.println("numDesigns = " + numDesigns);
     165        System.out.println("numTreatments = " + numTreatments);
     166        System.out.println("numReplicates = " + numReplicates);
     167        System.out.println("dyeSwap = " + dyeSwap);
     168        System.out.println("organism = " + organism);
     169        System.out.println("refSample = " + refSample);
     170        System.out.println("expFactors = " + expFactors);
     171        System.out.println("numReplicates = " + numReplicates);
     172        System.out.println("tissues = " + tissues);
     173        System.out.println("pooling = " + pooling);
    207174       
    208         storeValue(job, request, fileParameter);
    209         storeValue(job, request, directoryParameter);
    210         storeValue(job, request, tab2mageFileNameParameter);
    211         storeValue(job, request, experimentParameter);
    212         storeValue(job, request, validationParameter);
    213         storeValue(job, request, statusPathParameter);
    214         storeValue(job, request, overWriteParameter);
    215         storeValue(job, request, emailHostParameter);
    216         String dirName= (String)job.getValue("directory");
    217         File file = (File) job.getValue("file");
    218         if (dirName!=null)
    219         {
    220           if (validateDirectory(file,dirName))
    221           {
    222             response.setError("Directory exists: "+ dirName,null);
    223             return;
    224           }
    225         }
    226         response.setDone("The job configuration is complete");
    227175      }
    228176    }
    229     catch(Throwable ex)
    230     {
     177    catch (Throwable ex)
     178    {
     179      ex.printStackTrace();
    231180      response.setError(ex.getMessage(), Arrays.asList(ex));
    232181    }
    233    
    234   }
     182
     183  }
     184
    235185  /*
    236     From the InteractivePlugin interface
    237     -------------------------------------------
    238   */
     186   * From the InteractivePlugin interface -------------------------------------------
     187   */
    239188  /**
    240     Return a set containing the context:s [ARRAY DESIGN, LIST],
    241    */
    242   public Set<GuiContext> getGuiContexts() 
     189   * Return a set containing the context:s [ARRAY DESIGN, LIST],
     190   */
     191  public Set<GuiContext> getGuiContexts()
    243192  {
    244193    return guiContexts;
    245194  }
    246  
     195
    247196  /**
    248     checks that the we are using the experiment object and that it is not null
    249     returns null if we are not working on an ITEM but a LIST
     197   * checks that the we are using the experiment object and that it is not null returns null if we are not working on an ITEM but a LIST
    250198   */
    251199  public String isInContext(GuiContext context, Object item)
     
    255203    {
    256204      message = "The object is null";
    257      
     205
    258206    }
    259207    else if (!(item instanceof Experiment))
     
    263211    else
    264212    {
    265       Experiment exp = (Experiment)item;
    266       RawDataType rawDataType = exp.getRawDataType(); 
     213      Experiment exp = (Experiment) item;
     214      RawDataType rawDataType = exp.getRawDataType();
    267215      if (!Tab2MageHelper.supportedPlatforms(rawDataType.getId().toLowerCase()))
    268216      {
    269         message="This importer only supports Affymetrix, Agilent and Genepix Platforms. Your experiment's platform is :" + rawDataType.getId().toLowerCase();
    270       } 
     217        message = "This importer only supports Affymetrix, Agilent and Genepix Platforms. Your experiment's platform is :" + rawDataType.getId().toLowerCase();
     218      }
    271219    }
    272220    return message;
    273221  }
    274222
    275   public RequestInformation getRequestInformation(GuiContext context, String command)
    276   throws BaseException
    277   {
     223  public RequestInformation getRequestInformation(GuiContext context, String command) throws BaseException
     224  {
     225    System.out.println("Tab2MAGEImporter.getRequestInformation()");
     226
    278227    RequestInformation requestInformation = null;
    279     if (Request.COMMAND_CONFIGURE_JOB.equals(command))
    280     {
    281       requestInformation = getConfigureJobParameters();
    282     }
     228
     229    try
     230    {
     231      // first create the parameter types
     232      StringParameterType stringPT = new StringParameterType(255, null, true);
     233
     234      // create the plugin parameter objects here
     235      zipFile = new PluginParameter<String>("zipFile", " Zip file", "Contains raw data files", stringPT);
     236      platform = new PluginParameter<String>("platform", "Platform", "chip platform used", stringPT);
     237      organism = new PluginParameter<String>("organism", "Organism", "First string", stringPT);
     238      numDesigns = new PluginParameter<String>("numDesigns", "NumDesigns", "Second string", stringPT);
     239      dyeSwap = new PluginParameter<String>("dyeSwap", "dyeSwap", "dyeSwap", stringPT);
     240      refSample = new PluginParameter<String>("refSample","refSample","refSample", stringPT);
     241      numTreatments = new PluginParameter<String>("numTreatments","numTreatments","numTreatments", stringPT);
     242      expFactors = new PluginParameter<String>("expFactors","expFactors","expFactors",stringPT);
     243      numReplicates = new PluginParameter<String>("numReplicates","numReplicates","numReplicates", stringPT);
     244      tissues = new PluginParameter<String>("tissues","tissues","tissues", stringPT);
     245      pooling = new PluginParameter<String>("pooling","pooling","pooling",stringPT);
     246
     247      // add them all to our list
     248      List<PluginParameter<?>> parameters = new LinkedList<PluginParameter<?>>();
     249      parameters.add(zipFile);
     250      parameters.add(platform);
     251      parameters.add(organism);
     252      parameters.add(numDesigns);
     253      parameters.add(dyeSwap);
     254      parameters.add(refSample);
     255      parameters.add(numTreatments);
     256      parameters.add(expFactors);
     257      parameters.add(numReplicates);
     258      parameters.add(tissues);
     259      parameters.add(pooling);
     260
     261      //the request information object provides the parameter list and the name of the custom input page to navigate to for
     262      //the configuration of the plugin run
     263      requestInformation = new RequestInformation(Request.COMMAND_CONFIGURE_JOB, null, null, parameters, "input.jsp");
     264    }
     265    catch (Throwable e)
     266    {
     267      e.printStackTrace();
     268    }
     269
    283270    return requestInformation;
    284271  }
    285  
     272
    286273  /*
    287     From the Plugin interface
    288     --------------------------------
    289    */
    290   public About getAbout()
     274   * From the Plugin interface --------------------------------
     275   */
     276  public About getAbout()
    291277  {
    292278    return about;
    293279  }
    294280
    295   public MainType getMainType() 
     281  public MainType getMainType()
    296282  {
    297283    return Plugin.MainType.IMPORT;
    298284  }
    299  
     285
    300286  public void run(Request request, Response response, ProgressReporter progress)
    301287  {
    302     DbControl dc=null;
    303     String hostName="";
    304     boolean validPlatform=false, validateImageFile, validTab2mageFile, validTab2mageFileName=false;
    305     boolean overwrite= false, validation = false;
     288    // DbControl dc=null;
     289    // String hostName="";
     290    // boolean validPlatform=false, validateImageFile, validTab2mageFile, validTab2mageFileName=false;
     291    // boolean overwrite= false, validation = false;
     292    // try
     293    // {
     294    // //who is using this plugin
     295    // dc= sc.newDbControl();
     296    // User user= User.getById(dc, sc.getLoggedInUserId());
     297
     298    // /*
     299    // obtain all job parameters
     300    // */
     301    // File file = (File) job.getValue("file");
     302    // file= File.getById(dc, file.getId());
     303
     304    // String directoryName = (String)job.getValue("directory");
     305
     306    // String tab2MageFileName= (String) job.getValue("tab2mageFileName");
     307    // hostName= (String) job.getValue("emailHost");
     308
     309    // if ((Boolean)job.getValue("overwrite") != null) overwrite = (Boolean)job.getValue("overwrite");
     310    // if ((Boolean)job.getValue("validation") != null) validation = (Boolean)job.getValue("validation");
     311
     312    // Experiment experiment= (Experiment)job.getValue("experiment");
     313    // experiment= Experiment.getById(dc,experiment.getId());
     314    // RawDataType rdt= experiment.getRawDataType(); // experiment platform
     315
     316    // String statusp=(String)job.getValue("statusPath");
     317    // File statusFile=Helper.processFilePath(user,overwrite, sc,statusp);
     318
     319    // /*
     320    // FILE UNZIP MODULE: unzip the files into user specified directory
     321    // */
     322
     323    // ZipUnpacker importUnpacker = new ZipUnpacker(file, user, sc);
     324    // importUnpacker.unpack(directoryName);
     325    // Directory dir= importUnpacker.getUnzippedFilesDirectory(); // this may return the id of the unzipped file directory instead
     326    // if (dir==null)
     327    // {
     328    // response.setError("IMPORT FAILS: The zip file cannot be unzipped. You may NOT have sufficient Disk Space or " +
     329    // "Lack permission to read or use the Directory" ,Arrays.asList(new Throwable()));
     330    // return;
     331    // }
     332
     333    // // -- end of file unzip module
     334
     335    // /*
     336    // VALIDATION MODULE
     337    // */
     338
     339    // if (dc == null || !dc.isConnected()|| dc.isClosed()) dc = sc.newDbControl();
     340
     341    // // validate files supplied to platform
     342    // validPlatform=Tab2MageHelper.validatePlatform(dir, dc, rdt);
     343    // if (!validPlatform)
     344    // {
     345    // response.setError("IMPORT FAILS: Invalid File format: files supplied not appropriate for the experiment platform: [ " + rdt.getId() +" ]" ,Arrays.asList(new Throwable()));
     346    // return;
     347    // }
     348
     349    // // validate image file
     350    // List<File> imageFiles=Tab2MageHelper.getImageFiles(dir, dc) ;
     351    // if (!imageFiles.isEmpty()|| imageFiles==null)
     352    // {
     353    // validateImageFile= Tab2MageHelper.validateImages(imageFiles, rdt);
     354    // if (!validateImageFile)
     355    // {
     356    // response.setError("IMPORT FAILS: Invalid Image File format: image files supplied not appropriate for the experiment platform: [ " + rdt.getId() +" ]" ,Arrays.asList(new
     357    // Throwable()));
     358    // return;
     359    // }
     360    // }
     361    // // validate the tab2mage file (do initialisation here too)
     362
     363    // Tab2MageValidationFactory validator = new Tab2MageValidationFactory(tab2MageFileName, sc, dir, rdt.getId(), response, statusFile);
     364    // validTab2mageFileName = validator.validateTab2MageFileName();
     365    // if (!validTab2mageFileName)
     366    // {
     367    // response.setError("IMPORT FAILS: The Tab2Mage filename provided as parameter on the GUI : [ " + tab2MageFileName+ " ] does not match that contained in the zip file"
     368    // ,Arrays.asList(new Throwable()));
     369    // return;
     370    // }
     371
     372    // Map<ValidationConstants, Boolean> validations= validator.validateTab2MageFile();
     373    // StringBuffer failureMessage = new StringBuffer();
     374    // if (!validations.isEmpty())
     375    // {
     376    // for (ValidationConstants key : validations.keySet())
     377    // {
     378    // failureMessage.append(key.getKeyMessage()+";") ;
     379    // }
     380    // response.setError("IMPORT FAILS: Tab2Mage file validation is UNSUCCESSFUL. The ['"+ failureMessage.substring(0, failureMessage.length()-1)+ "'] Failed. " +
     381    // "Check the Validation ReportFile ["+statusFile.getPath().toString()+"] on BASE File System for Details" ,Arrays.asList(new Throwable()));
     382    // return;
     383    // }
     384
     385    // // -- end of validation module
     386    // if (validation)
     387    // {
     388    // Directory delDir =Directory.getById(dc, dir.getId());
     389    // response.setDone("Validation Successful. Check the Validation File [ "+statusFile.getPath().toString()+" ] for annotations warning. The unzipped directory " +
     390    // "name [ "+delDir.getName()+" ] CANNOT be re-used as a parameter to re-run the tab2mage importer.");
     391    // return;
     392    // }
     393
     394    // /*
     395    // TAB2MAGE FILE IMPORT MODULE.
     396    // */
     397    // // create annotation types
     398    // AnnotationTypesWriter atWriter= new AnnotationTypesWriter (sc, validator.getAtFile(),progress);
     399    // boolean writtenAT =atWriter.write(); // note if this action failed the transaction is completely rolled back
     400    // if (!writtenAT)
     401    // {
     402    // response.setError("IMPORT FAILS: Annotation Type was not written to the Database. Check Log error for details" ,Arrays.asList(new Throwable()));
     403    // return;
     404    // }
     405
     406    // // write protocols and hybs
     407    // Tab2MageWriterFactory hibernateItemsWriter = new Tab2MageWriterFactory
     408    // (sc,Tab2MageValidationFactory.getCatchedProtocol(),
     409    // Tab2MageValidationFactory.getCatchedHybs(),rdt,
     410    // validator.getSampleExtractMap(),
     411    // validator.getBioSourceSampleMap(),
     412    // validator.getExtractLabeledExtractMap());
     413
     414    // // if the protocol type is not found, write it into the database.
     415    // // alternative is to fail at validation instead of a warning, if the protocol type
     416    // // provided in tab2mage file is not in Base2 database.
     417
     418    // hibernateItemsWriter.writeProtocolTypes();
     419
     420    // boolean writtenHibItems = hibernateItemsWriter.write();
     421    // if (!writtenHibItems)
     422    // {
     423    // response.setError("IMPORT FAILS: Protocol and Hybridization items were not written to the Database. Check Log error for details" ,Arrays.asList(new Throwable()));
     424    // return;
     425    // }
     426
     427    // boolean writtenPoolItems = hibernateItemsWriter.writePooledMetaData();
     428    // if (!writtenPoolItems)
     429    // {
     430    // response.setError("IMPORT FAILS: Pooled items were not written to the Database. Check Log error for details" ,Arrays.asList(new Throwable()));
     431    // return;
     432    // }
     433    // // -- end of Tab2Mage file import module
     434
     435    // /*
     436    // RAW DATA IMPORT MODULE
     437
     438    // */
     439
     440    // if (dc == null || !dc.isConnected()|| dc.isClosed()) dc = sc.newDbControl();
     441
     442    // // get raw data files
     443    // List<File> rawDataFiles= Tab2MageHelper.getRawDataFiles(dir, dc, rdt.getId(), tab2MageFileName);
     444
     445    // // do data import
     446    // Tab2MageDataImportFactory dataImport = new Tab2MageDataImportFactory(sc,rdt.getId(),rawDataFiles,
     447    // hibernateItemsWriter.getRbas(), progress);
     448    // boolean writtenRawData = dataImport.importData();
     449    // if (!writtenRawData)
     450    // {
     451    // response.setError("IMPORT FAILS: Raw Data cannot not be written to the Database. Check Log error for details" ,Arrays.asList(new Throwable()));
     452    // return;
     453    // }
     454    // // -- end of raw data import module
     455
     456    // /*
     457    // EXPERIMENT CONFIGURATION AND LOADING MODULE
     458
     459    // */
     460    // //write experiment, attaching raw bio-assays
     461    // Tab2MageExperimentWriter expWriter= new Tab2MageExperimentWriter(hibernateItemsWriter.getRbas(),sc,
     462    // experiment,hibernateItemsWriter.getExpFactors(),
     463    // validator.getTExperiment());
     464    // boolean writtenExp= expWriter.LoadExperiment();
     465    // // -- end of experiment configuration and loading module
     466
     467    // /*
     468    // MESSAGING MODULE
     469    // */
     470    // // send an email to the user on the success of the experiment (if email server name and email address are provided)
     471    // if (hostName!= null && hostName.length()>=5)
     472    // {
     473    // if (!user.getEmail().equals("") && user.getEmail()!=null )
     474    // {
     475    // Tab2MageEMessaging message= new Tab2MageEMessaging(writtenExp,"", user.getEmail(),tab2MageFileName, user.getName(), experiment.getName(),hostName );
     476    // message.sendEmail();
     477    // }
     478    // }
     479    // // -- end of messaging module
     480    // dc.commit();
     481    // response.setDone("Import plugin ended successfully");
     482    // }
     483    // catch(Throwable tr)
     484    // {
     485    // response.setError(tr.getMessage(), Arrays.asList(tr));
     486    // }
     487    // finally
     488    // {
     489    // if (dc!=null)
     490    // dc.close();
     491    // }
     492
     493    System.out.println("running Tab2MageImporter plugin (testing run method only)");
     494    response.setDone("Plugin ended successfully");
     495  }
     496
     497  /*
     498   * From AutoDetectionImporter interface
     499   */
     500  /**
     501   * checks whether the zip file supplied by the user is actually a zip file.
     502   */
     503  public boolean isImportable(InputStream in) throws BaseException
     504  {
     505    ZipInputStream zin = null;
    306506    try
    307507    {
    308       //who is using this plugin
    309       dc= sc.newDbControl();
    310       User user= User.getById(dc, sc.getLoggedInUserId());
    311    
    312       /*
    313         obtain all job parameters
    314        */
    315       File file = (File) job.getValue("file");
    316       file= File.getById(dc, file.getId());
    317      
    318       String directoryName = (String)job.getValue("directory");
    319          
    320       String tab2MageFileName= (String) job.getValue("tab2mageFileName");
    321       hostName= (String) job.getValue("emailHost");
    322            
    323       if ((Boolean)job.getValue("overwrite") != null) overwrite = (Boolean)job.getValue("overwrite");
    324       if ((Boolean)job.getValue("validation") != null)  validation = (Boolean)job.getValue("validation");
    325      
    326       Experiment experiment= (Experiment)job.getValue("experiment");
    327       experiment= Experiment.getById(dc,experiment.getId());
    328       RawDataType rdt= experiment.getRawDataType(); // experiment platform
    329      
    330       String statusp=(String)job.getValue("statusPath");
    331       File statusFile=Helper.processFilePath(user,overwrite, sc,statusp);
    332          
    333       /*
    334         FILE UNZIP MODULE: unzip the files into user specified directory
    335        */
    336    
    337       ZipUnpacker importUnpacker = new ZipUnpacker(file, user, sc);
    338       importUnpacker.unpack(directoryName);
    339       Directory dir= importUnpacker.getUnzippedFilesDirectory(); // this may return the id of the unzipped file directory instead
    340       if (dir==null)
     508      zin = new ZipInputStream(in);
     509      // if this is not a zip file, this will throw an exception:
     510      ZipEntry zn = zin.getNextEntry();
     511    }
     512    catch (Exception e)
     513    {
     514      return false;
     515    }
     516    finally
     517    {
     518      try
    341519      {
    342         response.setError("IMPORT FAILS: The zip file cannot be unzipped. You may NOT have sufficient Disk Space or " +
    343             "Lack permission to read or use the Directory" ,Arrays.asList(new Throwable()));
    344         return;
     520        zin.close();
    345521      }
    346          
    347       // -- end of file unzip module
    348      
    349       /*
    350         VALIDATION MODULE
    351        */
    352        
    353       if (dc == null || !dc.isConnected()|| dc.isClosed()) dc = sc.newDbControl();
    354      
    355         // validate files supplied to platform
    356       validPlatform=Tab2MageHelper.validatePlatform(dir, dc, rdt);
    357       if (!validPlatform)
    358             {
    359         response.setError("IMPORT FAILS: Invalid File format: files supplied not appropriate for the experiment platform: [ " + rdt.getId() +" ]" ,Arrays.asList(new Throwable()));
    360         return;
    361             }
    362      
    363         // validate image file
    364       List<File> imageFiles=Tab2MageHelper.getImageFiles(dir, dc) ;
    365       if (!imageFiles.isEmpty()|| imageFiles==null)
     522      catch (IOException ex)
    366523      {
    367         validateImageFile= Tab2MageHelper.validateImages(imageFiles, rdt);
    368         if (!validateImageFile)
    369         {
    370           response.setError("IMPORT FAILS: Invalid Image File format: image files supplied not appropriate for the experiment platform: [ " + rdt.getId() +" ]" ,Arrays.asList(new Throwable()));
    371           return;
    372         }
     524        throw new BaseException(ex);
    373525      }
    374         // validate the tab2mage file (do initialisation here too)
    375      
    376       Tab2MageValidationFactory validator = new Tab2MageValidationFactory(tab2MageFileName, sc, dir, rdt.getId(), response, statusFile);
    377       validTab2mageFileName = validator.validateTab2MageFileName();
    378       if (!validTab2mageFileName)
    379       {
    380         response.setError("IMPORT FAILS: The Tab2Mage filename provided as parameter on the GUI : [ " + tab2MageFileName+ " ] does not match that contained in the zip file" ,Arrays.asList(new Throwable()));
    381         return;
    382       }
    383      
    384       Map<ValidationConstants, Boolean> validations= validator.validateTab2MageFile();
    385       StringBuffer failureMessage = new StringBuffer();
    386       if (!validations.isEmpty())
    387       {
    388         for (ValidationConstants key : validations.keySet())
    389         {
    390           failureMessage.append(key.getKeyMessage()+";")  ;
    391         }
    392         response.setError("IMPORT FAILS: Tab2Mage file validation is UNSUCCESSFUL. The ['"+ failureMessage.substring(0, failureMessage.length()-1)+ "'] Failed. " +
    393             "Check the Validation ReportFile ["+statusFile.getPath().toString()+"] on BASE File System for Details" ,Arrays.asList(new Throwable()));
    394         return;
    395       }
    396      
    397       // -- end of validation module
    398       if (validation)
    399       {
    400         Directory delDir =Directory.getById(dc, dir.getId());
    401         response.setDone("Validation Successful. Check the Validation File [ "+statusFile.getPath().toString()+" ] for annotations warning. The unzipped directory " +
    402             "name [ "+delDir.getName()+" ] CANNOT be re-used as a parameter to re-run the tab2mage importer.");
    403         return;
    404       }
    405      
    406       /*
    407         TAB2MAGE FILE IMPORT MODULE.
    408        */
    409         //  create annotation types
    410       AnnotationTypesWriter atWriter= new AnnotationTypesWriter (sc, validator.getAtFile(),progress);
    411       boolean writtenAT =atWriter.write(); // note if this action failed the transaction is completely rolled back
    412       if (!writtenAT)
    413       {
    414         response.setError("IMPORT FAILS: Annotation Type was not written to the Database. Check Log error for details" ,Arrays.asList(new Throwable()));
    415         return;
    416       }
    417      
    418         // write protocols and hybs
    419       Tab2MageWriterFactory hibernateItemsWriter = new Tab2MageWriterFactory
    420                           (sc,Tab2MageValidationFactory.getCatchedProtocol(),
    421                             Tab2MageValidationFactory.getCatchedHybs(),rdt,
    422                             validator.getSampleExtractMap(),
    423                             validator.getBioSourceSampleMap(),
    424                             validator.getExtractLabeledExtractMap());
    425      
    426         // if the protocol type is not found, write it into the database.
    427         // alternative is to fail at validation instead of a warning, if the protocol type
    428         // provided in tab2mage file is not in Base2 database.
    429      
    430       hibernateItemsWriter.writeProtocolTypes();
    431      
    432       boolean writtenHibItems = hibernateItemsWriter.write();
    433       if (!writtenHibItems)
    434       {
    435         response.setError("IMPORT FAILS: Protocol and Hybridization items were not written to the Database. Check Log error for details" ,Arrays.asList(new Throwable()));
    436         return;
    437       }
    438      
    439       boolean writtenPoolItems = hibernateItemsWriter.writePooledMetaData();
    440       if (!writtenPoolItems)
    441       {
    442         response.setError("IMPORT FAILS: Pooled items were not written to the Database. Check Log error for details" ,Arrays.asList(new Throwable()));
    443         return;
    444       }
    445       // -- end of Tab2Mage file import module
    446      
    447       /*
    448         RAW DATA IMPORT MODULE
    449        
    450        */
    451        
    452       if (dc == null || !dc.isConnected()|| dc.isClosed()) dc = sc.newDbControl();
    453      
    454         // get raw data files
    455       List<File> rawDataFiles= Tab2MageHelper.getRawDataFiles(dir, dc, rdt.getId(), tab2MageFileName);
    456        
    457         // do data import
    458       Tab2MageDataImportFactory dataImport = new Tab2MageDataImportFactory(sc,rdt.getId(),rawDataFiles,
    459                         hibernateItemsWriter.getRbas(), progress);
    460       boolean writtenRawData = dataImport.importData();
    461       if (!writtenRawData)
    462       {
    463         response.setError("IMPORT FAILS: Raw Data cannot not be written to the Database. Check Log error for details" ,Arrays.asList(new Throwable()));
    464         return;
    465       }
    466       // -- end of raw data import module
    467      
    468       /*
    469         EXPERIMENT CONFIGURATION AND LOADING MODULE
    470        
    471        */     
    472         //write experiment, attaching raw bio-assays
    473       Tab2MageExperimentWriter expWriter= new Tab2MageExperimentWriter(hibernateItemsWriter.getRbas(),sc,
    474                                       experiment,hibernateItemsWriter.getExpFactors(),
    475                                       validator.getTExperiment());
    476       boolean writtenExp= expWriter.LoadExperiment();
    477       // -- end of experiment configuration and loading module
    478      
    479       /*
    480         MESSAGING MODULE
    481        */
    482         //  send an email to the user on the success of the experiment (if email server name and email address are provided)
    483       if (hostName!= null && hostName.length()>=5)
    484       {
    485         if (!user.getEmail().equals("") && user.getEmail()!=null )
    486         {
    487           Tab2MageEMessaging message= new Tab2MageEMessaging(writtenExp,"", user.getEmail(),tab2MageFileName, user.getName(), experiment.getName(),hostName );
    488           message.sendEmail();
    489         }
    490       }
    491       // -- end of messaging module
    492       dc.commit();
    493       response.setDone("Import plugin ended successfully");
    494     }
    495     catch(Throwable tr)
    496     {
    497       response.setError(tr.getMessage(), Arrays.asList(tr));
    498     }
    499     finally
    500     {
    501       if (dc!=null)
    502         dc.close();
    503     }
    504   }
    505 
    506   /*
    507      From  AutoDetectionImporter interface
    508    */
     526    }
     527    return true;
     528  }
     529
     530  public void doImport(InputStream in, ProgressReporter progress) throws BaseException
     531  {
     532  }
     533
    509534  /**
    510     checks whether the zip file supplied by the user is actually a zip file.
    511    */
    512   public boolean isImportable(InputStream in) throws BaseException
    513   {
    514     ZipInputStream zin=null;
    515     try
    516       {
    517           zin = new ZipInputStream(in);
    518         //if this is not a zip file, this will throw an exception:
    519         ZipEntry zn = zin.getNextEntry();
    520       }
    521       catch (Exception e)
    522       {
    523         return false;
    524       }
    525       finally
    526       {
    527         try
    528         {
    529           zin.close();
    530         }
    531         catch(IOException ex)
    532         {
    533           throw new BaseException(ex);
    534         }
    535       }
    536       return true;
    537   }
    538  
    539   public void doImport(InputStream in, ProgressReporter progress) throws BaseException
    540   { }
    541  
    542   /**
    543     validates the directory parameter specified by user
    544     @param file, the zip file. its directory, is checked for the existence of directoryName given by the user
    545     @param directoryName, the name of the directory specified by the user
    546     @return TRUE if directory exist and FALSE otherwise
    547    */
    548   private boolean validateDirectory (File file, String directoryName)
     535   * validates the directory parameter specified by user
     536   *
     537   * @param file,
     538   *                the zip file. its directory, is checked for the existence of directoryName given by the user
     539   * @param directoryName,
     540   *                the name of the directory specified by the user
     541   * @return TRUE if directory exist and FALSE otherwise
     542   */
     543  private boolean validateDirectory(File file, String directoryName)
    549544  {
    550545    DbControl dc = sc.newDbControl();
    551546    try
    552547    {
    553       file = File.getById(dc, file.getId());
    554       return Directory.exists(dc, file.getDirectory(), directoryName);
     548      file = File.getById(dc, file.getId());
     549      return Directory.exists(dc, file.getDirectory(), directoryName);
    555550    }
    556551    finally
    557552    {
    558       if (dc != null) dc.close();
    559     }
     553      if (dc != null)
     554        dc.close();
     555    }
    560556  }
    561557}
Note: See TracChangeset for help on using the changeset viewer.