src/core/net/sf/basedb/util/export/spotdata/SerialBaseFileExporter.java

Code
Comments
Other
Rev Date Author Line
4925 08 May 09 nicklas 1 /**
4925 08 May 09 nicklas 2   $Id$
4925 08 May 09 nicklas 3
4925 08 May 09 nicklas 4   Copyright (C) 2009 Nicklas Nordborg
4925 08 May 09 nicklas 5
4925 08 May 09 nicklas 6   This file is part of BASE - BioArray Software Environment.
4925 08 May 09 nicklas 7   Available at http://base.thep.lu.se/
4925 08 May 09 nicklas 8
4925 08 May 09 nicklas 9   BASE is free software; you can redistribute it and/or
4925 08 May 09 nicklas 10   modify it under the terms of the GNU General Public License
4925 08 May 09 nicklas 11   as published by the Free Software Foundation; either version 3
4925 08 May 09 nicklas 12   of the License, or (at your option) any later version.
4925 08 May 09 nicklas 13
4925 08 May 09 nicklas 14   BASE is distributed in the hope that it will be useful,
4925 08 May 09 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
4925 08 May 09 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4925 08 May 09 nicklas 17   GNU General Public License for more details.
4925 08 May 09 nicklas 18
4925 08 May 09 nicklas 19   You should have received a copy of the GNU General Public License
4925 08 May 09 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
4925 08 May 09 nicklas 21 */
4925 08 May 09 nicklas 22 package net.sf.basedb.util.export.spotdata;
4925 08 May 09 nicklas 23
4925 08 May 09 nicklas 24 import java.util.Arrays;
4925 08 May 09 nicklas 25 import java.util.List;
4925 08 May 09 nicklas 26
4925 08 May 09 nicklas 27 import net.sf.basedb.core.BioAssay;
4925 08 May 09 nicklas 28 import net.sf.basedb.core.DbControl;
4925 08 May 09 nicklas 29 import net.sf.basedb.core.DynamicSpotQuery;
4925 08 May 09 nicklas 30 import net.sf.basedb.core.Type;
5405 10 Sep 10 nicklas 31 import net.sf.basedb.core.signal.ThreadSignalHandler;
4925 08 May 09 nicklas 32 import net.sf.basedb.util.basefile.BaseFileWriter;
4925 08 May 09 nicklas 33
4925 08 May 09 nicklas 34 /**
4925 08 May 09 nicklas 35   Exporter implementation that exports bioassay set data as a serial
4925 08 May 09 nicklas 36   BASEfile.
4925 08 May 09 nicklas 37   
4925 08 May 09 nicklas 38   @author Nicklas
4925 08 May 09 nicklas 39   @version 2.12
4925 08 May 09 nicklas 40   @base.modified $Date$
4925 08 May 09 nicklas 41 */
4925 08 May 09 nicklas 42 public class SerialBaseFileExporter
4925 08 May 09 nicklas 43   extends BaseFileExporter
4925 08 May 09 nicklas 44 {
4925 08 May 09 nicklas 45
5373 03 Aug 10 nicklas 46   public static final String SUBTYPE = "serial";
5373 03 Aug 10 nicklas 47
4925 08 May 09 nicklas 48   private List<BioAssay> bioAssays;
4925 08 May 09 nicklas 49   private int nextBioAssay;
4925 08 May 09 nicklas 50   private BaseFileWriter out;
4925 08 May 09 nicklas 51   private DynamicSpotQuery spotQuery;
4925 08 May 09 nicklas 52   private DynamicSpotQuery countQuery;
4925 08 May 09 nicklas 53   private long spotCount;
4925 08 May 09 nicklas 54   
4925 08 May 09 nicklas 55   /**
4925 08 May 09 nicklas 56     Create a new serial BASEfile exporter.
4925 08 May 09 nicklas 57   */
4925 08 May 09 nicklas 58   public SerialBaseFileExporter()
4925 08 May 09 nicklas 59   {}
4925 08 May 09 nicklas 60
4925 08 May 09 nicklas 61   /**
4925 08 May 09 nicklas 62     From AbstractBioAssaySetExporter/BaseFileExporter class
4925 08 May 09 nicklas 63     -------------------------------------------------------
4925 08 May 09 nicklas 64   */
4925 08 May 09 nicklas 65   /**
4925 08 May 09 nicklas 66     Prepare the export by pre-loading some information and
4925 08 May 09 nicklas 67     configure the queries that we are going to use.
4925 08 May 09 nicklas 68   */
4925 08 May 09 nicklas 69   @Override
4925 08 May 09 nicklas 70   protected void beginExport()
4925 08 May 09 nicklas 71   {
4925 08 May 09 nicklas 72     super.beginExport();
4925 08 May 09 nicklas 73     bioAssays = getBioAssays();
4925 08 May 09 nicklas 74     nextBioAssay = 0;
4925 08 May 09 nicklas 75     out = getBaseFileWriter();
4925 08 May 09 nicklas 76     spotQuery = getSpotQuery(true);
4925 08 May 09 nicklas 77     countQuery = getCountQuery(true);
4925 08 May 09 nicklas 78     setProgress(0, "Caching reporter data...");
4925 08 May 09 nicklas 79     cacheReporterData();
4925 08 May 09 nicklas 80   }
4925 08 May 09 nicklas 81
4925 08 May 09 nicklas 82   /**
4925 08 May 09 nicklas 83     Exports headers for a 'spots' section, and make preparations
4925 08 May 09 nicklas 84     for the current data section (one section per bioassay).
4925 08 May 09 nicklas 85   */
4925 08 May 09 nicklas 86   @Override
4925 08 May 09 nicklas 87   protected void exportSectionHeader()
4925 08 May 09 nicklas 88   {
4925 08 May 09 nicklas 89     // Get configuration options
4925 08 May 09 nicklas 90     DbControl dc = getDbControl();
4925 08 May 09 nicklas 91     BioAssay current = bioAssays.get(nextBioAssay);
4925 08 May 09 nicklas 92     int bioAssayColumn = (int)current.getDataCubeColumnNo();
4925 08 May 09 nicklas 93     
4925 08 May 09 nicklas 94     // Set parameters on the queries
4925 08 May 09 nicklas 95     spotQuery.setParameter("bioAssayColumn", bioAssayColumn, Type.INT);
4925 08 May 09 nicklas 96     countQuery.setParameter("bioAssayColumn", bioAssayColumn, Type.INT);
4925 08 May 09 nicklas 97     
4925 08 May 09 nicklas 98     int percent = 10+(int)((90L * nextBioAssay) / bioAssays.size());
4925 08 May 09 nicklas 99     setProgress(percent, "Exporting bioassay '" + current.getName() + 
4925 08 May 09 nicklas 100       "' (" + (nextBioAssay+1)+" of " + bioAssays.size() + ")");
4925 08 May 09 nicklas 101
5689 11 Aug 11 nicklas 102     // Count the spots in this section. Delegate output to superclass
4925 08 May 09 nicklas 103     long count = countQuery.count(dc);
4925 08 May 09 nicklas 104     spotCount += count;
5405 10 Sep 10 nicklas 105     ThreadSignalHandler.checkInterrupted();
4925 08 May 09 nicklas 106     exportSpotSectionHeaders(Arrays.asList(current), count);
4925 08 May 09 nicklas 107   }
4925 08 May 09 nicklas 108
4925 08 May 09 nicklas 109   /**
4925 08 May 09 nicklas 110     Exports data for the current bioassay in a 'spots' section.
4925 08 May 09 nicklas 111   */
4925 08 May 09 nicklas 112   @Override
4925 08 May 09 nicklas 113   protected void exportSectionData()
4925 08 May 09 nicklas 114   {
4925 08 May 09 nicklas 115     BioAssay current = bioAssays.get(nextBioAssay);
4925 08 May 09 nicklas 116     exportSpotSectionData(Arrays.asList(current), spotQuery, null, 0);
4925 08 May 09 nicklas 117   }
4925 08 May 09 nicklas 118
4925 08 May 09 nicklas 119   /**
4925 08 May 09 nicklas 120     Ends the current 'spots' section.
4925 08 May 09 nicklas 121     @return Always FALSE if this was the last bioassay, or TRUE if 
4925 08 May 09 nicklas 122       there are more bioassays to export
4925 08 May 09 nicklas 123   */
4925 08 May 09 nicklas 124   @Override
4925 08 May 09 nicklas 125   protected boolean exportSectionFooter()
4925 08 May 09 nicklas 126   {
4925 08 May 09 nicklas 127     out.baseEndSection();
4925 08 May 09 nicklas 128     out.flush();
4925 08 May 09 nicklas 129     nextBioAssay++;
4925 08 May 09 nicklas 130     return nextBioAssay < bioAssays.size();
4925 08 May 09 nicklas 131   }
4925 08 May 09 nicklas 132
4925 08 May 09 nicklas 133   @Override
4925 08 May 09 nicklas 134   protected void endExport(RuntimeException e)
4925 08 May 09 nicklas 135   {
4926 11 May 09 nicklas 136     if (e == null) setProgress(100, "Export complete. " + spotCount + " spots done");
4925 08 May 09 nicklas 137     out = null;
4925 08 May 09 nicklas 138     bioAssays = null;
4925 08 May 09 nicklas 139     spotQuery = null;
4925 08 May 09 nicklas 140     countQuery = null;
4925 08 May 09 nicklas 141     super.endExport(e);
4925 08 May 09 nicklas 142   }
4925 08 May 09 nicklas 143   // -------------------------------------------------------
4925 08 May 09 nicklas 144   
4925 08 May 09 nicklas 145   
4925 08 May 09 nicklas 146   
4925 08 May 09 nicklas 147   
4925 08 May 09 nicklas 148 }