Changeset 459


Ignore:
Timestamp:
Oct 31, 2007, 6:19:32 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
Files:
13 edited

Legend:

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

    r417 r459  
    4747    this.valueType = valueType;
    4848    this.parameter=parameter;
    49     this.itemTypes.addAll(itemTypes); // itemTpes =itemTypes doesn't work. the list of item gets truncated.
     49    this.itemTypes.addAll(itemTypes);
    5050  }
    5151 
     
    195195    this.enumeration = enumeration;
    196196  }
    197 
    198 
    199197}
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/DetectablePluginTypes.java

    r417 r459  
    1010  @version 1.0
    1111  @email oyeniran@ebi.ac.uk
    12   @nutribase.modified $Date
    1312*/
    1413public enum DetectablePluginTypes
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/ExperimentPlatformsLibrary.java

    r417 r459  
    1515    @author Dominic Oyeniran
    1616    @version 1.0
    17     @nutribase.modified $Date
     17    @email oyeniran@ebi.ac.uk
    1818 
    1919 */
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/GenePixDataColumns.java

    r417 r459  
    3030    the name of the feature derived from the Array List (up to 40 characters long, contained in quotation marks).
    3131   */
    32   Name (3,"name"),
     32  Name (4,"name"),
    3333 
    3434  /**
    3535    the unique identifier of the feature derived from the Array List (up to 40 characters long, contained in quotation marks).
    3636   */
    37   ID (4, "id"),
     37  ID (5, "id"),
    3838  /**
    3939    the X-coordinate in µm of the center of the feature-indicator associated with the feature, where (0,0) is the top left of the image.
    4040   */
    41   X (5,"x" ),
     41  X (6,"x" ),
    4242  /**
    4343    the Y-coordinate in µm of the center of the feature-indicator associated with the feature, where (0,0) is the top left of the image.
    4444   */
    45   Y (6,"y"),
     45  Y (7,"y"),
    4646  /**
    4747    the diameter in µm of the feature-indicator.
    4848   */
    49   Dia (7, "dia."),
     49  Dia (8, "dia."),
    5050  /**
    5151    median feature pixel intensity at wavelength #1 (635 nm).
    5252   */
    53   F635Median (8,"f635 median"),
     53  F635Median (9,"f635 median"),
    5454  /**
    5555    mean feature pixel intensity at wavelength #1 (635 nm).
    5656   */
    57   F635Mean (9,"f635 mean"),
     57  F635Mean (10,"f635 mean"),
    5858  /**
    5959    the standard deviation of the feature pixel intensity at wavelength #1 (635 nm).
    6060   */
    61   F635SD (10, "f635 sd"),
     61  F635SD (11, "f635 sd"),
    6262  /**
    6363    the median feature background intensity at wavelength #1 (635 nm).
    6464   */
    65   B635Median (11,"b635 median"),
     65  B635Median (12,"b635 median"),
    6666  /**
    6767    the mean feature background intensity at wavelength #1 (635 nm).
    6868   */
    69   B635Mean (12,"b635 mean" ) ,
     69  B635Mean (13,"b635 mean" ) ,
    7070  /**
    7171    the standard deviation of the feature background intensity at wavelength #1 (635 nm).
    7272   */
    73   B635SD (13,"b635 sd" ),
     73  B635SD (14,"b635 sd" ),
    7474  /**
    7575    median feature pixel intensity at wavelength #2 (532 nm).
    7676   */
    77   F532Median (14,"f532 median" ),
     77  F532Median (15,"f532 median" ),
    7878  /**
    7979    mean feature pixel intensity at wavelength #2 (532 nm).
    8080   */
    81   F532Mean (15, "f532 mean" ),
     81  F532Mean (16, "f532 mean" ),
    8282  /**
    8383    the standard deviation of the feature intensity at wavelength #2 (532 nm).
    8484   */
    85   F532SD (16,"f532 sd" ),
     85  F532SD (17,"f532 sd" ),
    8686  /**
    8787    the median feature background intensity at wavelength #2 (532 nm)
    8888   */
    89   B532Median (17,"b532 median" ),
     89  B532Median (18,"b532 median" ),
    9090  /**
    9191    the mean feature background intensity at wavelength #2 (532 nm).
    9292   */
    93   B532Mean (18, "b532 mean"),
     93  B532Mean (19, "b532 mean"),
    9494  /**
    9595    the standard deviation of the feature background intensity at wavelength #2 (532 nm).
    9696   */
    97   B532SD(19, "b532 sd");
     97  B532SD(20, "b532 sd");
    9898 
    9999  //instance variable
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/parser/AgilentRDParser.java

    r417 r459  
    1212import java.io.InputStreamReader;
    1313
     14import net.sf.basedb.core.BaseException;
    1415import net.sf.basedb.core.DbControl;
    1516import net.sf.basedb.core.File;
     
    8687        if (values.startsWith(RAWDATASEPARATOR))
    8788        { // beginning of raw data
    88           //String head = values.replaceAll("\"", ""); // NOT REQQUIRES AS HEADERS DO NOT HAVE QUOTES
    89           //String[] headers = head.split("\t");
    9089          String[] headers = values.split("\t");
    9190          this.headers = headers;
     
    102101      {
    103102        log.warn("Couldn't close the BufferedReader object.");
     103        throw new BaseException("Couldn't close the BufferedReader object."+e1);
    104104      }
    105105      return null;
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/parser/Base2GenePixRDParser.java

    r417 r459  
    2323/**
    2424  This class parses the genepix raw data file for validation.
    25   A new class is required for base2 implementation to utilise base2 file system.Also we do read the
    26   raw data rows. The class also reused some code from Charles Giradot and Soaja at EMBL, Heildelberg
    2725  @author Dominic Oyeniran
    2826  @version 1.0
    29   @see org.embl.cg.bloader.io.rawdataparser.GenePixRDParser
     27 
    3028 */
    3129public class Base2GenePixRDParser
     
    8280      return;
    8381    }
    84    
    8582  }
    8683 
     
    119116      {
    120117        log.warn("Couldn't close the BufferedReader object.");
     118       
    121119      }
    122120      return null;
     
    217215      throw new RawDataParserException(e.getMessage());
    218216    }
    219   }  // close the buffered reader : dom
     217  }
    220218
    221219  public String[] getHeaders()
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/io/parser/CSVParser.java

    r426 r459  
    2727 * Created on May 18, 2005
    2828 *
    29   This class is a modified version of  org.embl.cg.utilitytools.parser.csv.CVSParser to handle base2 file systems. The ideal way to solve
    30   the problem in BASELoader, I think, is to read
     29  This class is a modified version of   base Loader CVSParser to handle base2 file systems. The ideal way to solve
     30  the problem in BASELoader, I reckon, is to read
    3131  a system.database=BASE2 or system.platform=BASE2 property from the BASELoader /conf/baseloader.properties.
    3232  Pass the property as a string parameter to the getBufferedReader() method below.
     
    160160  }
    161161 
    162   /*
    163    * changed the parameter to the base2  temporary file created earlier so no need to create a new file
    164    */
     162 
    165163  /**
    166164   * @param filePath
     
    216214          continue;
    217215      }
    218       /*
    219         do not understand why this returns null
    220         [TODO] confirm with author: Charles
    221        
    222        
    223        */
     216     
    224217      if (!initColNumBasedOnFirstValidLine && !isValidLine(cols)) {
    225218          //log.debug("not a valid line");
     
    478471  protected BufferedReader getBufferedReader() throws FileNotFoundException {
    479472    BufferedReader bf = null; //get the file
    480     //File f = new File(this.filePath);
    481 
    482       //if (!f.exists()) {
    483         //throw new FileNotFoundException(
    484         //  "File specified by path does not exists, path is: "
    485         //      + filePath);
    486     //  }
    487     //System.out.println("Filename in the cvs parser is : "+ file.getName());
    488     //File file = file.
    489473    bf = new BufferedReader(new InputStreamReader(this.file.getDownloadStream(0)));
    490474    return bf;
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/mail/Tab2MageEMessaging.java

    r417 r459  
    3333  private String mailFrom = "";
    3434  private String mailTo = "";
    35   //private String host = "smtp.ebi.ac.uk";
    3635  private String host="";
    3736  private String body = "";
     
    114113    {
    115114      log.error("Email message cannot be sent, your email address maybe invalid. Or " +me.getMessage()+ ". Contact your smtp sever adminstrator");
    116      
    117       //throw new NutribasePluginException("Email message cannot be sent, your email address maybe invalid. Or " +me.getMessage()+ ". Contact your smtp sever adminstrator");
    118115    }
    119116    catch (UnsupportedEncodingException e)
    120117    {
    121118      log.error("You have some unsupported characters in your base/nutribase username or email address.");
    122      
    123       //throw new NutribasePluginException(e.getMessage());
    124119    }
    125120  }
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation/AgilentValidation.java

    r417 r459  
    77package uk.ac.ebi.nugo.plugins.tab2mageimport.validation;
    88
     9import java.io.Writer;
    910import java.util.Arrays;
     11import java.util.LinkedList;
    1012import java.util.List;
    1113
     
    5355   
    5456 
    55   public boolean validate() throws Throwable
     57  public boolean validate(Writer writer) throws Throwable
    5658  {
     59    List<String> errors = new LinkedList<String>();
    5760    boolean success = true;
    5861    try
     
    7174          {
    7275            log.error("Mandatory Column: ["+man.getAgilentColumnName().toUpperCase()+ "] is missing in the agilent file: ["+ agFile + "]. Must be rectified to continue");
    73             return success =false;
     76            writer.write("Mandatory Column: ["+man.getAgilentColumnName().toUpperCase()+ "] is missing in the agilent file: ["+ agFile + "]. Must be rectified to continue");
    7477          }
    7578        }
     79      }
     80      if (!errors.isEmpty())
     81      {
     82        writer.write("\n+++ Agilent File validation errors +++ \n");
     83        for (String error : errors)
     84        {
     85          writer.write(error+"\n");
     86        }
     87        writer.write("\n+++ End of Agilent File validation errors +++ \n");
     88        writer.write("\n");
     89        success =false;
    7690      }
    7791    }
     
    8195      log.error("The agilent files cannot be validated");
    8296    }
     97    finally
     98    {
     99      if (!errors.isEmpty()) errors.clear();
     100    }
    83101    return success;
    84102  }
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation/GenePixFileValidation.java

    r417 r459  
    77package uk.ac.ebi.nugo.plugins.tab2mageimport.validation;
    88
    9 import java.util.ArrayList;
     9import java.io.Writer;
    1010import java.util.Arrays;
     11import java.util.LinkedList;
    1112import java.util.List;
    1213
     
    1516
    1617import org.apache.log4j.Logger;
    17 import org.embl.cg.bloader.exceptions.TAB2MAGEException;
    18 import org.embl.cg.bloader.exceptions.ValidationException;
    19 import org.embl.cg.bloader.models.Tab2MAGEHybridization;
    2018
    2119import uk.ac.ebi.nugo.common.Helper;
     
    6159      @return true if validation is successful and false otherwise.
    6260   */
    63   public boolean validate()
     61  public boolean validate(Writer writer)
    6462  {
     63    List<String> errors = new LinkedList<String>();
    6564    boolean success = true;
    6665    try
     
    7271        //log.info("\n..........The list of Genepix headers\n");
    7372        List<String> headerList = Helper.arrayContentToLowercase(headers);
    74         //int i=0;
    75         //for (String header :headerList )
    76         //{
    77         //  i++;
    78         //  log.info("Header " + i + ": "+ header);
    79         //}
    80       //  log.info("End of Genepix headers\n");
    8173        List<GenePixDataColumns> mandatoryColumns= Arrays.asList(GenePixDataColumns.values());
    8274        for (GenePixDataColumns man :mandatoryColumns )
     
    8577          {
    8678            log.error("Mandatory Column: ["+man.getColumnName().toUpperCase()+ "] is missing in the genepix file: ["+ gprFile + "]. Must be rectified to continue");
    87             return success =false;
     79            errors.add("Mandatory Column: ["+man.getColumnName().toUpperCase()+ "] is missing in the genepix file: ["+ gprFile + "]. Must be rectified to continue");
     80           
    8881          }
    8982        }
     83      }
     84      if (!errors.isEmpty())
     85      {
     86        writer.write("\n+++ GenePix File validation errors +++ \n");
     87        for (String error : errors)
     88        {
     89          writer.write(error+"\n");
     90        }
     91        writer.write("\n+++ End of GenePix File validation errors +++ \n");
     92        writer.write("\n");
     93        success =false;
    9094      }
    9195    }
     
    9397    {
    9498      success = false;
    95       log.error("The gpr files cannot be validated"+tr.getMessage());
    96      
     99      log.error("The gpr files cannot be validated : "+tr.getMessage());
     100    }
     101    finally
     102    {
     103      if (!errors.isEmpty()) errors.clear();
    97104    }
    98105    return success;
    99106  }
    100  
    101   // code from charles and sajoucha @ embl, Heidelberg does nothing at the moment
    102   public static boolean validateRawFiles(ArrayList<Tab2MAGEHybridization> hybs) throws ValidationException
    103   {
    104     try
    105     {
    106       for(Tab2MAGEHybridization hyb : hybs)
    107       {
    108         String file = hyb.getFileRaw();
    109       }
    110     }
    111     catch(TAB2MAGEException e)
    112     {
    113       throw new ValidationException(e);
    114     }
    115     return false;
    116   }
     107
    117108}
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation/RawDataValidation.java

    r417 r459  
    66package uk.ac.ebi.nugo.plugins.tab2mageimport.validation;
    77
     8import java.io.Writer;
     9
    810/**
    911  This interface is for the validation of raw data files.
    1012  Note: seperate implementation to base1/ baseloader
    1113    @author Dominic Oyeniran
    12   @email
     14  @email oyeniran@ebi.ac.uk
    1315  @version 1.0
    1416 */
     
    2022    @return TRUE if file is validated and FALSE otherwise.
    2123   */
    22   public boolean  validate() throws Throwable;
     24  public boolean  validate(Writer writer) throws Throwable;
    2325
    2426}
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation/Tab2MageExperimentValidation.java

    r417 r459  
    66package uk.ac.ebi.nugo.plugins.tab2mageimport.validation;
    77
     8import java.io.IOException;
     9import java.io.Writer;
     10import java.util.ArrayList;
     11import java.util.Arrays;
    812import java.util.List;
     13
     14import net.sf.basedb.core.BaseException;
     15import net.sf.basedb.core.plugin.Response;
    916
    1017import org.apache.log4j.Logger;
     
    1219import org.embl.cg.bloader.validation.base1.Tab2MAGEExperimentValidation;
    1320
    14 import uk.ac.ebi.nugo.common.NutribasePluginException;
    1521import uk.ac.ebi.nugo.plugins.tab2mageimport.io.Base2Tab2MageFileReader;
    1622/**
     
    3238   * @return  True if all values are correct. False if one or more are incorrect.
    3339   */
    34   public boolean validate()
     40  public boolean validate(Writer writer, Response response)
    3541  {
    3642    log.info("\n+++ Begin experiment validation +++\n");
    37     boolean valid = false;
     43    boolean valid = true;
     44    List<String> errors = new ArrayList<String>();
    3845    //if(!super.validate()) return false; was causing the validation to fail so commented out.
    3946    try
     
    4249      List<String> foundMandatoryFields= reader.getFoundExprMandatoryFields();
    4350      List<String> mandatoryFields = experiment.getMandatoryExpFields();
    44       for (String tag : foundMandatoryFields)
     51      for (String tag : mandatoryFields)
    4552      {
    46         if (!mandatoryFields.contains(tag.trim())) // if a mandatory field is not found throw an exception
     53        if (!foundMandatoryFields.contains(tag.trim())) // if a mandatory field is not found throw an exception
    4754        {
    48           log.error("Mandatory tag:" + tag + " is not present in the tab2mage experiment section. Must be provided to proceed");
    49           throw new NutribasePluginException("Mandatory tag:" + tag + " is not present in the tab2mage experiment section. Must be provided to proceed");
     55          log.error("Mandatory tag: [" + tag + "] is not present in the tab2mage experiment section. Must be provided to proceed");
     56          errors.add("Mandatory tag: [" + tag + "] is not present in the tab2mage experiment section. Must be provided to proceed");
    5057        }
    5158      }
    52       valid= true;
     59      if (!errors.isEmpty())
     60      {
     61        writer.write("\n+++ Experiment validation errors +++ \n");
     62        for (String error : errors)
     63        {
     64          writer.write(error+"\n");
     65        }
     66        writer.write("\n+++ End of experiment validation errors +++ \n");
     67        writer.write("\n");
     68        valid= false;
     69      }
    5370    }
    5471    catch(Throwable tr)
    5572    {
    5673      valid= false;
     74      response.setError("IMPORT FAILS: experiment cannot be validated" ,Arrays.asList(tr));
     75      try
     76      {
     77        writer.write("IMPORT FAILS: experiment cannot be validated" + tr.getMessage());
     78      }
     79      catch(IOException ioe)
     80      {
     81        throw new BaseException(ioe.getMessage());
     82      }
    5783    }
    58    
     84    finally
     85    {
     86      if (!errors.isEmpty()) errors.clear();
     87    }
    5988    return valid;
    6089  }
    6190 
     91  /**
     92    create a new Tab2MageExperimentValidation
     93   * @param fileReader, the file reader object
     94   */
    6295  public Tab2MageExperimentValidation (Base2Tab2MageFileReader fileReader)
    6396  {
  • trunk/uk/ac/ebi/Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/tab2mageimport/validation/Tab2MageHybridizationValidation.java

    r417 r459  
    77
    88
     9import java.io.Writer;
    910import java.util.ArrayList;
    1011import java.util.HashMap;
    1112import java.util.HashSet;
     13import java.util.LinkedList;
    1214import java.util.List;
    1315import java.util.Map;
     
    1820import net.sf.basedb.core.Directory;
    1921import net.sf.basedb.core.File;
    20 import net.sf.basedb.core.Include;
    21 import net.sf.basedb.core.ItemQuery;
    22 import net.sf.basedb.core.ItemResultList;
    2322import net.sf.basedb.core.Path;
    2423import net.sf.basedb.core.SessionControl;
     
    2928import org.embl.cg.bloader.exceptions.ValidationException;
    3029import org.embl.cg.bloader.models.Tab2MAGEHybridization;
    31 import org.embl.cg.bloader.models.Tab2MAGEHybridizationLine;
    3230import org.embl.cg.bloader.utils.Constants;
    3331import org.embl.cg.bloader.validation.HybridizationValidation;
    3432
     33import uk.ac.ebi.nugo.common.Helper;
     34import uk.ac.ebi.nugo.common.NutribasePluginException;
    3535import uk.ac.ebi.nugo.common.Tab2MageConstants;
    3636import uk.ac.ebi.nugo.plugins.tab2mageimport.ExperimentPlatformsLibrary;
     
    3838
    3939/**
    40   This  class validates the experiment section of a tab2mage file and also relies on the validation interface by 
     40  This  class validates the Hybridization section of a tab2mage file and also implements base1Loader validation interface by 
    4141  Sajoscha Sauer,  and Charles Giradot of EMBL, Heildelberg.
    4242  @author Dominic Oyeniran
    4343  @see org.embl.cg.bloader.validation.PtotocolValidation
    44   NOTE: Tab2MageConstants class was used at some stage because the naming convention in the baseLoader is different in some areas.
     44 
    4545*/
    4646public class Tab2MageHybridizationValidation
     
    6161  protected Path spath;
    6262 
    63   // must be added from the HybridizationValidation interface
    6463  protected String path;
    6564  /**
     
    122121     
    123122   */
    124   public boolean validate() throws Exception
     123  public boolean validate(Writer out) throws Exception
    125124  {
     125    List<String> errors = new LinkedList<String>();
     126    boolean valid = true;
    126127    log.info("\nBEGIN: start validation ........\n");
    127     for(Tab2MAGEHybridization hyb : hybs)
    128     {
    129       // check if the raw data files really exist
    130       log.info("Checking that file exist.......");
    131       if (!checkIfFilesExist(hyb,  spath))
    132       {
    133         return false;
    134       }
    135       log.info("Checking that file has proper type......");
    136       // check if the files have the proper type
    137       if (!checkFileTypes(hyb, platform))
    138       {
    139         return false;
    140       }
    141      
    142       // check if the array design provided is in BASE2 DATABASE, otherwise fail.
    143       if (!checkArrayDesign(hyb))
    144       {
    145         log.error("Array design does not match the ones on Base2. Ensure array design have been created and shared to you.");
    146         return false;
    147       }
    148      
    149       //  check the array designs for equality
    150       String at = "";
    151       if(!at.equals("") && !at.equals(hyb.getArrayInformation().get(Constants.ARRAY_ACCESSION).toString())) //to change to base2 contants
    152       {
    153           log.error("The array designs (ArrayTypes) must be identical for each hybridization in a batch upload");
    154           return false;
    155       }
    156       if(at.equals(""))
    157           at = hyb.getArrayInformation().get(Constants.ARRAY_ACCESSION).toString(); // to change to base2 contants
    158     }
    159     return true;
     128    try
     129    {
     130      for(Tab2MAGEHybridization hyb : hybs)
     131      {
     132        log.info("Checking that file exist.......");
     133        List<String> fileErrors= checkIfFilesExist(hyb,  spath);
     134        if (!fileErrors.isEmpty()) errors.addAll(fileErrors);
     135       
     136        log.info("Checking that file has proper type......");
     137        List<String> fileTypesErrors = checkFileTypes(hyb, platform);
     138        if (!fileTypesErrors.isEmpty())errors.addAll(fileTypesErrors);
     139       
     140        // check if the array design provided is in BASE2 DATABASE, otherwise fail.
     141        if (!checkArrayDesign(hyb))
     142        {
     143          errors.add("Array Design DOES NOT exist in BASE2 or NOT-SHARED to you. Contact your base administrator");
     144          //return false;
     145        }
     146      }
     147      if (!errors.isEmpty())
     148      {
     149        out.write("\n+++ Hybridization validation errors +++ \n");
     150        for (String error : errors)
     151        {
     152          out.write(error+"\n");
     153        }
     154        out.write("\n+++ End of hybridization validation errors +++ \n");
     155        out.write("\n");
     156        valid= false;
     157      }
     158    }
     159    catch(Throwable tr)
     160    {
     161      valid  = false;
     162      throw new NutribasePluginException(tr.getMessage());
     163    }
     164    finally
     165    {
     166      if (!errors.isEmpty()) errors.clear();
     167    }
     168    return valid;
    160169  }
    161170 
     
    163172      Validate the hybridization headers from the Tab2MAGE file.
    164173      This code MUST be modified for MAGE-TAB implementation.
    165       [TODO] convert all headers to lowercase, to facilitate matching of hyb section header to Tab2mageConstants/Spec
    166174      @param header an <code>ArrayList</code> with all headers from the Tab2MAGE file
    167175      @return true if the headers are valid, false otherwise
    168176   */
    169   public static boolean validateHeader(ArrayList<String> header)
    170   {
    171     //[TODO] convert all headers to lowercase, to facilitate matching of hyb section header to Tab2mageConstants/Spec
     177  public static boolean validateHeader(ArrayList<String> header, Writer writer)
     178  {
    172179    //header= header2LowerCase(header);
     180    List<String> headerErrors = new LinkedList<String>();
     181    boolean valid = true, foundBioMat= false, foundFactVal= false;
     182    try
     183    {
     184      if(!header.contains(Tab2MageConstants.hybridization.getName()))
     185      {
     186        log.error("The column \"" + Tab2MageConstants.hybridization.getName() + "\" wasn't found!");
     187        headerErrors.add("The column \"" + Tab2MageConstants.hybridization.getName() + "\" wasn't found!");
     188      }
     189     
     190      if (!header.contains(Tab2MageConstants.labeledextract.getName()))
     191      {
     192        log.error("The column \"" + Tab2MageConstants.labeledextract.getName() + "\" wasn't found!");
     193        headerErrors.add("The column \"" + Tab2MageConstants.labeledextract.getName() + "\" wasn't found!");
     194      }
     195       
     196      if (!header.contains(Tab2MageConstants.dye.getName()))
     197      {
     198        log.error("The column \"" + Tab2MageConstants.dye.getName() + "\" wasn't found!");
     199        headerErrors.add("The column \"" + Tab2MageConstants.dye.getName() + "\" wasn't found!");
     200      }
     201     
     202      if (!header.contains(Tab2MageConstants.extract.getName()))
     203      {
     204        log.error("The column \"" + Tab2MageConstants.extract.getName()+ "\" wasn't found!");
     205        headerErrors.add("The column \"" + Tab2MageConstants.extract.getName()+ "\" wasn't found!");
     206      }
     207     
     208      if (!header.contains(Tab2MageConstants.sample.getName()))
     209      {
     210        log.error("The column \"" + Tab2MageConstants.sample.getName() + "\" wasn't found!");
     211        headerErrors.add("The column \"" + Tab2MageConstants.sample.getName() + "\" wasn't found!");
     212      }
    173213   
    174     boolean valid = true, foundBioMat= false, foundFactVal= false;
    175     if(!header.contains(Tab2MageConstants.hybridization.getName()))
    176     {
    177       log.error("The column \"" + Tab2MageConstants.hybridization.getName() + " wasn't found!");
    178       valid = false;
    179     }
     214      if (!header.contains(Tab2MageConstants.biosource.getName()))
     215      {
     216        log.error("The column \"" + Tab2MageConstants.biosource.getName() + "\" wasn't found!");
     217        headerErrors.add("The column \"" + Tab2MageConstants.biosource.getName() + "\" wasn't found!");
     218      }
     219     
     220      if (!header.contains(Tab2MageConstants.array_accession.getName()))
     221      {
     222        log.error("The column \"" + Tab2MageConstants.array_accession.getName() + "\" wasn't found!");
     223        headerErrors.add("The column \"" + Tab2MageConstants.array_accession.getName() + "\" wasn't found!");
     224      }
     225     
     226      cont:
     227      for (String  head : header)
     228      {
     229        // check that at least one BioMaterialCharacrteristic[AT] header is present
     230        if (head.startsWith(Tab2MageConstants.bio_mat_charact.getName() + "["))
     231        {
     232          foundBioMat = true;
     233          continue cont;
     234        }
     235        // check that at least one FactorValue[AT] header is present
     236        if (head.startsWith(Tab2MageConstants.factor_value.getName()+ "["))
     237        {
     238          foundFactVal=true;
     239          continue cont;
     240        }
     241      }
    180242   
    181     if (!header.contains(Tab2MageConstants.labeledextract.getName()))
    182     {
    183       log.error("The column \"" + Tab2MageConstants.labeledextract.getName() + " wasn't found!");
    184       valid = false;
    185     }
    186     /*
    187       we decided to make our implementation a bit flexible to accommodate non provision of labeledextract material
    188       Not mandatory in tab2mage specification
    189      */
    190     //else
    191     //{
    192     //  if (!header.contains(Tab2MAGEHybridization.LABELEDEXTRACTMATERIAL))
    193     //  {
    194     //    log.error("The column \"" + Tab2MAGEHybridization.LABELEDEXTRACTMATERIAL + " wasn't found!");
    195     //    valid = false;
    196     //  }
    197     //}
     243      if (!foundBioMat)
     244      {
     245        log.error("At least one BioMaterial Characteristics should be provided!");
     246        headerErrors.add("At least one BioMaterial Characteristics should be provided!");
     247      }
     248     
     249      if (!foundFactVal)
     250      {
     251        log.error("At least one Experimental Factor should be provided!");
     252        headerErrors.add("At least one Experimental Factor should be provided!");
     253      }
     254       
     255      allowedProtocol =getAllowedProtocols(); //get all the allowed protocols for the tab2mage specification
     256      boolean tmpValid1 = false, tmpValid2 = false, tmpValid3 = false;
     257     
     258      for(String head : header)
     259      {
     260        if(head.startsWith(Tab2MageConstants.protocol.getName()+ "["))
     261        {
     262          String tmp = head.substring(Tab2MageConstants.protocol.getName().length()+1, head.length()-1);
     263          String extprotype= Tab2MageConstants.protocol_extraction.getName().substring(Tab2MageConstants.protocol.getName().length()+1, Tab2MageConstants.protocol_extraction.getName().length()-1);
     264          String labprotype= Tab2MageConstants.protocol_labeling.getName().substring(Tab2MageConstants.protocol.getName().length()+1, Tab2MageConstants.protocol_labeling.getName().length()-1);
     265          if(tmp.toUpperCase().equals(Tab2MageConstants.nucleicacidextraction.getName().toUpperCase()) || tmp.toUpperCase().equals(extprotype.toUpperCase())) //extraction protocol
     266            tmpValid1 = true;
     267         
     268          if(tmp.toUpperCase().equals(Tab2MageConstants.hybridization.getName().toUpperCase())) //hybridization protocol
     269            tmpValid2 = true;
     270          if(tmp.toUpperCase().equals(labprotype.toUpperCase())) //labelling protocol
     271            tmpValid3 = true;
     272         
     273          // check that the protocol formats are valid with the tab2mage specification, report an error otherwise
     274          if (!allowedProtocol.contains(head.toUpperCase()))
     275          {
     276            log.error("The protocol column \"" + head + "\" is not a valid protocol format allowed in the tab2mage specification!");
     277            headerErrors.add("The protocol column \"" + head + "\" is not a valid protocol format allowed in the tab2mage specification!");
     278          }
     279        }
     280       
     281      }
     282      if(!tmpValid1 || !tmpValid2 || !tmpValid3){
     283        log.error("The protocol columns of the Tab2MAGE hybridization section aren't valid!");
     284        headerErrors.add("The protocol columns of the Tab2MAGE hybridization section aren't valid!");
     285      }
    198286   
    199     if (!header.contains(Tab2MageConstants.dye.getName()))
    200     {
    201       log.error("The column \"" + Tab2MageConstants.dye.getName() + " wasn't found!");
    202       valid = false;
    203     }
    204    
    205     if (!header.contains(Tab2MageConstants.extract.getName()))
    206     {
    207       log.error("The column \"" + Tab2MageConstants.extract.getName()+ " wasn't found!");
    208       valid = false;
    209     }
    210     /*
    211       we decided to make our implementation a bit flexible to accommodate non provision of extract material.
    212       Also not mandatory in tab2mage specification. Not supported by base2 as well
    213      */
    214     //else
    215     //{
    216     //  if (!header.contains(Tab2MAGEHybridization.EXTRACTMATERIAL))
    217     //  {
    218     //    log.error("The column \"" + Tab2MAGEHybridization.EXTRACTMATERIAL + " wasn't found!");
    219     //    valid = false;
    220     //  }
    221     //}
    222    
    223     if (!header.contains(Tab2MageConstants.sample.getName()))
    224     {
    225       log.error("The column \"" + Tab2MageConstants.sample.getName() + " wasn't found!");
    226       valid = false;
    227     }
    228     /*
    229       we decided to make our implementation a bit flexible to accommodate non provision of sample material
    230       Not mandatory in tab2mage specification
    231      */
    232     //else
    233     //{
    234     //  if (!header.contains(Tab2MAGEHybridization.SAMPLEMATERIAL))
    235     //  {
    236     //    log.error("The column \"" + Tab2MAGEHybridization.SAMPLEMATERIAL + " wasn't found!");
    237     //    valid = false;
    238     //  }
    239     //}
    240  
    241     if (!header.contains(Tab2MageConstants.biosource.getName()))
    242     {
    243       log.error("The column \"" + Tab2MageConstants.biosource.getName() + " wasn't found!");
    244       valid = false;
    245     }
    246    
    247     if (!header.contains(Tab2MageConstants.array_accession.getName()))
    248     {
    249       log.error("The column \"" + Tab2MageConstants.array_accession.getName() + " wasn't found!");
    250       valid = false;
    251     }
    252    
    253     /*
    254       we decided to make our implmentation a bit flexible to accommodate non provision of array serial
    255      */
    256     //if (!header.contains(Tab2MAGEHybridization.ARRAY + "[" + Constants.ARRAY_SERIAL + "]")){
    257     //  log.error("The column \"" + Tab2MAGEHybridization.ARRAY + "[" + Constants.ARRAY_SERIAL + "]" + " wasn't found!");
    258     //  valid = false;
    259     //}
    260    
    261     /*
    262       check for biomaterial characteristics - simply biosource annotation in base2.
    263       And exisitence of experimental factors
    264       NOTE: "Characteristics" would be used for MAGE-TAB implementation
    265      */
    266  
    267    
    268     cont:
    269     for (String  head : header)
    270     {
    271       // check that at least one BioMaterialCharacrteristic[AT] header is present
    272       if (head.startsWith(Tab2MageConstants.bio_mat_charact.getName() + "["))
    273       {
    274         foundBioMat = true;
    275         continue cont;
    276       }
    277       // check that at least one FactorValue[AT] header is present
    278       if (head.startsWith(Tab2MageConstants.factor_value.getName()+ "["))
    279       {
    280         foundFactVal=true;
    281         continue cont;
    282       }
    283     }
    284  
    285     if (!foundBioMat)
    286     {
    287       log.error("At least one BioMaterial Characteristics should be provided!");
    288       valid = false;
    289     }
    290    
    291     if (!foundFactVal)
    292     {
    293       log.error("At least one Experimental Factor should be provided!");
    294       valid = false;
    295     }
    296      
    297     allowedProtocol =getAllowedProtocols(); //get all the allowed protocols for the tab2mage specification
    298     boolean tmpValid1 = false, tmpValid2 = false, tmpValid3 = false;
    299    
    300     for(String head : header)
    301     {
    302       if(head.startsWith(Tab2MAGEHybridization.PROTOCOL + "["))
    303       {
    304         String tmp = head.substring(Tab2MAGEHybridization.PROTOCOL.length()+1, head.length()-1);
    305         String protype= Tab2MageConstants.protocol_extraction.getName().substring(Tab2MAGEHybridization.PROTOCOL.length()+1, Tab2MageConstants.protocol_extraction.getName().length()-1);
    306         if(tmp.toUpperCase().equals(Constants.PROTOCOL_EXTRACTION_FILE) || tmp.toUpperCase().equals(protype.toUpperCase())) //extraction protoocol
    307           tmpValid1 = true;
     287      for (String head : header)
     288      {
     289        if(head.startsWith(Tab2MageConstants.parameter.getName()+ "["))
     290        {
     291          //obtain the [AT] of the header Parameter[AT]
     292          String tmp = head.substring(Tab2MageConstants.parameter.getName().length()+1, head.length()-1);
     293          if (!Tab2MageProtocolValidation.getProtocolParameters().contains(tmp))
     294          {
     295            log.error("The parameter " + head + " does not match parameters specified in the protocol section!");
     296            headerErrors.add("The parameter: [" + head + "] does not match parameters specified in the protocol section!");
     297          }
     298        }
    308299       
    309         if(tmp.toUpperCase().equals(Constants.PROTOCOL_HYBRIDIZATION_FILE)) //hybridization protocol
    310           tmpValid2 = true;
    311         if(tmp.toUpperCase().equals(Constants.PROTOCOL_LABELING_FILE)) //labelling protocol
    312           tmpValid3 = true;
    313        
    314         // check that the protocol formats are valid with the tab2mage specification, report an error otherwise
    315         if (!allowedProtocol.contains(head.toUpperCase()))
    316         {
    317           log.error("The protocol column \"" + head + " is not a valid protocol format allowed in the tab2mage specification!");
    318           valid = false;
    319         }
    320       }
    321      
    322     }
    323     if(!tmpValid1 || !tmpValid2 || !tmpValid3){
    324       log.error("The protocol columns of the Tab2MAGE hybridization section aren't valid!");
    325       valid = false;
    326     }
    327  
    328     for (String head : header)
    329     {
    330       if(head.startsWith(Tab2MageConstants.parameter.getName()+ "["))
    331       {
    332         //obtain the [AT] of the header Parameter[AT]
    333         String tmp = head.substring(Tab2MageConstants.parameter.getName().length()+1, head.length()-1);
    334         if (!Tab2MageProtocolValidation.getProtocolParameters().contains(tmp))
    335         {
    336           log.error("The parameter " + head + " does not match parameters specified in the protocol section!");
    337           valid = false;
    338         }
    339       }
    340      
    341       if (head.startsWith(Tab2MageConstants.bio_mat_charact.getName() + "["))
    342       {
    343         //put all biomaterial xteristics header in a list for future calls  from the Tab2MageImportValidatorUtils class
    344         bioMatHeaderList.add(head);
    345       }
    346     }
    347    
    348     return valid;
    349   }
    350  
    351   /**
    352    * Validate a single Hybridization line.
    353    *
    354    * @param line the <code>Tab2MAGEHybridizationLine</code> object to validat
    355    * @return  true if the line is valid, false otherwise
    356    */
    357   public static boolean validateHybLine(Tab2MAGEHybridizationLine line){
    358     boolean valid = true;
    359     if(line.getHybridization() ==  null || line.getHybridization().equals("")){
    360       log.error("No value for \"" + Tab2MAGEHybridization.HYBRIDIZATION + " available!");
    361       valid = false;
     300        if (head.startsWith(Tab2MageConstants.bio_mat_charact.getName() + "["))
     301        {
     302          //put all biomaterial xteristics header in a list for future calls  from the Tab2MageImportValidatorUtils class
     303          bioMatHeaderList.add(head);
     304        }
     305      }
     306      if (!headerErrors.isEmpty())
     307      {
     308        writer.write("\n+++ Hybridization header validation errors +++ \n");
     309        for (String error : headerErrors)
     310        {
     311          writer.write(error+"\n");
     312        }
     313        writer.write("\n+++ End of hybridization header validation errors +++ \n");
     314        writer.write("\n");
     315        valid= false;
     316      }
     317    }
     318    catch(Throwable tr)
     319    {
     320      valid= false;
     321    }
     322    finally
     323    {
     324      if (!headerErrors.isEmpty()) headerErrors.clear();
    362325    }
    363326    return valid;
     
    375338      @throws ValidationException
    376339   */
    377   private boolean checkIfFilesExist(Tab2MAGEHybridization hyb, Path path) throws TAB2MAGEException, ValidationException
     340  private List<String> checkIfFilesExist(Tab2MAGEHybridization hyb, Path path) throws TAB2MAGEException, ValidationException
    378341  {
    379342    DbControl dc=null;
     343    List<String> errs = new LinkedList<String>();
    380344    try
    381345    {
     
    387351        if(!fileExist)
    388352        {
    389           log.error("The raw data file " + hyb.getFileRaw() + " doesn't exist or couldn't be accessed!");
    390           return false;
    391         }
    392        
     353          log.error("The raw data file [" + hyb.getFileRaw() + "] doesn't exist or couldn't be accessed!");
     354          errs.add("The raw data file [" + hyb.getFileRaw() + "] doesn't exist or couldn't be accessed!");
     355        }
    393356      }
    394357     
     
    397360        if(!File.exists(dc, dir, hyb.getFileImage()))
    398361        {
    399           log.error("The image file " + hyb.getFileImage() + " doesn't exist or couldn't be accessed!");
    400           return false;
    401         }
    402       }
    403     /*
    404       Uncomment to ADD support for cdf and chp file
    405      */
    406       //System.out.println("cheking the cdf file.....");
    407       //if(hyb.getFileCDF() != null)
    408       //{
    409       //  if(!File.exists(dc, dir, hyb.getFileCDF()))
    410       //  {
    411       //    log.error("The cdf file " + hyb.getFileCDF() + " doesn't exist or couldn't be accessed!");
    412       //    return false;
    413       //  }
    414       //}
    415       //System.out.println("cheking the chp file.....");
    416       //if(hyb.getFileCHP() != null && !hyb.getFileCHP().equals("NA"))
    417       //{
    418       //  if (!File.exists(dc, dir, hyb.getFileCHP()))
    419       //  {
    420       //    log.error("The chp file " + hyb.getFileCHP() + " doesn't exist or couldn't be accessed!");
    421       //    return false;
    422       //  }
    423       //}
    424      
    425       /*
    426         code to be used for support of file[normalised], file[transformed] not supported yet in Base2
    427         hyb.getFileTransformed and hyb.getFileNormalised should be added to Tab2MAGEHybridization Class.
    428      
    429      
    430       //if(hyb.getFileTransformed() != null )
    431       //{
    432       //  if (!File.exists(dc, directory, hyb.getFileTransformed()))
    433       //  {
    434       //    log.error("The transformed file " + hyb.getFileTransformed() + " doesn't exist or couldn't be accessed!");
    435       //    return false;
    436       //  }
    437       //}
    438      
    439       //if(hyb.getFileNormalised() != null )
    440       //{
    441       //  if (!File.exists(dc, directory, hyb.getFileNormalised()))
    442       //  {
    443       //    log.error("The normalised file " + hyb.getFileNormalised() + " doesn't exist or couldn't be accessed!");
    444       //    return false;
    445       //  }
    446       //}
    447      
    448       END OF THE SECTION TO ADD FUNCTIONALITY ADD-ONS.
    449      */
     362          log.error("The image file [" + hyb.getFileImage() + "] doesn't exist or couldn't be accessed!");
     363          errs.add("The image file [" + hyb.getFileImage() + "] doesn't exist or couldn't be accessed!");
     364        }
     365      }
    450366    }
    451367    catch (Throwable tr)
    452368    {
    453369      tr.getMessage();
    454       log.error("Files declared in the ctab2mage files are not accessible");
    455       dc.close();
     370      log.error("Files declared in the tab2mage files are not accessible");
     371      errs.add("Files declared in the tab2mage files are not accessible in BASE");
    456372    }
    457373    finally
     
    459375      if (dc!=null) dc.close();
    460376    }
    461     return true;
    462   }
    463  
    464   private boolean checkFileTypes(Tab2MAGEHybridization hyb, String platform) throws TAB2MAGEException{
     377    return errs;
     378  }
     379 
     380  private List<String> checkFileTypes(Tab2MAGEHybridization hyb, String platform) throws TAB2MAGEException{
    465381    String file = "", ext = "";
     382    List<String> er= new LinkedList<String>();
    466383    if(platform.equalsIgnoreCase(ExperimentPlatformsLibrary.CEL.getPlatformName()) )
    467384    {
     
    472389      if(!ext.equalsIgnoreCase(ExperimentPlatformsLibrary.CEL.getFileExtension()))
    473390      {
    474         log.error("The raw data file from the hybridization " + hyb.getName() + " has not the proper type.");
    475         return false;
     391        log.error("The raw data file from the hybridization [" + hyb.getName() + "] has not the proper type.");
     392        er.add("The raw data file from the hybridization [" + hyb.getName() + "] has not the proper type.");
    476393      }
    477394      file = hyb.getFileCHP();
     
    483400        if(!ext.equalsIgnoreCase(Constants.FILE_EXTENSION_GCOSCHP)) // may need to change it to ref ExperimentPlatforms Enum for BASE2 implementation
    484401        {
    485           log.error("The CHP file from the hybridization " + hyb.getName() + " has not the proper type.");
    486           return false;
     402          log.error("The CHP file from the hybridization [" + hyb.getName() + "] has not the proper type.");
     403          er.add("The CHP file from the hybridization [" + hyb.getName() + "] has not the proper type.");
    487404        }
    488405      }
     
    494411      if(!ext.equalsIgnoreCase(ExperimentPlatformsLibrary.GPR.getFileExtension()))
    495412      {
    496         log.error("The GPR file from the hybridization " + hyb.getName() + " has not the proper type.");
    497         return false;
    498       }
    499     }
    500    
    501     //add code to check other raw data file here, do extend the experiment platform enum class too
    502    
    503     return true;
    504   }
    505   /**
    506    
    507       @return
     413        log.error("The GPR file from the hybridization [" + hyb.getName() + "] has not the proper type.");
     414        er.add("The GPR file from the hybridization [" + hyb.getName() + "] has not the proper type.");
     415      }
     416    }
     417    return er;
     418  }
     419  /**
     420    check that the array design has been created and accessible in BASE
     421      @param hyb,  the hybridization
     422      @return TRUE if available and FALSE otherwise
    508423   */
    509424  @SuppressWarnings("unchecked")
     
    525440              }
    526441          }
    527       ItemQuery<ArrayDesign> arrayDesignQuery = ArrayDesign.getQuery();
    528       arrayDesignQuery.include(Include.MINE, Include.IN_PROJECT, Include.SHARED, Include.NOT_REMOVED);
    529       ItemResultList<ArrayDesign> arrayDesigns = arrayDesignQuery.list(dc);
    530      
    531       for (ArrayDesign ad : arrayDesigns)
    532       {
    533         if (ad.getName().trim().equalsIgnoreCase(accession.trim())) // compare the tab2mage file array design with the name of existing array designs in BASE2
    534         {
    535           found = true;
    536           break;
    537         }
    538       }
     442      // get the array design
     443        ArrayDesign ad= Helper.getArrayDesign(accession, dc);
     444        if (ad!=null)
     445        {
     446          found =true;
     447        }
    539448    }
    540449    catch(Exception e)
     
    550459  }
    551460 
     461  /**
     462    gets the list of allowed protocol for the tab2mage specification
     463      @return
     464   */
    552465  private static Set<String> getAllowedProtocols()
    553466  {
     
    608521  }
    609522 
    610  
    611523  public void setAllowSlideCreation(boolean allowSlideCreation)
    612524  {
     
    659571    return this.path;
    660572  }
     573 
     574  public boolean validate() throws Exception
     575  {
     576    return false;
     577  }
    661578}
Note: See TracChangeset for help on using the changeset viewer.