Changeset 516


Ignore:
Timestamp:
Dec 7, 2007, 3:06:52 PM (14 years ago)
Author:
mbayer
Message:

first two sections of tab2mage file now get generated ok

Location:
branches/uk_ac_ebi_Tab2MageImporter/src/uk/ac/ebi/nugo/plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/uk_ac_ebi_Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/Tab2MageImporter.java

    r515 r516  
    105105  private static final Set<GuiContext> guiContexts = Collections.singleton(experimentItemGuiContext);
    106106 
     107  //add all the parameter names to a String array for processing
     108  String [] paramNames = new String []{"experimentId","domain","accession","qualityControl","experimentalDesign",
     109          "experimentName","description","releaseDate","submissionDate","submitter","organization",
     110          "publicationTitle","authors","journal","volume","issue","pages","year","pubmedId","treatmentProtocol",
     111          "extractionProtocol","labelingProtocol","hybridizationProtocol","scanningProtocol",
     112          "treatmentProtocolParams","extractionProtocolParams","labelingProtocolParams",
     113          "hybridizationProtocolParams","scanningProtocolParams","platform","organism",
     114          "numDesigns","dyeSwap","refSample","numTreatments","expFactors","numReplicates",
     115          "tissues","pooling","zipFile"};
     116 
    107117
    108118//  =====================================================c'tor================================== 
     
    123133  private void initParams()
    124134  {   
    125     //add all the parameter names to a String array for processing
    126     String [] paramNames = new String []{"experimentId","domain","accession","qualityControl","experimentalDesign",
    127             "experimentName","description","releaseDate","submissionDate","submitter","organization",
    128             "publicationTitle","authors","journal","volume","issue","pages","year","pubmedId","treatmentProtocol",
    129             "extractionProtocol","labelingProtocol","hybridizationProtocol","scanningProtocol",
    130             "treatmentProtocolParams","extractionProtocolParams","labelingProtocolParams",
    131             "hybridizationProtocolParams","scanningProtocolParams","platform","organism",
    132             "numDesigns","dyeSwap","refSample","numTreatments","expFactors","numReplicates",
    133             "tissues","pooling","zipFile"};
    134135       
    135     // next create the parameter type - everyone is a String here
     136    //create the parameter type - every parameter is a String
    136137    StringParameterType stringPT = new StringParameterType(255, null, true);
    137138   
     
    419420      //this takes all the inputs provided by the user on the custom interface (input.jsp)
    420421      //give the file a unique name so we don't get any conflicts
    421       Tab2MageWriter t2mWriter = new Tab2MageWriter(job, dir,sc);
     422      Tab2MageWriter t2mWriter = new Tab2MageWriter(job, dir,sc,paramNames);
    422423      t2mWriter.writeTab2MageFile();
    423424
  • branches/uk_ac_ebi_Tab2MageImporter/src/uk/ac/ebi/nugo/plugins/Tab2MageWriter.java

    r515 r516  
    11package uk.ac.ebi.nugo.plugins;
    22
    3 import java.io.*;
    4 
    5 import net.sf.basedb.core.BaseException;
     3import java.io.BufferedWriter;
     4import java.io.OutputStreamWriter;
     5import java.io.Writer;
     6import java.lang.reflect.Field;
     7
    68import net.sf.basedb.core.DbControl;
    79import net.sf.basedb.core.Directory;
    8 import net.sf.basedb.core.InvalidDataException;
    9 import net.sf.basedb.core.PermissionDeniedException;
    10 import net.sf.basedb.core.PluginConfigurationRequest;
    1110import net.sf.basedb.core.SessionControl;
    1211import net.sf.basedb.core.plugin.ParameterValues;
    13 import net.sf.basedb.core.plugin.Request;
    1412
    1513public class Tab2MageWriter
    1614{
    17 //===================================================vars================================================
    18  
    19   int numReplicates;
    20   int numTissues;
    21   int numTreatments;
     15//  ===================================================vars================================================
     16
    2217  Directory dir;
    2318  SessionControl sc;
    24  
     19  String t2mContent = "";
     20  ParameterValues job;
     21  String [] paramNames;
     22
     23  String domain;
     24  String accession;
     25  String qualityControl;
     26  String experimentalDesign;
     27  String experimentName;
     28  String description;
     29  String releaseDate;
     30  String submissionDate;
     31  String submitter;
     32  String organization;
     33  String publicationTitle;
     34  String authors;
     35  String journal;
     36  String volume;
     37  String issue;
     38  String pages;
     39  String year;
     40  String pubmedId;
     41  String treatmentProtocol;
     42  String extractionProtocol;
     43  String labelingProtocol;
     44  String hybridizationProtocol;
     45  String scanningProtocol;
     46  String treatmentProtocolParams;
     47  String extractionProtocolParams;
     48  String labelingProtocolParams;
     49  String hybridizationProtocolParams;
     50  String scanningProtocolParams;
     51  String platform;
     52  String organism;
     53  String numDesigns;
     54  String dyeSwap;
     55  String refSample;
     56  String numTreatments;
     57  String expFactors;
     58  String numReplicates;
     59  String tissues;
     60  String pooling;
     61  String zipFile;
     62  String experimentId;
     63 
     64 
     65
    2566//  ===================================================c'tor================================================
    26  
    27   public Tab2MageWriter(ParameterValues job,Directory dir,SessionControl sc)
     67
     68  public Tab2MageWriter(ParameterValues job,Directory dir,SessionControl sc,String [] paramNames)
    2869  {
    2970    this.dir = dir;
    3071    this.sc = sc;
    31 
    32     //get values for the parameters we need here
    33     int numReplicates = Integer.parseInt((String)job.getValue("numReplicates"));
    34     int numTreatments = Integer.parseInt((String)job.getValue("numTreatments"));   
    35     String tissues = (String)job.getValue("tissues");
    36     int numTissues = tissues.split(",").length;
    37    
    38     System.out.println("numReplicates extracted from job = " +numReplicates);
     72    this.job = job;
     73    this.paramNames = paramNames;
     74    initJobParamValues();
     75  }
     76
     77  //for testing only
     78  public Tab2MageWriter()
     79  {
     80    initTestParamValues();
    3981  }
    4082
    4183//  ===================================================methods================================================ 
    42  
    43   public static void main(String [] args)
    44   {
    45   }
    46  
     84
     85  //sets all the values of the local variables to those found in the job object
     86  private void initJobParamValues()
     87  {
     88    try
     89    {
     90      Class cls = Class.forName("uk.ac.ebi.nugo.plugins.Tab2MageWriter");     
     91      for (int i = 0; i < paramNames.length; i++)
     92      {
     93        Field field = cls.getField(paramNames[i]);
     94        field.set(this, job.getValue(paramNames[i]));
     95      }
     96    }
     97    catch (Exception e)
     98    {
     99      e.printStackTrace();
     100    }
     101  }
     102
     103//  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     104
     105  public String generateFileContents()
     106  {
     107    makeExperimentSection();
     108    makeProtocolSection();
     109    makeHybridizationsSection();
     110    return t2mContent;
     111  }
     112
     113//  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------   
     114 
     115  private void makeExperimentSection()
     116  {
     117    //header for this section
     118    t2mContent += "Experiment section\n";
     119   
     120    String [] rowHeaders = new String [] {"domain","accession","quality_control","experiment_design_type","name","description","release_date","submission_date","submitter","organization","publication_title","authors","journal","volume","issue","pages","year","pubmed_id"};
     121    String [] experimentParams = new String [] {domain,accession,qualityControl,experimentalDesign,experimentName,description,releaseDate,submissionDate,submitter,organization,publicationTitle,authors,journal,volume,issue,pages,year,pubmedId};
     122   
     123    for (int i = 0; i < rowHeaders.length; i++)
     124    {
     125      t2mContent += rowHeaders[i] + "\t" + experimentParams[i] + "\n";
     126    }
     127   
     128    //separate from next section by a blank line
     129    t2mContent += "\n\n";
     130  }
     131 
     132//  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------   
     133 
     134  private void makeProtocolSection()
     135  {
     136    //header for this section
     137    t2mContent += "Protocol section\n";
     138   
     139    //section needs to look like this:
     140    /*
     141    accession name      text    parameters    type
     142    P-DIET-1  treatment   text            grow
     143    P-EXTR-1  extraction    text            extraction
     144    P-LABL-1  labeling      text            labeling
     145    P-HYBR-1  hybridization text            hybridization
     146    P-SCAN-1  scanning    text            scanning
     147    */
     148    String [] accessions = new String [] {"P-DIET-1","P-EXTR-1","P-LABL-1","P-HYBR-1","P-SCAN-1"};
     149    String [] names = new String [] {"treatment","extraction","labeling","hybridization","scanning"};
     150    String [] values = new String [] { treatmentProtocol, extractionProtocol, labelingProtocol, hybridizationProtocol, scanningProtocol};
     151    String [] parameters = new String [] {treatmentProtocolParams, extractionProtocolParams,labelingProtocolParams,hybridizationProtocolParams,scanningProtocolParams};
     152    String [] types = new String [] {"grow","extraction","labeling","hybridization","scanning"};
     153   
     154    //print header
     155    t2mContent += "accession\tname\ttext\tparameters\ttype\n";
     156   
     157    //print rows
     158    for (int i = 0; i < accessions.length; i++)
     159    {
     160      t2mContent += accessions[i] + "\t" + names[i] + "\t" + values[i] + "\t" + parameters[i] + "\t" + types[i] + "\n";
     161    }
     162   
     163    //separate from next section by a blank line
     164    t2mContent += "\n\n";
     165  }
     166
     167//  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------   
     168 
     169  private void makeHybridizationsSection()
     170  {
     171    //header for this section
     172    t2mContent += "Hybridization section\n";
     173  }
     174 
     175//  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     176
    47177  public void writeTab2MageFile()
    48178  {
     
    55185      t2mFile.setName("tab2mage.txt");     
    56186      dc.saveItem(t2mFile);
    57      
     187
    58188      if(dc==null)
    59189        dc = sc.newDbControl();
    60      
     190
    61191      Writer out= new BufferedWriter(new OutputStreamWriter(t2mFile.getUploadStream(false),"ISO-8859-1"));
    62      
    63       //write stuff to file
    64       out.write("test String");
    65      
     192
     193      //write content to file
     194      out.write(t2mContent);
     195
    66196      //close writer
    67197      if (out!= null) out.close();
    68      
     198
    69199      dc.commit();
    70200      if(dc!=null)
     
    76206    }   
    77207  }
     208
     209//  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    78210 
    79211  private int calcNumHybs()
    80212  {
     213    //get values for the parameters we need here
     214    int numReps = Integer.parseInt(numReplicates);
     215    int numTreats = Integer.parseInt(numTreatments);   
     216    int numTissues = tissues.split(",").length;
    81217    //Number of hybridizations (NH) = Number of subjects (NS) x Number of Target Tissue (NTT) x Number of Study groups (NSG)
    82     return numReplicates * numTissues * numTreatments;
    83 
    84   }
    85 
    86 }
     218    return numReps * numTissues * numTreats;
     219  }
     220
     221//  -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     222
     223  private void initTestParamValues()
     224  {
     225    experimentId = "2";
     226    domain = "scri.ac.uk";
     227    accession = "E-SCRI-001";
     228    qualityControl = "biological replicate,spike quality control";
     229    experimentalDesign = "cell_component_comparison_design,RNA_stability_design,family_history_design,";
     230    experimentName = "New experiment";
     231    description = "description goes here";
     232    releaseDate = "2007-12-03";
     233    submissionDate = "2007-12-03";
     234    submitter = "Joe Bloggs";
     235    organization = "SCRI";
     236    publicationTitle = "My Ropey Paper";
     237    authors = "Bloggs, Joe";
     238    journal = "The Journal of Irreproducible Results";
     239    volume = "5";
     240    issue = "2";
     241    pages = "1234-1235";
     242    year = "2007";
     243    pubmedId = "11009762";
     244    treatmentProtocol = "my treatment protocol text";
     245    extractionProtocol = " my extraction protocol text";
     246    labelingProtocol = " my labeling protocol text";
     247    hybridizationProtocol = "my hybs protocol text";
     248    scanningProtocol = " my scanning protocol text";
     249    treatmentProtocolParams = "param1";
     250    extractionProtocolParams = "param2";
     251    labelingProtocolParams = "param3";
     252    hybridizationProtocolParams = "param4";
     253    scanningProtocolParams = " param5";
     254    platform = "Affymetrix";
     255    organism = "barley";
     256    numDesigns = "1";
     257    dyeSwap = "no";
     258    refSample = "no";
     259    numTreatments = "2";
     260    expFactors = "Factor 1(value1,value2,...valueN)";
     261    numReplicates = "3";
     262    tissues = "tissues1,tissue2";
     263    pooling = "no";
     264    zipFile = "/home/michab/potato_small.zip";
     265
     266  }
     267//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     268}//end class
Note: See TracChangeset for help on using the changeset viewer.