Changeset 449


Ignore:
Timestamp:
Oct 30, 2007, 3:54:31 PM (14 years ago)
Author:
dominic
Message:

added tab2mage export version 2

Location:
trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo
Files:
5 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo/common/Helper.java

    r423 r449  
    1111import net.sf.basedb.core.ArrayDesign;
    1212import net.sf.basedb.core.ArraySlide;
     13import net.sf.basedb.core.BaseException;
    1314import net.sf.basedb.core.BioSource;
    1415import net.sf.basedb.core.DbControl;
     16import net.sf.basedb.core.Directory;
    1517import net.sf.basedb.core.Extract;
    1618import net.sf.basedb.core.File;
     
    2325import net.sf.basedb.core.Path;
    2426import net.sf.basedb.core.Sample;
     27import net.sf.basedb.core.SessionControl;
    2528import net.sf.basedb.core.Type;
    2629import net.sf.basedb.core.User;
     
    3134/**
    3235  A plugin utils class for the tab2mage export and export. 
    33   [TODO] This class may be merged to other utils in the main base 2 source code
    34   @author Dominic Oyeniran
     36  @author Dominic Oyeniran
    3537  @version 1.0
    3638*/
     
    6870 
    6971   
     72   public static File processFilePath (User user,boolean overwrite, SessionControl sc, String pathString)
     73   {
     74    DbControl dc= null;
     75    File file =null;
     76     try
     77     {
     78      dc= sc.newDbControl();
     79      if (pathString.startsWith("~/"))
     80      {
     81       pathString = "~"+user.getLogin()+pathString.substring(1);
     82      }
     83      Path path = new Path(pathString, Path.Type.FILE);   
     84     
     85      file= File.getByPath(dc, path, true);
     86      file.setMimeType("text/plain"); //set the type of the file
     87      if (file.isInDatabase() && !overwrite && !file.isRemoved())
     88      {
     89        throw new ItemAlreadyExistsException("File[path="+path+"]");     
     90      }
     91      else if(!file.isInDatabase())
     92      {
     93        dc.saveItem(file);
     94      }
     95      dc.commit();
     96    }
     97    catch(Exception e)
     98    {
     99      dc.close();
     100    }
     101    finally
     102    {
     103      if (dc!=null)
     104        dc.close();
     105    }
     106     
     107    return file;
     108   }
    70109  /**
    71110    Displays the content of the map. Helps to check that the content displayed is correct.
     
    109148    of a tab2mage file
    110149    @param atName , annotation type name
    111     @return annotationTypes,  <code>AnnotationType</code>
     150    @return annotationType,  <code>AnnotationType</code>
    112151   */
    113152  public static AnnotationType getAnnotationTypeByName(String atName, DbControl dc)
     
    211250    return  ar;
    212251  }
    213   /**
    214     writes a string to standard output
    215       @param o
    216    */
    217   public static void write(String o)
    218   {
    219     System.out.println("&& DEBUG : "+o);
    220   }
    221  
     252
    222253 
    223254  /**
     
    311342      return le;   
    312343  }
     344 
     345
     346  /**
     347    gets the currently looged in user default directory
     348      @param sc, the seesion control
     349      @return path of the user directory as a string object
     350   */
     351  public static String getUserDefaultDirectory( SessionControl sc)
     352  {
     353    DbControl  dc = sc.newDbControl();
     354    String p ="";
     355    try
     356    {
     357      User user = User.getById(dc, sc.getLoggedInUserId());
     358      Directory dir= user.getHomeDirectory();
     359      Path path = dir.getPath();
     360      p=path.toString();
     361    }
     362    catch(Exception e)
     363    {
     364      new BaseException(e.getMessage());
     365    }
     366    finally
     367    {
     368      if (dc!=null) dc.close();
     369    }
     370    return p;
     371  }
    313372}
  • trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo/common/Tab2MageConstants.java

    r396 r449  
    1 /**
    2  *
    3  */
     1/* $Id: Tab2MageConstants.java 2006-08-08 dominic $
     2
     3  This file is for NutriBASE - Nutrigenomics BioArray Software Environment.
     4  A customisation of the BASE SOFTWARE.
     5  Developed at the EBI , Cambridge.
     6  Author: Dominic Oyeniran: oyeniran@ebi.ac.uk
     7*/
    48package uk.ac.ebi.nugo.common;
    59
     
    1317  @author Dominic Oyeniran
    1418  @version 1.0
    15   @base.modified $Date
    1619 */
    1720public enum Tab2MageConstants
     
    193196    The parameter header
    194197   */
    195   parameter(49, "Parameter");
     198  parameter(49, "Parameter"),
     199 
     200  /**
     201    The protocol header
     202   */
     203  protocol(50, "Protocol"),
     204 
     205  /**
     206    nucleic acid extraction
     207   */
     208  nucleicacidextraction(51, "Nucleic_Acid_Extraction");
     209  ;
    196210 
    197211  /**
  • trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo/common/ValueFormatter.java

    r423 r449  
    1616/**
    1717  A utility class containing static methods for formatting parameter values.
    18   [TODO] This class may be merged to util class in the main base 2 source code
    1918  @author Dominic Oyeniran
    2019  @email oyeniran@ebi.ac.uk
  • trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo/common/ZipUnpacker.java

    r423 r449  
    1313import java.util.zip.ZipInputStream;
    1414
     15import net.sf.basedb.core.DatabaseException;
    1516import net.sf.basedb.core.DbControl;
    1617import net.sf.basedb.core.Directory;
     
    3132/**
    3233    This class unpacks zip file provided by users into the base file structure
    33     Note: Parts of the codes are authored by Misha Bayer - email: sbrn@scri.ac.uk,
     34    Note: Parts of the codes were authored by Misha Bayer - email: sbrn@scri.ac.uk,
    3435    @author Dominic Oyeniran
    3536    @email oyeniran@ebi.ac.uk
    36     @see BatchDataImport.java and BatchLoader plugin developed by Misha Bayer.
    37    
    3837   
    3938 */
     
    7574      {
    7675        createSubDirectory( file, user);
    77         // now call the mathod to unpack the zip files
     76        // now call the method to unpack the zip files
    7877        PluginDefinition zipFilePlugin = PluginDefinition.getByClassName(dc, "net.sf.basedb.plugins.ZipFileUnpacker");
    7978        FileUnpacker unpacker = zipFilePlugin.newInstance(net.sf.basedb.plugins.ZipFileUnpacker.class, null, dc.getSessionControl(), null, null);
     
    115114    //unlimited storage (e.g. for user root) will return -1
    116115    long quotaValue = quota.getQuotaValue(totalQuotaType, Location.PRIMARY);   
    117     //System.out.println("the quota value of the user: " + user.getName()+ " is: "+quotaValue );
     116    log.info("the quota value of the user: " + user.getName()+ " is: "+quotaValue );
    118117    long currentDiskUsage = user.getDiskUsage(totalQuotaType, Location.PRIMARY);
    119118      //check whether remaining disk space and zip file size are compatible
    120119    long remainingSpace = quotaValue - currentDiskUsage;
    121     //System.out.println("the remaining space for user: " + user.getName()+ " is: "+remainingSpace );
     120    log.info("the remaining space for user: " + user.getName()+ " is: "+remainingSpace );
    122121    if(remainingSpace < zipFileSize && quotaValue!=-1)
    123122    {
     
    172171      //get the parent directory
    173172      Directory zipFileDir = zipFile.getDirectory();
    174       //System.out.println("zipFile is located in dir " + zipFile.getPath());
     173      log.info("zipFile is located in dir " + zipFile.getPath());
    175174      Directory d = Directory.getById(dc, zipFileDir.getId());
    176175      Directory subDir = d.newSubDirectory();
    177       String fileName = zipFile.getName();
    178         String fileNameNoExt = fileName.substring(0, fileName.indexOf("."));
    179         subDir.setName(fileNameNoExt);
    180         subDir.setDescription("Unzippped directory created at "+new Date());
    181         dc.saveItem(subDir);
    182         dc.commit();
    183         //unzippedFilesDirectory = subDir;
     176      if (subDir.isInDatabase())
     177      {
     178        throw new DatabaseException("The Directory ["+ subDir.getPath().toString()+ "] already exists");
     179      }
     180      else if (!subDir.isInDatabase())
     181      {
     182        String fileName = zipFile.getName();
     183          String fileNameNoExt = fileName.substring(0, fileName.indexOf("."));
     184          subDir.setName(fileNameNoExt);
     185          subDir.setDescription("Unzippped directory created at "+new Date());
     186          dc.saveItem(subDir);
     187      }
     188      dc.commit();
    184189        setUnzippedFilesDirectory(subDir);
    185190    }
    186191    catch (Throwable ex)
    187192    {
    188       log.error("--Create subdirectory FAILED");
     193      log.error("--Create subdirectory FAILED", ex);
    189194    }
    190195    finally
  • trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/Tab2MageExporter.java

    r396 r449  
    1 /* $Id: Tab2MageExporter.java 2006-10-22 dominic $
    2 
    3   Copyright (C) Authors contributing to this file.
     1/* $Id: Tab2MageExporter.java 2007-09-01 dominic $
     2
     3  Copyright (C) 2007 Authors contributing to this file.
    44
    55  This file is for NutriBASE - Nutrigenomics BioArray Software Environment.
     
    2222*/
    2323package uk.ac.ebi.nugo.plugins;
     24
     25
    2426import java.io.Writer;
    2527import java.util.ArrayList;
     
    2830import java.util.Collections;
    2931import java.util.Date;
    30 import java.util.HashMap;
    3132import java.util.LinkedHashSet;
    32 import java.util.LinkedList;
    3333import java.util.List;
    34 import java.util.Map;
    3534import java.util.Set;
    3635import java.util.concurrent.ConcurrentHashMap;
     
    8180import uk.ac.ebi.nugo.common.Helper;
    8281import uk.ac.ebi.nugo.common.Tab2MageConstants;
    83 import uk.ac.ebi.nugo.plugins.ta2mageexport.ExporHelper;
    84 import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageWriter;
    85 
     82import uk.ac.ebi.nugo.plugins.ta2mageexport.ExportHelper;
     83import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageFileWriter;
     84import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageHybridization;
     85import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageHybridizationLine;
     86import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageSubHybLine;
     87import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageValidator;
    8688
    8789/**
    8890  A plugin that exports an experiment in tab2mage specification for submission to ArrayExpress public repository.
    8991  @author Dominic Oyeniran
     92  @email oyeniran@ebi.ac.uk /doyeniran@gmail.com
    9093  @version 1.0
    91   @base.modified $Date$
     94
    9295*/
    93 
    94 public class Tab2MageExporter
    95   extends AbstractPlugin
    96   implements InteractivePlugin
     96public class Tab2MageExporter extends AbstractPlugin
     97                implements InteractivePlugin
    9798{
    9899  private static final About about=
    99100    new AboutImpl
    100101    (
    101         "Tab2MAGE exporter",
    102         "This plugin is used to export an experiment in the tab2mage format specfication. The tab2mage specification " +
     102        "Tab2Mage exporter",
     103        "This plugin is for exporting an experiment in the tab2mage format specfication. The tab2mage specification " +
    103104        "is provided by the microarray informatics team at the EBI, Cambridge. The exported experiment can later be " +
    104         "imported by the corresponding import plugin.",
    105         "2.0",
     105        "imported into BASE by the corresponding import plugin.",
     106        "1.0",
    106107        "2006, NutriBase development team",
    107108        null,
    108109        "oyeniran@ebi.ac.uk",
    109         "http://base.thep.lu.se"
     110        "http://www.ebi.ac.uk/~oyeniran"
    110111    );
    111112 
     
    114115 
    115116  private PluginParameter<String> pathParameter;
    116   private static final String pathDefaultValue="/home/tab2mage.txt";
    117117  private PluginParameter<String> statusPathParameter;
    118   private static final String statusPathDefaultValue="/home/statusreport.txt";
    119118  private PluginParameter<Experiment> experimentParameter;
    120119  private BooleanParameterType overwriteType= new BooleanParameterType(false, false);;
     
    138137          "Save as",
    139138          "Please specify the file name where the plugin should store it's output",
    140           new PathParameterType(Path.Type.FILE, pathDefaultValue, true));
     139          new PathParameterType(Path.Type.FILE, Helper.getUserDefaultDirectory(sc)+"/tab2mage.txt", true));
    141140     
    142141      statusPathParameter = new PluginParameter<String>(
     
    144143          "Save Status File as",
    145144          "Please specify the file name where the plugin should store causes for failure and errors",
    146           new PathParameterType(Path.Type.FILE, statusPathDefaultValue, true));
     145          new PathParameterType(Path.Type.FILE, Helper.getUserDefaultDirectory(sc)+"/statusreport.txt", true));
    147146     
    148147      experimentParameter = new PluginParameter<Experiment>(
     
    259258    return about;
    260259  }
     260  @Override
    261261  public boolean supportsConfigurations()
    262262  {
    263263    return false;
    264264  }
     265  @Override
    265266  public boolean requiresConfiguration()
    266267  {
     
    272273  {
    273274    DbControl dc=null;
    274     Set<Protocol> protocols = new LinkedHashSet<Protocol>(); //to get protocols as they are entered
    275      
     275    //use a linked list to get objects e.g. protocols as they are entered.
     276    Set<Protocol> protocols = new LinkedHashSet<Protocol>();
    276277    Set<String> hybSectionHeader= new LinkedHashSet<String>();
    277278    Set<String>  protocolHybSectionHeader= new LinkedHashSet<String>();
    278     List<String> protocolRefId= new LinkedList<String>();
    279     List<String> hybridizationDataRows=new LinkedList<String>();
    280     List<String> parameterValues= new LinkedList<String>();
    281    
    282     List<Annotation> expFactorValues= new LinkedList<Annotation>();
    283     Map<AnnotationType, Annotation> factorValues= new HashMap<AnnotationType,Annotation>();
    284     List<String> twoColorHybDataRows=new LinkedList<String>();
    285     List<String> twoColorParameterValues=new LinkedList<String>();
    286     List<String> twoColorFirstParameterValues=new LinkedList<String>();
    287     List<String> twoColorProtocolRefId= new LinkedList<String>();
    288     List<String> twoColorFirstProtocolRefId= new LinkedList<String>();
    289    
    290     //pooling data strutures - //NOTE:Pooling is not fully supported at the moment
    291     List<String> poolSampleHeader=new LinkedList<String>();
    292     List<String> poolSampleTail= new LinkedList<String>();
    293     List<String> poolHybDataRows=new LinkedList<String>();
    294        
     279 
    295280    boolean overwrite = false;
    296     boolean twoColorHyb= false;
    297     //pooling attributes
    298     boolean pooledSampleFlag= false;
    299    
     281     
    300282    try
    301283    {
     
    309291      Experiment experiment= (Experiment)job.getValue("experiment");
    310292      experiment= Experiment.getById(dc,experiment.getId());
     293               
    311294      //  check if the logged in user owned the experiment, if not the export exit with a message.
     295     
    312296      if (!(experiment.getOwner().equals(user)))
    313297      {
    314         response.setDone("[EXPORT FAILED: User - "+user.getName()+ " do not own this experiment or have permission to export it].");
     298        response.setError("[EXPORT FAILED: User - "+user.getName()+ " do not own this experiment or have permission to export it].", Arrays.asList(new Throwable()));
    315299        return;
    316300      }
    317301       if (experiment.getExperimentalFactors().list(dc).size()==0)
    318302      {
    319         response.setError("[Export Failed] Experimental factors have not been specified for this experiment].", Arrays.asList(new Throwable()));
     303        response.setError("[EXPORT FAILED: Experimental factors have not been specified for this experiment].", Arrays.asList(new Throwable()));
    320304        return; 
    321  
    322       }
    323       //initialise, count resources used, create concurrentmap for all parameter headers
    324       getResourceCounter(experiment,dc);
     305      }
    325306           
    326       Tab2MageWriter.createFileWriters(file, statusFile);
    327                
    328       // Get all protocols and hybs   
     307      // check that raw bio assays have been added to experiment, otherwise fails
     308     
    329309      ItemQuery<RawBioAssay> rawBioAssaysQuery = experiment.getRawBioAssays();
    330310      rawBioAssaysQuery.order(Orders.asc(Hql.property("name")));
     
    335315        return;
    336316      }
     317     
     318      // create all the required writers for the status file and the export file
     319     
     320      Tab2MageFileWriter.createFileWriters(file, statusFile);
     321     
     322      //initialise, count resources used, create concurrentmap for all parameter and biomaterial headers
     323      Tab2MageValidator validator = new Tab2MageValidator (experiment, sc, response);
     324     
     325      //Tab2MageHybridization hybridization= new Tab2MageHybridization ();
     326     
    337327      for (RawBioAssay rba : rawBioAssays)
    338328      {
    339         initialiseMaps(parameterMap,true);
    340         initialiseMaps(twoColorParameterMap,true);
    341         initialiseMaps(twoColorFirstParameterMap,true);
    342         initialiseMaps(bioXterParameterMap,false);
    343         initialiseMaps(twoColorBioXterParameterMap,false);
    344        
    345         twoColorHybDataRows.add("-done-");
     329        // create the Tab2MageHybridization object
     330        Tab2MageHybridization hybridization= new Tab2MageHybridization ();
     331        // create the Tab2MageHybridizationLine object
     332        Tab2MageHybridizationLine hybRow = new Tab2MageHybridizationLine();
     333       
     334        // set the number of channels for the Hybridization
     335        hybridization.setChannelNumber(validator.getChannelNumber()); // mainly useful during the writing stage
     336                       
    346337        /*
    347           Data files and array information section//
    348          */
     338          Experimental Factor Section
     339        */
     340        AnnotationSet annotationSet =rba.isAnnotated() ? rba.getAnnotationSet() : null;
     341        ItemQuery<AnnotationType> experimentalFactorsQuery= experiment.getExperimentalFactors();
     342        experimentalFactorsQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT, Include.NOT_REMOVED);
     343        ItemResultList<AnnotationType> experimentalFactors = experimentalFactorsQuery.list(dc);
     344        for (AnnotationType exprFactor :experimentalFactors)
     345        {
     346          if (!exprFactor.isRemoved())
     347          {
     348            if (annotationSet!=null)
     349            {
     350              Annotation an= annotationSet.findAnnotation(exprFactor);
     351              if (an!=null) //exprFacor has annotations
     352              {
     353                List<?> values=  an.getValues();
     354                hybRow.set("FactorValue", exprFactor.getName(), values==null || values.size()==0 ? "" : Values.getString(values, ", ", true));
     355              }
     356              else // exprFactor has no annotations
     357              {
     358                hybRow.set("FactorValue", exprFactor.getName(), "" );
     359              }
     360            }
     361            else //The raw bio assay is not annotated
     362            {
     363              hybRow.set("FactorValue", exprFactor.getName(), "" );
     364            }
     365          }
     366        }
     367       
    349368            //Array Design
    350         ArrayDesign arrayDesign= rba.getArrayDesign();
    351         if (arrayDesign.isAffyChip())
     369        ArrayDesign arrayDesign = null;
     370        try
    352371        {
    353           File cdfFile= Affymetrix.getCdfFile(arrayDesign);
    354           File celFile=Affymetrix.getCelFile(rba);
    355           hybSectionHeader.add(Tab2MageConstants.raw_file.getName());
    356           hybridizationDataRows.add(celFile.getName());
    357           twoColorHybDataRows.add(celFile.getName());
    358           hybSectionHeader.add(Tab2MageConstants.cdf_file.getName());
    359           hybridizationDataRows.add(cdfFile.getName());
    360           twoColorHybDataRows.add(cdfFile.getName());
     372          arrayDesign= rba.getArrayDesign();
    361373        }
    362         else
     374        catch(Throwable tr)
    363375        {
    364           hybSectionHeader.add(Tab2MageConstants.raw_file.getName());
    365           hybridizationDataRows.add(rba.getName());
    366           twoColorHybDataRows.add(rba.getName());
     376          response.setError("[EXPORT FAILED: All Array Design(s) must be provided in BASE to continue].",Arrays.asList(tr));
    367377        }
    368         hybSectionHeader.add(Tab2MageConstants.array_accession.getName());
    369         hybridizationDataRows.add(arrayDesign.getName());
    370         twoColorHybDataRows.add(arrayDesign.getName());
    371        
    372           //Raw BioAssay protocol
    373         protocols.add(rba.getProtocol());
    374         if (extractionProtocolCount>0)
    375         {
    376           protocolHybSectionHeader.add(Tab2MageConstants.protocol_featureextraction.getName());
    377           protocolRefId.add(getFormattedProtocolId(rba.getProtocol()));
    378           twoColorFirstProtocolRefId.add(getFormattedProtocolId(rba.getProtocol()));
    379         }
    380                
    381         // rba protocol parameters
    382         if (rba.isAnnotated())  setParameterValues(rba,dc);
    383          
    384         //Scanning Protocol
     378        // Populate the Array file map in HybLine
     379        setArraysAttributes(hybRow, arrayDesign );
     380       
     381        // Populate the Data file map in HybLine
     382        setFileAttributes(hybRow, arrayDesign, rba, response);
     383       
     384        //Raw BioAssay protocol and parameter
     385        setProtocolAndParameterAtrributes(hybRow,rba,Tab2MageValidator.getFeProtocolCount(),
     386            Tab2MageConstants.protocol_featureextraction.getName(), response, dc);
     387       
     388        //Scanning Protocol and Parameters
    385389        Scan scan= rba.getScan();
    386         if (scanningProtocolCount>0)
    387         {
    388           protocolHybSectionHeader.add(Tab2MageConstants.protocol_scanning.getName());
    389           protocolRefId.add(getFormattedProtocolId(scan.getProtocol()));
    390           twoColorFirstProtocolRefId.add(getFormattedProtocolId(scan.getProtocol()));
    391         }
    392         protocols.add(scan.getProtocol());  // add scanning protocol
    393           //  Scanning protocol parameter
    394         if (scan.isAnnotated()) setParameterValues(scan,dc);
    395        
    396           //Hybridization
     390        setProtocolAndParameterAtrributes(hybRow,scan,Tab2MageValidator.getScanningProtocolCount(),
     391            Tab2MageConstants.protocol_scanning.getName(),response, dc);
     392       
     393        /*
     394          Array Slide
     395         */
    397396        Hybridization hyb= scan.getHybridization();
    398397        if (hyb.getArraySlide()==null)
     
    403402        else
    404403        {
    405           hybSectionHeader.add("Array[serial]");
    406           hybridizationDataRows.add(hyb.getArraySlide().getName());
    407           twoColorHybDataRows.add(hyb.getArraySlide().getName());
     404          hybRow.set("Array","serial", hyb.getArraySlide().getName());
    408405        }
    409406         
    410407        /*
    411           Names of materials and processes section
     408          Hybridization
    412409         */
    413         hybSectionHeader.add(Tab2MageConstants.hybridization.getName());
    414         hybridizationDataRows.add(hyb.getName());
    415         twoColorHybDataRows.add(hyb.getName());
    416        
     410        hybRow.set(Tab2MageConstants.hybridization.getName(), null,hyb.getName());
    417411        BioMaterialEvent bioMaterialEvent= hyb.getCreationEvent(); // an event that created the hyridization
    418        
    419         Protocol hybProtocol= bioMaterialEvent.getProtocol(); //hybridization protocol
    420         protocols.add(hybProtocol);
    421        
    422         if (hybridizationProtocolCount>0)
    423         {
    424           protocolHybSectionHeader.add(Tab2MageConstants.protocol_hyb.getName());
    425           protocolRefId.add(getFormattedProtocolId(hybProtocol));
    426           twoColorFirstProtocolRefId.add(getFormattedProtocolId(hybProtocol));
    427         }
    428         //  Hybridization protocol parameter
    429         if (hyb.isAnnotated()) setParameterValues(hyb,dc);
    430          
     412     
     413        // Hybridization protocol and parameter
     414        setProtocolAndParameterAtrributes(hybRow,hyb,Tab2MageValidator.getHybridizationProtocolCount(),
     415            Tab2MageConstants.protocol_hyb.getName(), response, dc);
     416       
    431417        ItemQuery<LabeledExtract> labeledExtractQuery =(ItemQuery<LabeledExtract>) bioMaterialEvent.getSources(); // get all the labeled extract
    432418        ItemResultList<LabeledExtract> labeledExtracts= labeledExtractQuery .list(dc);
    433         int hybsize=labeledExtracts.size();
    434         int count=1;
    435         for (LabeledExtract labeledExtract :labeledExtracts) // can have more than one labeled extract (2 color experiments)
     419        int size = labeledExtracts.size();
     420       
     421        // create the Tab2MageSubHybLine object List
     422        List<Tab2MageSubHybLine> subLines = new ArrayList<Tab2MageSubHybLine>();
     423       
     424        int count=1; // initialise the count variable to 1
     425        // Loop through all the labeled extracts
     426        for (LabeledExtract labeledExtract :labeledExtracts) // can have more than one labeled extract (e.g. 2 color experiments)
    436427        {
    437           //  labeled extract
    438           hybSectionHeader.add(Tab2MageConstants.labeledextract.getName());
     428          //create the new SubHyb Line
     429          Tab2MageSubHybLine subLine = new Tab2MageSubHybLine();
     430         
     431          /*
     432            labeled extract
     433           */
    439434          Protocol lbExtractProtocol= labeledExtract.getCreationEvent().getProtocol();
    440           protocols.add(lbExtractProtocol); // labeled extract protocol
    441           if (labelingProtocolCount>0)protocolHybSectionHeader.add(Tab2MageConstants.protocol_labeling.getName());
    442           if (count<hybsize || count==1)
    443           {
    444             hybridizationDataRows.add(labeledExtract.getName());
    445             if (labelingProtocolCount>0) protocolRefId.add(getFormattedProtocolId(lbExtractProtocol));
    446           }
    447           else if (count==2)
    448           {
    449             twoColorHyb=true;
    450             twoColorHybDataRows.add(labeledExtract.getName());
    451             if (labelingProtocolCount>0)twoColorProtocolRefId.add(getFormattedProtocolId(lbExtractProtocol));
    452           }
    453             //  labelling protocol parameter
    454           setParameterValues(labeledExtract,dc, count, hybsize);
    455          
    456           // Label
     435          subLine.set(Tab2MageConstants.labeledextract.getName(), null, labeledExtract.getName());
     436         
     437            // labelling protocol and parameter
     438          setProtocolAndParameterAtrributes(dc, subLine,labeledExtract,Tab2MageValidator.getLabelingProtocolCount(),
     439              Tab2MageConstants.protocol_labeling.getName(),lbExtractProtocol, response);
     440          /*
     441            Label
     442           */
    457443          String labelName= labeledExtract.getLabel().getName(); // the name of the label
    458           hybSectionHeader.add(Tab2MageConstants.dye.getName());
    459           if (count < hybsize || count==1)
    460           {
    461             hybridizationDataRows.add(labelName);
    462           }
    463           else if (count==2)
    464           {
    465             twoColorHybDataRows.add(labelName);
    466           }
    467          
    468           //  Extract
    469           Extract extract= labeledExtract.getExtract();
     444          subLine.set(Tab2MageConstants.dye.getName(), null,labelName);
     445                         
     446          /*
     447            Extract
     448          */
     449         
     450          Extract extract= ExportHelper.getExtract(labeledExtract, dc);
    470451          if (extract!=null)
    471452          {
    472             hybSectionHeader.add(Tab2MageConstants.extract.getName());
    473453            Protocol extractProtocol =extract.getCreationEvent().getProtocol(); //extract protocol
    474             if (extractProtocolCount>0) protocolHybSectionHeader.add(Tab2MageConstants.protocol_extraction.getName());
    475             protocols.add(extractProtocol);
    476             if (count < hybsize || count==1)
    477             {
    478               hybridizationDataRows.add(extract.getName());
    479               if (extractProtocolCount>0)protocolRefId.add(getFormattedProtocolId(extractProtocol));
    480             }
    481             else if (count==2)
    482             {
    483               twoColorHybDataRows.add(extract.getName());
    484               if (extractProtocolCount>0)twoColorProtocolRefId.add(getFormattedProtocolId(extractProtocol));
    485             }
    486               //  extraction protocol parameter
    487             setParameterValues(extract,dc,count,hybsize);
     454            subLine.set(Tab2MageConstants.extract.getName(), null, extract.getName());
     455           
     456            // extraction protocol  and parameter
     457            setProtocolAndParameterAtrributes(dc, subLine,extract,Tab2MageValidator.getExtractProtocolCount(),
     458                Tab2MageConstants.protocol_extraction.getName(), extractProtocol, response);
    488459          }
    489460         
    490           //Sample
    491           Sample sample =extract.getSample(); // The sample, extract is created from
     461          /*
     462            Sample
     463          */
     464         
     465          Sample sample= ExportHelper.getSample(extract, dc);
    492466          if (sample != null)
    493467          {
    494             hybSectionHeader.add(Tab2MageConstants.sample.getName());
    495468            Protocol sampleProtocol=sample.getCreationEvent().getProtocol();    //sampling protocol
    496             if (samplingProtocolCount>0)protocolHybSectionHeader.add(Tab2MageConstants.protocol_treatment.getName());
    497             protocols.add(sampleProtocol);
    498             if (count < hybsize || count==1)
     469            subLine.set(Tab2MageConstants.sample.getName(), null, sample.getName());
     470           
     471            // sampling protocol and parameter
     472            setProtocolAndParameterAtrributes(dc, subLine,sample,Tab2MageValidator.getSamplingProtocolCount(),
     473                Tab2MageConstants.protocol_treatment.getName(),sampleProtocol, response );
     474          }
     475         
     476          /* 
     477            Biosource
     478           */
     479         
     480          BioSource  bioSource=ExportHelper.getBioSource(sample, dc);
     481          if (bioSource != null)
     482          {
     483            subLine.set(Tab2MageConstants.biosource.getName(), null, bioSource.getName());
     484           
     485            //section for biomaterial xterixtics
     486            ItemQuery<Annotation> query = bioSource.getAnnotationSet().getAnnotations();
     487            query.include(Include.MINE, Include.NOT_REMOVED, Include.IN_PROJECT,Include.SHARED);
     488            List<Annotation> annotations = query.list(dc);
     489            for (Annotation annotation: annotations)
    499490            {
    500               hybridizationDataRows.add(sample.getName());
    501               if (samplingProtocolCount>0)protocolRefId.add(getFormattedProtocolId(sampleProtocol));
    502             }
    503             else if (count==2)
    504             {
    505               twoColorHybDataRows.add(sample.getName());
    506               if (samplingProtocolCount>0) twoColorProtocolRefId.add(getFormattedProtocolId(sampleProtocol));
    507             }
    508               // sampling protocol parameter
    509             setParameterValues(sample,dc,count,hybsize);
    510           }
    511          
    512           // Biosource
    513           Set<BioSource> bioSources= new LinkedHashSet();
    514           if (sample.isPooled())
    515           {
    516             pooledSampleFlag=true;
    517             poolSampleHeader.addAll(hybridizationDataRows);
    518            
    519             bioSources.addAll(ExporHelper.getBiosources(sample, dc));
    520           }
    521           else if (!sample.isPooled())
    522           {
    523             bioSources.add(sample.getBioSource());
    524           }
    525           int bioSourceCount=1;
    526           for (BioSource bioSource: bioSources)
    527           {
    528             if (bioSource!=null)
    529             {
    530               hybSectionHeader.add(Tab2MageConstants.biosource.getName());
    531               if (count < hybsize || count==1)
     491              AnnotationType at=annotation.getAnnotationType();
     492              if(!at.isRemoved())
    532493              {
    533                 if (bioSourceCount==1) // this caters for the the first Biosource for pooling and non pooling
    534                 {
    535                   hybridizationDataRows.add(bioSource.getName());
    536                 }
    537                 else if (pooledSampleFlag && bioSourceCount>1) // this cater for other biources when samples were pooled
    538                 {
    539                   poolSampleTail.add(bioSource.getName());
    540                 }
    541               }
    542               else if(count==2)
    543               {
    544                 twoColorHybDataRows.add(bioSource.getName());
    545                 if (pooledSampleFlag && bioSourceCount>1) poolSampleTail.add(bioSource.getName());
    546               }
    547              
    548               //section for biomaterial xterixtics
    549               List<Annotation> annotations = bioSource.getAnnotationSet().getAnnotations().list(dc);
    550               for (Annotation annotation: annotations)
    551               {
    552                 AnnotationType at=annotation.getAnnotationType();
    553                 if(!at.isRemoved())
    554                 {
    555                   List<?> values= annotation==null? null:annotation.getValues();
    556                   if (count < hybsize || count==1)
    557                   {
    558                     if (bioSourceCount==1) // this caters for the the first Biosource for pooling and non pooling
    559                     {
    560                       for (String header : bioXterParameterMap.keySet())
    561                       {
    562                         if (header.equals(annotation.getAnnotationType().getName()))
    563                         {
    564                           bioXterParameterMap.replace(header, values==null || values.size()==0 ? getDefaultValue(at) : Values.getString(values, ", ", true));
    565                         }
    566                       }
    567                     }
    568                     else if (pooledSampleFlag && bioSourceCount>1) // this cater for other biources when samples were pooled
    569                     {
    570                       poolSampleTail.add(values==null || values.size()==0 ? getDefaultValue(at) : Values.getString(values, ", ", true));
    571                     }
    572                   }
    573                   else if(count==2)
    574                   {
    575                     for (String header : twoColorBioXterParameterMap.keySet())
    576                     {
    577                       if (header.equals(annotation.getAnnotationType().getName()))
    578                       {
    579                         twoColorBioXterParameterMap.replace(header, values==null || values.size()==0 ? getDefaultValue(at) : Values.getString(values, ", ", true));
    580                       }
    581                     }
    582                     if (pooledSampleFlag && bioSourceCount>1) poolSampleTail.add(values==null || values.size()==0 ? getDefaultValue(at) : Values.getString(values, ", ", true));
    583                   }
    584                 }
    585               }
    586             }
    587             if (pooledSampleFlag && bioSourceCount>1) poolSampleTail.add("--*poolend*--");
    588             bioSourceCount++;
    589           }
    590           count++;
    591          
    592         } //end of labeled extract loop
    593        
    594         /*
    595           Populate the Hyb data row before display
    596          */
    597         for (Map.Entry<String, String> e: bioXterParameterMap.entrySet())
    598         {
    599           hybridizationDataRows.add(e.getValue());
    600           bioXterHybSectionHeader.add(e.getKey());
    601         }
    602         if (twoColorHyb)
    603         {
    604           for (Map.Entry<String, String> e: twoColorBioXterParameterMap.entrySet())
    605           {
    606             twoColorHybDataRows.add(e.getValue());
    607           }
    608         }
    609         // add protocol hyb ref ids
    610         for (String protcolId : protocolRefId) //add protocol id
    611         {
    612           hybridizationDataRows.add(protcolId);
    613         }
    614         if (twoColorHyb)
    615         {
    616           twoColorFirstProtocolRefId.addAll(twoColorProtocolRefId);
    617           for (String protocolId : twoColorFirstProtocolRefId )
    618           {
    619             twoColorHybDataRows.add(protocolId);
    620           }
    621         }
    622           //  add parameter values
    623        
    624         for (Map.Entry<String, String> entry: parameterMap.entrySet())
    625         {
    626           hybridizationDataRows.add(entry.getValue());
    627           parameterHybSectionHeader.add(entry.getKey());
    628         }
    629         if (twoColorHyb)
    630         {
    631           for (Map.Entry<String, String> firstMapE :twoColorFirstParameterMap.entrySet())
    632           {
    633             for (Map.Entry<String, String> mapE :twoColorParameterMap.entrySet())
    634             {
    635               if (firstMapE.getKey().equals(mapE.getKey()))
    636               {
    637                 twoColorFirstParameterMap.replace(firstMapE.getKey(), firstMapE.getValue()==""? mapE.getValue():"" ) ;
     494                List<?> values= annotation==null? null:annotation.getValues();
     495                subLine.set(Tab2MageConstants.bio_mat_charact.getName(), annotation.getAnnotationType().getName(),
     496                    values==null || values.size()==0 ? ExportHelper.getDefaultValue(at) : Values.getString(values, ", ", true));
    638497              }
    639498            }
    640499          }
    641           for (String paramValue : twoColorFirstParameterMap.values())
    642           {
    643             twoColorHybDataRows.add(paramValue);
    644           }
     500       
     501          subLines.add(subLine);  //make a list of subLines
     502          count++;
     503        } //end of labeled extract loop
     504     
     505        hybRow.addHybSubLines(size, hybRow.getName(), subLines); // add the subLines (i.e. Tab2MageSubHybLine objectc list to Tab2MageHybridizationLine Object
     506         
     507        hybridization.addLine(hybRow);  // add Tab2MageHybridizationLine Object to Tab2MageHybridization object
     508        if(!hybs.contains(hybridization))
     509          hybs.add(hybridization);    // add Tab2MageHybridization Object to the List of Tab2MageHybridization object
     510     
     511      }// end of raw biossay for loop
     512     
     513      // create headers for biomaterial xteristics
     514      Set<String> bioMatHeaders = new LinkedHashSet<String>();
     515     
     516      //create  headers for the parameters
     517      Set<String> paramHeaders = new LinkedHashSet<String>();
     518     
     519      //create headers for experimental factor values
     520      Set<String> factorValueHeaders = new LinkedHashSet<String>();
     521     
     522      for (Tab2MageHybridization h : hybs)
     523      {
     524       
     525        Tab2MageHybridizationLine l = h.getLine();
     526             
     527        // add headers to main parameter header list
     528        paramHeaders.addAll(ExportHelper.getHeaderWithValuesOnly(l.getParameter()));
     529       
     530        for (Tab2MageSubHybLine sl: l.getSubLineSet())
     531        {
     532          // get the headers for biomaterial xteristics and add to  biomaterial xteristics header set
     533          bioMatHeaders.addAll(ExportHelper.getHeaderWithValuesOnly(sl.getBioMaterialCharacteristics()));
     534          // get the parameter values headers and add to the set of parameter headers
     535          paramHeaders.addAll(ExportHelper.getHeaderWithValuesOnly(sl.getParameter()));
     536         
    645537        }
    646538       
    647         /*
    648           Experimental Factor Section
    649         */
    650         expFactorValues=getExperimentalFactorValues(dc,experiment,rba);
    651         for(Annotation value: expFactorValues) 
    652         {
    653           if (value!=null)
    654           {
    655             List<?> values= value.getValues();
    656             hybridizationDataRows.add(values==null || values.size()==0 ? "" : Values.getString(values, ", ", true));
    657             if (twoColorHyb) twoColorHybDataRows.add(values==null || values.size()==0 ? "" : Values.getString(values, ", ", true));
    658           }
    659           else
    660           {
    661             hybridizationDataRows.add("");
    662             if (twoColorHyb) twoColorHybDataRows.add("");
    663           }
    664         }
    665        
    666         if (twoColorHyb)hybridizationDataRows.addAll(twoColorHybDataRows);
    667        
    668        
    669         // clear all necessary data holder for reuse
    670         parameterMap.clear();
    671         twoColorParameterMap.clear();
    672         twoColorFirstParameterMap.clear();
    673         bioXterParameterMap.clear();
    674         twoColorBioXterParameterMap.clear();
    675         protocolRefId.clear();
    676         parameterValues.clear();
    677         factorValues.clear();
    678         twoColorParameterValues.clear();
    679         twoColorFirstParameterValues.clear();
    680         twoColorFirstProtocolRefId.clear();
    681         twoColorProtocolRefId.clear();
    682        
    683         if (!twoColorHybDataRows.isEmpty())
    684         {
    685           twoColorHybDataRows.clear();
    686           twoColorHyb=false;
    687         }
    688        
    689         poolSampleHeader.clear();
    690         poolSampleTail.clear();
    691        
    692         hybridizationDataRows.add(Tab2MageConstants.hybrow_delimeter.getName());
    693       }// end of raw biossay for loop
    694      
    695       //add headers
    696       for (String bioXterHeader: bioXterHybSectionHeader)
    697       {
    698         hybSectionHeader.add("BioMaterialCharacteristics["+bioXterHeader+"]");
    699       }
    700       for (String protocolHeader: protocolHybSectionHeader)
    701       {
    702         hybSectionHeader.add(protocolHeader);
    703       }
    704       for (String parameterHeader :parameterHybSectionHeader)
    705       {
    706         hybSectionHeader.add("Parameter["+parameterHeader+"]");
    707       }
    708       for (String factorValueHeader :factorValuesHybSectionHeader)
    709       {
    710         hybSectionHeader.add(factorValueHeader);
     539        // get the headers for the experiment factor values and add to experimental factor values header set
     540        factorValueHeaders.addAll(ExportHelper.getHeaderWithValuesOnly(l.getFactorValues()));
    711541      }
    712542     
    713543      /*
    714         Write the tab2mage file
     544        Create all the used protocols objects
    715545       */
    716       Tab2MageWriter.writeTab2MageFile(experiment, protocols, hybSectionHeader, hybridizationDataRows, job, response, dc);
    717            
     546      protocols = ExportHelper.createProtocols(rawBioAssays, dc);
     547     
     548      /*
     549        create all used Tab2Mage Hybridization sections protocol headers
     550       */
     551      protocolHybSectionHeader= Tab2MageValidator.getProtocolHybSectionHeader();
     552     
     553      /*
     554        Create Tab2Mage Hybridization Section Header
     555       */
     556         
     557      hybSectionHeader= ExportHelper.createHybridizationSectionHeader(dc,hybs,bioMatHeaders,
     558                                  protocolHybSectionHeader,  paramHeaders, factorValueHeaders);
     559      /*
     560          Write the tab2mage file
     561       */
     562         
     563      Tab2MageFileWriter.writeTab2MageFile(experiment, protocols,hybs, hybSectionHeader,bioMatHeaders,
     564                      protocolHybSectionHeader, paramHeaders,factorValueHeaders, job, response, dc);
     565     
    718566      //statusOut.close();
    719       Writer out= Tab2MageWriter.getOut();
     567      Writer out= Tab2MageFileWriter.getOut();
    720568      out.flush();
    721569      out.close();
     
    730578    {
    731579      if (dc != null) dc.close();
    732       scanningProtocolCount=0;
    733       extractionProtocolCount=0;
    734       hybridizationProtocolCount=0;
    735       labelingProtocolCount=0;
    736       extractProtocolCount=0;
    737       samplingProtocolCount=0;
    738       newParameterHybSectionHeader.clear();
    739       bioMatXteristicsHeader.clear();
    740       bioXterHybSectionHeader.clear();
    741       factorValuesHybSectionHeader.clear();
    742       parameterHybSectionHeader.clear();
    743580    }       
    744581  }
    745582 
    746583  /**
    747      get all the experimental factors for an experiments
    748      @param DcControl dc, the database control
    749      @param Experiment experiment, the experiment
    750      @param RawBioassay, the rawbioassay that the experimental factors are obtained from
    751      @return List, list of annotations
    752    */
    753   private static List<Annotation> getExperimentalFactorValues(DbControl dc, Experiment experiment, RawBioAssay rba)
    754   {
    755     List<Annotation> values= new LinkedList<Annotation>();
    756     AnnotationSet annotationSet = rba.isAnnotated() ? rba.getAnnotationSet() : null;
    757     ItemQuery<AnnotationType> experimentalFactorsQuery= experiment.getExperimentalFactors();
    758     experimentalFactorsQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT);
    759     ItemResultList<AnnotationType> experimentalFactors = experimentalFactorsQuery.list(dc);
    760     if (annotationSet!=null)
    761     {
    762       for (AnnotationType exprFactor :experimentalFactors)
    763       {
    764         if (!exprFactor.isRemoved())
    765         {
    766           //factorValuesHybSectionHeader.add("FactorValue["+exprFactor.getName()+"]");
    767           values.add(annotationSet.findAnnotation(exprFactor));
    768           if (annotationSet.findAnnotation(exprFactor)!=null)factorValuesHybSectionHeader.add("FactorValue["+exprFactor.getName()+"]");
    769         }
    770       }
    771     }
    772     return values;
     584    set the array attributes  of the the <code>Tab2MageHybridizationLine</code> object
     585      @param hybRow, the <code>Tab2MageHybridizationLine</code> object
     586      @param arrayDesign, the Array Design
     587   */
     588  private void setArraysAttributes (Tab2MageHybridizationLine hybRow, ArrayDesign arrayDesign )
     589  {
     590    hybRow.set("Array",Tab2MageConstants.array_accession.getName(),arrayDesign.getName());
    773591  }
    774592 
    775593  /**
    776     Gets the base format id for the protocol, if protocol is null an empty string is returned
    777     this is required to have consistent tab delimited format
    778     @param protocol, the protocol used in the experiment
    779     @return protocol id, an empty string is returned when the protocol is null
    780    */
    781   private static String getFormattedProtocolId (Protocol protocol)
    782   {
    783     String tab="";
    784     String protocolId;
    785     if (protocol!=null)
    786     {
    787       protocolId = "P-BASE-"+protocol.getId();
    788     }
    789     else
    790     {
    791       protocolId= tab;
    792     }
    793     return  protocolId ;
     594    set the file attributes  of the the <code>Tab2MageHybridizationLine</code> object
     595      @param hybRow, the Tab2MageHybridizationLine object
     596      @param arrayDesign, the Array Design
     597      @param rba, the raw bio assay
     598      @param response, the response object to return errors in case of failure during the setting of file values
     599   */
     600  private void setFileAttributes(Tab2MageHybridizationLine hybRow, ArrayDesign arrayDesign, RawBioAssay rba, Response response)
     601  {
     602    try
     603    {
     604      if (arrayDesign.isAffyChip())
     605      {
     606        File cdfFile= Affymetrix.getCdfFile(arrayDesign);
     607        File celFile=Affymetrix.getCelFile(rba);
     608        hybRow.set("File", Tab2MageConstants.raw_file.getName(), celFile.getName());
     609        hybRow.set("File",Tab2MageConstants.cdf_file.getName(), cdfFile.getName());
     610      }
     611      else
     612      {
     613        hybRow.set("File", Tab2MageConstants.raw_file.getName(), rba.getName());
     614      }
     615     
     616    }
     617    catch(Throwable tr)
     618    {
     619      response.setError(tr.getMessage(), Arrays.asList(tr));
     620    }
    794621  }
    795622  /**
    796     Set all resource counters used within an experiment
    797       @param experiment, the experiment
    798       @param dc, the database control object
     623    set the protocol and parameters attributes/values for Labeling -to- Sampling protocol and parameters
     624    @param dc, the database control
     625      @param subLine, the <code>Tab2MageSubHybLine</code> object
     626      @param anotatable, the annotatable item to extract protocol and parameters from
     627      @param protocolCount, the number of protocols already identified for the annotatable item
     628      @param keyEntry, the header to set for the protocol in the <code>SubHybridizationLine</code> protocol map attributes
     629      @param protocol, the protocol object
     630      @param response, the response object to return errors in case of failure during the setting of parameter values
    799631   */
    800   @SuppressWarnings({"deprecation","unchecked"})
    801   private static void getResourceCounter(Experiment experiment,DbControl dc)
    802   {
    803     ItemResultList<RawBioAssay> rbas= experiment.getRawBioAssays().list(dc);
    804     for (RawBioAssay rba : rbas)
    805     {
    806       if (rba.getProtocol()!=null)
    807       {
    808         extractionProtocolCount++ ;
    809         getParameterSectionHeader(rba, dc );
    810       }
    811       if (rba.getScan().getProtocol()!=null)
    812       {
    813         scanningProtocolCount++;
    814         getParameterSectionHeader(rba.getScan(), dc );
    815       }
    816       if (rba.getScan().getHybridization().getProtocol()!=null)
    817       {
    818         hybridizationProtocolCount++;
    819         getParameterSectionHeader(rba.getScan().getHybridization(), dc );
    820       }
    821       ItemResultList<LabeledExtract>labeledExtracts = (ItemResultList<LabeledExtract>)
    822                               rba.getScan().getHybridization().getCreationEvent().getSources().list(dc);
    823       for (LabeledExtract labeledExtract :labeledExtracts)
    824       {
    825         if (labeledExtract.getProtocol()!=null)
    826         {
    827           labelingProtocolCount++;
    828           getParameterSectionHeader(labeledExtract, dc );
    829         }
    830         if (labeledExtract.getExtract().getProtocol()!=null)
    831         {
    832           extractProtocolCount++;
    833           getParameterSectionHeader(labeledExtract.getExtract(), dc );
    834         }
    835         if  (labeledExtract.getExtract().getSample().getProtocol()!=null)
    836         {
    837           samplingProtocolCount++;
    838           getParameterSectionHeader(labeledExtract.getExtract().getSample(), dc );
    839         }
    840         if (labeledExtract.getExtract().getSample().getBioSource()!=null)
    841         setAllBioMatXteristicsHeader(labeledExtract.getExtract().getSample().getBioSource(),dc);
    842       }
    843     }
    844   }
     632  private void setProtocolAndParameterAtrributes(DbControl dc,Tab2MageSubHybLine subLine, Annotatable anotatable, int protocolCount, String keyEntry, Protocol protocol, Response response)
     633  {
     634    if (protocolCount>0)
     635    {
     636      subLine.set("Protocol",keyEntry,ExportHelper.getFormattedProtocolId(protocol));
     637    }
     638           
     639    // MeasuredBioMaterial protocol parameters
     640    if (anotatable.isAnnotated()) setParameterValues(anotatable,dc, null,subLine, response);
     641  }
     642 
    845643  /**
    846       Gets the used annotation types (parameters) for an annotatable item
    847       @param annotatable, an item that implements annotatable
    848       @param dc, the database control object
     644    set the protocol and parameters attributes/values for Image_Analysis -to- Hybridization protocol and parameters
     645      @param hybRow, the Tab2MageHybridizationLine object
     646      @param anotatable, the annotatable item to extract protocol and parameters from
     647      @param protocolCount, the number of protocols already identified for the annotatable item
     648      @param keyEntry, the header to set for the protocol in the <code>SubHybridizationLine</code> protocol map attributes
     649      @param protocol, the protocol object
     650      @param response, the response object to return errors in case of failure during the setting of parameter values
     651      @param dc, the database control
    849652   */
    850  
    851   private static void getParameterSectionHeader(Annotatable anotatable, DbControl dc )
    852   {
    853     ItemResultList<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc);
    854     for (Annotation annotation: annotations)
    855     {
    856       if (anotatable.getProtocol().isParameter(annotation.getAnnotationType()) && !annotation.getAnnotationType().isRemoved())
    857         newParameterHybSectionHeader.add(annotation.getAnnotationType().getName());
    858     }
    859     //Helper.displayParameterHeader(newParameterHybSectionHeader);
    860   }
    861   /**
    862     Gets the annotation types used as biomaterial characteristics for an annotatable item
    863     @param annotatable, an item that implements annotatable
    864       @param dc, the database control object
    865    */
    866  
    867   private static void setAllBioMatXteristicsHeader(Annotatable anotatable, DbControl dc)
    868   {
    869     List<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc);
    870     for (Annotation annotation: annotations)
    871     {
    872       AnnotationType at=annotation.getAnnotationType();
    873       if(!at.isRemoved())
    874         bioMatXteristicsHeader.add(at.getName());
    875     }
    876   }
    877  
    878   /**
    879     initialises the maps required to manage tab2mage data 
    880     @param map, the map to be intitialised
    881     @param isForParameter, TRUE if map is for parameters and FALSE otherwise
    882    */
    883    
    884   private static void initialiseMaps(ConcurrentHashMap<String,String> map, boolean isForParameter)
    885   {
    886     if (map.isEmpty())
    887     {
    888       if (isForParameter)
    889       {
    890         for (String param: newParameterHybSectionHeader)
    891         {
    892           if (param!=null) map.put(param, "");
    893         }
    894       }
    895       else if (!isForParameter)
    896       {
    897         for (String bioXterParam: bioMatXteristicsHeader)
    898         {
    899           if (bioXterParam!=null) map.put(bioXterParam, "");
    900         }
    901       }
    902     }
    903   }
     653  private void setProtocolAndParameterAtrributes(Tab2MageHybridizationLine hybRow, Annotatable anotatable, int protocolCount,String keyEntry, Response response, DbControl dc)
     654  {
     655    if (protocolCount>0)
     656    {
     657      hybRow.set("Protocol", keyEntry, ExportHelper.getFormattedProtocolId(anotatable.getProtocol()));
     658    }
     659      //  protocol parameter
     660    if (anotatable.isAnnotated()) setParameterValues(anotatable,dc, hybRow,null, response);
     661   
     662  }
     663 
    904664  /**
    905665    sets protocol parameter values
     
    907667      @param dc, the dabatabase control
    908668   */
    909   private static void setParameterValues(Annotatable anotatable, DbControl dc)
    910   {
    911     ItemResultList<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc);
    912     for (Annotation annotation: annotations)
    913     {
    914       if (anotatable.getProtocol()!=null) // only check if the annotation is not null, watch this!
    915       {   
    916         if (anotatable.getProtocol().isParameter(annotation.getAnnotationType()) && !annotation.getAnnotationType().isRemoved())
    917         {
    918           List<?> values= annotation.getValues();
    919           for (String header : parameterMap.keySet())
     669  private static void setParameterValues(Annotatable anotatable, DbControl dc, Tab2MageHybridizationLine hybRow, Tab2MageSubHybLine subLine, Response response)
     670  {
     671    try
     672    {
     673      ItemResultList<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc);
     674      for (Annotation annotation: annotations)
     675      {
     676        if (anotatable.getProtocol()!=null) // only check if the annotation is not null, watch this!
     677        {   
     678          if (anotatable.getProtocol().isParameter(annotation.getAnnotationType()) && !annotation.getAnnotationType().isRemoved())
    920679          {
    921             if (header.equals(annotation.getAnnotationType().getName()))
    922             {
    923               parameterMap.replace(header, "", values==null || values.size()==0 ? "" : Values.getString(values, ", ", true));
    924             }
    925           }
    926           for (String twoColorFirstHeader : twoColorFirstParameterMap.keySet())
    927           {
    928             if (twoColorFirstHeader.equals(annotation.getAnnotationType().getName()))
    929             {
    930               twoColorFirstParameterMap.replace(twoColorFirstHeader, "", values==null || values.size()==0 ? "" : Values.getString(values, ", ", true));
    931             }
     680            List<?> values= annotation.getValues();
     681            AnnotationType at= annotation.getAnnotationType();
     682            if (hybRow!=null)
     683              hybRow.set("Parameter", at.getName(), values==null || values.size()==0 ? "" : Values.getString(values, ", ", true));
     684            if (subLine!=null)
     685              subLine.set("Parameter", at.getName(), values==null || values.size()==0 ? "" : Values.getString(values, ", ", true));
    932686          }
    933687        }
    934688      }
    935689    }
    936   }
     690    catch(Throwable tr)
     691    {
     692      response.setError(tr.getMessage(), Arrays.asList(tr));
     693    }
     694   
     695  }
     696 
    937697  /**
    938     sets protocol parameter values
    939       @param anotatable, the annotatable item
    940     @param dc, the database control
    941     @param count, the two channel count
    942     @param hybsize, the number of labeled extract to a Hybridization.
     698    get headers from the concurrent hasp maps
     699    @return set of string : headers
    943700   */
    944   private static void setParameterValues (Annotatable anotatable, DbControl dc, int count, int hybsize )
    945   {
    946     ItemResultList<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc);
    947     for (Annotation annotation: annotations)
    948     {
    949       if (anotatable.getProtocol()!=null)
    950       {
    951         if (anotatable.getProtocol().isParameter(annotation.getAnnotationType()) && !annotation.getAnnotationType().isRemoved())
    952         {
    953           List<?> values= annotation.getValues();
    954           if (count < hybsize || count==1)
    955           {
    956             for (String header : parameterMap.keySet())
    957             {
    958               if (header.equals(annotation.getAnnotationType().getName()))
    959               {
    960                 parameterMap.replace(header, "", values==null || values.size()==0 ? "" : Values.getString(values, ", ", true));
    961               }
    962             }
    963           }
    964           else if(count==2)
    965           {
    966             for (String twoColorHeader : twoColorParameterMap.keySet())
    967             {
    968               if (twoColorHeader.equals(annotation.getAnnotationType().getName()))
    969               {
    970                 twoColorParameterMap.replace(twoColorHeader, "", values==null || values.size()==0 ? "" : Values.getString(values, ", ", true));
    971               }
    972             }
    973           }
    974         }
    975       }
    976     }
    977   }
    978  
     701  public static Set<String> getHeaders(ConcurrentHashMap<String,String> map)
     702  {
     703    Set<String> headers= new LinkedHashSet<String>();
     704    headers.addAll(map.keySet());
     705    return headers;
     706  }
     707   
    979708  /**
    980     gets the default value of an annotation type, used when annotation value is null
    981     @param at, annotation type to obtain the default value from
    982     @return string, deafult value or an empty string if the default value is null
     709    List of Hybridizations
    983710   */
    984   private static String getDefaultValue(AnnotationType at)
    985   {
    986    
    987     return at.getDefaultValue()!=null? at.getDefaultValue():"";
    988   }
    989   private static int scanningProtocolCount=0;
    990   private static int extractionProtocolCount=0;
    991   private static int hybridizationProtocolCount=0;
    992   private static int labelingProtocolCount=0;
    993   private static int extractProtocolCount=0;
    994   private static int samplingProtocolCount=0;
    995   private static ConcurrentHashMap<String,String> parameterMap = new ConcurrentHashMap<String, String>();
    996   private static ConcurrentHashMap<String,String> twoColorParameterMap = new ConcurrentHashMap<String, String>();
    997   private static ConcurrentHashMap<String,String> twoColorFirstParameterMap = new ConcurrentHashMap<String, String>();
    998   private static ConcurrentHashMap<String,String> bioXterParameterMap = new ConcurrentHashMap<String, String>();
    999   private static ConcurrentHashMap<String,String> twoColorBioXterParameterMap = new ConcurrentHashMap<String, String>();
    1000   private static Set<String> factorValuesHybSectionHeader= new LinkedHashSet<String>();
    1001   private static Set<String> parameterHybSectionHeader= new LinkedHashSet<String>();
    1002   private static Set<String> newParameterHybSectionHeader= new LinkedHashSet<String>();
    1003   private static Set<String> bioMatXteristicsHeader=  new LinkedHashSet<String>();
    1004   private static Set<String> bioXterHybSectionHeader=  new LinkedHashSet<String>();
     711  private List<Tab2MageHybridization> hybs = new ArrayList<Tab2MageHybridization>();   
     712
    1005713}
     714
  • trunk/uk/ac/ebi/Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageValidator.java

    r396 r449  
     1/* $Id: Tab2MageValidator.java 2007-10-01 dominic $
     2
     3  Copyright (C) 2007 Authors contributing to this file.
     4
     5  This file is for NutriBASE - Nutrigenomics BioArray Software Environment.
     6  A customisation of the BASE SOFTWARE.
     7 
     8  BASE is free software; you can redistribute it and/or
     9  modify it under the terms of the GNU General Public License
     10  as published by the Free Software Foundation; either version 2
     11  of the License, or (at your option) any later version.
     12
     13  BASE is distributed in the hope that it will be useful,
     14  but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  GNU General Public License for more details.
     17
     18  You should have received a copy of the GNU General Public License
     19  along with this program; if not, write to the Free Software
     20  Foundation, Inc., 59 Temple Place - Suite 330,
     21  Boston, MA  02111-1307, USA.
     22*/
    123package uk.ac.ebi.nugo.plugins.ta2mageexport;
    224
     25import java.util.Arrays;
    326import java.util.LinkedHashSet;
     27import java.util.LinkedList;
    428import java.util.List;
    529import java.util.Set;
     30import java.util.concurrent.ConcurrentHashMap;
    631
    732import net.sf.basedb.core.Annotatable;
    833import net.sf.basedb.core.Annotation;
     34import net.sf.basedb.core.AnnotationSet;
    935import net.sf.basedb.core.AnnotationType;
     36import net.sf.basedb.core.BioSource;
    1037import net.sf.basedb.core.DbControl;
    1138import net.sf.basedb.core.Experiment;
     39import net.sf.basedb.core.Extract;
     40import net.sf.basedb.core.Include;
     41import net.sf.basedb.core.ItemQuery;
    1242import net.sf.basedb.core.ItemResultList;
    1343import net.sf.basedb.core.LabeledExtract;
    1444import net.sf.basedb.core.RawBioAssay;
    15 
    16 /*
    17   What the validation class should do: (for next implementation)
    18   Export NO FAILURE
    19     ----
    20     if raw bioassay data have no protocol, export but report 'missing feature extraction protocol'
    21    
    22     if raw bioassay data are of type 'Affymetrix' but have no CEL file, export but report missing CEL file (AE may refuse your submission)
    23    
    24     if scan has no protocol or no scanner, export but report 'missing scanning protocol (MIAME data)' and/or 'missing scanner'
    25    
    26     if hybridization has no protocol or no hardware, export report 'missing hybridization protocol (MIAME data)' and/or 'missing hardware'
    27    
    28     if hybridization has no ArraySlide, export but report 'missing ArraySlide (barcode) information'
    29    
    30     Note: There is no need to fail here as the ArrayDesign information can be rescued from the Scan (please check)
    31    
    32     if labeled extract has no protocol, export but report 'missing labeling protocol (MIAME data)'
    33    
    34     if extract has no protocol, export but report 'missing extraction protocol (MIAME data)'
    35    
    36     if sample has no protocol, export but report 'missing sampling protocol (MIAME data)'
    37    
    38     IMPORTANT: There is probably a need for keeping track of how many protocols are missing for every records, so that if no protocols are used, then the export should output a BIG error message:
    39     'Tab2mage submission incomplete: you must provide which protocols have been used and with which item '
    40    
    41     This is where the Experiment overview if a complementary effort to the tab2mage plugin: it already has a facility for checking all missing items)
    42    
    43    
    44     if biosource has no annotationtype 'Species' reported, export but report 'Key MIAME annotation missing: AE may refuse your submission'
    45    
    46     if Experiment has no Experimental Factor declared and Experimental design and experiment design type are missing, export but report missing information (AE may refuse your submission)
    47    
    48     if Protocol description is empty or less than 25 characters in length, export but report 'description is too short and may compromise MIAME compliance'
    49   FAILURE - No Export
    50     ----
    51     if raw bioassay data has no ArrayDesign or no Scan associated, then FAIL and report cause of failure=link missing between Raw Bioassay and Scan, or/and. Raw Bioassay data and ArrayDesign
    52 
    53     (scan and hyb are automatically associated so no risk of breakage here)
    54 
    55     if hybridization has no labeled extract associated, then FAIL and report cause of failure=link missing between Hyb and Labeled Extract
    56     if labeled extract has no parent 'Extract', FAIL and report cause of failure=link missing between extracts and labeled extract
    57     if extract has no parent 'Sample',  FAIL and report cause of failure=link missing between sample and extract
    58     if sample has no parent 'BioSource', FAIL and report cause of failure=link missing between biosource and sample
    59 
     45import net.sf.basedb.core.Sample;
     46import net.sf.basedb.core.SessionControl;
     47import net.sf.basedb.core.plugin.Response;
     48
     49import org.apache.log4j.Logger;
     50
     51import uk.ac.ebi.nugo.common.Tab2MageConstants;
     52
     53
     54/**
     55  The tab2mage export validator
     56  @author Dominic Oyeniran
     57    @email  oyeniran@ebi.ac.uk/doyeniran@gmail.com
     58  @version 1.0
    6059 */
    61 
    6260public class Tab2MageValidator
    6361{
    64  
     62  // logger
     63  private static Logger log = Logger.getLogger(Tab2MageValidator.class);
     64   
     65  // counts the number of feature extraction protocol used in the experiment
     66  private static int feProtocolCount=0;
     67 
     68  // counts the number of scanning protocols used in the experiment
    6569  private static int scanningProtocolCount=0;
    66   private static int extractionProtocolCount=0;
     70 
     71  // counts the number of hybridization protocol used in the experiment
    6772  private static int hybridizationProtocolCount=0;
     73 
     74  // counts the number of labelling protocol used in the experiment
    6875  private static int labelingProtocolCount=0;
     76 
     77  // counts the number of extraction protocol used in the experiment
    6978  private static int extractProtocolCount=0;
     79 
     80  // counts the number of extraction protocol used in the experiment
    7081  private static int samplingProtocolCount=0;
    71   private static Set<String> newParameterHybSectionHeader= new LinkedHashSet<String>();
    72   private static Set<String> bioMatXteristicsHeader=  new LinkedHashSet<String>();
     82 
     83  private Set<String> parameterHeaders= new LinkedHashSet<String>();
     84 
     85  private Set<String> bioMaterialXteristicsHeaders=  new LinkedHashSet<String>();
     86 
     87  private static Set<String> factorValuesHybSectionHeader= new LinkedHashSet<String>();
     88 
     89  private static Set<String>  protocolHybSectionHeader= new LinkedHashSet<String>();
     90 
     91  /* channel number to indicate platforms
     92    1-- affymetrix
     93    2-- agilent. genepix etc
     94    3-- ......
     95   */
     96  private int channelNumber = 0;
     97  // the experiment
    7398  private Experiment experiment;
    7499 
    75   /**
    76     creates a new Tab2Mage Validator
    77    * @param experiment
    78    */
    79   public Tab2MageValidator(Experiment experiment)
     100  private SessionControl sc;
     101 
     102  private Response response;
     103 
     104  /**
     105      creates a new Tab2Mage Validator
     106      @param experiment
     107      @param sc
     108      @param response
     109   */
     110  public Tab2MageValidator(Experiment experiment, SessionControl sc, Response response)
    80111  {
    81112    this.experiment=experiment;
    82     getResourceCounter(experiment,experiment.getDbControl());
    83   }
    84  
    85   /**
    86   Set all resource counters used within an experiment
    87     @param experiment, the experiment
    88     @param dc, the database control object
    89  */
     113    this.sc = sc;
     114    this.response= response;
     115    countProtocols();
     116    createHeaders();
     117  }
     118 
     119  /**
     120    counts all protocols used in the experiment and initialise protocol variables
     121   */
     122  @SuppressWarnings("unchecked")
     123  private void countProtocols()
     124  {
     125    DbControl dc =null;
     126    try
     127    {
     128      dc = sc.newDbControl();
     129      ItemResultList<RawBioAssay> rbas= experiment.getRawBioAssays().list(dc);
     130      for (RawBioAssay rba : rbas)
     131      {
     132        if (rba.getProtocol()!=null)
     133          feProtocolCount++ ;
     134       
     135        if (rba.getScan().getProtocol()!=null)
     136          scanningProtocolCount++;
     137     
     138        if (rba.getScan().getHybridization().getProtocol()!=null)
     139          hybridizationProtocolCount++;
     140       
     141        ItemResultList<LabeledExtract>labeledExtracts = (ItemResultList<LabeledExtract>)
     142                                rba.getScan().getHybridization().getCreationEvent().getSources().list(dc);
     143        if (channelNumber==0)
     144              setChannelNumber(labeledExtracts.size());
     145        for (LabeledExtract labeledExtract :labeledExtracts)
     146        {
     147          if (labeledExtract.getProtocol()!=null)
     148            labelingProtocolCount++; 
     149         
     150          //Extract extract = labeledExtract.getExtract(); // RefExtract
     151          Extract extract = ExportHelper.getExtract(labeledExtract, dc);
     152          if (extract.getProtocol()!=null)
     153            extractProtocolCount++;
     154                   
     155          //sample
     156          Sample sample = ExportHelper.getSample(extract, dc);
     157          if (sample.getProtocol()!=null)
     158            samplingProtocolCount++;
     159         
     160        }
     161      }
     162    }
     163    catch(Throwable tr)
     164    {
     165      log.error("the protocol count was not successful", tr);
     166      response.setError("the protocol counting was not successful", Arrays.asList(tr));
     167      dc.close();
     168    }
     169    finally
     170    {
     171      if (dc!=null)
     172        dc.close();
     173    }
     174  }
     175 
     176  /**
     177    create both the parameter [AT] header and BioMaterialCharactertistic[AT] headers found in the whole experiment
     178   */
    90179  @SuppressWarnings({"deprecation","unchecked"})
    91   private static void getResourceCounter(Experiment experiment,DbControl dc)
    92   {
    93     ItemResultList<RawBioAssay> rbas= experiment.getRawBioAssays().list(dc);
    94     for (RawBioAssay rba : rbas)
    95     {
    96       if (rba.getProtocol()!=null)
    97       {
    98         extractionProtocolCount++ ;
    99         getParameterSectionHeader(rba, dc );
    100       }
    101       if (rba.getScan().getProtocol()!=null)
    102       {
    103         scanningProtocolCount++;
    104         getParameterSectionHeader(rba.getScan(), dc );
    105       }
    106       if (rba.getScan().getHybridization().getProtocol()!=null)
    107       {
    108         hybridizationProtocolCount++;
    109         getParameterSectionHeader(rba.getScan().getHybridization(), dc );
    110       }
    111       ItemResultList<LabeledExtract>labeledExtracts = (ItemResultList<LabeledExtract>)
    112                               rba.getScan().getHybridization().getCreationEvent().getSources().list(dc);
    113       for (LabeledExtract labeledExtract :labeledExtracts)
    114       {
    115         if (labeledExtract.getProtocol()!=null)
    116         {
    117           labelingProtocolCount++;
    118           getParameterSectionHeader(labeledExtract, dc );
    119         }
    120         if (labeledExtract.getExtract().getProtocol()!=null)
    121         {
    122           extractProtocolCount++;
    123           getParameterSectionHeader(labeledExtract.getExtract(), dc );
    124         }
    125         if  (labeledExtract.getExtract().getSample().getProtocol()!=null)
    126         {
    127           samplingProtocolCount++;
    128           getParameterSectionHeader(labeledExtract.getExtract().getSample(), dc );
    129         }
    130         if (labeledExtract.getExtract().getSample().getBioSource()!=null)
    131         setAllBioMatXteristicsHeader(labeledExtract.getExtract().getSample().getBioSource(),dc);
    132       }
    133     }
    134   }
    135   /**
    136       Gets the used annotation types (parameters) for an annotatable item
     180  private void createHeaders()
     181  {
     182    DbControl dc =null;
     183    try
     184    {
     185      dc = sc.newDbControl();
     186      ItemResultList<RawBioAssay> rbas= experiment.getRawBioAssays().list(dc);
     187      for (RawBioAssay rba : rbas)
     188      {
     189        if (rba.getProtocol()!=null)
     190        {
     191          createParameterSectionHeaders(rba, dc );
     192          createProtocolHybSectionHeader(Tab2MageValidator.getFeProtocolCount(),Tab2MageConstants.protocol_featureextraction.getName());
     193        }
     194        if (rba.getScan().getProtocol()!=null)
     195        {
     196          createParameterSectionHeaders(rba.getScan(), dc );
     197          createProtocolHybSectionHeader(Tab2MageValidator.getScanningProtocolCount(), Tab2MageConstants.protocol_scanning.getName());
     198        }
     199        if (rba.getScan().getHybridization().getProtocol()!=null)
     200        {
     201          createParameterSectionHeaders(rba.getScan().getHybridization(), dc );
     202          createProtocolHybSectionHeader(Tab2MageValidator.getHybridizationProtocolCount(), Tab2MageConstants.protocol_hyb.getName());
     203        }
     204        ItemResultList<LabeledExtract>labeledExtracts = (ItemResultList<LabeledExtract>)
     205                                rba.getScan().getHybridization().getCreationEvent().getSources().list(dc);
     206        for (LabeledExtract labeledExtract :labeledExtracts)
     207        {
     208          if (labeledExtract.getProtocol()!=null)
     209          {
     210            createParameterSectionHeaders(labeledExtract, dc );
     211            createProtocolHybSectionHeader(Tab2MageValidator.getLabelingProtocolCount(), Tab2MageConstants.protocol_labeling.getName());
     212          }
     213          //Extract extract= labeledExtract.getExtract();
     214          Extract extract = ExportHelper.getExtract(labeledExtract, dc);
     215          if (extract.getProtocol()!=null)
     216          {
     217            createParameterSectionHeaders(labeledExtract.getExtract(), dc );
     218            createProtocolHybSectionHeader(Tab2MageValidator.getExtractProtocolCount(), Tab2MageConstants.protocol_extraction.getName());
     219          }
     220          Sample sample = ExportHelper.getSample(extract, dc);
     221          if  (sample.getProtocol()!=null)
     222          {
     223            createParameterSectionHeaders(sample, dc );
     224            createProtocolHybSectionHeader(Tab2MageValidator.getSamplingProtocolCount(), Tab2MageConstants.protocol_treatment.getName());
     225          }
     226          BioSource bioSource= ExportHelper.getBioSource(sample, dc);
     227          if (bioSource!=null)
     228            createBioMatXteristicsSectionHeader(bioSource,dc);
     229        }
     230      }
     231    }
     232    catch(Throwable tr)
     233    {
     234      log.error("cannot create / set parameters headers and biomaterials headers", tr );
     235      response.setError("cannot create / set parameters headers and biomaterials headers", Arrays.asList(tr));
     236      dc.close();
     237    }
     238    finally
     239    {
     240      if (dc!=null)
     241        dc.close();
     242    }
     243   
     244  }
     245  /**
     246      Gets the used annotation types (parameters) for an annotatable item and add it to a set of PARAMETER[AT] headers
    137247      @param annotatable, an item that implements annotatable
    138248      @param dc, the database control object
    139249   */
    140250 
    141   private static void getParameterSectionHeader(Annotatable anotatable, DbControl dc )
     251  private void createParameterSectionHeaders(Annotatable anotatable, DbControl dc )
    142252  {
    143253    ItemResultList<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc);
     
    145255    {
    146256      if (anotatable.getProtocol().isParameter(annotation.getAnnotationType()) && !annotation.getAnnotationType().isRemoved())
    147         newParameterHybSectionHeader.add(annotation.getAnnotationType().getName());
    148     }
    149     //Tab2MageHelper.displayParameterHeader(newParameterHybSectionHeader);
     257        parameterHeaders.add(annotation.getAnnotationType().getName());
     258    }
    150259  }
    151260 
     
    156265   */
    157266 
    158   private static void setAllBioMatXteristicsHeader(Annotatable anotatable, DbControl dc)
    159   {
    160     List<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc);
     267  private void createBioMatXteristicsSectionHeader(Annotatable anotatable, DbControl dc)
     268  {
     269   
     270    List<Annotation> annotations = anotatable.getAnnotationSet().getAnnotations().list(dc);
    161271    for (Annotation annotation: annotations)
    162272    {
    163       AnnotationType at=annotation.getAnnotationType();
    164       if(!at.isRemoved())
    165         bioMatXteristicsHeader.add(at.getName());
    166     }
    167   }
    168  
    169   public static Set<String> getBioMatXteristicsHeader()
    170   {
    171     return bioMatXteristicsHeader;
    172   }
    173 
    174   public static int getExtractionProtocolCount()
    175   {
    176     return extractionProtocolCount;
    177   }
    178 
     273      if (annotation.getValues()!=null && !annotation.getValues().isEmpty())
     274      {
     275        AnnotationType at=annotation.getAnnotationType();
     276        if(!at.isRemoved())
     277        {
     278          bioMaterialXteristicsHeaders.add(at.getName());
     279          //("bio header added is :"+ at.getName());
     280        }
     281      }
     282    }
     283   
     284  }
     285  /**
     286    create a list of the protocol headers for the hyridization section of tab2mage file.
     287    duplicates are eliminated with the use of linked hash set.
     288      @param count, the number of each protocol used across the raw bio assay.
     289      @param header, the header for each protocol used across the raw bio assay
     290   */
     291  private static void createProtocolHybSectionHeader(int count, String header)
     292  {
     293    if (count>0)
     294    {
     295      protocolHybSectionHeader.add(header);
     296    }
     297  }
     298 
     299  /**
     300    initialises the maps required to manage tab2mage data 
     301    @param map, the map to be intitialised
     302    @param isForParameter, TRUE if map is for parameters and FALSE otherwise
     303   */
     304   
     305  public ConcurrentHashMap<String,String> initialiseMaps(ConcurrentHashMap<String,String> map, boolean isForParameter)
     306  {
     307   
     308    if (map.isEmpty())
     309    {
     310      if (isForParameter) // get the parameter[AT] headers and put in a ConcurrentHashMap
     311      {
     312        for (String param: parameterHeaders)
     313        {
     314          if (param!=null) map.put(param, "");
     315        }
     316      }
     317      else if (!isForParameter) // get all biomaterial xteristics [AT] headers and put in a ConcurrentHashMap
     318      {
     319        for (String bioXterParam: bioMaterialXteristicsHeaders)
     320        {
     321          if (bioXterParam!=null) map.put(bioXterParam, "");
     322        }
     323      }
     324    }
     325    return map;
     326  }
     327 
     328  /**
     329     get all the experimental factors for an experiments
     330     @param DcControl dc, the database control
     331     @param Experiment experiment, the experiment
     332     @param RawBioassay, the rawbioassay that the experimental factors are obtained from
     333     @return List, list of annotations
     334  */ 
     335  public static List<Annotation> getExperimentalFactorValues(DbControl dc, Experiment experiment, RawBioAssay rba)
     336  {
     337    List<Annotation> values= new LinkedList<Annotation>();
     338    AnnotationSet annotationSet = rba.isAnnotated() ? rba.getAnnotationSet() : null;
     339    ItemQuery<AnnotationType> experimentalFactorsQuery= experiment.getExperimentalFactors();
     340    experimentalFactorsQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT);
     341    ItemResultList<AnnotationType> experimentalFactors = experimentalFactorsQuery.list(dc);
     342    if (annotationSet!=null)
     343    {
     344      for (AnnotationType exprFactor :experimentalFactors)
     345      {
     346        if (!exprFactor.isRemoved())
     347        {
     348          values.add(annotationSet.findAnnotation(exprFactor));
     349          if (annotationSet.findAnnotation(exprFactor)!=null)factorValuesHybSectionHeader.add("FactorValue["+exprFactor.getName()+"]");
     350        }
     351      }
     352    }
     353    return values;
     354  }
     355 
     356  /**
     357     get all the experimental factors headers for an experiments
     358     @param DcControl dc, the database control
     359     @param Experiment experiment, the experiment
     360     @param RawBioassay, the rawbioassay that the experimental factors are obtained from
     361     @return List, list of annotations
     362  */ 
     363  public static Set<String> getExperimentalFactorHeader(DbControl dc, Experiment experiment, RawBioAssay rba)
     364  {
     365    Set<String> headers= new LinkedHashSet<String>();
     366    AnnotationSet annotationSet = rba.isAnnotated() ? rba.getAnnotationSet() : null;
     367    ItemQuery<AnnotationType> experimentalFactorsQuery= experiment.getExperimentalFactors();
     368    experimentalFactorsQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT);
     369    ItemResultList<AnnotationType> experimentalFactors = experimentalFactorsQuery.list(dc);
     370    if (annotationSet!=null)
     371    {
     372      for (AnnotationType exprFactor :experimentalFactors)
     373      {
     374        if (!exprFactor.isRemoved())
     375        {
     376   
     377          if (annotationSet.findAnnotation(exprFactor)!=null)headers.add("FactorValue["+exprFactor.getName()+"]");
     378        }
     379      }
     380    }
     381    return headers;
     382  }
     383 
     384 
     385  // get the extraction protocol count
    179386  public static int getExtractProtocolCount()
    180387  {
    181388    return extractProtocolCount;
    182389  }
    183 
     390  // get the hybidization protocol count
    184391  public static int getHybridizationProtocolCount()
    185392  {
    186393    return hybridizationProtocolCount;
    187394  }
    188 
     395  // get the labelling protocol count
    189396  public static int getLabelingProtocolCount()
    190397  {
    191398    return labelingProtocolCount;
    192399  }
    193 
    194   public static Set<String> getNewParameterHybSectionHeader()
    195   {
    196     return newParameterHybSectionHeader;
    197   }
    198 
     400  // get the sampling protocol count
    199401  public static int getSamplingProtocolCount()
    200402  {
    201403    return samplingProtocolCount;
    202404  }
    203 
     405  // get the scanning protocol count
    204406  public static int getScanningProtocolCount()
    205407  {
    206408    return scanningProtocolCount;
    207409  }
    208  
    209   private static void validateUsers()  //
    210   {
    211        
    212    
    213   }
    214  
     410
     411  // get the feature extraction protocol count
     412  public static int getFeProtocolCount()
     413  {
     414    return feProtocolCount;
     415  }
     416
     417  // get the parameter headers
     418  public Set<String> getParameterHeaders()
     419  {
     420    return parameterHeaders;
     421  }
     422  // get the bio material characteristics headers
     423  public Set<String> getBioMaterialXteristicsHeaders()
     424  {
     425    return bioMaterialXteristicsHeaders;
     426  }
     427
     428  // get the factor values header used in the experiment
     429  public static Set<String> getFactorValuesHybSectionHeader()
     430  {
     431    return factorValuesHybSectionHeader;
     432  }
     433
     434  // get the protocol Hyb section header
     435  public static Set<String> getProtocolHybSectionHeader()
     436  {
     437    return protocolHybSectionHeader;
     438  }
     439
     440
     441  public int getChannelNumber()
     442  {
     443    return channelNumber;
     444  }
     445
     446   void setChannelNumber(int channelNumber)
     447  {
     448    this.channelNumber = channelNumber;
     449  }
    215450}
Note: See TracChangeset for help on using the changeset viewer.