src/core/net/sf/basedb/util/export/spotdata/MatrixBaseFileExporter.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.List;
4925 08 May 09 nicklas 25
4925 08 May 09 nicklas 26 import net.sf.basedb.core.BioAssay;
4925 08 May 09 nicklas 27 import net.sf.basedb.core.DbControl;
4925 08 May 09 nicklas 28 import net.sf.basedb.core.DynamicSpotQuery;
4925 08 May 09 nicklas 29 import net.sf.basedb.core.ProgressReporter;
4925 08 May 09 nicklas 30 import net.sf.basedb.util.ChainedProgressReporter;
4925 08 May 09 nicklas 31 import net.sf.basedb.util.basefile.BaseFileWriter;
4925 08 May 09 nicklas 32
4925 08 May 09 nicklas 33 /**
4925 08 May 09 nicklas 34   Exporter implementation that exports bioassay set data as a matrix
4925 08 May 09 nicklas 35   BASEfile.
4925 08 May 09 nicklas 36
4925 08 May 09 nicklas 37   @author Nicklas
4925 08 May 09 nicklas 38   @version 2.12
4925 08 May 09 nicklas 39   @base.modified $Date$
4925 08 May 09 nicklas 40 */
4925 08 May 09 nicklas 41 public class MatrixBaseFileExporter
4925 08 May 09 nicklas 42   extends BaseFileExporter
4925 08 May 09 nicklas 43 {
4925 08 May 09 nicklas 44
5373 03 Aug 10 nicklas 45   public static final String SUBTYPE = "matrix";
5373 03 Aug 10 nicklas 46
4925 08 May 09 nicklas 47   private BaseFileWriter out;
4925 08 May 09 nicklas 48   private List<BioAssay> bioAssays;
4925 08 May 09 nicklas 49   private DynamicSpotQuery spotQuery;
4925 08 May 09 nicklas 50   private DynamicSpotQuery countQuery;
4925 08 May 09 nicklas 51   private ChainedProgressReporter progress;
4925 08 May 09 nicklas 52   private long spotCount;
4925 08 May 09 nicklas 53   
4925 08 May 09 nicklas 54   /**
4925 08 May 09 nicklas 55     Create a new matrix BASEfile exporter.
4925 08 May 09 nicklas 56   */
4925 08 May 09 nicklas 57   public MatrixBaseFileExporter()
4925 08 May 09 nicklas 58   {}
4925 08 May 09 nicklas 59
4925 08 May 09 nicklas 60   /**
4925 08 May 09 nicklas 61     From AbstractBioAssaySetExporter/BaseFileExporter class
4925 08 May 09 nicklas 62     -------------------------------------------------------
4925 08 May 09 nicklas 63   */
4925 08 May 09 nicklas 64   /**
4925 08 May 09 nicklas 65     Prepare the export by pre-loading some information and
4925 08 May 09 nicklas 66     configure the queries that we are going to use.
4925 08 May 09 nicklas 67   */
4925 08 May 09 nicklas 68   @Override
4925 08 May 09 nicklas 69   protected void beginExport()
4925 08 May 09 nicklas 70   {
4925 08 May 09 nicklas 71     super.beginExport();
4925 08 May 09 nicklas 72     bioAssays = getBioAssays();
4925 08 May 09 nicklas 73     out = getBaseFileWriter();
4925 08 May 09 nicklas 74     spotQuery = getSpotQuery(false);
4925 08 May 09 nicklas 75     countQuery = getCountQuery(false);
4925 08 May 09 nicklas 76     ProgressReporter p = getProgressReporter();
4925 08 May 09 nicklas 77     if (p != null) progress = new ChainedProgressReporter(p);
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 single 'spots' section.
4925 08 May 09 nicklas 84   */
4925 08 May 09 nicklas 85   @Override
4925 08 May 09 nicklas 86   protected void exportSectionHeader()
4925 08 May 09 nicklas 87   {
4925 08 May 09 nicklas 88     // Get configuration options
4925 08 May 09 nicklas 89     DbControl dc = getDbControl();
4925 08 May 09 nicklas 90     
5689 11 Aug 11 nicklas 91     // Count the spots in this section. Delegate output to superclass
5229 04 Feb 10 nicklas 92     setProgress(10, "Counting number of spots...");
4925 08 May 09 nicklas 93     spotCount = countQuery.count(dc);
4925 08 May 09 nicklas 94     exportSpotSectionHeaders(bioAssays, spotCount);
4925 08 May 09 nicklas 95   }
4925 08 May 09 nicklas 96
4925 08 May 09 nicklas 97   /**
4925 08 May 09 nicklas 98     Exports data for all bioassays in a single 'spots' section.
4925 08 May 09 nicklas 99   */
4925 08 May 09 nicklas 100   @Override
4925 08 May 09 nicklas 101   protected void exportSectionData()
4925 08 May 09 nicklas 102   {
5229 04 Feb 10 nicklas 103     if (progress != null) progress.setRange(20, 100);
4925 08 May 09 nicklas 104     exportSpotSectionData(bioAssays, spotQuery, progress, spotCount);
4925 08 May 09 nicklas 105   }
4925 08 May 09 nicklas 106
4925 08 May 09 nicklas 107   /**
4925 08 May 09 nicklas 108     Ends the 'spots' section.
4925 08 May 09 nicklas 109     @return Always FALSE, since there are no more spot sections
4925 08 May 09 nicklas 110   */
4925 08 May 09 nicklas 111   @Override
4925 08 May 09 nicklas 112   protected boolean exportSectionFooter()
4925 08 May 09 nicklas 113   {
4925 08 May 09 nicklas 114     out.baseEndSection();
4925 08 May 09 nicklas 115     out.flush();
4925 08 May 09 nicklas 116     return false;
4925 08 May 09 nicklas 117   }
4925 08 May 09 nicklas 118   
4925 08 May 09 nicklas 119   @Override
4925 08 May 09 nicklas 120   protected void endExport(RuntimeException e)
4925 08 May 09 nicklas 121   {
4926 11 May 09 nicklas 122     if (e == null) setProgress(100, "Export complete. " + spotCount + " spots done");
4925 08 May 09 nicklas 123     out = null;
4925 08 May 09 nicklas 124     bioAssays = null;
4925 08 May 09 nicklas 125     spotQuery = null;
4925 08 May 09 nicklas 126     countQuery = null;
4925 08 May 09 nicklas 127     progress = null;
4925 08 May 09 nicklas 128     super.endExport(e);
4925 08 May 09 nicklas 129   }
4925 08 May 09 nicklas 130   // -------------------------------------------------------
4925 08 May 09 nicklas 131
4925 08 May 09 nicklas 132   
4925 08 May 09 nicklas 133 }