Changeset 2481


Ignore:
Timestamp:
Aug 2, 2006, 1:59:48 PM (17 years ago)
Author:
Johan Enell
Message:

Base1PluginExecuter can now export data to base1 plug-in and import from it

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/util/parser/FlatFileParser.java

    r2409 r2481  
    797797    throws IOException
    798798  {
    799     if (nextData == null && nextSection == null)
     799    if (nextData == null)
    800800    {
    801801      boolean done = false;
  • trunk/src/plugins/core/net/sf/basedb/plugins/Base1PluginExecuter.java

    r2462 r2481  
    11/*
    2   $Id$
    3 
    4   Copyright (C) 2006 Johan Enell
    5  
    6   This file is part of BASE - BioArray Software Environment.
    7   Available at http://base.thep.lu.se/
    8 
    9   BASE is free software; you can redistribute it and/or
    10   modify it under the terms of the GNU General Public License
    11   as published by the Free Software Foundation; either version 2
    12   of the License, or (at your option) any later version.
    13 
    14   BASE is distributed in the hope that it will be useful,
    15   but WITHOUT ANY WARRANTY; without even the implied warranty of
    16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17   GNU General Public License for more details.
    18 
    19   You should have received a copy of the GNU General Public License
    20   along with this program; if not, write to the Free Software
    21   Foundation, Inc., 59 Temple Place - Suite 330,
    22   Boston, MA  02111-1307, USA.
    23 */
     2 $Id$
     3
     4 Copyright (C) 2006 Johan Enell
     5 
     6 This file is part of BASE - BioArray Software Environment.
     7 Available at http://base.thep.lu.se/
     8
     9 BASE is free software; you can redistribute it and/or
     10 modify it under the terms of the GNU General Public License
     11 as published by the Free Software Foundation; either version 2
     12 of the License, or (at your option) any later version.
     13
     14 BASE is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18
     19 You should have received a copy of the GNU General Public License
     20 along with this program; if not, write to the Free Software
     21 Foundation, Inc., 59 Temple Place - Suite 330,
     22 Boston, MA  02111-1307, USA.
     23 */
    2424
    2525package net.sf.basedb.plugins;
     
    4949import net.sf.basedb.core.PluginConfiguration;
    5050import net.sf.basedb.core.PluginParameter;
     51import net.sf.basedb.core.PositionBatcher;
    5152import net.sf.basedb.core.ProgressReporter;
    5253import net.sf.basedb.core.RawBioAssay;
     
    103104{
    104105  /**
    105    Plugin description
     106   * Plugin description
    106107   */
    107108  private static final About about = new AboutImpl(
     
    117118
    118119  /**
    119    Parameter definition that asks for the file that should be imported.
    120    This is a required parameter for the job configuration.
     120   * Parameter definition that asks for the file that should be imported. This
     121   * is a required parameter for the job configuration.
    121122   */
    122123  private static final PluginParameter<File> fileParameter = new PluginParameter<File>(
     
    132133    new StringParameterType(255, null, true));
    133134
    134   /** File configuration parameters **/
     135  /** File configuration parameters * */
    135136  private static final String serialFormatParameterName = "serialFormat";
    136137
     
    153154  private static final String usedFieldsParameterName = "usedFields";
    154155
    155   /****/
    156 
    157   /** Job parameters **/
     156  /** * */
     157
     158  /** Job parameters * */
    158159  private static final PluginParameter<BioAssaySet> bioAssaySetParameter = new PluginParameter<BioAssaySet>(
    159160    "bioAssaySet",
     
    164165  private static final String pluginDirectoryParameterName = "pluginDirectory";
    165166
    166   /****/
     167  /** * */
    167168
    168169  private static final String PARSE_CONFIG_FILE = "PARSE_CONFIG_FILE";
     
    175176
    176177  /**
    177    This list holds the job parameters derived from the configuration file.
     178   * This list holds the job parameters derived from the configuration file.
    178179   */
    179180  private List<PluginParameter<?>> jobParameters;
    180181
    181182  /**
    182    This list holds the configure parameters derived from the headers in the configuration file.
     183   * This list holds the configure parameters derived from the headers in the
     184   * configuration file.
    183185   */
    184186  private List<PluginParameter<?>> configureFileParameters;
    185187
    186188  /**
    187    This is the directory where the plugin will generate its output.
     189   * This is the directory where the plugin will generate its output.
    188190   */
    189191  private java.io.File execDirectory;
     
    215217      int channels = bas.getRawDataType().getChannels();
    216218
    217       //      int maxChannels = (Integer) configuration.getValue(maxChannelsParameterName);
    218       //      int minChannels = (Integer) configuration.getValue(minChannelsParameterName);
    219       //      if (channels <= minChannels || (channels > maxChannels && maxChannels != 0))
    220       //      {
    221       //        message = about.getName() + " can not work on " + channels + "-channel data.";
    222       //      }
     219      // int maxChannels = (Integer)
     220      // configuration.getValue(maxChannelsParameterName);
     221      // int minChannels = (Integer)
     222      // configuration.getValue(minChannelsParameterName);
     223      // if (channels <= minChannels || (channels > maxChannels &&
     224      // maxChannels != 0))
     225      // {
     226      // message = about.getName() + " can not work on " + channels +
     227      // "-channel data.";
     228      // }
    223229    }
    224230    return message;
     
    324330
    325331        FileOutputStream out = new FileOutputStream(new java.io.File(getExecDirectory(), "stdout.txt"));
    326         StreamHandler inputStream = new StreamHandler(
    327           new BufferedInputStream(p.getInputStream()),
    328           new BufferedOutputStream(out));
     332        StreamHandler inputStream = new StreamHandler(new BufferedInputStream(p.getInputStream()), new BufferedOutputStream(out));
    329333
    330334        java.io.File stdin = createStdin(dc, source);
     
    337341        outputStream.start();
    338342        int exitValue = p.waitFor();
    339        
     343
     344        err.flush();
     345        out.close();
    340346        if (exitValue == 0)
    341347        {
    342           out.close();
    343348          dc.reattachItem(source);
    344349          Transformation t = source.newTransformation(Job.getById(dc, job.getId()));
    345350          t.setName("Something---");
    346           BioAssaySet bas = t.newProduct(null, "new");
    347           bas.setName("Something after");
    348351          dc.saveItem(t);
    349           dc.saveItem(bas);
    350          
    351           createNewBioAssaySet(dc, bas);
     352
     353          createNewBioAssaySet(dc, t);
    352354
    353355          response.setDone(err.toString());
     
    355357        else
    356358        {
    357           err.flush();
    358359          response.setError("Process ended with error: " + exitValue + "\n" + err, null);
    359360        }
    360        
     361
    361362        importTempFiles(dc, getExecDirectory().listFiles(), getPluginDirectory(dc));
    362363        getExecDirectory().delete();
     364        //TODO: remove stdin.txt and stdout.txt if flags are true
    363365        dc.commit();
    364366      }
     
    388390    ffp.setDataHeaderRegexp(Pattern.compile("%"));
    389391    ffp.setDataSplitterRegexp(Pattern.compile("\\t"));
    390     ffp.setMinDataColumns(8);
    391     ffp.setMaxDataColumns(8);
    392 
     392   
    393393    ffp.setInputStream(stream);
    394394    return ffp;
     
    518518
    519519    FlatFileParser ffp = getInitializedFlatFileParser(f.getDownloadStream(0));
     520    ffp.setMinDataColumns(8);
    520521
    521522    FlatFileParser.Line section = ffp.nextSection();
     
    548549        switch (dataline.get(valueTypeCol).charAt(0))
    549550        {
    550           //String parameter
     551          // String parameter
    551552          case 't':
    552553          {
     
    556557            break;
    557558          }
    558           //Integer parameter
     559          // Integer parameter
    559560          case 'i':
    560561          {
     
    565566            break;
    566567          }
    567           //HiddenString parameter
     568          // HiddenString parameter
    568569          case 'h':
    569570          {
     
    573574            break;
    574575          }
    575           //Float parameter
     576          // Float parameter
    576577          case 'f':
    577578          {
     
    582583            break;
    583584          }
    584           //TextField parameter
     585          // TextField parameter
    585586          case 'a':
    586587          {
     
    597598            break;
    598599          }
    599           //Annotation parameter
     600          // Annotation parameter
    600601          case 'n':
    601602          {
     
    603604            break;
    604605          }
    605           //Enum Parameter
     606          // Enum Parameter
    606607          case 'e':
    607608          {
     
    698699  }
    699700
    700   private void createNewBioAssaySet(DbControl dc, BioAssaySet bas)
     701  private void createNewBioAssaySet(DbControl dc, Transformation t)
    701702    throws IOException
    702703  {
    703     SpotBatcher batcher = bas.getSpotBatcher();
    704 
    705 //    File stdout = File.getFile(dc, getPluginDirectory(dc),"stdout.txt", false);
    706     HashMap<Integer, BioAssay> idMap = new HashMap<Integer, BioAssay>();
     704    BioAssaySet bas = null;
     705    SpotBatcher spotBatcher = null;
     706    PositionBatcher posBatcher = null;
     707
     708    HashMap<String, BioAssay> idMap = new HashMap<String, BioAssay>();
    707709
    708710    FlatFileParser ffp = getInitializedFlatFileParser(new FileInputStream(new java.io.File(getExecDirectory(), "stdout.txt")));
     
    711713      FlatFileParser.Line section = ffp.nextSection();
    712714      ffp.parseHeaders();
     715
    713716      if (section.name().equals("assays"))
    714717      {
     718        bas = t.newProduct("new", "new");
     719        bas.setName("Something after");
     720        dc.saveItem(bas);
     721
    715722        List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t"));
    716723        int idCol = columns.indexOf("id");
     
    718725        int parentCol = columns.indexOf("parents");
    719726
    720         if (parentCol > -1 && nameCol > -1 && idCol > -1)
    721         {
    722           while (ffp.hasMoreData())
    723           {
    724             FlatFileParser.Data dataline = ffp.nextData();
    725             Integer id = new Integer(dataline.get(idCol));
    726             String name = dataline.get(nameCol);
    727             String[] parentIds = dataline.get(parentCol).split("/");
    728             Set<BioAssay> balist = new HashSet<BioAssay>(parentIds.length);
     727        ffp.setMinDataColumns(columns.size());
     728
     729        while (ffp.hasMoreData())
     730        {
     731          FlatFileParser.Data dataline = ffp.nextData();
     732         
     733          String id = dataline.get(idCol);
     734          String name = dataline.get(nameCol);
     735          Set<BioAssay> baParents;
     736          if (parentCol > -1)
     737          {
     738            String[] parentIds;
     739            parentIds = dataline.get(parentCol).split("/");
     740            baParents = new HashSet<BioAssay>(parentIds.length);
    729741            for (String parent : parentIds)
    730742            {
    731               balist.add(BioAssay.getById(dc, new Integer(parent)));
     743              baParents.add(BioAssay.getById(dc, new Integer(parent)));
    732744            }
    733             BioAssay ba = bas.newBioAssay(balist);
    734             ba.setName(name);
    735             dc.saveItem(ba);
    736             idMap.put(id, ba);
    737           }
    738         }
    739         else if (nameCol > -1 && idCol > -1)
    740         {
    741           while (ffp.hasMoreData())
    742           {
    743             FlatFileParser.Data dataline = ffp.nextData();
    744             Integer id = new Integer(dataline.get(idCol));
    745             String name = dataline.get(nameCol);
    746             BioAssay ba = bas.newBioAssay(BioAssay.getById(dc, id));
    747             ba.setName(name);
    748             dc.saveItem(ba);
    749             idMap.put(id, ba);
    750           }
     745          }
     746          else
     747          {
     748            baParents = Collections.singleton(BioAssay.getById(dc, Integer.parseInt(id)));
     749          }
     750          BioAssay ba = bas.newBioAssay(baParents);
     751          ba.setName(name);
     752          dc.saveItem(ba);
     753          idMap.put(id, ba);
    751754        }
    752755      }
    753756      else if (section.name().equals("spots"))
    754757      {
    755 
     758        spotBatcher = bas.getSpotBatcher(); // TODO: BioAssaySet can be null
    756759        List<String> columns = Arrays.asList(ffp.getHeader("columns").split("\\t"));
    757760        List<String> assays = Arrays.asList(ffp.getHeader("assays").split("\\t"));
    758761        List<String> assayFields = Arrays.asList(ffp.getHeader("assayFields").split("\\t"));
    759762
     763        ffp.setMinDataColumns(columns.size() - 1 + assays.size() * assayFields.size());
     764        ffp.setUseNullIfEmpty(false);
     765
    760766        int posCol = columns.indexOf("position");
    761767        int repCol = columns.indexOf("reporter");
    762         int dataCol = columns.indexOf("assatData");
     768        int dataCol = columns.indexOf("assayData");
    763769        int int1Col = assayFields.indexOf("intensity1");
    764770        int int2Col = assayFields.indexOf("intensity2");
     
    767773        boolean intCols = false;
    768774
    769         if (int1Col > -1 && int2Col > -1)
    770         {
    771           intCols = true;
    772         }
    773         else if (mCol > -1 && aCol > -1)
    774         {
    775           intCols = false;
     775        if (dataCol > -1)
     776        {
     777          if (int1Col > -1 && int2Col > -1)
     778          {
     779            intCols = true;
     780            int1Col += dataCol;
     781            int2Col += dataCol;
     782          }
     783          else if (mCol > -1 && aCol > -1)
     784          {
     785            intCols = false;
     786            mCol += dataCol;
     787            aCol += dataCol;
     788          }
     789          else
     790          {
     791            throw new BaseException(
     792              "Can't find the columns intensity1/intensity2 or l2ratio1_2/l10intgmean1_2. No data could be inmported.");
     793          }
    776794        }
    777795        else
    778796        {
    779           throw new BaseException(
    780             "Can't find the columns intensity1/intensity2 or l2ratio1_2/l10intgmean1_2. No data could be inmported.");
    781         }
    782 
    783         int1Col += dataCol;
    784         int2Col += dataCol;
    785 
     797          throw new BaseException("Can't find the column 'assayData' in header assayFields.");
     798        }
     799       
    786800        while (ffp.hasMoreData())
    787801        {
    788802          FlatFileParser.Data dataline = ffp.nextData();
    789           for (int i = 0; i < assays.size(); i++)
    790           {
    791             String assayId = assays.get(i);
     803          for (String assayId : assays)
     804          {
    792805            BioAssay ba = idMap.get(assayId);
    793806
     
    795808            float int2;
    796809
    797             if (intCols)
     810            try
    798811            {
    799               int1 = Float.parseFloat(dataline.get(int1Col));
    800               int2 = Float.parseFloat(dataline.get(int2Col));
     812              int position = Integer.parseInt(dataline.get(posCol));
     813              if (intCols)
     814              {
     815                int1 = Float.parseFloat(dataline.get(int1Col));
     816                int2 = Float.parseFloat(dataline.get(int2Col));
     817              }
     818              else
     819              {
     820                double a = Double.parseDouble(dataline.get(aCol));
     821                double m = Double.parseDouble(dataline.get(mCol));
     822
     823                // int2 = 10^a / 2^(0.5*m)
     824                // int1 = int2 * 2^m
     825                int2 = (float) (Math.pow(10, a) / Math.pow(2, 0.5 * m));
     826                int1 = (float) (int2 * Math.pow(2, m));
     827              }
     828             
     829              if (!Float.isNaN(int1) && !Float.isNaN(int2))
     830              {
     831                spotBatcher.insert(ba.getDataCubeColumnNo(), position, int1, int2);
     832              }
    801833            }
    802             else
    803             {
    804               float a = Float.parseFloat(dataline.get(aCol));
    805               float m = Float.parseFloat(dataline.get(mCol));
    806 
    807               // int2 = 10^a / 2^(0.5*m)
    808               // int1 = int2 * 2^m
    809               int2 = (float) (Math.pow(10, a) / Math.pow(2, 0.5 * m));
    810               int1 = (float) (int2 * Math.pow(2, m));
    811             }
    812 
    813             batcher.insert(ba.getDataCubeColumnNo(), 1, int1, int2);
    814           }
    815         }
    816       }
    817     }
    818     batcher.close();
     834            catch (NumberFormatException e)
     835            {}
     836          }
     837        }
     838      }
     839    }
    819840  }
    820841
     
    862883    {
    863884      out.println(ba.getId() + "\t" + ba.getName());
    864       //TODO print annotations
     885      // TODO print annotations
    865886    }
    866887    out.println();
     
    874895    fields.retainAll(base1columns.keySet());
    875896
    876     String fieldString  = fields.toString().substring(1, fields.toString().length() - 1).replace(", ", "\t");
    877     String columnString = columns.toString().substring(1, columns.toString().length() - 1).replace(", ", "\t")+"\tassayData";
     897    String fieldString = fields.toString().substring(1, fields.toString().length() - 1).replace(", ", "\t");
     898    String columnString = columns.toString().substring(1, columns.toString().length() - 1).replace(", ", "\t") + "\tassayData";
    878899    String spotHeader = "section\tspots" + "\nchannels\t" + bas.getRawDataType().getChannels() + "\nassayFields\t" + fieldString + "\ncolumns\t" + columnString;
    879900    if (configuration.getValue(serialFormatParameterName).equals("1"))
     
    965986      base1columns.put("vector", Selects.expression(Dynamic.reporter("vector"), "vector"));
    966987
    967       //Spot fields
     988      // Spot fields
    968989      base1columns.put("intensity1", Selects.expression(Dynamic.column(VirtualColumn.channel(1)), "intensity1"));
    969990      base1columns.put("intensity2", Selects.expression(Dynamic.column(VirtualColumn.channel(2)), "intensity2"));
     
    9911012        Dynamic.column(VirtualColumn.channel(2))), "ratio1_2"));
    9921013
    993       //Rawdata fields
     1014      // Rawdata fields
    9941015      base1columns.put("BCh1Mean", Selects.expression(Dynamic.rawData("ch1BgMean"), "BCh1Mean"));
    9951016      base1columns.put("BCh1Median", Selects.expression(Dynamic.rawData("ch1BgMedian"), "BCh1Median"));
     
    10481069
    10491070      /*
    1050        CCh1Mean
    1051        CCh1Median
    1052        CCh2Mean
    1053        CCh2Median
    1054        MeanRatio
    1055        MedianRatio
     1071       * CCh1Mean CCh1Median CCh2Mean CCh2Median MeanRatio MedianRatio
    10561072       */
    10571073
     
    10931109  private void importTempFiles(DbControl dc, java.io.File[] files, Directory d)
    10941110  {
     1111    // TODO: associate file with job
    10951112    for (java.io.File f : files)
    10961113    {
Note: See TracChangeset for help on using the changeset viewer.