View Javadoc
1   package com.github.celldynamics.quimp.filesystem;
2   
3   import com.github.celldynamics.quimp.BOAState;
4   import com.github.celldynamics.quimp.BOA_;
5   import com.github.celldynamics.quimp.QParams;
6   import com.github.celldynamics.quimp.QParamsQconf;
7   import com.github.celldynamics.quimp.SnakePluginList;
8   import com.github.celldynamics.quimp.ViewUpdater;
9   import com.github.celldynamics.quimp.filesystem.converter.FormatConverter;
10  import com.github.celldynamics.quimp.plugin.engine.PluginFactory;
11  import com.github.celldynamics.quimp.plugin.qanalysis.STmap;
12  
13  /**
14   * Integrate outputs from every module of QuimP.
15   * 
16   * <p>All modules can add here their configuration sets. This structure is used for exchanging data
17   * between modules. It can be dynamically modified.
18   * 
19   * @author p.baniukiewicz
20   * @see FormatConverter
21   * @see QParams
22   * @see QParamsQconf
23   */
24  public class DataContainer implements IQuimpSerialize {
25  
26    /**
27     * Indicate that BOAState module is not null.
28     */
29    public static final int BOA_RUN = 1024;
30    /**
31     * Indicate that ECMM module is not null (it has been run already on those data).
32     */
33    public static final int ECMM_RUN = 2048;
34    /**
35     * Indicate that ANA module is not null (it has been run already on those data).
36     */
37    public static final int ANA_RUN = 4096;
38    /**
39     * Indicate that Q module is not null (it has been run already on those data).
40     */
41    public static final int Q_RUN = 8192;
42    /**
43     * Indicate that QCONF contains statistics.
44     */
45    public static final int STATS_AVAIL = 16384;
46  
47    /**
48     * Object to store all BOA state. Can be <tt>null</tt> when module has not been run yet.
49     */
50    public BOAState BOAState;
51    /**
52     * Object to store ECCM output. Can be <tt>null</tt> when module has not been run yet.
53     */
54    public OutlinesCollection ECMMState;
55    /**
56     * Hold ANA state.
57     */
58    public ANAParamCollection ANAState;
59    /**
60     * Store maps generated by Q Analysis plugin for every OutlineHandler from ECMMState. Can be
61     * <tt>null</tt> when module has not been run yet.
62     * 
63     * <p>The order of STmap object in this array is correlated with the order of OutlineHandlers in
64     * <tt>ECMMState</tt>, thus <i>n-th</i> STmap has been calculated from <i>n-th</i> Outline by Q
65     * Analysis module.
66     */
67    public STmap[] QState;
68    /**
69     * Store statistics for cells computed for outlines and fluorescence data.
70     */
71    public StatsCollection Stats;
72  
73    private transient PluginFactory pf;
74    private transient ViewUpdater vu;
75  
76    /**
77     * Default constructor. Create empty data containers.
78     */
79    public DataContainer() {
80      BOAState = null;
81      ECMMState = null;
82      ANAState = null;
83      QState = null;
84    }
85  
86    /**
87     * Create DataContainer with attached {@link PluginFactory PluginFactory} and {@link ViewUpdater
88     * ViewUpdater}.
89     * 
90     * @param pf {@link PluginFactory PluginFactory} object reference
91     * @param vu {@link ViewUpdater ViewUpdater} object reference
92     */
93    public DataContainer(final PluginFactory pf, final ViewUpdater vu) {
94      this();
95      this.pf = pf;
96      this.vu = vu;
97    }
98  
99    /**
100    * getBOAState.
101    * 
102    * @return the bOAState
103    */
104   public BOAState getBOAState() {
105     return BOAState;
106   }
107 
108   /**
109    * getECMMState.
110    * 
111    * @return the eCMMState
112    */
113   public OutlinesCollection getEcmmState() {
114     return ECMMState;
115   }
116 
117   /**
118    * getQState.
119    * 
120    * @return the qState
121    */
122   public STmap[] getQState() {
123     return QState;
124   }
125 
126   /**
127    * getANAState.
128    * 
129    * @return the aNAState
130    */
131   public ANAParamCollection getANAState() {
132     return ANAState;
133   }
134 
135   /**
136    * getStats.
137    * 
138    * @return the stats
139    */
140   public StatsCollection getStats() {
141     return Stats;
142   }
143 
144   /**
145    * Get information about available modules in object.
146    * 
147    * @return Flags according to loaded modules.
148    * @see com.github.celldynamics.quimp.filesystem.QconfLoader
149    */
150   public int validateDataContainer() {
151     int ret = QconfLoader.QCONF_INVALID;
152     // check for all modules
153     if (getBOAState() != null) {
154       ret += DataContainer.BOA_RUN;
155     }
156     if (getEcmmState() != null) {
157       ret += DataContainer.ECMM_RUN;
158     }
159     if (getANAState() != null) {
160       ret += DataContainer.ANA_RUN;
161     }
162     if (getQState() != null) {
163       if (getQState().length > 0) {
164         int count = 0;
165         for (STmap tmp : getQState()) {
166           if (tmp != null && tmp.getT() != 0) {
167             count++;
168           }
169         }
170         if (count == getQState().length) { // qstate can be !null but contain invalid
171           // data, e.g fluoro[3] array with initial default vales but empty. This is e,g, after
172           // paQP-QCONF conversion. So check resolution T (array size)
173           ret += DataContainer.Q_RUN;
174         }
175       }
176     }
177     if (getStats() != null) {
178       ret += DataContainer.STATS_AVAIL;
179     }
180     return ret;
181   }
182 
183   /**
184    * Called before serialization.
185    * 
186    * <p>Call similar method for all stored object allowing them for self-preparation for normal
187    * operations after loading
188    */
189   @Override
190   public void beforeSerialize() {
191     if (BOAState != null) {
192       BOAState.beforeSerialize(); // serialize first stored data
193     }
194     if (ECMMState != null) {
195       ECMMState.beforeSerialize(); // serialize second stored data
196     }
197     if (ANAState != null) {
198       ANAState.beforeSerialize();
199     }
200     if (QState != null) {
201       for (STmap stM : QState) {
202         if (stM != null) {
203           stM.beforeSerialize();
204         }
205       }
206     }
207     if (Stats != null) {
208       Stats.beforeSerialize();
209     }
210 
211   }
212 
213   /**
214    * Called after serialization.
215    * 
216    * <p>Call similar method for all stored object allowing them for self-preparation for saving
217    */
218   @Override
219   public void afterSerialize() throws Exception {
220     if (BOAState != null) {
221       BOAState.snakePluginList = new SnakePluginList(BOA_.NUM_SNAKE_PLUGINS, pf, vu);
222       BOAState.afterSerialize();
223       for (SnakePluginList sl : BOAState.snakePluginListSnapshots) {
224         sl.updateRefs(pf, vu);
225       }
226     }
227     if (ECMMState != null) {
228       ECMMState.afterSerialize();
229     }
230     if (ANAState != null) {
231       ANAState.afterSerialize();
232     }
233     if (QState != null) {
234       for (STmap stM : QState) {
235         if (stM != null) {
236           stM.afterSerialize();
237         }
238       }
239     }
240     if (Stats != null) {
241       Stats.afterSerialize();
242     }
243   }
244 }