Changeset 458


Ignore:
Timestamp:
Oct 31, 2007, 6:19:07 PM (14 years ago)
Author:
dominic
Message:

commit file for the latest version of the tab2mage importer

Location:
trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation/Tab2MageImportValidatorUtils.java

    r417 r458  
    113113  }
    114114  /**
    115     initialiase maps for FactorValue, Parameter and BioMaterialXtaristics
     115    initialise maps for FactorValue, Parameter and BioMaterialXtaristics
    116116    extract Annotation Type [AT] and creates the [annotation type - valuetype] pair map
    117117   
     
    186186        if (parameterAnnotationType.containsKey(e.getKey()))
    187187        {
    188           //log.info("Found Parameter key : [" + e.getKey()+ "] and value is :" + parameterAnnotationType.get(e.getKey()));
     188          log.info("Found Parameter key : [" + e.getKey()+ "] and value is :" + parameterAnnotationType.get(e.getKey()));
    189189          parameter="true";
    190190        }
    191         //log.info(".....checking biomat map");
    192191        if (bioMaterialAnnotationType.containsKey(e.getKey()))
    193192        {
    194           //log.info("Found BioMat key: [" + e.getKey()+ "] and value is :" + bioMaterialAnnotationType.get(e.getKey()));
     193          log.info("Found BioMat key: [" + e.getKey()+ "] and value is :" + bioMaterialAnnotationType.get(e.getKey()));
    195194          items.add("biosource");
    196195        }
    197         //log.info(".....checking factor value map");
     196         
    198197        if (factorValueAnnotationType.containsKey(e.getKey()))
    199198        {
    200           //log.info("Found Factor Value key: [" + e.getKey()+ "] and value is :" + factorValueAnnotationType.get(e.getKey()));
     199          log.info("Found Factor Value key: [" + e.getKey()+ "] and value is :" + factorValueAnnotationType.get(e.getKey()));
    201200          items.add("rawbioassay");
    202201        }
     
    229228  }
    230229  /**
    231     creates a simple flatfile into a specified directory using the format of exisiting similar file
     230    creates a simple flatfile into a specified directory using the format of existing similar file
    232231      @param dc, the db control
    233232      @param dir, the directory- parent directory
     
    273272      log.error("Error: " + tex.getMessage());
    274273     
    275       throw new NutribasePluginException("Temporary File cannot be created");
     274      throw new NutribasePluginException("Temporary File cannot be created"+tex.getMessage());
    276275    }
    277276    finally
     
    293292  public boolean checkForPoolingProtocol()
    294293  {
    295     boolean pooled = header.contains(Tab2MageConstants.protocol_pool.getName())? true : false;
    296     return pooled;
     294    boolean isPooled= false;
     295    isPooled = header.contains(Tab2MageConstants.protocol_pool.getName())? true : false;
     296    return isPooled;
    297297  }
    298298 
     
    329329            BioSourceSampleMap.put(line.getBioSource(), s) ;
    330330          }
    331          
    332331          if (SampleExtractMap.containsKey(line.getSample()))
    333332            SampleExtractMap.get(line.getSample()).add(line.getExtract()) ;
     
    357356      log.error("Failed pooling processing : " + tr.getMessage());
    358357    }
     358    finally
     359    {
     360      if (!BioSourceSampleMap.isEmpty()) BioSourceSampleMap.clear();
     361      if (!SampleExtractMap.isEmpty()) SampleExtractMap.clear();
     362      if (!ExtractLabeledExtractMap.isEmpty()) ExtractLabeledExtractMap.clear();
     363    }
    359364  }
    360365 
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation/Tab2MageProtocolValidation.java

    r417 r458  
    66package uk.ac.ebi.nugo.plugins.tab2mageimport.validation;
    77
     8import java.io.Writer;
    89import java.util.ArrayList;
    910import java.util.Collections;
     11import java.util.LinkedList;
    1012import java.util.List;
    1113import java.util.Set;
     
    2628
    2729  /**
    28     This  class validates the experiment section of a tab2mage file and also relies on the
     30    This  class validates the protocol section of a tab2mage file and also relies on the
    2931    validation interface authored by  charles and saojorsha at EMBL.
    3032    @author Dominic Oyeniran
     
    4143  private DbControl dc;
    4244 
    43   // getting a dbcontrol here may not be very tidy. May need reworking
     45  /**
     46    creates a new Tab2MageProtocolValidation class constructors
     47      @param protocol, the set of protocols to validate
     48    @param dControl, the database control
     49   */
    4450  public Tab2MageProtocolValidation(Set<Tab2MAGEProtocol> protocol, DbControl dControl)
    4551  {
     
    4854  }
    4955 
    50   public Tab2MageProtocolValidation()
    51   {
    52  
    53   }
    5456  /**
    5557    Validate the values from the <code>TAB2MAGEProtocol</code> object.
     
    6062    @throws RawDataWriterException
    6163   */
    62   public boolean validate() throws TAB2MAGEException
     64  public boolean validate(Writer writer) throws TAB2MAGEException
    6365  {
    6466    boolean found =false;
    6567    boolean allowed =false;
    66     if(!super.validate()) return false;       
     68    boolean done = true;
     69    if(!super.validate()) return done=false; 
     70    List<String> errors = new LinkedList<String>();
    6771    try
    6872    {
     
    7478            {
    7579                log.error("The protocol type is empty. Must be provided");
    76                 return false;
     80                errors.add("Protocol Type for protocol with accession number: [" + protocol.getAccession()+ "] is empty. Must be provided");
    7781            }
    7882           
    7983            //check if protocol is allowed in tab2mage.
    80          
    8184            Set<Tab2MageConstants> allowedProtocols = Collections.unmodifiableSet(Tab2MageConstants.protocolContants());
    8285          for  (Tab2MageConstants  allowedProtocol : allowedProtocols  )
     
    9093          if(!allowed)
    9194            {
    92                 // if it is not reachable log the error message and stop
    9395                log.error("The protocol : " + protocol.getName() + " isn't permissible in the tab2mage specification.!");
    94                 return false;
     96                errors.add("The protocol : [" + protocol.getName() + "] isn't permissible in the tab2mage specification.!");
    9597            }
    9698         
    9799          // check if all protocol types are reachable in base2
    98          
    99100          ItemQuery<ProtocolType> protocolTypesQuery = ProtocolType.getQuery();
    100101          ItemResultList<ProtocolType> protocolTypes =protocolTypesQuery.list(dc);
     
    103104          for (ProtocolType protType : protocolTypes)
    104105          {
    105             if (protType.getName().equalsIgnoreCase(type))  // note protocol types are identified by thier names
     106            if (protType.getName().equalsIgnoreCase(type))  // note protocol types are identified by their names
    106107            {
    107108              found = true;
     
    110111          }
    111112          if(!found)
    112            {
    113                 // if it is not reachable log the error message and stop
    114                 log.warn("The protocol type: " + protocol.getType() + " isn't existing in BASE 2.!\n The importer may FAIL and your experiment may not be loaded");
    115             //    return false;
    116            }
     113          {
     114                log.warn("The protocol type: " + protocol.getType() + " isn't existing in BASE.!\n The importer may FAIL and your experiment may not be loaded");
     115                errors.add("The protocol type: [" + protocol.getType() + "] isn't existing in BASE.!\n The importer may FAIL and your experiment may not be loaded");
     116          }
    117117         
    118118          // check name and accession
     
    120120            {
    121121                log.error("A protocol accession is empty.");
    122                 return false;
     122                errors.add("A protocol accession is empty in the protocol section. Must be provided to proceed");
    123123            }
    124124            if(protocol.getName().equals("") || protocol.getName() == null)
    125125            {
    126126                log.error("A protocol name is empty.");
    127                 return false;
     127                errors.add("A protocol name is empty in the protocol section. Must be provided to proceed");
    128128            }
    129            
    130129            getAllProtocolParameters(protocol);
    131130        }
     131        if (!errors.isEmpty())
     132      {
     133        writer.write("\n+++ Protocol validation errors +++ \n");
     134        for (String error : errors)
     135        {
     136          writer.write(error+"\n");
     137        }
     138        writer.write("\n+++ End of protocol validation errors +++ \n");
     139        writer.write("\n");
     140        done= false;
     141      }
    132142    }
    133143    catch (Throwable tr)
    134144    {
     145      done =false;
    135146      new TAB2MAGEException(tr.getMessage());
    136147    }
    137     return true;
     148    finally
     149    {
     150      if (!errors.isEmpty()) errors.clear();
     151    }
     152    return done;
    138153  }
    139154 
     
    181196    Tab2MageProtocolValidation.protocolParameters = protocolParameters;
    182197  }
    183 
    184198}
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation/Tab2MageValidationFactory.java

    r417 r458  
    77package uk.ac.ebi.nugo.plugins.tab2mageimport.validation;
    88
     9import java.io.BufferedWriter;
     10import java.io.IOException;
     11import java.io.OutputStreamWriter;
     12import java.io.UnsupportedEncodingException;
     13import java.io.Writer;
    914import java.util.ArrayList;
    1015import java.util.Arrays;
     16import java.util.HashMap;
    1117import java.util.List;
    1218import java.util.Map;
    1319import java.util.Set;
    1420
     21import net.sf.basedb.core.BaseException;
    1522import net.sf.basedb.core.DbControl;
    1623import net.sf.basedb.core.Directory;
     
    1926import net.sf.basedb.core.ItemResultList;
    2027import net.sf.basedb.core.SessionControl;
     28import net.sf.basedb.core.plugin.Response;
    2129
    2230import org.apache.log4j.Logger;
    23 import org.embl.cg.bloader.exceptions.ValidationException;
    2431import org.embl.cg.bloader.models.Tab2MAGEExperiment;
    2532import org.embl.cg.bloader.models.Tab2MAGEHybridization;
     
    2835
    2936import uk.ac.ebi.nugo.common.NutribasePluginException;
     37import uk.ac.ebi.nugo.plugins.tab2mageimport.ValidationConstants;
    3038import uk.ac.ebi.nugo.plugins.tab2mageimport.io.AnnotationTypeFileWriter;
    3139import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Base2Tab2MageFileReader;
     
    3341
    3442/**
    35   Tab2mage validator class. This class validates the tab2mage file supplied by the user. It also calls the tab2mageinit class.
    36   Depends all on the Tab2mage Validator interface and implementation provided by Sajoscha Sauer <sauer@embl.de>
    37   and Charles Girardot <charles.girardot@embl.de> at EMBL, Germany.
    38  
     43  Tab2mage validator class. This class validates the tab2mage file supplied by the user.
    3944  @author Dominic Oyeniran
    4045  @version 1.0
     
    5156   private static ArrayList<Tab2MAGEHybridization> catchedHybs=null;
    5257   
    53    private static Map<String , List<String>> sampleExtractMap= null;
    54    private static Map<String, List<String>> bioSourceSampleMap =null;
    55    private static Map<String, List<String>>  extractLabeledExtractMap = null;
     58   // Extract -to- List of Samples map.
     59   private Map<String , List<String>> sampleExtMap = new HashMap<String,List<String>>() ;
     60   // Sample -to- List of Biosource map.
     61   private Map<String, List<String>> bioSourceSampMap = new HashMap<String,List<String>>();
     62  // the L. Extract -to- List of Extract map.
     63   private Map<String, List<String>>  extractLabeledExtMap = new HashMap<String,List<String>>();
    5664   
    5765   /**
     
    8997   private File atFile;
    9098   
    91   private Tab2MAGEExperiment tExperiment;
     99   private Tab2MAGEExperiment tExperiment;
    92100/**
    93101      variable that indicates if experiment is pooled or not.
    94102    */
    95103   private boolean pooled =false;
    96 
     104   
     105   /**
     106      The response object to return all error messages
     107    */
     108   private Response response;
     109   
     110   private static final String encoding="ISO-8859-1";
     111   
     112   private Writer statusOut;
     113   private File statusFile;
     114   
    97115   /**
    98116     
     
    105123      @param expPlatform
    106124    */
    107   public Tab2MageValidationFactory(String fileName, SessionControl sControl, Directory fileDirectory, String expPlatform)
     125  public Tab2MageValidationFactory(String fileName, SessionControl sControl, Directory fileDirectory, String expPlatform, Response resp, File file)
    108126  {
    109127    filename= fileName;
     
    112130    dir=fileDirectory;
    113131    platform= expPlatform;
    114  
    115     //this calls the Tab2mage file validation routine
    116     validateTab2MageFile();
    117   }
    118  
    119   /**
    120     creates  a new tab2mage validator, passing the tab2mage file name as parameter
    121    */
    122   public Tab2MageValidationFactory(String fileName)
    123   {
    124     filename= fileName;
     132    response = resp;
     133    statusFile = file; 
     134    createWriter();
     135  }
     136 
    125137   
    126   }
    127  
    128138  /**
    129139    Validates the file name provided  by the user as parameter
     
    132142      @return
    133143   */
    134   private boolean validateTab2MageFileName()
    135   {
    136      boolean valid =false;
    137      ItemQuery<File> fileQuery = dir.getFiles();
    138      ItemResultList<File> fileList = fileQuery.list(dc);
    139      for (File file: fileList)
    140      {
    141       //compare the file name supplied by the user to each of the filenames.
    142       String fileName= file.getName();
    143       if (fileName.equals(filename))
    144       {
    145         tab2MageFile= file;
    146         valid = true;
    147         break;
    148       }
    149      }
    150      return valid;
     144  public boolean validateTab2MageFileName()
     145  {
     146    DbControl newDc = null;
     147    boolean valid =false;
     148    try
     149    {
     150       newDc = sc.newDbControl();
     151       ItemQuery<File> fileQuery = dir.getFiles();
     152       ItemResultList<File> fileList = fileQuery.list(newDc);
     153       for (File file: fileList)
     154       {
     155        //compare the file name supplied by the user to each of the filenames.
     156        String fileName= file.getName();
     157        if (fileName.equals(filename))
     158        {
     159          tab2MageFile= file;
     160          valid = true;
     161          break;
     162        }
     163       }
     164    }
     165    catch(Throwable tr)
     166    {
     167      new BaseException("Tab2Mage File Name cannot be validated");
     168    }
     169    finally
     170    {
     171      if (newDc!=null)
     172        newDc.close();
     173    }
     174    return valid;
    151175    }
    152176 
     177  void  createWriter()
     178  {
     179    try
     180    {
     181      statusFile =File.getById(dc, statusFile.getId());
     182      statusOut= new BufferedWriter(new OutputStreamWriter(statusFile.getUploadStream(false),encoding));
     183      statusOut.write("\n %%%%%% The Tab2Mage Importer Validation File %%%%%% \n");
     184    }
     185    catch(UnsupportedEncodingException e)
     186    {
     187      throw new NutribasePluginException(e.getMessage());
     188    }
     189    catch(IOException ei)
     190    {
     191      throw new NutribasePluginException(ei.getMessage());
     192    }
     193  }
    153194 
    154195  /**
     
    157198   */
    158199  @SuppressWarnings("static-access")
    159   private void validateTab2MageFile()
    160   {
     200  public Map<ValidationConstants, Boolean> validateTab2MageFile()
     201  {
     202    Map<ValidationConstants, Boolean> validationMap = new HashMap<ValidationConstants, Boolean>();
     203    boolean doneExperiment =true;
     204    boolean doneHybridizationHeaders= true;
     205    boolean doneHybridization = true;
     206    boolean doneProtocol = true;
     207    boolean doneGenepix= true;
     208    boolean doneAgilent= true;
    161209    try
    162210    {
    163       boolean isFileValid= false;
    164       // validate the tab2mage file name
    165       isFileValid = validateTab2MageFileName();
    166       if (isFileValid) // if the tab2mage file is validated proceed.
    167       {
    168         //  parse and read the tab2magefile
    169         reader = new Base2Tab2MageFileReader(tab2MageFile, sc);
    170         reader.createTemporaryFiles();
     211      if (dc == null || !dc.isConnected() || dc.isClosed())
     212        dc= sc.newDbControl();
     213
     214      //  parse and read the tab2magefile
     215      tab2MageFile= File.getById(dc, tab2MageFile.getId());
     216      reader = new Base2Tab2MageFileReader(tab2MageFile, sc);
     217      reader.createTemporaryFiles();
     218           
     219      //validate experiment
     220     
     221      tExperiment= reader.getExperiment();
     222      Tab2MageExperimentValidation experimentVal= new Tab2MageExperimentValidation(reader);
     223      boolean expValidated= experimentVal.validate(statusOut, response); // return true or false
     224      if (!expValidated)
     225      {
     226        log.error("SORRY: The experiment section of the tab2mage file: " +filename+ " is invalid. Mandatory fields: experiment name, submitter and email must be provided to proceed");
     227        statusOut.write("Mandatory fields are: experiment name, and submitter.\n");
     228        doneExperiment =false;
     229      }
     230      log.warn(doneExperiment ? " \n.... Experiment validation is SUCCESSFUL .... \n" :" \n.... Experiment validation FAILED .... \n");   
     231      statusOut.write( doneExperiment ? " \n.... Experiment validation is SUCCESSFUL .... \n" :" \n.... Experiment validation FAILED .... \n");
     232     
     233      //validate protocols
     234     
     235      if (dc == null || !dc.isConnected() || dc.isClosed())
     236        dc= sc.newDbControl();
     237      log.info("\n+++ Begin Protocol validation +++\n");
     238      Set<Tab2MAGEProtocol> protocols = reader.getProtocols(); // gets all the  protocols
     239      Tab2MageProtocolValidation protocolVal= new Tab2MageProtocolValidation(protocols, dc);
     240      boolean protocolsValidated = protocolVal.validate(statusOut);
     241      if (!protocolsValidated)
     242      {
     243        log.error("SORRY: The protocol section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed. See the log file for more details");
     244        statusOut.write("Sorry the protocol section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed.");
     245        doneProtocol= false;
     246      }
     247                 
     248      log.info( doneProtocol ? " \n.... Protocol validation is SUCCESSFUL .... \n" :" \n.... Protocol validation FAILED .... \n");
     249      statusOut.write( doneProtocol ? " \n.... Protocol validation is SUCCESSFUL .... \n" :" \n.... Protocol validation FAILED .... \n");
     250      statusOut.flush();
     251      /*
     252        Validate Hybridization
     253      */
     254     
     255      if (dc == null || !dc.isConnected() || dc.isClosed()) dc = sc.newDbControl();
     256      log.info("\n+++ Begin Hybridization validation +++\n");
     257     
     258      ArrayList<Tab2MAGEHybridization> hybs = reader.getHybridizations();
     259     
     260        // validate headers
     261      boolean validateHeaders= Tab2MageHybridizationValidation.validateHeader(new ArrayList<String>(Arrays.asList(reader.getHeaders())), statusOut);
     262      if (!validateHeaders)
     263      {
     264        log.error("SORRY: The header for the hybridization section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed. See the log file for more details");
     265        statusOut.write("Sorry the header for the hybridization section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed.");
     266        doneHybridizationHeaders = false;
     267      }
     268      statusOut.write( doneHybridizationHeaders ? " \n.... Hybridization header validation is SUCCESSFUL .... \n" :" \n.... Hybridization header validation FAILED .... \n");
     269           
     270        //validate rows /lines
     271     
     272      Tab2MageHybridizationValidation validateHyb = new Tab2MageHybridizationValidation(dir, platform, hybs, reader, sc);
     273      if (!validateHyb.validate(statusOut))
     274      {
     275        log.error("SORRY: The hybridization section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed. See the log file for more details");
     276        statusOut.write("Sorry the hybridization section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed.");
     277        doneHybridization=false;
    171278       
    172         //validate experiment
    173        
    174         tExperiment= reader.getExperiment();
    175         Tab2MageExperimentValidation experimentVal= new Tab2MageExperimentValidation(reader);
    176         boolean expValidated= experimentVal.validate(); // return true or false
    177        
    178         log.info(expValidated ? "yes the exp is validated" : "No exp is not validated");
    179         if (!expValidated)
     279      }
     280      log.info(doneHybridization ? " \n.... Hybridization validation is SUCCESSFUL  .... \n" :" \n.... Hybridization validation FAILED .... \n");
     281      statusOut.write( doneHybridization ? " \n.... Hybridization validation is SUCCESSFUL  .... \n" :" \n.... Hybridization validation FAILED .... \n");     
     282      statusOut.flush();
     283     
     284      /*
     285         validate Genepix file for two channel experiments
     286         
     287       */
     288      if (dc == null || !dc.isConnected() || dc.isClosed()) dc = sc.newDbControl();
     289      dir= Directory.getByPath(dc, dir.getPath());
     290      if (platform.equalsIgnoreCase("genepix")) 
     291      {
     292        log.info("\n+++ Begin GenePix File validation +++\n");   
     293        List<File> gprFiles= Tab2MageHelper.getRawDataFiles(dir, dc, platform, filename);
     294        GenePixFileValidation gprValidation= new GenePixFileValidation(gprFiles, dc);
     295        if (!gprValidation.validate(statusOut))
     296        {
     297          log.error("Sorry the gpr files cannot be validated. Mandatory Columns are missing. Must be rectified to proceed. See the log file for more details");
     298          statusOut.write("Sorry the gpr files cannot be validated. Mandatory Columns are missing. Must be rectified to proceed.");
     299          doneGenepix =false;
     300        }
     301        GenePixValidation.validateRawFiles(hybs);
     302        log.info("\n+++ Finished GenePix File validation +++\n");
     303        statusOut.write( doneGenepix ? " \n.... Genepix validation is SUCCESSFUL  .... \n" :" \n.... Genepix validation FAILED .... \n");     
     304      }
     305      /*
     306        Validate agilent file for two channel experiment
     307       */
     308     
     309      if (platform.equalsIgnoreCase("agilent"))
     310      {
     311        // we need to parse the headers
     312        // obtain and check if the headers is within the allowed range
     313        log.info("\n+++ Begin Agilent File validation +++\n");   
     314        List<File> agFiles= Tab2MageHelper.getRawDataFiles(dir, dc, platform, filename);
     315        AgilentValidation agValidation= new AgilentValidation(agFiles,dc);
     316        if (!agValidation.validate(statusOut))
    180317        {
    181           log.error("SORRY: The experiment section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed");
    182           throw new NutribasePluginException("SORRY: The experiment section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed");
     318          log.error("Sorry the agilent files cannot be validated. Mandatory Columns are missing. Must be rectified to proceed. See the log file for more details");
     319          statusOut.write("Sorry the agilent files cannot be validated. Mandatory Columns are missing. Must be rectified to proceed.");
     320          doneAgilent =false;
    183321        }
    184         log.info("\n+++ Finished  experiment validation +++\n");   
    185        
    186         //validate protocols
    187         if (dc == null || !dc.isConnected() || dc.isClosed()) //dc = dir.getDbControl();
    188           dc= sc.newDbControl();
    189         log.info("\n+++ Begin Protocol validation +++\n");
    190         Set<Tab2MAGEProtocol> protocols = reader.getProtocols(); // we get all the  protocols
    191         Tab2MageProtocolValidation protocolVal= new Tab2MageProtocolValidation(protocols, dc);
    192         boolean protocolsValidated = protocolVal.validate();
    193         if (!protocolsValidated)
    194         {
    195           log.error("SORRY: The protocol section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed. See the log file for more details");
    196           throw new NutribasePluginException("SORRY: The protocol section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed. See the log file for more details");
    197         }
    198         // Display the protocols only for debugging     
    199         //log.info("\n+++++++++++++++++++++++ALL THE PROTOCOLS++++++++++++++++++++++++++++++++++++++\n");
    200         //for (Tab2MAGEProtocol p : protocols)
    201         //{
    202         //  log.info(p.getAccession()+ "\t" +p.getText()+ "\t" +p.getName() + "\t" +p.getType()+ "\t" +p.getParameters());
    203         //}
    204         //Display all the parameters, only for debugging
    205        
    206         //log.info("\n++++++++++++++++++++ The parameters ++++++++++++++\n");
    207         //List<String> params= protocolVal.getProtocolParameters();
    208         //for (String p : params)
    209         //{
    210         //  log.info(p);
    211         //}
    212              
    213         log.info("\n+++ Finished  protocol validation +++\n");
    214        
    215         /*
    216           Validate Hybridization
    217         */
    218         if (dc == null || !dc.isConnected()) dc = sc.newDbControl();
    219         log.info("\n+++ Begin Hybridization validation +++\n");
    220         ArrayList<Tab2MAGEHybridization> hybs = reader.getHybridizations();
    221        
    222           // validate headers
    223         boolean validateHeaders= Tab2MageHybridizationValidation.validateHeader(new ArrayList<String>(Arrays.asList(reader.getHeaders())));
    224         if (!validateHeaders)
    225         {
    226           log.error("SORRY: The header for the hybridization section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed. See the log file for more details");
    227           throw new NutribasePluginException("The header for the hybridization section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed. See the log file for more details");
    228         }
    229           //validate rows /lines
    230        
    231         Tab2MageHybridizationValidation validateHyb = new Tab2MageHybridizationValidation(dir, platform, hybs, reader, sc);
    232         if (!validateHyb.validate())
    233         {
    234           log.error("SORRY: The hybridization section of the tab2mage file: " +filename+ " is invalid. Must be rectified to proceed. See the log file for more details");
    235           throw new ValidationException("There is an error in the Tab2Mage Hybridization section!");
    236         }
    237         log.info("\n+++ Finished  Hybridization validation +++\n");
    238              
    239         /*
    240            initialise all annotation types data structure for AT creation
    241          */
    242        
    243         log.info("\n+++ Begin initialisation and writing of annotation types +++\n");
    244         if (dc == null || !dc.isConnected() || dc.isClosed()) dc = sc.newDbControl();
    245        
    246         Tab2MageImportValidatorUtils utils = new Tab2MageImportValidatorUtils(hybs, new ArrayList<String>(Arrays.asList(reader.getHeaders())));
    247         utils.initialiseMaps();
    248         utils.createAnnotationTypes();
    249        
    250         tab2MageFile= File.getByPath(dc, tab2MageFile.getPath(), false); 
    251         log.info("create file and directory");
    252         String filename= "anntype.txt";
    253         utils.createFile(sc, dir, "tempAT",  tab2MageFile.getMimeType(),tab2MageFile.getFileType() , filename);
    254         atFile = utils.getFile();
    255        
    256         if (dc == null || !dc.isConnected() || dc.isClosed()) dc = sc.newDbControl();
    257         atFile= File.getByPath(dc, atFile.getPath(), false);
    258         AnnotationTypeFileWriter writer= new AnnotationTypeFileWriter(atFile,utils.getAnnotationTypeFileMappings() );
    259         writer.writeFile();
    260         dc.commit();
    261        
    262         log.info("Writing file :"+atFile.getName()+ " completed!");
    263         log.info("\n+++ Finished initialisation and writing of annotation types +++\n");
    264        
    265         /*
    266           - check if there exist the pooling protocol
    267         */
    268         pooled=utils.checkForPoolingProtocol();
    269        
    270         if (pooled)
    271         {
    272           log.info("Protocol[pool] property is specifed");
    273           utils.handlePool();
    274           sampleExtractMap=utils.getSampleExractPoolMap();
    275           bioSourceSampleMap = utils.getBioSourceSamplePoolMap();
    276           extractLabeledExtractMap= utils.getExractLabeledExtractPoolMap();
    277         }
    278         /*
    279            validate Genepix file for two channel experiments
    280            
    281          */
    282         // check if the dc is closed, or disconnected and create a new one if yes
    283         if (dc == null || !dc.isConnected() || dc.isClosed()) dc = sc.newDbControl();
    284         dir= Directory.getByPath(dc, dir.getPath());
    285         if (platform.equalsIgnoreCase("genepix")) 
    286         {
    287           log.info("\n+++ Begin GenePix File validation +++\n");   
    288           List<File> gprFiles= Tab2MageHelper.getRawDataFiles(dir, dc, platform, filename);
    289           GenePixFileValidation gprValidation= new GenePixFileValidation(gprFiles, dc);
    290           if (!gprValidation.validate())
    291           {
    292             log.error("SORRY: The gpr files cannot be validated. Mandatory Columns are missing. Must be rectified to proceed. See the log file for more details");
    293             throw new ValidationException("A gpr file is missing once or more mandatory columns!");
    294           }
    295           GenePixValidation.validateRawFiles(hybs);
    296           log.info("\n+++ Finished GenePix File validation +++\n");
    297         }
    298         /*
    299           Validate agilent file for two channel experiment
    300          */
    301        
    302         if (platform.equalsIgnoreCase("agilent"))
    303         {
    304           // we need to parse the headers
    305           // obtain and check if the headers is within the allowed range
    306           log.info("\n+++ Begin Agilent File validation +++\n");   
    307           List<File> agFiles= Tab2MageHelper.getRawDataFiles(dir, dc, platform, filename);
    308           AgilentValidation agValidation= new AgilentValidation(agFiles,dc);
    309           if (!agValidation.validate())
    310           {
    311             log.error("SORRY: The agilent files cannot be validated. Mandatory Columns are missing. Must be rectified to proceed. See the log file for more details");
    312             throw new ValidationException("An agilent file is missing once or more mandatory columns!");
    313           }
    314           log.info("\n+++ Finished Agilent File validation +++\n");
    315         }
    316          
    317         /*
    318           add other validations as required
    319          */
    320        
    321         //catche all the protocols and hybridizations
    322         catchedProtocol= protocols;
    323         catchedHybs=hybs;
    324       }
    325       else
    326       { log.error("The Tab2Mage filename provided as parameter on the GUI : [ " + filename+ " ] does not match that contained in the zip file");
    327         throw new  NutribasePluginException("The Tab2Mage filename provided as parameter on the GUI : [ " + filename+ " ] does not match that contained in the zip file");
    328       }
    329       // if the code survives the validation task, set validated to true
    330       validated= true;
     322        log.info("\n+++ Finished Agilent File validation +++\n");
     323        statusOut.write( doneAgilent ? " \n.... Agilent validation is SUCCESSFUL  .... \n" :" \n.... Agilent validation FAILED .... \n");     
     324      }
     325      statusOut.flush();
     326     
     327      //catche all the protocols and hybridizations
     328      catchedProtocol= protocols;
     329      catchedHybs=hybs;
     330      /*
     331        check if annotations are allowed values
     332       */
     333      AnnotationValidation attValidator = new AnnotationValidation(hybs, dc);
     334      attValidator.checkAnnotations(statusOut);
     335      statusOut.flush();
     336      /*
     337        add other validations as required
     338       */
     339     
     340      /*
     341         initialise all annotation types data structure for AT creation
     342       */
     343     
     344      log.info("\n+++ Begin initialisation and writing of annotation types +++\n");
     345      if (dc == null || !dc.isConnected() || dc.isClosed()) dc = sc.newDbControl();
     346     
     347      Tab2MageImportValidatorUtils utils = new Tab2MageImportValidatorUtils(hybs, new ArrayList<String>(Arrays.asList(reader.getHeaders())));
     348      utils.initialiseMaps();
     349      utils.createAnnotationTypes();
     350     
     351      tab2MageFile= File.getByPath(dc, tab2MageFile.getPath(), false); 
     352      log.info("create file and directory");
     353      String filename= "anntype.txt";
     354      utils.createFile(sc, dir, "tempAT",  tab2MageFile.getMimeType(),tab2MageFile.getFileType() , filename);
     355      atFile = utils.getFile();
     356     
     357      if (dc == null || !dc.isConnected() || dc.isClosed()) dc = sc.newDbControl();
     358      atFile= File.getByPath(dc, atFile.getPath(), false);
     359      AnnotationTypeFileWriter writer= new AnnotationTypeFileWriter(atFile,utils.getAnnotationTypeFileMappings() );
     360      writer.writeFile();
     361      dc.commit();
     362     
     363      log.info("Writing file : "+atFile.getName()+ " completed!");
     364      log.info("\n+++ Finished initialisation and writing of annotation types +++\n");
     365     
     366      /*
     367        - check if there exist the pooling protocol i.e. protocol[pool]
     368      */
     369      pooled=utils.checkForPoolingProtocol();
     370     
     371      if (pooled)
     372      {
     373        log.info("Protocol[pool] property is specifed");
     374        utils.handlePool();
     375        sampleExtMap.putAll(utils.getSampleExractPoolMap());
     376        bioSourceSampMap.putAll(utils.getBioSourceSamplePoolMap());
     377        extractLabeledExtMap.putAll(utils.getExractLabeledExtractPoolMap());
     378      }
     379     
     380      if (!doneExperiment) validationMap.put(ValidationConstants.Experiment, doneExperiment);
     381      if (!doneProtocol)validationMap.put(ValidationConstants.Protocol, doneProtocol);
     382      if (!doneHybridizationHeaders) validationMap.put(ValidationConstants.Hybridization_Header,doneHybridizationHeaders);
     383      if (!doneHybridization)  validationMap.put(ValidationConstants.Hybridization,doneHybridization);
     384      if (!doneGenepix) validationMap.put(ValidationConstants.Genepix,doneGenepix);
     385      if (!doneAgilent)validationMap.put(ValidationConstants.Agilent,doneAgilent);
     386     
     387      statusOut.close();
    331388    }
    332389    catch(Throwable tr)
    333390    {
    334       validated = false;
     391      try
     392      {
     393        if (statusOut!=null) statusOut.close();
     394      }
     395      catch(Throwable ex)
     396      {
     397        new IOException(ex.getMessage());
     398      }
     399      log.error("Validation failed with : ", tr);
     400      validationMap.put(ValidationConstants.validation, false);
     401      throw new BaseException("The Validation/Intialisation Phase Failed: "+tr.getMessage());
    335402    }
    336403    finally
     
    338405      if (dc!=null)
    339406        dc.close();
    340     }
    341    
    342   }
     407    }
     408    return validationMap;
     409  }
     410 
    343411  /**
    344412    returns true if validation is successful and false otherwise.
     
    417485      @return  Map<String, List<String>
    418486   */
    419   public static Map<String, List<String>> getSampleExtractMap()
    420   {
    421     return sampleExtractMap;
     487  public Map<String, List<String>> getSampleExtractMap()
     488  {
     489    return sampleExtMap;
    422490  }
    423491  /**
     
    425493      @return map
    426494   */
    427   public static Map<String, List<String>> getBioSourceSampleMap()
    428   {
    429     return bioSourceSampleMap;
     495  public Map<String, List<String>> getBioSourceSampleMap()
     496  {
     497    return bioSourceSampMap;
    430498  }
    431499  /**
     
    433501    @return map
    434502   */
    435   public static Map<String, List<String>> getExtractLabeledExtractMap()
    436   {
    437     return extractLabeledExtractMap;
     503  public Map<String, List<String>> getExtractLabeledExtractMap()
     504  {
     505    return extractLabeledExtMap;
    438506  }
    439507}
Note: See TracChangeset for help on using the changeset viewer.