Changeset 3037


Ignore:
Timestamp:
Dec 15, 2006, 7:25:31 PM (15 years ago)
Author:
dominic
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/tab2mage_ebi/src/plugins/core/net/sf/basedb/plugins/Tab2MageExporter.java

    r3031 r3037  
    2121  Boston, MA  02111-1307, USA.
    2222*/
    23 package net.sf.basedb.plugins;
     23package com.plugin;
    2424
    2525import java.io.BufferedWriter;
     
    4747import net.sf.basedb.core.BioSource;
    4848import net.sf.basedb.core.BooleanParameterType;
     49import net.sf.basedb.core.DateParameterType;
    4950import net.sf.basedb.core.DbControl;
    5051import net.sf.basedb.core.Experiment;
     
    6869import net.sf.basedb.core.Sample;
    6970import net.sf.basedb.core.Scan;
    70 import net.sf.basedb.core.StringParameterType;
     71import net.sf.basedb.core.Type;
    7172import net.sf.basedb.core.User;
    7273import net.sf.basedb.core.plugin.About;
     
    7879import net.sf.basedb.core.plugin.Request;
    7980import net.sf.basedb.core.plugin.Response;
     81import net.sf.basedb.core.query.Expressions;
    8082import net.sf.basedb.core.query.Hql;
    8183import net.sf.basedb.core.query.Orders;
    82 import net.sf.basedb.util.Values;
     84import net.sf.basedb.core.query.Restrictions;
     85import utils.Values;
    8386
    8487/**
     
    116119  private PluginParameter<Boolean> overWriteParameter;
    117120 
    118   private PluginParameter<String> releaseDateParameter;
     121  private PluginParameter<Date> releaseDateParameter;
     122 
    119123 
    120124  private RequestInformation configureJob;
     
    142146          new ItemParameterType<Experiment>(Experiment.class, null,true,1,null));
    143147     
    144        releaseDateParameter= new PluginParameter<String>(
     148       releaseDateParameter= new PluginParameter<Date>(
    145149           "releaseDate",
    146150           "Release Date",
    147151           "Please specify the release date of the experiment. This is optional at this point and can be entered into the exported file",
    148            new StringParameterType(255, null, false));
     152           new DateParameterType(null, true));
    149153       
    150154       overWriteParameter = new PluginParameter<Boolean>(
     
    265269    Set<String> hybSectionHeader= new LinkedHashSet<String>();
    266270    Set<String>  protocolHybSectionHeader= new LinkedHashSet<String>();
    267     //Set<String>  parameterHybSectionHeader= new LinkedHashSet<String>();
    268    
    269     //Map<String, String> bioMaterials= new LinkedHashMap<String, String>();
    270     //Map<String, String> arrayDataInfo= new LinkedHashMap<String,String>();
    271271    List<String> protocolRefId= new LinkedList<String>();
    272272    List<String> hybridizationDataRows=new LinkedList<String>();
     
    308308      experiment= Experiment.getById(dc,experiment.getId());
    309309      //  check if the logged in user owned the experiment
    310       if (!(experiment.getOwner().equals(user))) return; //if not the logged in user do not own the experiment. This can be re-coded to return a message for usability
    311       String releaseDate= (String)job.getValue("releaseDate"); // get the release date string and convert it into date format
     310      if (!(experiment.getOwner().equals(user))) return; //if not return. This can be re-coded to return a message for usability
    312311     
    313312      //create an output stream writer to the file
     
    332331      String description = experiment.getDescription()!=null || experiment.getDescription()!="" ? experiment.getDescription():experiment.getAbstract();
    333332      out.write("description\t"+description +"\n");
    334       out.write("release_date\t"+Values.getEmptyStringIfNull(releaseDate)+"\n");
     333      out.write("release_date\t"+Values.getEmptyStringIfNull(job.getValue("releaseDate"))+"\n");
    335334      out.write("submission_date\t"+Values.formatDate(new Date())+"\n");
    336335      out.write("submitter\t"+experiment.getOwner().getName()+"\n");
     
    475474        int hybsize=labeledExtracts.size();
    476475        int count=1;
    477         System.out.println("The size of the two color data hyb data row before the labeled extract section: " +twoColorHybDataRows.size());
    478         System.out.println("The size of the tow color param value before adding the labeled extract section is: " +twoColorFirstParameterValues.size());
    479         System.out.println(hybsize ==1 ? "Affy Expriment. Hyb size:"+hybsize :"2 - color Expreriment. Hyb size : "+hybsize );
     476        //System.out.println("The size of the two color data hyb data row before the labeled extract section: " +twoColorHybDataRows.size());
     477        //System.out.println("The size of the tow color param value before adding the labeled extract section is: " +twoColorFirstParameterValues.size());
     478        //System.out.println(hybsize ==1 ? "Affy Expriment. Hyb size:"+hybsize :"2 - color Expreriment. Hyb size : "+hybsize );
    480479        for (LabeledExtract labeledExtract :labeledExtracts) // can have more than one labeled extract (2 color experiments)
    481480        {
     
    501500          if (lbprotocolParameters!=null )
    502501          {
    503             System.out.println("Labeled Extract protocol parameters size is: "+lbprotocolParameters.size());
     502            //System.out.println("Labeled Extract protocol parameters size is: "+lbprotocolParameters.size());
    504503            if (lbprotocolParameters.size()!=0)
    505504            {
     
    533532          }
    534533            //  Extract
    535           //Set <Annotatable> extractOrPooledLabeledExtract= labeledExtract.getAnnotatableParents(); //get extract or pooled labelled extract
    536           //if (extractOrPooledLabeledExtract instanceof Extract)
    537534          Extract extract= labeledExtract.getExtract();
    538535          if (extract!=null)
     
    557554            if (protocolParameters!=null )
    558555            {
    559               System.out.println("Extract protocol parameters size is: "+protocolParameters.size());
     556              //System.out.println("Extract protocol parameters size is: "+protocolParameters.size());
    560557              if (protocolParameters.size()!=0)
    561558              {
     
    580577         
    581578            //Sample
    582           //Set<Annotatable>sampleOrPooledExtract= extract.getAnnotatableParents(); //get the sample or pooled extract
    583579          Sample sample =extract.getSample(); // The sample, extract is created from
    584580          if (sample != null)
     
    586582            hybSectionHeader.add("Sample");
    587583            protocolHybSectionHeader.add("Protocol[treatment]");
    588             Protocol sampleProtocol=sample.getCreationEvent().getProtocol();      //sampling protocol
     584            Protocol sampleProtocol=sample.getCreationEvent().getProtocol();    //sampling protocol
    589585            protocols.add(sampleProtocol);
    590586            if (count < hybsize || count==1)
     
    598594              twoColorProtocolRefId.add(getFormattedProtocolId(sampleProtocol));
    599595            }
    600             System.out.println("Is the Sample Annotated?");
    601            
    602596              // sampling protocol parameter
    603597            AnnotationSet as = sample.isAnnotated()? sample.getAnnotationSet(): null;
     
    605599            if (protocolParameters!=null )
    606600            {
    607               System.out.println("Sample protocol parameters size is: "+protocolParameters.size());
     601              //System.out.println("Sample protocol parameters size is: "+protocolParameters.size());
    608602              if (protocolParameters.size()!=0)
    609603              {
     
    628622          }
    629623            // Biosource
    630           //sample.getAnnotatableParents(); //get the biosource or pooled samples
    631624          BioSource bioSource=sample.getBioSource();
    632625          if (bioSource!=null)
    633626          {
    634            
    635627            hybSectionHeader.add("Biosource");
    636628            if (count < hybsize || count==1)
     
    642634              twoColorHybDataRows.add(bioSource.getName());
    643635            }
    644             AnnotationSet bsAnnotationSet =bioSource.getAnnotationSet();
    645             ItemQuery<Annotation> annotationsQuery= bsAnnotationSet.getAnnotations();
    646             annotationsQuery.include(Include.MINE,Include.IN_PROJECT, Include.SHARED); // should not export other people's data.
    647             ItemResultList<Annotation> annotations=annotationsQuery.list(dc);
    648             for (Annotation annotation: annotations)
    649             {
    650               if (!annotation.getAnnotationType().isRemoved())
     636            AnnotationSet bsAnnotationSet = bioSource.isAnnotated()? bioSource.getAnnotationSet():null;
     637            ItemQuery<AnnotationType> annotationTypesQuery= getAnnotationTypesQuery(bioSource.getType(), false); // returns no annotationtypes for parameters
     638            List<AnnotationType> annotationTypes= annotationTypesQuery.list(dc);
     639            System.out.println("Biomaterial Xteristics");
     640            for (AnnotationType at : annotationTypes)
     641            {
     642              if(!at.isRemoved() )
    651643              {
    652                 hybSectionHeader.add("BioMaterialCharacteristics["+annotation.getAnnotationType().getName()+"]");
    653                 for (int i=0; i<annotation.getValues().size(); i++)
     644                hybSectionHeader.add("BioMaterialCharacteristics["+at.getName()+"]");
     645                List<?> values =  bsAnnotationSet == null || ! bsAnnotationSet.hasAnnotation(at) ? null :  bsAnnotationSet.getAnnotation(at).getValues();
     646                if (count < hybsize || count==1)
    654647                {
    655                   if (count < hybsize || count==1)
    656                   {
    657                     hybridizationDataRows.add(annotation.getValues().get(i).toString());
    658                   }
    659                   else if(count==2)
    660                   {
    661                     twoColorHybDataRows.add(annotation.getValues().get(i).toString());
    662                   }
     648                  hybridizationDataRows.add(values==null || values.size()==0 ? getDefaultValue(at) : Values.getString(values, ", ", true));
     649                  System.out.println(values==null || values.size()==0 ? "-none-" : Values.getString(values, ", ", true));
     650                }
     651                else if(count==2)
     652                {
     653                  twoColorHybDataRows.add(values==null || values.size()==0 ? getDefaultValue(at) : Values.getString(values, ", ", true));
     654                  System.out.println(values==null || values.size()==0 ? "-none-" : Values.getString(values, ", ", true));
    663655                }
    664656              }
     
    705697          if (value!=null)
    706698          {
    707             for (int i=0; i<value.getValues().size(); i++)
    708             {
    709               hybridizationDataRows.add(Values.getEmptyStringIfNull(value.getValues().get(i).toString()).toString());
    710               if (twoColorHyb) twoColorHybDataRows.add(Values.getEmptyStringIfNull(value.getValues().get(i).toString()).toString());
    711             }
     699            List<?> values= value.getValues();
     700            hybridizationDataRows.add(values==null || values.size()==0 ? "\t" : Values.getString(values, ", ", true));
     701            if (twoColorHyb) twoColorHybDataRows.add(values==null || values.size()==0 ? "\t" : Values.getString(values, ", ", true));
    712702          }
    713703          else
     
    773763                if (length < parameters.size()) out.write(";");   
    774764            }
     765            length=0;
    775766            out.write("\t\n");
    776767          }
     
    839830      {
    840831        values.add(annotationSet.findAnnotation(exprFactor));
    841        
    842832      }         
    843833    }
     
    889879   
    890880  }
    891    
     881  /**
     882  Get a query that returns all annotation types defined for a particular
     883  item type and, optionally, with a specific protocol parameter setting.
     884  @param itemType The item type
     885  @param isProtocolParameter, true to include assigned as protocol parameters
     886  and false to exclude prortocol parameters, a null value ignores the protocol parameter flag
     887  @return An <code>ItemQuery</code> object of annotation types
     888*/
     889  private static ItemQuery<AnnotationType> getAnnotationTypesQuery(Item itemType, Boolean isProtocolParameter)
     890  {
     891    ItemQuery<AnnotationType> q = AnnotationType.getQuery(itemType);
     892    q.order(Orders.asc(Hql.property("name")));
     893    q.include(Include.MINE, Include.SHARED, Include.IN_PROJECT);
     894    if (isProtocolParameter != null)
     895    {
     896      q.restrict(
     897        Restrictions.eq(
     898          Hql.property("protocolParameter"),
     899          Expressions.parameter("isParameter", isProtocolParameter, Type.BOOLEAN)
     900        )
     901      );
     902    }
     903    return q;
     904  }
     905 
     906  /**
     907    gets the default value of an annotation type, used when annotation value is null
     908    @param at, annotation type to obtain the default value from
     909    @return string, deafult value or a tab if default value is null
     910   */
     911  private static String getDefaultValue(AnnotationType at)
     912  {
     913   
     914    return at.getDefaultValue()!=null? at.getDefaultValue():"\t";
     915  }
     916 
    892917  private static Set<String>  factorValuesHybSectionHeader= new LinkedHashSet<String>();
    893918  private static Set<String>  parameterHybSectionHeader= new LinkedHashSet<String>();
Note: See TracChangeset for help on using the changeset viewer.