Changeset 1007


Ignore:
Timestamp:
Mar 27, 2009, 10:59:20 PM (14 years ago)
Author:
Jari Häkkinen
Message:

metadata is split into reporter and assay metadata. Added flags to assay meta data if ref assay.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/base2/net.sf.basedb.normalizers/trunk/src/net/sf/basedb/plugins/qQuantileNormalization.java

    r1003 r1007  
    5454import java.io.PrintWriter; // Jari, remove this?
    5555import java.sql.SQLException;
     56import java.util.ArrayList; // Jari, remove this?
    5657import java.util.EnumSet;
    5758import java.util.List; // Jari, remove this?
     
    111112  // http://base.thep.lu.se/ticket/1256, and
    112113  // http://baseplugins.thep.lu.se/ticket/183.
     114  @SuppressWarnings("unchecked")
    113115  private void exportData()
    114116    throws IOException
     
    128130    }
    129131
    130     // creating a meta-data file to track the information in the plain
    131     // matrix file created above. This will be removed when BASE
    132     // BioAssaySetExporter is refactored. Of course, the current
    133     // meta-data file is highly specific for the needs here, but this
    134     // use case should be covered hete. Or, way not fall back on a
    135     // BASEfile?
     132    // creating a reporter meta data file to track the information in
     133    // the plain matrix file created above. This will be removed when
     134    // BASE BioAssaySetExporter is refactored. Of course, the current
     135    // reporter meta data file is highly specific for the needs here,
     136    // but this use case should be covered hete. Or, way not fall back
     137    // on a BASEfile?
    136138
    137139    // The query must be the same as the one done in BASE core plug-in
     
    155157        column_channel[i]=spotData.getIndex(VirtualColumn.channel(i+1).getName());
    156158
    157       PrintWriter output = new PrintWriter(getExecDirectory() +
    158                                            java.io.File.separator + metadata);
    159 
    160       // first line in meta data is assay column numbers in BASE data cube
     159      ArrayList<Short> referenceSelection=new ArrayList<Short>();
     160      List<BioAssay> assays = (List<BioAssay>)job.getValues(selectBASid);
     161      for (BioAssay assay : assays)
     162      {
     163        assay = BioAssay.getById(dc, assay.getId());
     164        referenceSelection.add(assay.getDataCubeColumnNo());
     165      }
     166
     167      PrintWriter assayWriter = new PrintWriter(getExecDirectory() +
     168                                                java.io.File.separator +
     169                                                assaydata);
    161170      List<BioAssay> sourceAssays = sourceBAS.getBioAssays().list(dc);
    162171      int nofAssays=sourceAssays.size();
    163172      for (int i=0; i<nofAssays; ++i)
    164173      {
    165         if (i>0) output.print('\t');
    166         output.print(sourceAssays.get(i).getDataCubeColumnNo());
    167       }
    168       output.println();
    169 
     174        Short colno=sourceAssays.get(i).getDataCubeColumnNo();
     175        String ref=(referenceSelection.contains(colno) ? "yes" : "no");
     176        assayWriter.println(colno + "\t" + ref);
     177      }
     178      assayWriter.close();
     179
     180      PrintWriter reporterWriter = new PrintWriter(getExecDirectory() +
     181                                                   java.io.File.separator +
     182                                                   reporterdata);
    170183      // write positions needed for storing result in BASE.
    171184      int position=0;
     
    175188        SqlResult item = spotData.next();
    176189        position=item.getInt(column_position);
    177         if (position!=prev_position) output.println(position);
    178       }
    179       output.close();
     190        if (position!=prev_position) reporterWriter.println(position);
     191      }
     192      reporterWriter.close();
    180193    }
    181194    catch (SQLException e)
     
    198211    subprocess_stdin="in.data";
    199212    subprocess_stdout="out.data";
    200     metadata="meta.data";
     213    reporterdata="reporter.data";
     214    assaydata="assay.data";
    201215    exportData();
    202216    String[] cmd = { "qQN" };
     
    211225    try
    212226    {
    213       BufferedReader metainput =
     227      BufferedReader assayinput =
    214228        new BufferedReader(new FileReader(getExecDirectory() +
    215                                           java.io.File.separator + metadata));
     229                                          java.io.File.separator + assaydata));
     230      // first column on each row in assay meta data is assay column
     231      // numbers in BASE data cube
     232      String inputline=null;
     233      ArrayList<Short> column=new ArrayList<Short>();
     234      while ((inputline = assayinput.readLine()) != null)
     235      {
     236        String[] lineSplit = inputline.split("\\s");
     237        column.add(Short.parseShort(lineSplit[0]));
     238      }
     239      assayinput.close();
     240
     241      BufferedReader reporterinput =
     242        new BufferedReader(new FileReader(getExecDirectory() +
     243                                          java.io.File.separator +
     244                                          reporterdata));
    216245      BufferedReader input =
    217246        new BufferedReader(new FileReader(getExecDirectory() +
     
    219248                                          subprocess_stdout));
    220249
    221       // first line in meta data is assay column numbers in BASE data cube
    222       String inputline=metainput.readLine();
    223       String[] lineSplit = inputline.split("\\s");
    224       Short[] column=new Short[lineSplit.length];
    225       for (int i=0; i<lineSplit.length; ++i)
    226         column[i]=Short.parseShort(lineSplit[i]);
    227250      while ((inputline = input.readLine()) != null)
    228251      {
    229         lineSplit = inputline.split("\\s");
    230         if (lineSplit.length != column.length)
     252        String[] lineSplit = inputline.split("\\s");
     253        if (lineSplit.length != column.size())
    231254          throw new BaseException("File/bioassay set size mismatch");
    232         if ((inputline = metainput.readLine()) == null)
     255        if ((inputline = reporterinput.readLine()) == null)
    233256          throw new BaseException("Data and result file size mismatch");
    234257        int position = Integer.parseInt(inputline);
    235         for (int i=0; i<column.length; ++i)
     258        for (int i=0; i<column.size(); ++i)
    236259        {
    237260          // C/C++ style string nan's (Java expects NaN) will cause a
     
    240263          // resulting matrix. Postponing exception catching until
    241264          // they start occuring.
    242           batcher.insert(column[i], position, Float.parseFloat(lineSplit[i]));
     265          batcher.insert(column.get(i), position,
     266                         Float.parseFloat(lineSplit[i]));
    243267        }
    244268      }
    245269      input.close();
     270      reporterinput.close();
    246271    }
    247272    catch (Exception e)
Note: See TracChangeset for help on using the changeset viewer.