Changeset 3009


Ignore:
Timestamp:
Dec 8, 2006, 10:47:53 AM (16 years ago)
Author:
dominic
Message:
 
File:
1 edited

Legend:

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

    r3002 r3009  
    1919*/
    2020package net.sf.basedb.plugins;
     21
    2122
    2223import java.io.BufferedWriter;
     
    255256    Set<String>  protocolHybSectionHeader= new LinkedHashSet<String>();
    256257    Set<String>  parameterHybSectionHeader= new LinkedHashSet<String>();
    257    
    258258    Map<AnnotationType, Annotation> factorValues= new HashMap<AnnotationType,Annotation>();
    259259    List<String> protocolRefId= new LinkedList<String>();
    260260    List<String> hybridizationDataRows=new LinkedList<String>();
    261261    List<String> parameterValues= new LinkedList<String>();
     262    List<Annotation> expFactorValues= new LinkedList<Annotation>();
     263   
     264    List<String> twoColorHybDataRowsFirstSection=new LinkedList<String>();
     265    List<String> twoColorHybDataRowsSecondSection=new LinkedList<String>();
     266 
    262267   
    263268    boolean overwrite = false;
     269    boolean twoColorHyb= false;
    264270    try
    265271    {
     
    289295      //  check if the logged in user owned the experiment
    290296      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
    291       //  get the release date string and convert it into date format
    292       String releaseDate= (String)job.getValue("releaseDate");
     297      String releaseDate= (String)job.getValue("releaseDate"); // get the release date string and convert it into date format
    293298      //create an output stream writer to the file
    294299      //We use OutputStreamWriter so that characters written to it are encoded into bytes using a specified charset for all
    295300      //System.out.println("The java runtime default char set is  :" +Charset.defaultCharset());
    296301      Writer out= new BufferedWriter(new OutputStreamWriter(file.getUploadStream(false),"ISO-8859-1"));
    297    
     302     
     303      // Header section
     304      out.write("# This file contains an experiment exported in tab2mage specification from BASE2\n\n");
    298305      // Experiment Section
    299       //outputExperimentSection(out,experiment,releaseDate, response);
    300306      out.write("Experiment section \n");
    301307      out.write("domain\t"+Application.getHostName()+"\n");
    302308      out.write("accession\tE-BASE-"+experiment.getId()+"\n");
     309      out.write("quality_control\t\n");
    303310      out.write("experiment_design_type\t"+ Values.getEmptyStringIfNull(experiment.getExperimentDesign())+"\n");
    304311      out.write("name\t"+experiment.getName() +"\n");
     
    307314      out.write("release_date\t"+Values.getEmptyStringIfNull(releaseDate)+"\n");
    308315      out.write("submission_date\t"+Values.formatDate(new Date())+"\n");
    309       out.write("submitter\t"+experiment.getOwner().getName() +" email: "+Values.getEmptyStringIfNull(experiment.getOwner().getEmail()) +"\n");
     316      out.write("submitter\t"+experiment.getOwner().getName()+"\n");
     317      out.write("submitter_email\t"+Values.getEmptyStringIfNull(experiment.getOwner().getEmail())+"\n");
    310318      out.write("organization\t"+ Values.getEmptyStringIfNull(experiment.getOwner().getOrganisation()) +"\n");
     319      out.write("publication_title\t"+Values.getEmptyStringIfNull(experiment.getTitle()) +"\n"); 
    311320      out.write("authors\t"+Values.getEmptyStringIfNull(experiment.getAuthors())+"\n");
    312321      out.write("journal\t"+Values.getEmptyStringIfNull(experiment.getPublication())+"\n");
    313       out.write("year\t"+ String.format("%1$tY", experiment.getPublicationDate())+"\n");
    314       out.write("pubmed_id\t"+Values.getEmptyStringIfNull(experiment.getPubMedId())+"\n");
    315       out.write("quality_control\t\n");
    316       out.write("publication_title\t\n");
    317322      out.write("volume\t\n"); 
    318323      out.write("issue\t\n");
    319324      out.write("pages\t\n");
     325      out.write("year\t"+ String.format("%1$tY", experiment.getPublicationDate())+"\n");
     326      out.write("pubmed_id\t"+Values.getEmptyStringIfNull(experiment.getPubMedId())+"\n");
    320327      out.write("\n");
    321328      out.flush();
     329     
    322330     
    323331      // Get all protocols and hybs   
     
    327335      for (RawBioAssay rba : rawBioAssays)
    328336      {
     337        twoColorHybDataRowsFirstSection.add("-done-"); //initialise the twocolor hyb row with -done- as the delimeter
    329338        /*
    330339          Data files and array information section//
     
    339348          hybSectionHeader.add("File[raw]");
    340349          hybridizationDataRows.add(celFile.getName());
     350          twoColorHybDataRowsFirstSection.add(celFile.getName());
    341351          hybSectionHeader.add("File[cdf]");
    342352          hybridizationDataRows.add(cdfFile.getName());
     353          twoColorHybDataRowsFirstSection.add(cdfFile.getName());
    343354        }
    344355        else
     
    346357          hybSectionHeader.add("File[raw]");
    347358          hybridizationDataRows.add(rba.getName());
     359          twoColorHybDataRowsFirstSection.add(rba.getName());
    348360        }
    349361        hybSectionHeader.add("Array[accession]");
    350362        hybridizationDataRows.add(arrayDesign.getName());
     363        twoColorHybDataRowsFirstSection.add(arrayDesign.getName());
    351364       
    352365            //Raw BioAssay protocol
    353366        protocolRefId.add(getFormattedProtocolId(rba.getProtocol()));
    354367        protocolHybSectionHeader.add("Protocol[image_analysis]");
    355         protocols.add(rba.getProtocol()); //rawbioassay protocol
     368        //if (rba.getProtocol()!=null)
     369        //{
     370          protocols.add(rba.getProtocol()); //rawbioassay protocol
     371         
     372        //  System.out.println("raw bioassay protocol: P-BASE-"+rba.getProtocol().getId());
     373        //}
    356374        if (rba.isAnnotated())
    357375        {
     
    363381            {
    364382              parameterHybSectionHeader.add("Parameter["+annotation.getAnnotationType().getName()+"]");
    365               parameterValues.add(annotation.getValues().toString());
    366             }
     383              for (int i=0; i<annotation.getValues().size(); i++)
     384              {
     385                parameterValues.add(annotation.getValues().get(i).toString());
     386              }
     387            }
     388            //else
     389            //{
     390            //  parameterValues.add("\t");
     391            //}
    367392          }
    368393        }
     
    382407            {
    383408              parameterHybSectionHeader.add("Parameter["+annotation.getAnnotationType().getName()+"]");
    384               parameterValues.add(annotation.getValues().toString());
    385             }
    386            
     409              for (int i=0; i<annotation.getValues().size(); i++)
     410              {
     411                parameterValues.add(annotation.getValues().get(i).toString());
     412              }
     413            }
     414            //else
     415            //{
     416          //    parameterValues.add("\t");
     417          //  }
    387418          }
    388419        }
    389420       
    390           //Hybridization
     421        //Hybridization
    391422        Hybridization hyb= scan.getHybridization();
    392423        hybSectionHeader.add("Array[serial]");
    393424        hybridizationDataRows.add(hyb.getArraySlide().getName());
    394              
     425        twoColorHybDataRowsFirstSection.add(hyb.getArraySlide().getName());     
    395426        /*
    396427          Names of materials and processes section
     
    398429        hybSectionHeader.add("Hybridization");
    399430        hybridizationDataRows.add(hyb.getName());
    400      
     431        twoColorHybDataRowsFirstSection.add(hyb.getName());
     432       
    401433        System.out.println("The number of scans: "+hyb.countScans()); // count scans that created the hyb
    402434        BioMaterialEvent bioMaterialEvent= hyb.getCreationEvent(); // event that created the hyridization
     
    415447            {
    416448              parameterHybSectionHeader.add("Parameter["+annotation.getAnnotationType().getName()+"]");
    417               parameterValues.add(annotation.getValues().toString());
    418             }
    419            
    420           }
    421         }
    422        
    423        
     449              for (int i=0; i<annotation.getValues().size(); i++)
     450              {
     451                parameterValues.add(annotation.getValues().get(i).toString());
     452              }
     453            }
     454            //else
     455            //{
     456            //  parameterValues.add("\t");
     457            //}
     458          }
     459        }
     460         
    424461        ItemQuery<LabeledExtract> labeledExtractQuery =(ItemQuery<LabeledExtract>) bioMaterialEvent.getSources(); // get all the labeled extract
    425462        ItemResultList<LabeledExtract> labeledExtracts= labeledExtractQuery .list(dc);
    426         for (LabeledExtract labeledExtract :labeledExtracts) // can have more that one labeled extract
    427         {
     463        int hybsize=labeledExtracts.size();
     464        int count=1;
     465        //STOPPED HERE (LAST CODE) TRYING TO IMPLEMENT TWO COLOR HYBS
     466        //if (hybsize==2 && !hybridizationDataRows.contains("-done-"))
     467        //{
     468        //  twoColorHybDataRowsFirstSection.addAll(hybridizationDataRows); //create anew data row for 2 color experiment
     469        //  twoColorHybDataRowsSecondSection.addAll(hybridizationDataRows);
     470        //  twoColorHyb=true;
     471        //}else if(hybsize==2 && twoColorHyb )
     472        //{ //NOTE THE OUTPUT SHOWS THAT i AM ADDING THE LAST INFORMATION, SO FIX THIS
     473        //  twoColorHybDataRowsFirstSection.addAll(twoColorHybDataRowsSecondSection);
     474        //}
     475        // END OF LAST CODE
     476        System.out.println("The size of the two color data hyb data row before the labeled extract section: " +twoColorHybDataRowsFirstSection.size());
     477        System.out.println("The size of the hyb data row before adding to tow color hyb row: " +hybridizationDataRows.size());
     478        System.out.println(hybsize ==1 ? "Affy Expriment. Hyb size:"+hybsize :"2 - color Expreriment. Hyb size : "+hybsize );
     479        for (LabeledExtract labeledExtract :labeledExtracts) // can have more than one labeled extract (2 color experiments)
     480        {
     481         
    428482            //  labeled extract
    429483          hybSectionHeader.add("LabeledExtract");
    430           hybridizationDataRows.add(labeledExtract.getName());
    431          
     484          if (count<hybsize)
     485          {
     486            hybridizationDataRows.add(labeledExtract.getName());
     487          }
     488          else if (count==2)
     489          {
     490            twoColorHyb=true;
     491            twoColorHybDataRowsFirstSection.add(labeledExtract.getName());
     492          }
     493       
    432494          Protocol lbExtractProtocol= labeledExtract.getCreationEvent().getProtocol();
    433495          protocols.add(lbExtractProtocol); // labeled extract protocol
    434496          protocolRefId.add(getFormattedProtocolId(lbExtractProtocol));
    435497          protocolHybSectionHeader.add("Protocol[labeling]");
    436          
    437498          if (labeledExtract.isAnnotated())
    438499          {
     
    444505              {
    445506                parameterHybSectionHeader.add("Parameter["+annotation.getAnnotationType().getName()+"]");
    446                 parameterValues.add(annotation.getValues().toString());
     507                for (int i=0; i<annotation.getValues().size(); i++)
     508                {
     509                  parameterValues.add(annotation.getValues().get(i).toString());
     510                }
    447511              }
    448              
    449             }
    450           }
    451                  
     512              //else
     513              //{
     514              //  parameterValues.add("\t");
     515              //}
     516            }
     517          }
    452518          String labelName= labeledExtract.getLabel().getName(); // the name of the label
    453519          hybSectionHeader.add("Dye");
    454           hybridizationDataRows.add(labelName);
    455          
     520          if (count < hybsize)
     521          {
     522            hybridizationDataRows.add(labelName);
     523          }
     524          else if (count==2)
     525          {
     526            twoColorHybDataRowsFirstSection.add(labelName);
     527          }
    456528            //  Extract
    457           Set <Annotatable> extractOrPooledLabeledExtract= labeledExtract.getAnnotatableParents(); //get extract or pooled labelled extract
     529          //Set <Annotatable> extractOrPooledLabeledExtract= labeledExtract.getAnnotatableParents(); //get extract or pooled labelled extract
    458530          //if (extractOrPooledLabeledExtract instanceof Extract)
    459531          Extract extract= labeledExtract.getExtract();
     
    461533          {
    462534            hybSectionHeader.add("Extract");
    463             hybridizationDataRows.add(extract.getName());
     535            if (count < hybsize)
     536            {
     537              hybridizationDataRows.add(extract.getName());
     538            }
     539            else if (count==2)
     540            {
     541              twoColorHybDataRowsFirstSection.add(extract.getName());
     542            }
    464543           
    465544            Protocol extractProtocol =extract.getCreationEvent().getProtocol(); //extract protocol
     
    476555                {
    477556                  parameterHybSectionHeader.add("Parameter["+annotation.getAnnotationType().getName()+"]");
    478                   parameterValues.add(annotation.getValues().toString());
     557                  for (int i=0; i<annotation.getValues().size(); i++)
     558                  {
     559                    System.out.println("The extract protocol parameter is :" + annotation.getValues().get(i).toString());
     560                    parameterValues.add(annotation.getValues().get(i).toString());
     561                  }
    479562                }
    480                
     563                //else
     564                //{
     565                //  parameterValues.add("\t");
     566                //}
    481567              }
    482568            }
     
    489575          {
    490576            hybSectionHeader.add("Sample");
    491             hybridizationDataRows.add(sample.getName());
     577            if (count < hybsize)
     578            {
     579              hybridizationDataRows.add(sample.getName());
     580            }
     581            else if (count==2)
     582            {
     583              twoColorHybDataRowsFirstSection.add(sample.getName());
     584            }
    492585           
    493586            Protocol sampleProtocol=sample.getCreationEvent().getProtocol();      //sampling protocol
     
    505598                {
    506599                  parameterHybSectionHeader.add("Parameter["+annotation.getAnnotationType().getName()+"]");
    507                   parameterValues.add(annotation.getValues().toString());
     600                  for (int i=0; i<annotation.getValues().size(); i++)
     601                  {
     602                    System.out.println("The sample protocl parameter is :" + annotation.getValues().get(i).toString());
     603                    parameterValues.add(annotation.getValues().get(i).toString());
     604                  }
    508605                }
    509                
     606                //else
     607                //{
     608                //  parameterValues.add("\t");
     609                //}
    510610              }
    511611            }
    512612          }
    513613            // Biosource
    514          
     614          //sample.getAnnotatableParents(); //get the biosource or pooled samples
    515615          BioSource bioSource=sample.getBioSource();
    516616          if (bioSource!=null) //get the biosource
    517617          {
    518             hybridizationDataRows.add(bioSource.getName());
     618           
    519619            hybSectionHeader.add("Biosource");
     620            if (count < hybsize)
     621            {
     622              hybridizationDataRows.add(bioSource.getName());
     623            }
     624            else if(count==2)
     625            {
     626              twoColorHybDataRowsFirstSection.add(bioSource.getName());
     627            }
    520628            AnnotationSet bsAnnotationSet =bioSource.getAnnotationSet();
    521629            ItemQuery<Annotation> annotationsQuery= bsAnnotationSet.getAnnotations();
     
    529637                for (int i=0; i<annotation.getValues().size(); i++)
    530638                {
    531            
    532                   hybridizationDataRows.add(annotation.getValues().get(i).toString());
    533              
     639                  if (count < hybsize)
     640                  {
     641                    hybridizationDataRows.add(annotation.getValues().get(i).toString());
     642                  }
     643                  else if(count==2)
     644                  {
     645                    twoColorHybDataRowsFirstSection.add(annotation.getValues().get(i).toString());
     646                  }
     647                 
    534648                }
    535649              }
    536650            }
    537           }
     651          }
     652          System.out.println("The count before increament is :" +count);
     653          count++;
    538654         
    539         }
    540         for (String protcolId : protocolRefId)
    541         {
    542           System.out.println("----Test protocol id added----");
    543           System.out.println("Id: "+protcolId);
    544           hybridizationDataRows.add(protcolId);
    545         }
    546         for (String paramValue : parameterValues )
    547         {
    548           System.out.println("----Test parametervalue added----");
    549           hybridizationDataRows.add(paramValue);
    550         }
     655        } //end of labeled extract loop
     656       
     657        System.out.println("THE VALUE OF COUNT IS: "+ count);
     658        //for (String protcolId : protocolRefId) //add protocol id
     659        //{
     660          //System.out.println("----Test protocol id added----");
     661          //System.out.println("Id: "+protcolId);
     662        /// hybridizationDataRows.add(protcolId);
     663        //}
     664        //for (String paramValue : parameterValues ) //add parameter values
     665        //{
     666          //System.out.println("----Test parametervalue added----");
     667        //  hybridizationDataRows.add(paramValue);
     668        //}
    551669        /*
    552670          Experimental Factor Section
    553671        */
    554         factorValues= getExperimentalFactors(dc,experiment,rba);
    555         for(Annotation value: factorValues.values())
     672        expFactorValues=getExperimentalFactorValues(dc,experiment,rba);
     673        for(Annotation value: expFactorValues)  //add factor values
    556674        {
    557675          if (value!=null)
     
    562680            }
    563681          }
    564         }
    565        
     682          else
     683          {
     684            hybridizationDataRows.add("\t");
     685          }
     686        }
     687        if (twoColorHyb)
     688        {
     689          //twoColorHybDataRowsFirstSection.add("-done-");
     690          hybridizationDataRows.addAll(twoColorHybDataRowsFirstSection);
     691          //hybridizationDataRows.add("-done-");
     692        }
    566693        protocolRefId.clear();
    567694        parameterValues.clear();
    568695        factorValues.clear();
    569         System.out.println("done");
     696        if (!twoColorHybDataRowsFirstSection.isEmpty())
     697        {
     698          twoColorHybDataRowsFirstSection.clear();
     699          twoColorHyb=false;
     700        }
    570701        hybridizationDataRows.add("-done-");
     702        System.out.println("done - end of rawbioassay :" + rba.getName());
    571703      }// end of raw biossay for loop
    572704     
     
    579711        hybSectionHeader.add(parameterHeader);
    580712      }
     713      for (String factorValueHeader :factorValuesHybSectionHeader)
     714      {
     715        hybSectionHeader.add(factorValueHeader);
     716      }
     717     
    581718      //Protocol Section
    582719      out.write("Protocol section \n");
     
    614751        out.write(header.toString()+"\t");
    615752      }
    616       if (factorValues!=null)
    617       {
    618         for (AnnotationType fv : factorValues.keySet())
    619         {
    620           out.write("FactorValue["+fv.getName()+"]\t");
    621         }
    622       }
     753     
    623754      out.write("\n");
    624755      //values
     
    634765        }
    635766      }
     767      //for (String twoColor :twoColorHybDataRowsFirstSection )
     768      //{
     769      //  if (twoColor!="-done-")
     770      //  {
     771      //    out.write(twoColor+"\t");
     772      //  }
     773      //  else if("-done-".equals(twoColor))
     774      //  {
     775      //    out.write("\n");
     776      //  }
     777      //}
    636778      out.write("\n");
    637779   
     
    650792    }       
    651793  }
    652  
    653  
    654794  //   get all the experimental factors for this experiments,
    655   private static Map<AnnotationType, Annotation> getExperimentalFactors(DbControl dc, Experiment experiment, RawBioAssay rba)
    656   {
    657     Map<AnnotationType, Annotation> values= new HashMap<AnnotationType,Annotation>();
     795  private static List<Annotation> getExperimentalFactorValues(DbControl dc, Experiment experiment, RawBioAssay rba)
     796  {
     797    List<Annotation> values= new LinkedList<Annotation>();
    658798    ItemQuery<AnnotationType> experimentalFactorsQuery= experiment.getExperimentalFactors();
    659799    experimentalFactorsQuery.include(Include.MINE,Include.IN_PROJECT, Include.SHARED, Include.OTHERS);
     
    661801    for (AnnotationType exprFactor :experimentalFactors) //create the factor value for this experiment obtaining annotations from rawbioassay
    662802    {
     803      factorValuesHybSectionHeader.add("FactorValue["+exprFactor.getName()+"]");
    663804      AnnotationSet annotationSet = rba.isAnnotated() ? rba.getAnnotationSet() : null;
    664805      if (annotationSet!=null)
    665806      {
    666         values.put(exprFactor,annotationSet.findAnnotation(exprFactor));
     807        values.add(annotationSet.findAnnotation(exprFactor));
     808       
    667809      }         
    668810    }
    669811    return values;
    670812  }
    671  
    672   // get the base format id for the protocol if protocol is null and empty string is returned , this helps the mainatin the tab delim format
     813  // get the base format id for the protocol if protocol is null and empty string is returned , this helps to  mentain the tab delim format
    673814  private static String getFormattedProtocolId (Protocol protocol)
    674815  {
     
    685826    return  protocolId ;
    686827  }
     828   
     829  private static Set<String>  factorValuesHybSectionHeader= new LinkedHashSet<String>();
    687830}
Note: See TracChangeset for help on using the changeset viewer.