Changeset 2961


Ignore:
Timestamp:
Nov 27, 2006, 2:32:05 PM (16 years ago)
Author:
Johan Enell
Message:

References #429

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.1/src/plugins/core/net/sf/basedb/plugins/BioAssaySetExporter.java

    r2956 r2961  
    6969import net.sf.basedb.core.query.JoinType;
    7070import net.sf.basedb.core.query.Orders;
     71import net.sf.basedb.core.query.Selects;
    7172import net.sf.basedb.core.query.SqlResult;
    7273import net.sf.basedb.util.BioAssaySetUtil;
     
    186187
    187188 
    188   private void exportBASE(BioAssaySet bas, File file, Map<String, String> parameters, List<String> reporterFields, List<String> spotFields)
     189  private void exportBASE(BioAssaySet bas, File file, Map<String, String> parameters, List<String> reporterFields, List<String> spotFields, Boolean serialFormat, Boolean mergeReporters)
     190    throws IOException, SQLException
    189191  {
    190192    DbControl dc = bas.getDbControl();
     
    205207    // assay section   
    206208    out.println("section\tassays");
    207    
     209    out.println("count\t" + bas.getBioAssays().count(dc));
     210    String annotationString = "";
     211    for (AnnotationType at : getExperimentalFactors(dc, bas))
     212    {
     213      annotationString += "\t" + at.getName();
     214    }
     215    out.println("columns\tid\tname" + annotationString);
     216    out.println("annotationColumns" + annotationString);
    208217    out.println("%");
    209218    for (BioAssay ba : bas.getBioAssays().list(dc))
     
    214223        out.print("\t");
    215224        Set<Object> values = BioAssaySetUtil.getAnnotationValues(dc, ba, at);
    216         for (Object v : values) out.print("\t"+v);
     225        if (!values.isEmpty()) out.print(values.iterator().next());
    217226      }
    218227    }
     
    220229   
    221230    // spot section(s)
    222     out.println("section\tspots");
    223     out.println("%");
    224     out.println();
     231    String fieldString = spotFields.toString().substring(1, spotFields.toString().length() - 1).replace(", ", "\t");
     232    String columnString = reporterFields.toString().substring(1, reporterFields.toString().length() - 1).replace(", ", "\t") + "\tassayData";
     233
     234    if (serialFormat)
     235    {
     236      for (BioAssay ba : bas.getBioAssays().list(dc))
     237      {
     238        out.println("section\tspots");
     239        out.println("channels\t" + bas.getRawDataType().getChannels());
     240        out.println("assayFields\t" + fieldString);
     241        out.println("columns\t" + columnString);
     242        out.println("assays\t" + ba.getId());
     243        out.println("count\t" + ba.getNumSpots());
     244        out.println("%");
     245       
     246        DynamicSpotQuery query = ba.getSpotData();
     247        for (String field : reporterFields)
     248        {
     249          query.select(Selects.expression(BioAssaySetUtil.createJepExpression(dc, bas, field), field));
     250        }
     251        for (String field : spotFields)
     252        {
     253          query.select(Selects.expression(BioAssaySetUtil.createJepExpression(dc, bas, field), field));
     254        }
     255        if (mergeReporters)
     256        {
     257          // not implemented
     258        }
     259        DynamicResultIterator result = query.iterate(dc);
     260       
     261        List<Integer> reporterIndex = new ArrayList<Integer>(reporterFields.size());
     262        List<Integer> spotIndex = new ArrayList<Integer>(spotFields.size());
     263        for (String column : reporterFields)
     264        {
     265          reporterIndex.add(result.getIndex(column));
     266        }
     267        for (String field : spotFields)
     268        {
     269          spotIndex.add(result.getIndex(field));
     270        }
     271
     272        while (result.hasNext())
     273        {
     274          SqlResult r = result.next();
     275          boolean del = false;
     276          for (Integer column : reporterIndex)
     277          {
     278            if (del)
     279            {
     280              out.print("\t");
     281            }
     282            out.print(r.getString(column) != null ? r.getString(column) : "");
     283            del = true;
     284          }
     285          for (Integer field : spotIndex)
     286          {
     287            out.print("\t");
     288            out.print(r.getString(field) != null ? r.getString(field) : "");
     289          }
     290          out.println();
     291        }
     292       
     293        out.println();
     294      }
     295    }
     296    else
     297    {
     298     
     299    }
     300   
    225301  }
    226302 
     
    644720
    645721
     722  @SuppressWarnings("unchecked")
    646723  public void run(Request request, Response response, ProgressReporter progress)
    647724  {
     
    671748        List<String> spotFields = new ArrayList<String>((List<String>) job.getValues(usedFieldsParameter.getName()));
    672749       
    673         exportBASE(bioassayset, file, null, reporterFields, spotFields);
     750        boolean serialFormat = (Boolean) job.getValue(serialFormatParameter.getName());
     751        boolean geneAverage = (Boolean) job.getValue(geneAveragesParameter.getName());
     752       
     753        exportBASE(bioassayset, file, null, reporterFields, spotFields, serialFormat, geneAverage);
    674754      }
    675755      else
Note: See TracChangeset for help on using the changeset viewer.