Changeset 4318


Ignore:
Timestamp:
May 27, 2008, 10:08:15 AM (15 years ago)
Author:
Jari Häkkinen
Message:

Addresses #639. Exporting plain matrix for 1 and 2 channel data.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.7-stable/src/plugins/core/net/sf/basedb/plugins/BioAssaySetExporter.java

    r4235 r4318  
    44  Copyright (C) 2006 Johan Enell, Jari Hakkinen, Nicklas Nordborg, Martin Svensson
    55  Copyright (C) 2007 Johan Enell, Jari Hakkinen, Peter Johansson, Nicklas Nordborg, Martin Svensson
     6  Copyright (C) 2008 Jari Hakkinen, Nicklas Nordborg
    67
    78  This file is part of BASE - BioArray Software Environment.
     
    105106     use in MeV (available from http://www.tm4.org).
    106107   - BASEfile.
    107    - Plain Matrix
     108   - Plain Matrix, see documentation for exportPlainMatrix method for
     109     a description of the format.
    108110
    109111   @author enell, jari, peter
     
    602604 
    603605  /**
    604     Export bioassayset data in MeV format. The export includes
    605     all reporter information and all experimental factor information. If the
    606     expriment is a two-channel experiment the log ratio is exported as the
    607     expression value otherwise the raw intensity of channel 1 is exported.
     606    Export bioassayset data in MeV format. The export includes all
     607    reporter information and all experimental factor information. If
     608    the expriment is a two-channel experiment the ch1/ch2 ratio
     609    (non-log value!) is exported as the expression value otherwise the
     610    raw intensity of channel 1 is exported.
    608611   
    609612    @param bioassayset The bioassayset to export
     
    708711    int position=-1;
    709712    short column=nof_bioassays;
    710     double log2=Math.log(2.0);
    711713    int nof_reporters=bioassayset.getNumReporters();
    712714    int progress_report_interval=nof_reporters/10;
     
    771773
    772774
     775  /**
     776    Export bioassayset data in plain matrix format.
     777
     778    Plain matrix format is simply a matrix with no header nor reporter
     779    information. Each column in the matrix corresponds to an assay,
     780    and each row corresponds to a reporter.
     781
     782    Missing values are reported as entries with no number and 'NaN' is
     783    reported for undefined values (such as division with zero). Note,
     784    reporters with no measurement within a bioassay set are not
     785    reported at all, i.e., a row is not exported with misssing values
     786    only. To be clear, we state this once more: Rows (reporters) are
     787    only exported if one or more columns (assays) have a value. The
     788    value can be 'NaN'.
     789
     790    The data exported depends on the underlying microarray platform;
     791     - 1-channel: raw ch1 intensity
     792     - 2-channel: the fraction ch1/ch2, note! non-log value
     793    The justification for exporting non-log values for 2-channel data
     794    is to follow the MeV export format where non-log data is exported
     795    for 2-channel data. 'NaN' is returned for zero ch2 values.
     796
     797    The plug-in or user that uses this method must keep track of the
     798    row and column information themselves. The row is sorted in
     799    ascending position order, the columns are sorted in ascending
     800    column order.
     801
     802    @param bioassayset The bioassayset to export
     803    @param os The stream to write the exported data to
     804    @param progress An optional progress reporter
     805    @throws IOException If there is an IO error
     806    @throws SQLException If there is an error reading from the database
     807  */
    773808  public void exportPlainMatrix(BioAssaySet bioassayset, OutputStream os,
    774809                                ProgressReporter progress)
     
    778813    DbControl dc=bioassayset.getDbControl();
    779814    PrintWriter out = new PrintWriter(os);
    780     List<ExtendedProperty> reporterProperties =
    781       ExtendedProperties.getProperties("ReporterData");
    782815
    783816    int nof_bioassays=0;
    784817    nof_bioassays=bioassayset.getBioAssays().list(dc).size();
     818    int nof_channels=bioassayset.getRawDataType().getChannels();
    785819
    786820    if (progress != null)
     
    792826    query.select(Dynamic.select(VirtualColumn.POSITION));
    793827    query.select(Dynamic.select(VirtualColumn.COLUMN));
    794     query.select(Dynamic.select(VirtualColumn.channel(1)));
    795    
     828    for (int i=1; i<=nof_channels; ++i)
     829    {
     830      query.select(Dynamic.select(VirtualColumn.channel(i)));
     831    }
     832
    796833    query.order(Orders.asc(Dynamic.column(VirtualColumn.POSITION)));
    797834    query.order(Orders.asc(Dynamic.column(VirtualColumn.COLUMN)));
     
    801838    int column_position=spotData.getIndex(VirtualColumn.POSITION.getName());
    802839    int column_column=spotData.getIndex(VirtualColumn.COLUMN.getName());
    803     int column_channel=spotData.getIndex(VirtualColumn.channel(1).getName());
    804    
     840    int[] column_channel=new int[nof_channels];
     841    for (int i=0; i<nof_channels; ++i)
     842    {
     843      column_channel[i]=spotData.getIndex(VirtualColumn.channel(i+1).getName());
     844    }
     845
    805846    int position=-1;
    806847    int column=nof_bioassays;
    807     //double log2=Math.log(2.0);
    808848    int nof_spots=bioassayset.getNumSpots();
    809849    int progress_spot_interval=nof_spots/10;
     
    848888
    849889      // Calculate expression value
    850       String ch1=item.getString(column_channel);
    851       out.write(ch1);
    852     }
    853     out.flush();
     890      double exValue=item.getFloat(column_channel[0]);
     891      boolean goodvalue=true;
     892      if (nof_channels==2)
     893      {
     894        double ch2=item.getFloat(column_channel[1]);
     895        if (ch2!=0)
     896        {
     897          exValue/=ch2;
     898        }
     899        else
     900        {
     901          goodvalue=false;
     902        }
     903      }
     904
     905      out.write( "\t" + (goodvalue ? exValue : "NaN"));
     906    }
     907    out.close();
    854908  }
    855909
     
    10951149      formats.add(FORMAT_MEV, "MultiExperiment Viewer (MeV)");
    10961150      formats.add(FORMAT_BASEFILE, "BASEfile");
    1097 //      formats.add(FORMAT_PLAIN_MATRIX, "Plain Matrix");
     1151      /**
     1152         Plain matrix export is currently not supported from the web
     1153         interface. Simply move the code line below outside this
     1154         comment block to enable plain matrix export in the web
     1155         interface. If the export is enabled the About information
     1156         should be updated to reflect the change.
     1157
     1158         formats.add(FORMAT_PLAIN_MATRIX, "Plain Matrix");
     1159      */
    10981160      formatParameter = new PluginParameter<String>
    10991161        ( "fileformat",
     
    12921354      "- Tab Delimited, Multiple Sample Files (TDMS Format) for " +
    12931355      "use in MeV (available from http://www.tm4.org).\n"+
    1294       "- BASEfile",
     1356      "- BASEfile\n",
    12951357      "2.0",
    12961358      "2006, Base 2 development team",
Note: See TracChangeset for help on using the changeset viewer.