00001 #ifndef MST_NODE_CPP
00002 #define MST_NODE_CPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "MSTNode.h"
00038 #include "EST.h"
00039 #include <cstdio>
00040
00041
00042 #define MAX_LINE_SIZE 1024
00043
00044 std::ostream&
00045 operator<<(std::ostream& os, const MSTNode& node) {
00046 os << "parentIdx=" << node.parentIdx
00047 << ", estIdx=" << node.estIdx
00048 << ", metric=" << node.metric;
00049 return os;
00050 }
00051
00052 void
00053 MSTNode::serialize(std::ostream& os, const bool addAlignment) const {
00054 os << parentIdx << "," << estIdx << "," << metric;
00055 if (addAlignment) {
00056 os << "," << alignmentMetric;
00057 }
00058 os << "," << direction;
00059 os << std::endl;
00060 }
00061
00062 int
00063 MSTNode::deSerialize(std::istream& is, MSTNode& node, bool& haveAlignment) {
00064 bool done = false;
00065
00066
00067
00068 do {
00069 if (is.eof()) {
00070
00071 return -1;
00072 }
00073 if (!is.good()) {
00074
00075
00076 return 1;
00077 }
00078
00079 char line[MAX_LINE_SIZE + 1];
00080 is.getline(line, MAX_LINE_SIZE);
00081
00082 if (is.gcount() == MAX_LINE_SIZE) {
00083
00084 std::cerr << "Line longer than " << MAX_LINE_SIZE
00085 << " encountered in MST file. Aborting!" << std::endl;
00086 return 2;
00087 }
00088 if ((line[0] != '#') && (!is.eof())) {
00089
00090 done = true;
00091 int fields = 0;
00092
00093 if ((fields = sscanf(line, "%d,%d,%f,%d,%d", &node.parentIdx,
00094 &node.estIdx, &node.metric,
00095 &node.alignmentMetric, &node.direction)) < 3) {
00096
00097 std::cerr << "Non-comment line with invalid format "
00098 << "encountered." << std::endl;
00099 std::cerr << "The line is: '" << line << "'\n";
00100 return 3;
00101 }
00102
00103 haveAlignment = (fields >= 4);
00104 }
00105 } while (!done);
00106
00107 return 0;
00108 }
00109
00110 std::string
00111 MSTNode::getESTInfo() const {
00112 std::string info("ESTidx #");
00113 info += estIdx;
00114 const EST *est = EST::getEST(estIdx);
00115 if ((est != NULL) && (est->getInfo() != NULL)) {
00116 info = est->getInfo();
00117 }
00118 return info;
00119 }
00120
00121 #endif