MASA-Core
IManager.hpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2010-2015   Edans Sandes
00004  *
00005  * This file is part of MASA-Core.
00006  * 
00007  * MASA-Core is free software: you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation, either version 3 of the License, or
00010  * (at your option) any later version.
00011  * 
00012  * MASA-Core is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with MASA-Core.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  ******************************************************************************/
00021 
00022 #ifndef IMANAGER_HPP_
00023 #define IMANAGER_HPP_
00024 
00025 #include "libmasaTypes.hpp"
00026 #include "Partition.hpp"
00027 
00028 /* Recurrence Functions */
00029 
00030 /** NW recurrence function */
00031 #define NEEDLEMAN_WUNSCH        (0)
00032 /** SW recurrence function */
00033 #define SMITH_WATERMAN          (1)
00034 
00035 /* Predefined initialization functions */
00036 
00037 /** Init row/column with zeros */
00038 #define INIT_WITH_ZEROES                (0)
00039 
00040 /** Init row/column with gaps */
00041 #define INIT_WITH_GAPS                  (1)
00042 
00043 /** Init row/column with gaps and without gap opening penalty*/
00044 #define INIT_WITH_GAPS_OPENED   (3)
00045 
00046 /** Init row/column with custom data */
00047 #define INIT_WITH_CUSTOM_DATA   (2)
00048 
00049 /* Start type of the partition */
00050 
00051 /** Partition starts normally */
00052 #define START_TYPE_MATCH        (0)
00053 
00054 /** Partition starts with horizontal gap */
00055 #define START_TYPE_GAP_H        (1)
00056 
00057 /** Partition starts with vertical gap */
00058 #define START_TYPE_GAP_V        (2)
00059 
00060 
00061 /** @brief Interface that manages the MASA extension execution.
00062  *
00063  * The MASA framework has an implementation of the IManager interface, that is
00064  * responsible to receive commands from the Aligner. These commands are
00065  * classified in the following types:
00066  *
00067  * <ul>
00068  *  <li><b>getXXX</b> methods: Return information about the desired alignment. For
00069  *              example, the get methods returns the coordinates of the partition
00070  *              to be aligned; the sequences data; the start type of the alignment
00071  *  <li><b>receiveXXX</b> methods: Receives rows or columns from the MASA framework.
00072  *  <li><b>dispatchXXX</b> methods: Sends rows or columns to the MASA framework.
00073  *  <li><b>mustXXX</b> methods: Returns true if some requirement must be activated.
00074  * </ul>
00075  *
00076  * In order to test these conditional requirements, each aligner is associated
00077  * with an instance of the IManager interface (see setManager() function).
00078  * Besides the conditional requirement tests, the Manager also provides all
00079  * the parameters necessary to customize the alignment, for example
00080  * the sequences, the partitions coordinates.
00081  * The AbstractAligner hides the IManager invocation using some delegate
00082  * methods with protected visibility.
00083  *
00084  * @see The aligner_capabilities_t struct describes all the possible capabilities
00085  * and the requirement necessary to implement it.
00086  * @see The AbstractAligner has many methods that helps the implementation of
00087  * the IAligner interface.
00088  * @see The IManager interface manages the execution of the IAligner.
00089  */
00090 class IManager {
00091 public:
00092 
00093         /* "GET" METHODS */
00094 
00095         /**
00096          * @return the recurrence type of the alignment. Possible values are SMITH_WATERMAN and NEEDLEMAN_WUNSCH.
00097          */
00098         virtual int getRecurrenceType() const = 0;
00099 
00100         /**
00101          * @return the minimum distance between two special rows, or 0 if it must
00102          * not save special rows.
00103          */
00104         virtual int getSpecialRowInterval() const = 0;
00105 
00106         /**
00107          * @return the minimum distance between two special columns, or 0 if it must
00108          * not save special columns.
00109          */
00110         virtual int getSpecialColumnInterval() const = 0;
00111 
00112         /**
00113          * Returns the initialization type of the first column. Possible values are
00114          * <ul>
00115          *  <li>
00116          *      INIT_WITH_CUSTOM_DATA: the first column must be initialized with custom data
00117          *      that can only be obtained by the AbstractAligner::receiveFirstColumn method.
00118          *      </li>
00119          *
00120          *  <li>
00121          *      INIT_WITH_GAPS: the first column must be initialized considering gaps.
00122          *      The initialization equation is:
00123          *              \f{eqnarray*}{H_{0,0} &=& 0 \\ H_{k,0} &=& -k.G_{ext}-G_{open} \\ F_{k,0} &=& -\infty \f}
00124          *      </li>
00125          *
00126          *  <li>
00127          *      INIT_WITH_GAPS_OPENED: the first column must be initialized considering gaps,
00128          *      but without gap opening penalty.
00129          *      The initialization equation is:
00130          *              \f{eqnarray*}{H_{k,0} &=& -k.G_{ext} \\ F_{k,0} &=& -\infty \f}
00131          *      </li>
00132          *
00133          *  <li>
00134          *      INIT_WITH_ZEROES: the first column must be initialized considering zero values.
00135          *      The initialization equation is:
00136          *      \f{eqnarray*}{H_{k,0} &=& 0 \\ F_{k,0} &=& -\infty \f}
00137          *      </li>
00138          *
00139          * The initialization data of all types may be obtained by the AbstractAligner::receiveFirstColumn
00140          * method, but the subclass of AbstractAligner may implement the initialization functions
00141          * using some architectural dependent code (for example, using vectorial hardware instructions).
00142          *
00143          * </ul>
00144          * @return the initialization type.
00145          */
00146         virtual int getFirstColumnInitType() = 0;
00147 
00148         /**
00149          * Returns the initialization type of the first row. Possible values are
00150          * <ul>
00151          *  <li>
00152          *      INIT_WITH_CUSTOM_DATA: the first row must be initialized with custom data
00153          *      that can only be obtained by the AbstractAligner::receiveFirstRow method.
00154          *      </li>
00155          *
00156          *  <li>
00157          *      INIT_WITH_GAPS: the first column must be initialized considering gaps.
00158          *      The initialization equation is:
00159          *              \f{eqnarray*}{H_{0,0} &=& 0 \\ H_{0,k} &=& -k.G_{ext}-G_{open} \\ F_{0,k} &=& -\infty \f}
00160          *      </li>
00161          *
00162          *  <li>
00163          *      INIT_WITH_GAPS_OPENED: the first column must be initialized considering gaps,
00164          *      but without gap opening penalty.
00165          *      The initialization equation is:
00166          *              \f{eqnarray*}{H_{0,k} &=& -k.G_{ext} \\ F_{0,k} &=& -\infty \f}
00167          *      </li>
00168          *
00169          *  <li>
00170          *      INIT_WITH_ZEROES: the first row must be initialized considering zero values.
00171          *      The initialization equation is:
00172          *      \f{eqnarray*}{H_{0,k} &=& 0 \\ F_{0,k} &=& -\infty \f}
00173          *      </li>
00174          *
00175          * The initialization data of all types may be obtained by the AbstractAligner::receiveFirstRow
00176          * method, but the subclass of AbstractAligner may implement the initialization functions
00177          * using some architectural dependent code (for example, using vectorial hardware instructions).
00178          *
00179          * </ul>
00180          * @return the initialization type.
00181          */
00182         virtual int getFirstRowInitType() = 0;
00183 
00184 
00185 
00186         /**
00187          * Returns the super partition that includes all sub partitions being aligned.
00188          * This method must be used only by block pruning algorithms in order to
00189          * obtain the corner coordinates of the matrix.
00190          *
00191          * A super partition is a set of many smaller partitions and this occurs
00192          * in two situations. The first is when we are running stage1 in a
00193          * multiprocess environment, where we have one sub partition for each
00194          * process. The second situation happens when the aligner cannot handle
00195          * the full size of the matrix, so the partition is split in parts
00196          * smaller than the max sequence size capability of the aligner.
00197          *
00198          * @return the super partition.
00199          */
00200         virtual Partition getSuperPartition() = 0;
00201 
00202 
00203         /* "RECEIVE" METHODS */
00204 
00205         /**
00206          * Receives the first row of the partition. This function may block until
00207          * all the requested data is ready. So prefer to read data in chunks instead
00208          * of reading the full first row.
00209          * The data will be stored from 0 to len-1 positions of the vector passed in the parameters.
00210          *
00211          * @param buffer the vector where the first row data will be stored.
00212          * @param len the number of cells that will be read.
00213          */
00214         virtual void receiveFirstRow(cell_t* buffer, int len) = 0;
00215 
00216         /**
00217          * Receives the first column of the partition. This function may block until
00218          * all the requested data is ready. So prefer to read data in chunks instead
00219          * of reading the full first row.
00220          * The data will be stored from 0 to len-1 positions of the vector passed in the parameters.
00221          *
00222          * @param buffer the vector where the first column data will be stored.
00223          * @param len the number of cells that will be read.
00224          */
00225         virtual void receiveFirstColumn(cell_t* buffer, int len) = 0;
00226 
00227         /* "DISPATCH" METHODS */
00228 
00229         /**
00230          * Notifies to the MASA framework that some cells of a column has been processed.
00231          * This function must be called serially for each column. For example,
00232          * the invocation of dispatchColumn(50000, vector, 100) will dispatch the
00233          * first 100 cells of the column 50000 to MASA, and the cells are read from
00234          * the vector[0..99] elements. After this, a call to dispatchColumn(50000, vector, 50)
00235          * will dispatch the next 50 cells of the same column 5000, and the cells are read from
00236          * the vector[0..49] elements.
00237          *
00238          * @param j                     the column to be dispatched.
00239          * @param buffer        the vector containing the data (starting from cell 0).
00240          * @param len           the number of cells that will be read from the vector.
00241          */
00242         virtual void dispatchColumn(int j, const cell_t* buffer, int len) = 0;
00243 
00244         /**
00245          * Notifies to the MASA framework that some cells of a row has been processed.
00246          * This function must be called serially for each row, analogous to the
00247          * AbstractAligner::dispatchLastColumn method.
00248          *
00249          * @param i                     the row to be dispatched.
00250          * @param buffer        the vector containing the data (starting from cell 0).
00251          * @param len           the number of cells that will be read from the vector.
00252          */
00253         virtual void dispatchRow(int i, const cell_t* buffer, int len) = 0;
00254 
00255         /**
00256          * Notifies to the MASA framework that a new score has been computed.
00257          * This method may be called as many times it is necessary, and the
00258          * best score will be calculated among all calls of this method.
00259          *
00260          * If the Aligner supports the aligner_capabilities_t::dispatch_block_scores
00261          * capability, them it must dispatch the score with the bx, by parameters
00262          * set to the block indices and this method must be called only once for
00263          * each block.
00264          *
00265          * @param score the score to be dispatched
00266          * @param bx    the block position in the horizontal direction, starting from
00267          *                              0 up to AbstractAligner::getGridWidth() minus 1.
00268          * @param by    the block position in the vertical direction, starting from
00269          *                              0 up to AbstractAligner::getGridHeight() minus 1.
00270          */
00271         virtual void dispatchScore(score_t score, int bx=-1, int by=-1) = 0;
00272 
00273         /* "MUST" METHODS */
00274 
00275         /**
00276          * @return true if the execution must continue.
00277          */
00278         virtual bool mustContinue() = 0;
00279 
00280         /**
00281          * @return true if the last cell must be dispatched.
00282          */
00283         virtual bool mustDispatchLastCell() = 0;
00284 
00285         /**
00286          * @return true if the last row must be dispatched.
00287          */
00288         virtual bool mustDispatchLastRow() = 0;
00289 
00290         /**
00291          * @return true if the last column must be dispatched.
00292          */
00293         virtual bool mustDispatchLastColumn() = 0;
00294 
00295         /**
00296          * @return true if special rows must be dispatched.
00297          */
00298         virtual bool mustDispatchSpecialRows() = 0;
00299 
00300         /**
00301          * @return true if special columns must be dispatched.
00302          */
00303         virtual bool mustDispatchSpecialColumns() = 0;
00304 
00305         /**
00306          * @return true if intermediate scores must be dispatched.
00307          */
00308         virtual bool mustDispatchScores() = 0;
00309 
00310         /**
00311          * @return true if block pruning optimization may be used.
00312          */
00313         virtual bool mustPruneBlocks() = 0;
00314 
00315 protected:
00316 /* Avoid the creation/deletion of this interface */
00317                 ~IManager() {};
00318                 IManager() {};
00319 };
00320 
00321 
00322 #endif /* IMANAGER_HPP_ */