Changeset 1188


Ignore:
Timestamp:
Feb 11, 2010, 2:58:17 PM (12 years ago)
Author:
Jari Häkkinen
Message:

Committing patch provided by Gildas Le Corguillé

Location:
plugins/base2/uk.ac.ebi.tab2mage/trunk/Tab2MageExporter
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • plugins/base2/uk.ac.ebi.tab2mage/trunk/Tab2MageExporter/ChangeLog.txt

    • Property svn:keywords set to Id
    r500 r1188  
     1$Id$
     2
    13,____This file will contain information about changes in subsequent releases.
    24
    3 Latest version 2.0
    4 - Pooling of biomaterials - Pooled sample, extract, and labeled extract are now supported in this release.
     5version 1.0
     6- Pooling of biomaterials - Pooled sample, extract, and labeled
     7  extract are now supported in this release.
    58- Redesigned code to improve reuse.
     9
     10version 1.01 : 08/02/2010 - lecorguille
     11- Fix a problem with pooling which was not supported ... for me
     12- Modification : Filenames are use instead of RawBioAssays' names for
     13  File[raw] column in the Hybridization section
     14- Add the possibility to have several Files[raw] per RawBioAssay (ex :
     15  one cy3 and one cy5)
     16- Add a scan column in the Hybridization section
     17- Add a BioSourceDescription column in the Hybridization section
     18- Fix a problem with protocols in the Hybridization section
  • plugins/base2/uk.ac.ebi.tab2mage/trunk/Tab2MageExporter/README.txt

    • Property svn:keywords set to Id
    r502 r1188  
     1$Id$
     2
    13Release Note: Tab2Mage Export Current Implementation
    24==============================================
     
    911  Note: If you get a class Loader error while installing the exporter, you have two options:
    1012 
    11   i) Upgrade to BASE 2.4.6  or
     13  i) Upgrade to BASE 2.14.1  or
    1214  ii)  Place the two jar files: Tab2MageExporter.jar and ebi-plugins-utils.jar in your base installation classpath - i.e. : $BASE2_HOME/web-inf/lib, restart the tomcat server and proceed to install the plugin. In step (3) below, do not specify the plugin's path. Note that BASE do not recommend this approach but it's just a work around for a bug in base versions earlier than 2.4.6.
    1315 
     
    3941    - If experimental factors have not been specified for an experiment.
    4042    - Also, note that if experimental factors (annotation type) for an experiment have been specified, and the annotation types are shared to Project. Do set the     Project active before exporting in Tab2mage otherwise export fails.
    41     -Finally, if an array slide or array design has not been provided for Hybridization.
     43    - Finally, if an array slide or array design has not been provided for Hybridization.
    4244
    4345  Besides, using the experiment overview functionality would help to prevent most of these failure points.
  • plugins/base2/uk.ac.ebi.tab2mage/trunk/Tab2MageExporter/credit.txt

    • Property svn:keywords set to Id
    r447 r1188  
     1$Id$
     2
    13At this release, Nutribase developement team are  :
    24
     
    57
    68both based at the European Bioinformatics Institute, Cambridge, UK
     9
     10Release 1.01 :
     11 - Gildas Le Corguillé (lecorguille@sb-roscoff.fr) - Université Pierre
     12   et Marie Curie (UPMC), Station Biologique de Roscoff, FR
  • plugins/base2/uk.ac.ebi.tab2mage/trunk/Tab2MageExporter/src/uk/ac/ebi/nugo/common/Tab2MageConstants.java

    • Property svn:keywords set to Id
    r449 r1188  
    1 /* $Id: Tab2MageConstants.java 2006-08-08 dominic $
     1/* $Id$
     2
     3  Copyright (C) 2007, 2010 Authors contributing to this file.
    24
    35  This file is for NutriBASE - Nutrigenomics BioArray Software Environment.
    46  A customisation of the BASE SOFTWARE.
    5   Developed at the EBI , Cambridge.
    6   Author: Dominic Oyeniran: oyeniran@ebi.ac.uk
     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.
    722*/
     23
    824package uk.ac.ebi.nugo.common;
    925
     
    1733  @author Dominic Oyeniran
    1834  @version 1.0
     35 
     36 
     37  @author Gildas Le Corguillé
     38  @email lecorguille@sb-roscoff.fr
     39  @version 1.01
     40 
     41  ChangeLog :
     42    05/02/2010 - lecorguille : addition of Scan
     43    08/02/2010 - lecorguille : addition of BioSourceDescription
     44 
    1945 */
    2046public enum Tab2MageConstants
     
    112138  array_serial(26,"Array[serial]"),
    113139 
     140  scan(52, "Scan"),
     141 
    114142  hybridization(27, "Hybridization"),
    115143 
     
    123151 
    124152  biosource(32, "BioSource"),
     153 
     154  biosourcedescription(32, "BioSourceDescription"),
    125155 
    126156  protocol_transformation(33,"Protocol[transformation]"),
  • plugins/base2/uk.ac.ebi.tab2mage/trunk/Tab2MageExporter/src/uk/ac/ebi/nugo/common/ValueFormatter.java

    • Property svn:keywords set to Id
    r449 r1188  
    1 /*
    2 This file is for NutriBASE - Nutrigenomics BioArray Software Environment.
     1/* $Id$
     2
     3  Copyright (C) 2007, 2010 Authors contributing to this file.
     4
     5  This file is for NutriBASE - Nutrigenomics BioArray Software Environment.
    36  A customisation of the BASE SOFTWARE.
    4   Developed at the EBI , Cambridge.
    5   Author: Dominic Oyeniran: oyeniran@ebi.ac.uk
    6   */
     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*/
     23
    724package uk.ac.ebi.nugo.common;
    825
     
    1936  @email oyeniran@ebi.ac.uk
    2037  @version 1.0
     38 
     39 
     40  @author Gildas Le Corguillé
     41  @email lecorguille@sb-roscoff.fr
     42  @version 1.01
     43 
     44  ChangeLog :
     45    05/02/2010 - lecorguille : addition of getStringWithoutLineBreaker()
    2146*/
    2247
     
    2449  {
    2550 
    26   private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
     51  public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
    2752 
    2853  /**
     
    7297    return obj;
    7398  }
     99 
     100  /**
     101   * @author lecorguille
     102   This methods replace line breakers by space or nothing
     103   @param str<String>
     104   @return <String>
     105  */
     106  public static final String  getStringWithoutLineBreaker (String str)
     107  {
     108    String myreturn = new String();
     109    if (str != null && str != ""){
     110      myreturn = str.replaceAll("\n", " ").replaceAll("\r", "");
     111    }
     112    return myreturn; 
     113  }
    74114
    75115  /**
     
    97137    return  value;
    98138  }
    99  
    100    
    101139
    102140}
  • plugins/base2/uk.ac.ebi.tab2mage/trunk/Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/Tab2MageExporter.java

    • Property svn:keywords set to Id
    r488 r1188  
    1 /* $Id: Tab2MageExporter.java 2007-09-01 dominic $
    2 
    3   Copyright (C) 2007 Authors contributing to this file.
     1/* $Id$
     2
     3  Copyright (C) 2007, 2010 Authors contributing to this file.
    44
    55  This file is for NutriBASE - Nutrigenomics BioArray Software Environment.
     
    2424
    2525
    26 import java.io.Writer;
    2726import java.util.ArrayList;
    2827import java.util.Arrays;
     
    3534import java.util.concurrent.ConcurrentHashMap;
    3635
    37 import net.sf.basedb.core.Affymetrix;
    3836import net.sf.basedb.core.Annotatable;
    3937import net.sf.basedb.core.Annotation;
     
    8078import uk.ac.ebi.nugo.common.Helper;
    8179import uk.ac.ebi.nugo.common.Tab2MageConstants;
     80import uk.ac.ebi.nugo.common.ValueFormatter;
    8281import uk.ac.ebi.nugo.plugins.ta2mageexport.ExportHelper;
    8382import uk.ac.ebi.nugo.plugins.ta2mageexport.Tab2MageFileWriter;
     
    9291  @email oyeniran@ebi.ac.uk /doyeniran@gmail.com
    9392  @version 1.0
     93 
     94 
     95  @author Gildas Le Corguillé
     96  @email lecorguille@sb-roscoff.fr
     97  @version 1.01
     98 
     99  ChangeLog :
     100    05/02/2010 - lecorguille : modification of a lot of things about pooling depending of the other class
     101                      now, lines are repeated if there are several files per RawBioAssay or pooling of Sample, Extract or LabeledExtract
     102                   Tab2Mage format doesn't support pooling like Base2 does :
     103                    - Base2 pool 2 Samples in a Ref Sample
     104                    - Tab2Mage format pool 2 BioSources in the Ref Sample
     105    08/02/2010 - lecorguille : addition of BioSourceDescription
    94106
    95107*/
     
    277289    Set<String> hybSectionHeader= new LinkedHashSet<String>();
    278290    Set<String>  protocolHybSectionHeader= new LinkedHashSet<String>();
    279  
     291
    280292    boolean overwrite = false;
    281293     
     
    284296      dc=sc.newDbControl();
    285297      User user = User.getById(dc, sc.getLoggedInUserId());
     298     
     299
     300      /* -- output files -- */
    286301      if ((Boolean)job.getValue("overwrite") != null) overwrite = (Boolean)job.getValue("overwrite");
    287302      String p = (String)job.getValue("exportPath");
     
    289304      String statusp=(String)job.getValue("statusPath");
    290305      File statusFile=Helper.processFilePath(user,overwrite, dc,statusp);
     306      Tab2MageFileWriter.createFileWriters(file, statusFile);
     307     
     308     
     309      /* --- Experiment --- */
    291310      Experiment experiment= (Experiment)job.getValue("experiment");
    292       experiment= Experiment.getById(dc,experiment.getId());
    293                
     311      experiment= Experiment.getById(dc,experiment.getId());     
     312     
    294313      //  check if the logged in user owned the experiment, if not the export exit with a message.
    295      
    296       if (!(experiment.getOwner().equals(user)))
    297       {
     314      if (!(experiment.getOwner().equals(user))) {
    298315        response.setError("[EXPORT FAILED: User - "+user.getName()+ " do not own this experiment or have permission to export it].", Arrays.asList(new Throwable()));
    299316        return;
    300317      }
    301        if (experiment.getExperimentalFactors().list(dc).size()==0)
    302       {
     318       if (experiment.getExperimentalFactors().list(dc).size()==0) {
    303319        response.setError("[EXPORT FAILED: Experimental factors have not been specified for this experiment].", Arrays.asList(new Throwable()));
    304320        return; 
    305321      }
    306            
    307       // check that raw bio assays have been added to experiment, otherwise fails
    308      
     322       
     323       
     324      /* --- RawBioAssay --- */
    309325      ItemQuery<RawBioAssay> rawBioAssaysQuery = experiment.getRawBioAssays();
    310326      rawBioAssaysQuery.order(Orders.asc(Hql.property("name")));
    311327      ItemResultList<RawBioAssay> rawBioAssays= rawBioAssaysQuery.list(dc);
    312       if (rawBioAssays==null || rawBioAssays.size()==0)
    313       {
     328     
     329      // check that raw bio assays have been added to experiment, otherwise fails
     330      if (rawBioAssays==null || rawBioAssays.size()==0) {
    314331        response.setError("[EXPORT FAILED: Experiment - "+ experiment+ " do not have a rawbiosay specified].",Arrays.asList(new Throwable()));
    315332        return;
    316333      }
    317334     
    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 ();
     335     
     336      // initialise, count resources used, create concurrentmap for all parameter and biomaterial headers
     337      Tab2MageValidator validator = new Tab2MageValidator (rawBioAssays, sc, response);
     338     
    326339     
    327340      for (RawBioAssay rba : rawBioAssays)
    328341      {
    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                        
    337         /*
    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())
     342        Set<Tab2MageHybridizationLine> hybRows = ExportHelper.getRawBioAssayFiles(rba, dc, response);
     343        for (Tab2MageHybridizationLine hybRow : hybRows) {         
     344         
     345         
     346          /* --- Array design ---*/
     347          ArrayDesign arrayDesign = rba.getArrayDesign();
     348          hybRow.set("Array",Tab2MageConstants.array_accession.getName(),arrayDesign.getName());
     349          setProtocolAndParameterAtrributes(hybRow,rba,Tab2MageValidator.getFeProtocolCount(), Tab2MageConstants.protocol_featureextraction.getName(), response, dc);
     350         
     351         
     352          /* --- Scan --- */
     353          Scan scan= rba.getScan();
     354          hybRow.set(Tab2MageConstants.scan.getName(), null,scan.getName());
     355          setProtocolAndParameterAtrributes(hybRow,scan,Tab2MageValidator.getScanningProtocolCount(), Tab2MageConstants.protocol_scanning.getName(),response, dc);
     356         
     357         
     358          /* --- Experimental factor section --- */
     359          AnnotationSet annotationSet = rba.isAnnotated() ? rba.getAnnotationSet() : null;
     360          ItemQuery<AnnotationType> experimentalFactorsQuery = experiment.getExperimentalFactors();
     361          experimentalFactorsQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT, Include.NOT_REMOVED);
     362          ItemResultList<AnnotationType> experimentalFactors = experimentalFactorsQuery.list(dc);
     363          for (AnnotationType exprFactor :experimentalFactors)
    347364          {
    348             if (annotationSet!=null)
    349             {
    350               Annotation an= annotationSet.findAnnotation(exprFactor);
    351               /*
    352                 Please use the line below instead of the one above for base 2.5 API to get inherited annotation types.
    353               Annotation an = annotationSet.findAnnotations(exprFactor);
    354               List<Annotation> findAnnotations(dc, exprFactor, true);
    355               Loop through the list.....needs more check
    356               */
    357              
    358               if (an!=null) //exprFacor has annotations
    359               {
    360                 List<?> values=  an.getValues();
    361                 hybRow.set("FactorValue", exprFactor.getName(), values==null || values.size()==0 ? "" : Values.getString(values, ", ", true));
     365            if (!exprFactor.isRemoved()) {
     366              if (annotationSet!=null) {
     367                Annotation an= annotationSet.findAnnotation(exprFactor);
     368                /*
     369                  Please use the line below instead of the one above for base 2.5 API to get inherited annotation types.
     370                Annotation an = annotationSet.findAnnotations(exprFactor);
     371                List<Annotation> findAnnotations(dc, exprFactor, true);
     372                Loop through the list.....needs more check
     373                */
     374               
     375                if (an!=null) { //exprFacor has annotations
     376                  List<?> values=  an.getValues();
     377                  hybRow.set("FactorValue", exprFactor.getName(), values==null || values.size()==0 ? "" : Values.getString(values, ", ", true));
     378                }
     379                else { // exprFactor has no annotations
     380                  hybRow.set("FactorValue", exprFactor.getName(), "" );
     381                }
    362382              }
    363               else // exprFactor has no annotations
    364               {
     383              else { //The raw bio assay is not annotated
    365384                hybRow.set("FactorValue", exprFactor.getName(), "" );
    366385              }
    367386            }
    368             else //The raw bio assay is not annotated
    369             {
    370               hybRow.set("FactorValue", exprFactor.getName(), "" );
    371             }
    372387          }
    373         }
    374        
    375             //Array Design
    376         ArrayDesign arrayDesign = null;
    377         try
    378         {
    379           arrayDesign= rba.getArrayDesign();
    380         }
    381         catch(Throwable tr)
    382         {
    383           response.setError("[EXPORT FAILED: All Array Design(s) must be provided in BASE to continue].",Arrays.asList(tr));
    384         }
    385         // Populate the Array file map in HybLine
    386         setArraysAttributes(hybRow, arrayDesign );
    387        
    388         // Populate the Data file map in HybLine
    389         setFileAttributes(hybRow, arrayDesign, rba, response);
    390        
    391         //Raw BioAssay protocol and parameter
    392         setProtocolAndParameterAtrributes(hybRow,rba,Tab2MageValidator.getFeProtocolCount(),
    393             Tab2MageConstants.protocol_featureextraction.getName(), response, dc);
    394        
    395         //Scanning Protocol and Parameters
    396         Scan scan= rba.getScan();
    397         setProtocolAndParameterAtrributes(hybRow,scan,Tab2MageValidator.getScanningProtocolCount(),
    398             Tab2MageConstants.protocol_scanning.getName(),response, dc);
    399        
    400         /*
    401           Array Slide
    402          */
    403         Hybridization hyb= scan.getHybridization();
    404         if (hyb.getArraySlide()==null)
    405         {   
    406           response.setError("[Export Failed] please add an array slide for Hybridization:"+hyb.getName(), Arrays.asList(new Throwable()));
    407           return;
    408         }
    409         else
    410         {
     388         
     389         
     390           
     391          /* --- Hybridization --- */
     392          Hybridization hyb = scan.getHybridization();
     393          hybRow.set(Tab2MageConstants.hybridization.getName(), null,hyb.getName());
     394          setProtocolAndParameterAtrributes(hybRow,hyb,Tab2MageValidator.getHybridizationProtocolCount(), Tab2MageConstants.protocol_hyb.getName(), response, dc);
     395         
     396          /* --- Array slide --- */
    411397          hybRow.set("Array","serial", hyb.getArraySlide().getName());
    412         }
    413          
    414         /*
    415           Hybridization
    416          */
    417         hybRow.set(Tab2MageConstants.hybridization.getName(), null,hyb.getName());
    418         BioMaterialEvent bioMaterialEvent= hyb.getCreationEvent(); // an event that created the hyridization
    419      
    420         // Hybridization protocol and parameter
    421         setProtocolAndParameterAtrributes(hybRow,hyb,Tab2MageValidator.getHybridizationProtocolCount(),
    422             Tab2MageConstants.protocol_hyb.getName(), response, dc);
    423        
    424         ItemQuery<LabeledExtract> labeledExtractQuery =(ItemQuery<LabeledExtract>) bioMaterialEvent.getSources(); // get all the labeled extract
    425         ItemResultList<LabeledExtract> labeledExtracts= labeledExtractQuery .list(dc);
    426         int size = labeledExtracts.size();
    427        
    428         // create the Tab2MageSubHybLine object List
    429         List<Tab2MageSubHybLine> subLines = new ArrayList<Tab2MageSubHybLine>();
    430        
    431         int count=1; // initialise the count variable to 1
    432         // Loop through all the labeled extracts
    433         for (LabeledExtract labeledExtract :labeledExtracts) // can have more than one labeled extract (e.g. 2 color experiments)
    434         {
    435           //create the new SubHyb Line
    436           Tab2MageSubHybLine subLine = new Tab2MageSubHybLine();
    437          
    438           /*
    439             labeled extract
    440            */
    441           Protocol lbExtractProtocol= labeledExtract.getCreationEvent().getProtocol();
    442           subLine.set(Tab2MageConstants.labeledextract.getName(), null, labeledExtract.getName());
    443          
    444             // labelling protocol and parameter
    445           setProtocolAndParameterAtrributes(dc, subLine,labeledExtract,Tab2MageValidator.getLabelingProtocolCount(),
    446               Tab2MageConstants.protocol_labeling.getName(),lbExtractProtocol, response);
    447           /*
    448             Label
    449            */
    450           String labelName= labeledExtract.getLabel().getName(); // the name of the label
    451           subLine.set(Tab2MageConstants.dye.getName(), null,labelName);
    452                          
    453           /*
    454             Extract
    455           */
    456          
    457           Extract extract= ExportHelper.getExtract(labeledExtract, dc);
    458           if (extract!=null)
    459           {
    460             Protocol extractProtocol =extract.getCreationEvent().getProtocol(); //extract protocol
    461             subLine.set(Tab2MageConstants.extract.getName(), null, extract.getName());
     398         
     399          // create the Tab2MageSubHybLine object List
     400          List<Tab2MageSubHybLine> subLines = new ArrayList<Tab2MageSubHybLine>();
     401         
     402          /* --- labeled extract --- */
     403          BioMaterialEvent bioMaterialEvent= hyb.getCreationEvent(); // an event that created the hyridization
     404          ItemQuery<LabeledExtract> labeledExtractQuery =(ItemQuery<LabeledExtract>) bioMaterialEvent.getSources(); // get all the labeled extract
     405          ItemResultList<LabeledExtract> labeledExtracts= labeledExtractQuery.list(dc);
     406          int size = labeledExtracts.size();
     407          for (LabeledExtract labeledExtract :labeledExtracts) { // can have more than one labeled extract (e.g. 2 color experiments)
     408                       
     409            /* --- Label --- */
     410            String labelName = labeledExtract.getLabel().getName(); // the name of the label
     411             
    462412           
    463             // extraction protocol  and parameter
    464             setProtocolAndParameterAtrributes(dc, subLine,extract,Tab2MageValidator.getExtractProtocolCount(),
    465                 Tab2MageConstants.protocol_extraction.getName(), extractProtocol, response);
    466           }
    467          
    468           /*
    469             Sample
    470           */
    471          
    472           Sample sample= ExportHelper.getSample(extract, dc);
    473           if (sample != null)
    474           {
    475             Protocol sampleProtocol=sample.getCreationEvent().getProtocol();    //sampling protocol
    476             subLine.set(Tab2MageConstants.sample.getName(), null, sample.getName());
    477            
    478             // sampling protocol and parameter
    479             setProtocolAndParameterAtrributes(dc, subLine,sample,Tab2MageValidator.getSamplingProtocolCount(),
    480                 Tab2MageConstants.protocol_treatment.getName(),sampleProtocol, response );
    481           }
    482          
    483           /* 
    484             Biosource
    485            */
    486          
    487           BioSource  bioSource=ExportHelper.getBioSource(sample, dc);
    488           if (bioSource != null)
    489           {
    490             subLine.set(Tab2MageConstants.biosource.getName(), null, bioSource.getName());
    491            
    492             //section for biomaterial xterixtics
    493             ItemQuery<Annotation> query = bioSource.getAnnotationSet().getAnnotations();
    494             query.include(Include.MINE, Include.NOT_REMOVED, Include.IN_PROJECT,Include.SHARED);
    495             List<Annotation> annotations = query.list(dc);
    496             for (Annotation annotation: annotations)
    497             {
    498               AnnotationType at=annotation.getAnnotationType();
    499               if(!at.isRemoved())
    500               {
    501                 List<?> values= annotation==null? null:annotation.getValues();
    502                 subLine.set(Tab2MageConstants.bio_mat_charact.getName(), annotation.getAnnotationType().getName(),
    503                     values==null || values.size()==0 ? ExportHelper.getDefaultValue(at) : Values.getString(values, ", ", true));
     413            /* --- Extracts --- */
     414            Set<Extract> extracts = ExportHelper.getExtracts(labeledExtract, dc);
     415            for (Extract extract : extracts) {
     416             
     417              /* --- Samples --- */
     418              Set<Sample> samples = ExportHelper.getSamples(extract, dc);
     419              for (Sample sample : samples) {
     420               
     421                /* --- Biosources --- */
     422                Set<BioSource> bioSources = ExportHelper.getBioSources(sample, dc);
     423                for (BioSource bioSource : bioSources) {
     424                 
     425                  //create the new SubHyb Line
     426                  Tab2MageSubHybLine subLine = new Tab2MageSubHybLine();
     427                 
     428                  subLine.set(Tab2MageConstants.labeledextract.getName(), null, labeledExtract.getName());
     429                  setProtocolAndParameterAtrributes(subLine,labeledExtract,Tab2MageValidator.getLabelingProtocolCount(), Tab2MageConstants.protocol_labeling.getName(),response, dc);
     430                  subLine.set(Tab2MageConstants.dye.getName(), null,labelName);
     431                  subLine.set(Tab2MageConstants.extract.getName(), null, extract.getName());
     432                  setProtocolAndParameterAtrributes(subLine,extract,Tab2MageValidator.getExtractProtocolCount(), Tab2MageConstants.protocol_extraction.getName(), response, dc);
     433                  subLine.set(Tab2MageConstants.sample.getName(), null, sample.getName());
     434                  setProtocolAndParameterAtrributes(subLine,sample,Tab2MageValidator.getSamplingProtocolCount(), Tab2MageConstants.protocol_treatment.getName(), response, dc);
     435                  subLine.set(Tab2MageConstants.biosource.getName(), null, bioSource.getName());
     436                  subLine.set(Tab2MageConstants.biosourcedescription.getName(), null, ValueFormatter.getStringWithoutLineBreaker(bioSource.getDescription()));
     437                 
     438                  //section for biomaterial xterixtics
     439                  ItemQuery<Annotation> query = bioSource.getAnnotationSet().getAnnotations();
     440                  query.include(Include.MINE, Include.NOT_REMOVED, Include.IN_PROJECT,Include.SHARED);
     441                  List<Annotation> annotations = query.list(dc);
     442                  for (Annotation annotation: annotations)
     443                  {
     444                    AnnotationType at=annotation.getAnnotationType();
     445                    if(!at.isRemoved())
     446                    {
     447                      List<?> values= annotation==null? null:annotation.getValues();
     448                      subLine.set(Tab2MageConstants.bio_mat_charact.getName(), annotation.getAnnotationType().getName(),
     449                          values==null || values.size()==0 ? ExportHelper.getDefaultValue(at) : Values.getString(values, ", ", true));
     450                    }
     451                  }
     452                 
     453                 
     454                  subLines.add(subLine);  //make a list of subLines
     455                }
    504456              }
    505457            }
    506           }
    507        
    508           subLines.add(subLine);  //make a list of subLines
    509           count++;
    510         } //end of labeled extract loop
    511      
    512         hybRow.addHybSubLines(size, hybRow.getName(), subLines); // add the subLines (i.e. Tab2MageSubHybLine objectc list to Tab2MageHybridizationLine Object
    513          
    514         hybridization.addLine(hybRow);  // add Tab2MageHybridizationLine Object to Tab2MageHybridization object
    515         if(!hybs.contains(hybridization))
    516           hybs.add(hybridization);    // add Tab2MageHybridization Object to the List of Tab2MageHybridization object
     458          } //end of labeled extract loop
     459          hybRow.addHybSubLines(size, hybRow.getName(), subLines); // add the subLines (i.e. Tab2MageSubHybLine object list to Tab2MageHybridizationLine Object
     460
     461         
     462          // create the Tab2MageHybridization object
     463          Tab2MageHybridization hybridization= new Tab2MageHybridization ();
     464          // set the number of channels for the Hybridization
     465          hybridization.setChannelNumber(validator.getChannelNumber()); // mainly useful during the writing stage
     466          hybridization.addLine(hybRow);  // add Tab2MageHybridizationLine Object to Tab2MageHybridization object
     467          if(!hybs.contains(hybridization))
     468            hybs.add(hybridization);    // add Tab2MageHybridization Object to the List of Tab2MageHybridization object
     469        }
    517470     
    518471      }// end of raw biossay for loop
    519      
    520472      // create headers for biomaterial xteristics
    521473      Set<String> bioMatHeaders = new LinkedHashSet<String>();
     
    547499        factorValueHeaders.addAll(ExportHelper.getHeaderWithValuesOnly(l.getFactorValues()));
    548500      }
    549      
    550501      /*
    551502        Create all the used protocols objects
    552503       */
    553504      protocols = ExportHelper.createProtocols(rawBioAssays, dc);
    554      
    555505      /*
    556506        create all used Tab2Mage Hybridization sections protocol headers
    557507       */
    558508      protocolHybSectionHeader= Tab2MageValidator.getProtocolHybSectionHeader();
    559      
    560509      /*
    561510        Create Tab2Mage Hybridization Section Header
     
    570519      Tab2MageFileWriter.writeTab2MageFile(experiment, protocols,hybs, hybSectionHeader,bioMatHeaders,
    571520                      protocolHybSectionHeader, paramHeaders,factorValueHeaders, job, response, dc);
    572      
    573       //statusOut.close();
    574       Writer out= Tab2MageFileWriter.getOut();
    575       out.flush();
    576       out.close();
     521      Tab2MageFileWriter.getStatusOut().write("DONE\n");
     522      Tab2MageFileWriter.closeWriter();
     523     
    577524      dc.commit();
    578525      response.setDone("Experiment " + experiment.getName() + " exported successfully");
     
    580527    catch (Throwable ex)
    581528    {
     529      Tab2MageFileWriter.closeWriter();
    582530      response.setError(ex.getMessage(), Arrays.asList(ex));
    583531    }
    584532    finally
    585533    {
     534      Tab2MageFileWriter.closeWriter();
    586535      if (dc != null) dc.close();
    587536    }       
    588537  }
    589  
    590   /**
    591     set the array attributes  of the the <code>Tab2MageHybridizationLine</code> object
    592       @param hybRow, the <code>Tab2MageHybridizationLine</code> object
    593       @param arrayDesign, the Array Design
    594    */
    595   private void setArraysAttributes (Tab2MageHybridizationLine hybRow, ArrayDesign arrayDesign )
    596   {
    597     hybRow.set("Array",Tab2MageConstants.array_accession.getName(),arrayDesign.getName());
    598   }
    599  
    600   /**
    601     set the file attributes  of the the <code>Tab2MageHybridizationLine</code> object
    602       @param hybRow, the Tab2MageHybridizationLine object
    603       @param arrayDesign, the Array Design
    604       @param rba, the raw bio assay
    605       @param response, the response object to return errors in case of failure during the setting of file values
    606    */
    607   private void setFileAttributes(Tab2MageHybridizationLine hybRow, ArrayDesign arrayDesign, RawBioAssay rba, Response response)
    608   {
    609     try
    610     {
    611       if (arrayDesign.isAffyChip())
    612       {
    613         File cdfFile= Affymetrix.getCdfFile(arrayDesign);
    614         File celFile=Affymetrix.getCelFile(rba);
    615         hybRow.set("File", Tab2MageConstants.raw_file.getName(), celFile.getName());
    616         hybRow.set("File",Tab2MageConstants.cdf_file.getName(), cdfFile.getName());
    617       }
    618       else
    619       {
    620         hybRow.set("File", Tab2MageConstants.raw_file.getName(), rba.getName());
    621       }
    622      
    623     }
    624     catch(Throwable tr)
    625     {
    626       response.setError(tr.getMessage(), Arrays.asList(tr));
    627     }
    628   }
     538
    629539  /**
    630540    set the protocol and parameters attributes/values for Labeling -to- Sampling protocol and parameters
     
    637547      @param response, the response object to return errors in case of failure during the setting of parameter values
    638548   */
    639   private void setProtocolAndParameterAtrributes(DbControl dc,Tab2MageSubHybLine subLine, Annotatable anotatable, int protocolCount, String keyEntry, Protocol protocol, Response response)
     549  private void setProtocolAndParameterAtrributes(Tab2MageSubHybLine subLine, Annotatable anotatable, int protocolCount, String keyEntry, Response response, DbControl dc)
    640550  {
    641551    if (protocolCount>0)
    642552    {
    643       subLine.set("Protocol",keyEntry,ExportHelper.getFormattedProtocolId(protocol));
     553      subLine.set("Protocol",keyEntry,ExportHelper.getFormattedProtocolId(anotatable.getProtocol()));
    644554    }
    645555           
     
    662572    if (protocolCount>0)
    663573    {
    664       hybRow.set("Protocol", keyEntry, ExportHelper.getFormattedProtocolId(anotatable.getProtocol()));
     574      hybRow.set("Protocol",keyEntry,ExportHelper.getFormattedProtocolId(anotatable.getProtocol()));
    665575    }
    666576      //  protocol parameter
  • plugins/base2/uk.ac.ebi.tab2mage/trunk/Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/ExportHelper.java

    • Property svn:keywords set to Id
    r449 r1188  
     1/* $Id$
     2
     3  Copyright (C) 2007, 2010 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*/
     23
    124package uk.ac.ebi.nugo.plugins.ta2mageexport;
    225
     26import java.util.Arrays;
    327import java.util.LinkedHashSet;
    428import java.util.List;
     
    630import java.util.Set;
    731
     32import net.sf.basedb.core.Affymetrix;
    833import net.sf.basedb.core.Annotatable;
    934import net.sf.basedb.core.AnnotationType;
     35import net.sf.basedb.core.ArrayDesign;
    1036import net.sf.basedb.core.BaseException;
    1137import net.sf.basedb.core.BioSource;
     
    1339import net.sf.basedb.core.Directory;
    1440import net.sf.basedb.core.Extract;
     41import net.sf.basedb.core.File;
     42import net.sf.basedb.core.FileSetMember;
    1543import net.sf.basedb.core.Hybridization;
     44import net.sf.basedb.core.ItemQuery;
    1645import net.sf.basedb.core.ItemResultList;
    1746import net.sf.basedb.core.LabeledExtract;
     
    2352import net.sf.basedb.core.SessionControl;
    2453import net.sf.basedb.core.User;
     54import net.sf.basedb.core.plugin.Response;
    2555import uk.ac.ebi.nugo.common.Tab2MageConstants;
    2656
     
    3060  @author Dominic Oyeniran
    3161  @version 1.0
     62 
     63 
     64  @author Gildas Le Corguillé
     65  @email lecorguille@sb-roscoff.fr
     66  @version 1.01
     67 
     68  ChangeLog :
     69    05/02/2010 - lecorguille : modifification of the getItems fonctions to allow pooling
     70    05/02/2010 - lecorguille : substitution of RawBioAssay names in the File[Raw] be the filenames
     71   
    3272*/
    3373
    3474public class ExportHelper
    3575{
    36    public static Set<Sample> getSamples(Annotatable item, DbControl dc)
     76 
     77   /**
     78    * @deprecated by lecorguille
     79    * @param item
     80    * @param dc
     81    * @return
     82    */
     83   public static Set<Sample> getSamplesBk(Annotatable item, DbControl dc)
    3784   {
    3885    Set<Sample> itemList= new LinkedHashSet<Sample>();
     
    54101   
    55102   /**
     103    * @deprecated by lecorguille
    56104      gets a sample from extract.
    57105      returns the first item at random, if extract is pooled
     
    60108     @return Sample
    61109  */
    62    public static Sample getSample(Annotatable extract, DbControl dc)
     110   public static Sample getSampleBk(Annotatable extract, DbControl dc)
    63111    {
    64112      Sample sample=null;
     
    87135   
    88136  /**
     137   * @deprecated by lecorguille
    89138      gets an extract from a labeled extract.
    90139      returns the first item at random, if labeled extract is pooled
     
    93142      @return extract
    94143   */
    95    public static Extract getExtract(Annotatable labeledExtract, DbControl dc)
     144   public static Extract getExtractBk(Annotatable labeledExtract, DbControl dc)
    96145    {
    97146      Extract extract=null;
     
    118167      return extract;
    119168    }
    120    
    121    
    122    public static Set<Extract> getExtracts(Annotatable item, DbControl dc)
    123    {
    124     Set<Extract> itemList= new LinkedHashSet<Extract>();
    125     Set<Annotatable> pooledObjects= item.getAnnotatableParents();
    126     for (Annotatable pooled: pooledObjects)
    127     {
    128       if (pooled instanceof LabeledExtract)
    129       {
    130         Set<Annotatable> extracts= pooled.getAnnotatableParents();
    131         for (Annotatable extractItem: extracts)
    132         {
    133           Extract extract= Extract.getById(dc, extractItem.getId());
    134           itemList.add(extract);
    135         }
    136       }
    137     }
    138     return itemList;
    139     }
    140  
    141    
    142    public static Set<BioSource> getBiosources(MeasuredBioMaterial item, DbControl dc)
     169 
     170   /**
     171    * @deprecated by lecorguille
     172    * @param item
     173    * @param dc
     174    * @return
     175    */
     176   public static Set<BioSource> getBiosourcesBk(MeasuredBioMaterial item, DbControl dc)
    143177   {
    144178    Set<BioSource> bioSourceList= new LinkedHashSet<BioSource>();
     
    159193    }
    160194 
    161    
    162    /**
     195   /**
     196    * @deprecated by lecorguille
    163197        gets a biosource from sample.
    164198      returns the first item at random, if sample is pooled
     
    167201     @return BioSource
    168202   */
    169      
    170    public static BioSource getBioSource(Annotatable sample, DbControl dc)
     203   public static BioSource getBioSourceBk(Annotatable sample, DbControl dc)
    171204    {
    172205      BioSource biosource=null;
     
    194227
    195228    }
     229   
     230   /**
     231    * @author lecorguille
     232    * Return a Extract from a non-pooling LabeledExtract.
     233    * @param labeledExtract
     234    * @param dc the database control
     235    * @return Extract
     236    */
     237   private static Extract getExtract(LabeledExtract labeledExtract, DbControl dc) {
     238     Extract extract=null;
     239     
     240     Set<Annotatable> extractAnnots = labeledExtract.getAnnotatableParents();
     241     for (Annotatable extractAnnot : extractAnnots) {
     242       extract = Extract.getById(dc, extractAnnot.getId());
     243     }
     244     return extract;
     245   }
     246   
     247   /**
     248    * @author lecorguille
     249    * Return a set of Extract from a LabeledExtract.
     250    * this method can return several Extracts if there is a LabeledExtract pooling
     251    * @param labeledExtract
     252    * @param dc the database control
     253    * @return Set<Extract>
     254    */
     255   public static Set<Extract> getExtracts(LabeledExtract labeledExtract, DbControl dc) {
     256     
     257    Set<Extract> itemList= new LinkedHashSet<Extract>();
     258   
     259    // not pooled
     260    if (!labeledExtract.isPooled()) {
     261      itemList.add(getExtract(labeledExtract, dc));
     262    }
     263    // pooled
     264    else {
     265      Set<Annotatable> labeledExtractPoolAnnots = labeledExtract.getAnnotatableParents();
     266      for (Annotatable labeledExtractPoolAnnot : labeledExtractPoolAnnots) {
     267        LabeledExtract labeledExtractPooled = LabeledExtract.getById(dc, labeledExtractPoolAnnot.getId());
     268        itemList.add(getExtract(labeledExtractPooled, dc));
     269      }
     270    }
     271   
     272    return (itemList);
     273   }
     274
     275   /**
     276    * @author lecorguille
     277    * Return a Sample from a non-pooling Extract.
     278    * @param extract
     279    * @param dc the database control
     280    * @return Sample
     281    */
     282   private static Sample getSample(Extract extract, DbControl dc) {
     283     Sample sample=null;
     284     
     285     Set<Annotatable> sampleAnnots = extract.getAnnotatableParents();
     286     for (Annotatable sampleAnnot : sampleAnnots) {
     287       sample = Sample.getById(dc, sampleAnnot.getId());
     288     }
     289     return sample;
     290   }
     291   
     292   /**
     293    * @author lecorguille
     294    * Return a set of Sample from a Extract.
     295    * this method can return several Samples if there is a Extract pooling
     296    * @param extract
     297    * @param dc the database control
     298    * @return Set<Sample>
     299    */
     300   public static Set<Sample> getSamples(Extract extract, DbControl dc)
     301   {
     302    Set<Sample> itemList= new LinkedHashSet<Sample>();
     303   
     304    // not pooled
     305    if (!extract.isPooled()) {
     306      itemList.add(getSample(extract, dc));
     307    }
     308    // pooled
     309    else {
     310      Set<Annotatable> extractPoolAnnots = extract.getAnnotatableParents();
     311      for (Annotatable extractPoolAnnot : extractPoolAnnots) {
     312        Extract extractPooled = Extract.getById(dc, extractPoolAnnot.getId());
     313        itemList.add(getSample(extractPooled, dc));
     314      }
     315    }
     316   
     317    return (itemList);
     318   }
     319   
     320   /**
     321    * @author lecorguille
     322    * Return a Biosource from a non-pooling Sample.
     323    * @param sample
     324    * @param dc the database control
     325    * @return BioSource
     326    */
     327   private static BioSource getBioSource(Sample sample, DbControl dc) {
     328     BioSource bioSource=null;
     329     
     330     Set<Annotatable> bioSourceAnnots = sample.getAnnotatableParents();
     331     for (Annotatable bioSourceAnnot : bioSourceAnnots) {
     332       bioSource = BioSource.getById(dc, bioSourceAnnot.getId());
     333     }
     334     return bioSource;
     335   }
     336   
     337   /**
     338    * @author lecorguille
     339    * Return a set of Biosource from a Sample.
     340    * this method can return several Biosources if there is a Sample pooling
     341    * @param sample
     342    * @param dc the database control
     343    * @return Set<BioSource>
     344    */
     345   public static Set<BioSource> getBioSources(Sample sample, DbControl dc)
     346   {
     347    Set<BioSource> itemList= new LinkedHashSet<BioSource>();
     348   
     349    // not pooled
     350    if (!sample.isPooled()) {
     351      itemList.add(getBioSource(sample, dc));
     352    }
     353    // pooled
     354    else {
     355      Set<Annotatable> samplePoolAnnots = sample.getAnnotatableParents();
     356      for (Annotatable samplePoolAnnot : samplePoolAnnots) {
     357        Sample samplePooled = Sample.getById(dc, samplePoolAnnot.getId());
     358        itemList.add(getBioSource(samplePooled, dc));
     359      }
     360    }
     361   
     362    return (itemList);
     363    }
     364   
     365   /**
     366    * @author lecorguille
     367    * Return a set of Tab2MageHybridizationLine from a RawBioAssay.
     368    * This method can return several lines if there is several Files for the RawBioAssay (ex: Nimblegen 2 channels <=> 2 files per scan)
     369    * @param rba
     370    * @param dc the database control
     371    * @param response
     372    * @return Set<Tab2MageHybridizationLine>
     373    * @TODO use non-deprecated methods for Affymetrix
     374    * @TODO it's not very clean but it's work without huge modifications
     375    */
     376   public static Set<Tab2MageHybridizationLine> getRawBioAssayFiles(RawBioAssay rba, DbControl dc, Response response) {
     377     Set<Tab2MageHybridizationLine> itemList= new LinkedHashSet<Tab2MageHybridizationLine>();
     378     
     379     try
     380    {
     381      if (rba.getArrayDesign().isAffyChip())
     382      {
     383        Tab2MageHybridizationLine hybRow = new Tab2MageHybridizationLine();
     384
     385        File celFile=Affymetrix.getCelFile(rba);
     386        File cdfFile= Affymetrix.getCdfFile(rba.getArrayDesign());
     387       
     388        hybRow.set("File", Tab2MageConstants.raw_file.getName(), celFile.getName());
     389        hybRow.set("File",Tab2MageConstants.cdf_file.getName(), cdfFile.getName());
     390       
     391        itemList.add(hybRow);
     392      }
     393      else
     394      {
     395        ItemQuery<FileSetMember> fileSetMemberQuery =(ItemQuery<FileSetMember>) rba.getFileSet().getMembers(); // get all the labeled extract
     396        ItemResultList<FileSetMember> fileSetMembers= fileSetMemberQuery.list(dc);
     397       
     398        for (FileSetMember fileSetMember :fileSetMembers) {
     399          Tab2MageHybridizationLine hybRow = new Tab2MageHybridizationLine();
     400          hybRow.set("File", Tab2MageConstants.raw_file.getName(), fileSetMember.getFile().getName());
     401          itemList.add(hybRow);
     402        }       
     403      }
     404    }
     405    catch(Throwable tr)
     406    {
     407      response.setError(tr.getMessage(), Arrays.asList(tr));
     408    }
     409   
     410    return itemList;
     411   }
    196412   
    197413   /**
     
    227443    return at.getDefaultValue()!=null? at.getDefaultValue():"";
    228444  }
    229  
    230445   
    231446  /**
     
    235450   */
    236451 
    237   @SuppressWarnings("unchecked")
    238452  public static Set<String> createHybridizationSectionHeader( DbControl dc, List<Tab2MageHybridization> hybList,
    239453                              Set<String> bioXterHybSectionHeader, Set<String> protocolHybSectionHeader,
     
    266480          hybHeader.add("FactorValue["+factorValueHeader+"]");
    267481        }
     482       
     483        if (l.getScan()!=null && l.getScan().length()!=0)
     484          hybHeader.add(Tab2MageConstants.scan.getName());
    268485                   
    269486        if (l.getHybridization()!=null && l.getHybridization().length()!=0)
     
    311528  }
    312529 
    313  
    314530  /**
    315531    create the set of protocol objects for the tab2mage protocol section
     
    345561       
    346562        // add extract protocol
    347         Extract extract= getExtract(labeledExtract, dc);
    348         if (extract!=null)
    349         {
    350           Protocol extractProtocol =extract.getCreationEvent().getProtocol();
    351           protocols.add(extractProtocol);
    352         }
    353         // add sample protocol
    354        
    355         Sample sample = getSample(extract, dc);
    356         if (sample != null)
    357         {
    358           Protocol sampleProtocol=sample.getCreationEvent().getProtocol();
    359           protocols.add(sampleProtocol);
     563        Set<Extract> extracts = ExportHelper.getExtracts(labeledExtract, dc);
     564        for (Extract extract : extracts) {
     565          if (extract!=null)
     566          {
     567            Protocol extractProtocol =extract.getCreationEvent().getProtocol();
     568            protocols.add(extractProtocol);
     569          }
     570          // add sample protocol
     571          Set<Sample> samples = ExportHelper.getSamples(extract, dc);
     572          for (Sample sample : samples) {
     573            if (sample != null)
     574            {
     575              Protocol sampleProtocol=sample.getCreationEvent().getProtocol();
     576              protocols.add(sampleProtocol);
     577            }
     578          }
    360579        }
    361580      }
     
    390609    return p;
    391610  }
     611 
    392612  /**
    393613    utility method for the tab2mage exporter
  • plugins/base2/uk.ac.ebi.tab2mage/trunk/Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageFileWriter.java

    • Property svn:keywords set to Id
    r449 r1188  
    1 /* $Id: Tab2MageFileWriter.java 2007-09-01 dominic $
    2 
    3   Copyright (C) 2007 Authors contributing to this file.
     1/* $Id$
     2
     3  Copyright (C) 2007, 2010 Authors contributing to this file.
    44
    55  This file is for NutriBASE - Nutrigenomics BioArray Software Environment.
     
    6262  @email oyeniran@ebi.ac.uk/doyeniran@gmail.com
    6363  @version 1.0
     64 
     65  @author Gildas Le Corguillé
     66  @email lecorguille@sb-roscoff.fr
     67  @version 1.01
     68 
     69  ChangeLog :
     70    05/02/2010 - lecorguille : addition of a Scan column to the output file
     71    08/02/2010 - lecorguille : addition of a BioSourceDescription column to the output file
     72                   displaying of the protocol descriptions in one line
    6473*/
    6574public class Tab2MageFileWriter
     
    8493      out= new BufferedWriter(new OutputStreamWriter(outputFile.getUploadStream(false),encoding));
    8594      statusOut= new BufferedWriter(new OutputStreamWriter(statusFile.getUploadStream(false),encoding));
    86     }
    87     catch(UnsupportedEncodingException e)
     95     
     96      statusOut.write(" Please check the messages below for the status of the export\n\n");
     97    }
     98    catch (IOException e)
    8899    {
    89100      new NutribasePluginException(e.getMessage());
     
    139150    try
    140151    {
    141       statusOut.write(" Please check the messages below for the status of the export"); //not part of experiment and may be moved elsewhere.
     152     
    142153     
    143154      out.write("# This file contains an experiment exported in tab2mage specification from BASE\n\n");
     
    151162      out.write(Tab2MageConstants.description.getName()+"\t"+description +"\n");
    152163      out.write(Tab2MageConstants.release_date.getName()+"\t"+job.getValue("releaseDate").toString()+"\n");
    153       out.write(Tab2MageConstants.submission_date.getName()+"\t"+Values.formatDate(new Date())+"\n");
     164      out.write(Tab2MageConstants.submission_date.getName()+"\t"+ValueFormatter.DATE_FORMAT.format(new Date())+"\n");
    154165      out.write(Tab2MageConstants.submitter.getName()+"\t"+experiment.getOwner().getName()+"\n");
    155166      out.write(Tab2MageConstants.submitter_email.getName()+"\t"+ValueFormatter.getEmptyStringIfNull(experiment.getOwner().getEmail())+"\n");
     
    171182    }
    172183  }
     184 
    173185  /**
    174186    writes Tab2Mage protocol section
     
    191203        {
    192204          out.write("P-BASE-"+protocol.getId()+"\t");
    193           out.write(ValueFormatter.getEmptyStringIfNull(protocol.getDescription())+"\t");
     205          out.write(ValueFormatter.getStringWithoutLineBreaker(String.valueOf(ValueFormatter.getEmptyStringIfNull(protocol.getDescription())))+"\t");
    194206          out.write(ValueFormatter.getEmptyStringIfNull(protocol.getName())+"\t");
    195207          out.write(ValueFormatter.getEmptyStringIfNull(protocol.getProtocolType().getName())+"\t");
     
    248260 
    249261  /**
     262   *  @deprecated
    250263     Tab2Mage Hybridization  Channel Line Section
    251264     @param hybDataRow, the data rows to display
    252265     @param response, the response object to return failures or exceptions
    253266   */
    254 
    255267  public static void writeTab2MageHybridizationRow( List<String> hybDataRows,Response response)
    256268  {
     
    277289    }
    278290  }
     291 
    279292  /**
    280293     write the Tab2Mage File Hybridization Section
     
    286299      @param response, response object
    287300   */
    288 
    289301  private static void writeTab2MageHybridizationRows(List<Tab2MageHybridization> hybList,Set<String> bioXterHybSectionHeader,
    290302                          Set<String> protocolHeaders,Set<String>parameterHeaders,Set<String>factorValueHeaders,
     
    300312        tempList.add(ValueFormatter.getEmptyStringIfNull(h.getLine().getFileRaw())+"\t");
    301313       
    302         int channelNo = h.getChannelNumber();
    303314       
    304315        Tab2MageHybridizationLine l= h.getLine();       
     
    344355        parameterMap.putAll(l.getParameter());
    345356       
     357        //Scan
     358        out.write(ValueFormatter.getEmptyStringIfNull(l.getScan())+"\t") ;
     359        tempList.add(ValueFormatter.getEmptyStringIfNull(l.getScan())+"\t") ;
     360       
    346361        //Hybridization
    347362        out.write(ValueFormatter.getEmptyStringIfNull(l.getHybridization())+"\t") ;
     
    366381          out.write(ValueFormatter.getEmptyStringIfNull(sl.getSample())+"\t") ;
    367382          out.write(ValueFormatter.getEmptyStringIfNull(sl.getBioSource())+"\t") ;
     383          out.write(ValueFormatter.getEmptyStringIfNull(sl.getBioSourceDescription())+"\t") ;
    368384                   
    369385          // biomaterial xteristics
     
    412428  }
    413429 
     430  /** NOT USE
     431   * @deprecated */
    414432  public static void createZipFile(User user, File tab2mageFile, DbControl dc )
    415433  {
     
    426444   
    427445  }
    428   /**
     446 
     447  /**
    429448    closes the file writers
    430449   */
     
    433452    try
    434453    {
     454      out.flush();
     455      statusOut.flush();
    435456      if (out!= null) out.close();
    436457      if (statusOut!=null) statusOut.close();
  • plugins/base2/uk.ac.ebi.tab2mage/trunk/Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageHybridization.java

    • Property svn:keywords set to Id
    r449 r1188  
    1 /* $Id: Tab2MageHyridization.java 2007-10-01 dominic $
    2 
    3   Copyright (C) 2007 Authors contributing to this file.
     1/* $Id$
     2
     3  Copyright (C) 2007, 2010 Authors contributing to this file.
    44
    55  This file is for NutriBASE - Nutrigenomics BioArray Software Environment.
     
    3838    @author Dominic Oyeniran
    3939    @email  oyeniran@ebi.ac.uk/doyeniran@gmail.com
     40    @version 1.0
     41 
     42 
     43  @author Gildas Le Corguillé
     44  @email lecorguille@sb-roscoff.fr
     45  @version 1.01
     46 
     47  ChangeLog :
     48    05/02/2010 - lecorguille : addition of SCAN
    4049 */
    4150public class Tab2MageHybridization
     
    4554 
    4655  public static final String BIOSOURCE = "BioSource";
     56  public static final String BIOSOURCEDESCRIPTION = "BioSourceDescription";
    4757  public static final String SAMPLE = "Sample";
    4858  public static final String EXTRACT = "Extract";
     
    5060  public static final String DYE = "Dye";
    5161  public static final String HYBRIDIZATION = "Hybridization";
     62  public static final String SCAN = "Scan";
    5263  public static final String BIOMATERIALCHARACTERISTICS = "BioMaterialCharacteristics";
    5364  public static final String PROTOCOL = "Protocol";
     
    124135 
    125136  /**
     137   * @deprecated by lecorguille
    126138      Get the size of the <code>Tab2MageHybridization</code> object.
    127139      The size is the number of <code>Tab2MageHybridizationLine</code>
     
    142154 
    143155  /**
     156   * @deprecated by lecorguille
    144157      Get the set of all <code>Tab2MageHybridizationLine</code> objects.
    145158    @return A <code>HashMap</code> with a String as key and a <code>TAB2MAGEHybridizationLine</code> as value
     
    151164 
    152165  /**
     166   * @deprecated by lecorguille
    153167      Get the name of the raw data file.
    154168     @return The name of the raw data file
     
    178192   
    179193  /**
     194   * @deprecated by lecorguille
    180195    Get the information about the Array[...] entries in
    181196    the Tab2Mage files.
     
    204219
    205220  /**
     221   * @deprecated by lecorguille
    206222    Has the Hyb object a pooled property
    207223   */
     
    211227  }
    212228  /**
     229   * @deprecated by lecorguille
    213230    check if the Hyb line object a re pooled abnd set the global variable pooled
    214231   * @param pooled
     
    220237
    221238  /**
     239   * @deprecated by lecorguille
    222240    get the name of the Hybridization from the HybLine objects
    223241    @return
  • plugins/base2/uk.ac.ebi.tab2mage/trunk/Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageHybridizationLine.java

    • Property svn:keywords set to Id
    r449 r1188  
    1 /* $Id: Tab2MageHybridizationLine.java 2007-10-01 dominic $
    2 
    3   Copyright (C) 2007 Authors contributing to this file.
     1/* $Id$
     2
     3  Copyright (C) 2007, 2010 Authors contributing to this file.
    44
    55  This file is for NutriBASE - Nutrigenomics BioArray Software Environment.
     
    3737  @author Dominic Oyeniran
    3838  @email  oyeniran@ebi.ac.uk/doyeniran@gmail.com
     39 
     40 
     41  @author Gildas Le Corguillé
     42  @email lecorguille@sb-roscoff.fr
     43  @version 1.01
     44 
     45  ChangeLog :
     46    05/02/2010 - lecorguille : addition of scan methods
     47    05/02/2010 - lecorguille : deletion of number of line control which was limited by the comparison the channel number
    3948 */
    4049public class Tab2MageHybridizationLine
     
    4857  protected String dye;
    4958  protected String hybridization;
     59  protected String scan;
    5060  protected Map<String, String> file = new HashMap<String, String>();
    5161  protected Map<String, String> protocol = new HashMap<String, String>();
     
    8898  {
    8999    this.hybridization = hybridization;
     100  }
     101 
     102  /*
     103    Scan
     104   */
     105  public String getScan()
     106  {
     107    return scan;
     108  }
     109 
     110  public void setScan(String scan)
     111  {
     112    this.scan = scan;
    90113  }
    91114
     
    199222      return;
    200223    }
     224   
     225    // Scan
     226    if (key == Tab2MageHybridization.SCAN)
     227    {
     228      setScan((String)value);
     229      return;
     230    }
    201231       
    202232    // Parameters
     
    264294    else
    265295    {
    266       if (lines.size()!= channelNumber) // check the the line numbers matches the channel number
     296      /*if (lines.size()!= channelNumber) // check the the line numbers matches the channel number
    267297      {
    268298        log.error("The Hybridization " + name + " doesn't have the right number of lines!");
     
    270300      }
    271301      else
    272       {
     302      {*/
    273303        subLineSet.addAll(lines);
    274304        return true;
    275       }
     305      //}
    276306    }
    277307  }
  • plugins/base2/uk.ac.ebi.tab2mage/trunk/Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageSubHybLine.java

    • Property svn:keywords set to Id
    r449 r1188  
    1 /* $Id: Tab2MageSubHybLine.java 2007-10-01 dominic $
     1/* $Id$
    22
    33  Copyright (C) 2007 Authors contributing to this file.
     
    3131    @email  oyeniran@ebi.ac.uk/doyeniran@gmail.com
    3232  @version 1.0
     33 
     34 
     35  @author Gildas Le Corguillé
     36  @email lecorguille@sb-roscoff.fr
     37  @version 1.01
     38 
     39  ChangeLog :
     40    05/02/2010 - lecorguille : addition of BioSourceDescription
    3341 */
    3442
     
    3644{
    3745  protected String bioSource;
     46  protected String bioSourceDescription;
    3847  protected String sample;
    3948  protected String extract;
     
    7584  }
    7685 
     86 
     87  public String getBioSourceDescription()
     88  {
     89    return bioSourceDescription;
     90  }
     91 
     92  public void setBioSourceDescription(String bioSourceDescription)
     93  {
     94    this.bioSourceDescription = bioSourceDescription;
     95  }
     96 
    7797  /*
    7898    Sample
     
    183203      return;
    184204    }
     205   
     206    //set BioSource
     207    if (key == Tab2MageHybridization.BIOSOURCEDESCRIPTION)
     208    {
     209      setBioSourceDescription((String)value);
     210      return;
     211    }
    185212     
    186     // set sample
     213    // set Sample
    187214    if (key == Tab2MageHybridization.SAMPLE)
    188215    {
  • plugins/base2/uk.ac.ebi.tab2mage/trunk/Tab2MageExporter/src/uk/ac/ebi/nugo/plugins/ta2mageexport/Tab2MageValidator.java

    • Property svn:keywords set to Id
    r449 r1188  
    1 /* $Id: Tab2MageValidator.java 2007-10-01 dominic $
    2 
    3   Copyright (C) 2007 Authors contributing to this file.
     1/* $Id$
     2
     3  Copyright (C) 2007, 2010 Authors contributing to this file.
    44
    55  This file is for NutriBASE - Nutrigenomics BioArray Software Environment.
     
    2323package uk.ac.ebi.nugo.plugins.ta2mageexport;
    2424
     25import java.io.IOException;
    2526import java.util.Arrays;
    2627import java.util.LinkedHashSet;
     
    5758    @email  oyeniran@ebi.ac.uk/doyeniran@gmail.com
    5859  @version 1.0
     60 
     61 
     62  @author Gildas Le Corguillé
     63  @email lecorguille@sb-roscoff.fr
     64  @version 1.01
     65 
     66  ChangeLog :
     67    05/02/2010 - lecorguille : addition a pooling management for the setting of protocols
     68    08/02/2010 - lecorguille : fix a problem with protocols
    5969 */
    6070public class Tab2MageValidator
     
    8191  private static int samplingProtocolCount=0;
    8292 
     93  /** @deprecated  by lecorguille */
    8394  private Set<String> parameterHeaders= new LinkedHashSet<String>();
    8495 
     96  /** @deprecated  by lecorguille */
    8597  private Set<String> bioMaterialXteristicsHeaders=  new LinkedHashSet<String>();
    8698 
     99  /** @deprecated  by lecorguille */
    87100  private static Set<String> factorValuesHybSectionHeader= new LinkedHashSet<String>();
    88101 
     
    96109  private int channelNumber = 0;
    97110  // the experiment
    98   private Experiment experiment;
     111  private ItemResultList<RawBioAssay> rawBioAssays;
    99112 
    100113  private SessionControl sc;
     
    108121      @param response
    109122   */
    110   public Tab2MageValidator(Experiment experiment, SessionControl sc, Response response)
    111   {
    112     this.experiment=experiment;
     123  public Tab2MageValidator(ItemResultList<RawBioAssay> rawBioAssays, SessionControl sc, Response response)
     124  {
     125    this.rawBioAssays=rawBioAssays;
    113126    this.sc = sc;
    114127    this.response= response;
     
    127140    {
    128141      dc = sc.newDbControl();
    129       ItemResultList<RawBioAssay> rbas= experiment.getRawBioAssays().list(dc);
    130       for (RawBioAssay rba : rbas)
     142      for (RawBioAssay rba : rawBioAssays)
    131143      {
    132144        if (rba.getProtocol()!=null)
     
    148160            labelingProtocolCount++; 
    149161         
    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          
     162          Set<Extract> extracts = ExportHelper.getExtracts(labeledExtract, dc);
     163          for (Extract extract : extracts) {
     164            if (extract.getProtocol()!=null)
     165              extractProtocolCount++;
     166                 
     167            Set<Sample> samples = ExportHelper.getSamples(extract, dc);
     168            for (Sample sample : samples) {
     169              if (sample.getProtocol()!=null)
     170                samplingProtocolCount++;
     171            }
     172          }
    160173        }
    161174      }
     
    177190    create both the parameter [AT] header and BioMaterialCharactertistic[AT] headers found in the whole experiment
    178191   */
    179   @SuppressWarnings({"deprecation","unchecked"})
    180192  private void createHeaders()
    181193  {
     
    184196    {
    185197      dc = sc.newDbControl();
    186       ItemResultList<RawBioAssay> rbas= experiment.getRawBioAssays().list(dc);
    187       for (RawBioAssay rba : rbas)
     198      for (RawBioAssay rba : rawBioAssays)
    188199      {
    189200        if (rba.getProtocol()!=null)
    190201        {
    191           createParameterSectionHeaders(rba, dc );
     202          //createParameterSectionHeaders(rba, dc);
    192203          createProtocolHybSectionHeader(Tab2MageValidator.getFeProtocolCount(),Tab2MageConstants.protocol_featureextraction.getName());
    193204        }
    194205        if (rba.getScan().getProtocol()!=null)
    195206        {
    196           createParameterSectionHeaders(rba.getScan(), dc );
     207          //createParameterSectionHeaders(rba.getScan(), dc );
    197208          createProtocolHybSectionHeader(Tab2MageValidator.getScanningProtocolCount(), Tab2MageConstants.protocol_scanning.getName());
    198209        }
    199210        if (rba.getScan().getHybridization().getProtocol()!=null)
    200211        {
    201           createParameterSectionHeaders(rba.getScan().getHybridization(), dc );
     212          //createParameterSectionHeaders(rba.getScan().getHybridization(), dc );
    202213          createProtocolHybSectionHeader(Tab2MageValidator.getHybridizationProtocolCount(), Tab2MageConstants.protocol_hyb.getName());
    203214        }
    204         ItemResultList<LabeledExtract>labeledExtracts = (ItemResultList<LabeledExtract>)
     215        ItemResultList<LabeledExtract> labeledExtracts = (ItemResultList<LabeledExtract>)
    205216                                rba.getScan().getHybridization().getCreationEvent().getSources().list(dc);
    206217        for (LabeledExtract labeledExtract :labeledExtracts)
     
    208219          if (labeledExtract.getProtocol()!=null)
    209220          {
    210             createParameterSectionHeaders(labeledExtract, dc );
     221            //createParameterSectionHeaders(labeledExtract, dc );
    211222            createProtocolHybSectionHeader(Tab2MageValidator.getLabelingProtocolCount(), Tab2MageConstants.protocol_labeling.getName());
    212223          }
    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());
     224          Set<Extract> extracts = ExportHelper.getExtracts(labeledExtract, dc);
     225          for (Extract extract : extracts) {
     226            if (extract.getProtocol()!=null)
     227            {
     228              //createParameterSectionHeaders(labeledExtract.getExtract(), dc );
     229              createProtocolHybSectionHeader(Tab2MageValidator.getExtractProtocolCount(), Tab2MageConstants.protocol_extraction.getName());
     230            }
     231            Set<Sample> samples = ExportHelper.getSamples(extract, dc);
     232            for (Sample sample : samples) {
     233              if  (sample.getProtocol()!=null)
     234              {
     235                //createParameterSectionHeaders(sample, dc );
     236                createProtocolHybSectionHeader(Tab2MageValidator.getSamplingProtocolCount(), Tab2MageConstants.protocol_treatment.getName());
     237              }
     238              Set<BioSource> bioSources = ExportHelper.getBioSources(sample, dc);
     239              for (BioSource bioSource : bioSources) {
     240                if (bioSource!=null)
     241                  createBioMatXteristicsSectionHeader(bioSource,dc);
     242              }
     243            }
    219244          }
    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);
    229245        }
    230246      }
     
    241257        dc.close();
    242258    }
    243    
    244   }
    245   /**
     259  }
     260  /**
     261   * @deprecated by lecorguille
    246262      Gets the used annotation types (parameters) for an annotatable item and add it to a set of PARAMETER[AT] headers
    247263      @param annotatable, an item that implements annotatable
    248264      @param dc, the database control object
    249265   */
    250  
    251266  private void createParameterSectionHeaders(Annotatable anotatable, DbControl dc )
    252267  {
     
    259274  }
    260275 
    261   /**
     276  /** @deprecated by lecorguille
    262277    Gets the annotation types used as biomaterial characteristics for an annotatable item
    263278    @param annotatable, an item that implements annotatable
     
    298313 
    299314  /**
     315   *  @deprecated
    300316    initialises the maps required to manage tab2mage data 
    301317    @param map, the map to be intitialised
     
    327343 
    328344  /**
     345   *  @deprecated
    329346     get all the experimental factors for an experiments
    330347     @param DcControl dc, the database control
     
    355372 
    356373  /**
     374   *  @deprecated
    357375     get all the experimental factors headers for an experiments
    358376     @param DcControl dc, the database control
     
    415433  }
    416434
    417   // get the parameter headers
    418   public Set<String> getParameterHeaders()
     435  /** @deprecated  by lecorguille
     436   * get the parameter headers
     437   * */
     438  public Set<String> getParameterHead()
    419439  {
    420440    return parameterHeaders;
    421441  }
    422   // get the bio material characteristics headers
     442  /** @deprecated  by lecorguille
     443   * get the bio material characteristics headers
     444   * */
    423445  public Set<String> getBioMaterialXteristicsHeaders()
    424446  {
    425447    return bioMaterialXteristicsHeaders;
    426448  }
    427 
    428   // get the factor values header used in the experiment
     449 
     450  /** @deprecated  by lecorguille
     451   * get the factor values header used in the experiment
     452   * */
    429453  public static Set<String> getFactorValuesHybSectionHeader()
    430454  {
Note: See TracChangeset for help on using the changeset viewer.