00001 #ifndef MST_NODE_H 00002 #define MST_NODE_H 00003 00004 //-------------------------------------------------------------------- 00005 // 00006 // This file is part of PEACE. 00007 // 00008 // PEACE is free software: you can redistribute it and/or modify it 00009 // under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation, either version 3 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // PEACE is distributed in the hope that it will be useful, but 00014 // WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with PEACE. If not, see <http://www.gnu.org/licenses/>. 00020 // 00021 // Miami University makes no representations or warranties about the 00022 // suitability of the software, either express or implied, including 00023 // but not limited to the implied warranties of merchantability, 00024 // fitness for a particular purpose, or non-infringement. Miami 00025 // University shall not be liable for any damages suffered by licensee 00026 // as a result of using, result of using, modifying or distributing 00027 // this software or its derivatives. 00028 // 00029 // By using or copying this Software, Licensee agrees to abide by the 00030 // intellectual property laws, and all other applicable laws of the 00031 // U.S., and the terms of GNU General Public License (version 3). 00032 // 00033 // Authors: Dhananjai M. Rao raodm@muohio.edu 00034 // 00035 //--------------------------------------------------------------------- 00036 00037 #include <iostream> 00038 00039 /** A simple class to represent a MSTNode. 00040 00041 This inner class is used to represent a node in the MST. A 00042 MSTNode contains the information about each EST added to the MST 00043 as detailed below. Ecapsulation of the data into a single Node 00044 class eases creation and manipulation of the MST. 00045 00046 A MSTNode encapsulates the following information about each node 00047 in a MST: 00048 00049 <ul> 00050 00051 <li>\c parentIdx : (\c int) The zero-based index of the parent 00052 EST. If a node has no parent (it is the root of the MST) then 00053 this value is set to -1. The \c parentIdx is an offset into the 00054 list of ESTs returned by EST::getESTList() method. </li> 00055 00056 <li>\c estIdx : (\c int) The zero-based index of the EST that a 00057 given MST node represents. This value is the index of the 00058 corresponding EST in the list of ESTs returned by 00059 EST::getESTList() method. </li> 00060 00061 <li> \c metric : (\c float) The similarity/distance metric 00062 generated by a given EST analyzer indicating the relationship 00063 between this node and its parent node.</li> 00064 00065 <li> \c alignmentMetric : (\c int) The alignment metric generated 00066 by a given EST analyzer indicating alignment relationship between 00067 this node and its parent node.</li> 00068 00069 </ul> 00070 */ 00071 class MSTNode { 00072 // Insertion operator to make dumping MSTNode for debugging easier. 00073 friend std::ostream& operator<<(std::ostream&, const MSTNode&); 00074 public: 00075 /** A default constructor. 00076 00077 A default constructor is needed by STL for performing 00078 various operations. The default constructor merely sets 00079 all the members to an invalid value (-1). 00080 */ 00081 inline MSTNode() : parentIdx(-1), estIdx(-1), metric(-1), 00082 alignmentMetric(0), direction(1) {} 00083 00084 /** A convenience constructor to create a MSTNode. 00085 00086 This constructor provides a convenient mechanism to create 00087 and initialize an MSTNode object with necessary 00088 information. 00089 00090 \param[in] parentIndex The index of the parent EST for 00091 this Node. If a parent does not exist, then this value 00092 should be -1. 00093 00094 \param[in] estIndex The index of the EST. This value must 00095 be the index of the corresponding EST in the list of ESTs 00096 returned by EST::getESTList() method. 00097 00098 \param[in] nodeMetric The similarity/distance metric between 00099 this EST and its parent EST. 00100 00101 \param[in] alignment The alignment metric generated by a given 00102 EST analyzer indicating some of the alignment relationship 00103 between this node and its parent node. 00104 00105 \param[in] directionValue The direction value generated by a 00106 given EST analyzer indicating whether this node and its parent 00107 node are related by reverse-complementing (-1) or not (1). 00108 */ 00109 inline MSTNode(const int parentIndex, const int estIndex, 00110 const float nodeMetric, const int alignment = 0, 00111 const int directionValue = 1) : 00112 parentIdx(parentIndex), estIdx(estIndex), 00113 metric(nodeMetric), alignmentMetric(alignment), 00114 direction(directionValue){} 00115 00116 /** Method to write the node information to an output stream. 00117 00118 This method can be used to serialize the information in this 00119 node to a given output stream (or file). The data is written 00120 in the following comma format: 00121 00122 <pre>parentESTidx, ESTidx, metric</pre> 00123 00124 \param[out] os The output stream to which the data is to be 00125 written. 00126 00127 \param[in] addAlignment If this flag is \c true, then this 00128 method also serializes the alignment metric value associated 00129 with this node. 00130 */ 00131 void serialize(std::ostream& os, const bool addAlignment) const; 00132 00133 /** Returns the FASTA header corresponding to the EST for this 00134 node. 00135 00136 This function obtains the EST corresponding to the ESTidx 00137 value stored in this node via the EST::getEST() method and 00138 then returns the information associated with the EST. The 00139 information about the EST is determined via the EST::getInfo() 00140 method. 00141 00142 \return The FASTA header associated with the given EST. If no 00143 information is available this method returns an empty string. 00144 */ 00145 std::string getESTInfo() const; 00146 00147 /** Method to read the node information to an input stream. 00148 00149 This method can be used to deserialize the information for 00150 this node from a given input stream (or file) that was 00151 previous generated through a successful call to the 00152 serialize() method. If the first character in the line is a 00153 "#" (pound character) then this method ignores the line and 00154 proceeds to process the next one. 00155 00156 The data read is assumed to be in the the following comma 00157 separated format: 00158 00159 <pre>parentESTidx, ESTidx, metric</pre> 00160 00161 \param[in,out] is The input stream from which the data is to be 00162 written. 00163 00164 \param[out] node The node that must be populated with the data 00165 from the MST file. 00166 00167 \param[out] haveAlignment If the entry deserialized by this 00168 method had alignment data then this parameters is set to \c 00169 true. Otherwise this parameter is set to \c false. Note that 00170 the value is updated only if a valid line was successfully 00171 read. 00172 00173 \return This method returns 0 if the data for the node was 00174 successfully read. It returns -1 on EOF. On errors, it 00175 returns a positive, non-zero value. 00176 */ 00177 static int deSerialize(std::istream& is, MSTNode& node, 00178 bool& haveAlignment); 00179 00180 /** Returns the metric value set for this node. 00181 00182 This method returns the metric value for this node when the 00183 node was instantiated. 00184 00185 \return The metric value set for this node. 00186 */ 00187 inline float getMetric() const { return metric; } 00188 00189 /** Returns the distance metric value set for this node. 00190 00191 This method returns the distance metric value for this node 00192 when the node was instantiated. 00193 00194 \return The distance metric value set for this node. 00195 */ 00196 inline int getAlignmentMetric() const { return alignmentMetric; } 00197 00198 /** Returns the index of the EST that is set for this node. 00199 00200 This method returns the index of the EST that was set when 00201 this node was created. 00202 00203 \return The index of the EST set for this node. 00204 */ 00205 inline int getESTIdx() const { return estIdx; } 00206 00207 /** The zero-based index of the parent EST. If a node has no 00208 parent (it is the root of the MST) then this value is set 00209 to -1. The \c parentIdx is an offset into the list of 00210 ESTs returned by EST::getESTList() method. 00211 */ 00212 int parentIdx; 00213 00214 /** The zero-based index of the EST that a given MST node 00215 represents. This value is the index of the corresponding 00216 EST in the list of ESTs returned by EST::getESTList() 00217 method. 00218 */ 00219 int estIdx; 00220 00221 /** The similarity/distance metric generated by a given EST 00222 analyzer indicating the relationship between this node and its 00223 parent node. 00224 */ 00225 float metric; 00226 00227 /** The alignment metric generated by a given EST analyzer 00228 indicating some of the alignment relationship between this 00229 node and its parent node. 00230 */ 00231 int alignmentMetric; 00232 00233 /** A simple index to indicate the direction of the analysis. 00234 -1 indicates that the child EST is reverse-complemented from 00235 the parent EST. 00236 1 indicates that the parent and child ESTs are in the same direction. 00237 */ 00238 int direction; 00239 }; 00240 00241 /** \fn std::ostream& operator<<(std::ostream&, const MSTNode&) 00242 00243 Insertion operator to stream MSTNode information to a given output 00244 stream. This method provides a convenient mechanism to dump 00245 MSTNode information for debugging purposes. 00246 */ 00247 extern std::ostream& operator<<(std::ostream&, const MSTNode&); 00248 00249 #endif