00001 00010 #ifndef ORTHOMETHOD_H 00011 #define ORTHOMETHOD_H 00012 //#define HAVE_NAMESPACE_STD 00013 00014 //#include <multimap.h> in the std version, it is incuded in <map> 00015 #include <map> 00016 #include <vector> 00017 //#include "libpq++.h" 00018 #include <pqxx> 00019 #include "cluster.h" 00020 00021 using namespace std; 00022 using namespace pqxx; 00023 00026 set<int> grab(int k, multimap<int, int> &mm); 00027 00028 class clusmethod 00029 { 00030 public: 00031 /* connInfo is the connection info to the backend db, see 00032 * lbpq definition. Default is provided by a static 00033 * char dbconnInfo[] in this class. 00034 * The query must produce two columns of integers right now. 00035 * seed->target both are keys 00036 */ 00037 //clusmethod(const char *query, PgDatabase &db); 00038 //clusmethod(const char *query, const char *connInfo = "host=localhost dbname=orpara"); 00039 // replaced by simpler interface 00040 00043 clusmethod() { } 00044 00054 //clusmethod(PgDatabase &orthodb) { dbinput(orthodb); } 00055 clusmethod(result &orthodb) { dbinput(orthodb); } 00056 //void dbinput(PgDatabase &orthodb); 00062 void dbinput(result &qres); 00063 /* take data from a flat file 00064 * first_number second_number 00065 * use >> to read 00066 * */ 00067 clusmethod(char file[]) { fileinput(file); } 00068 void fileinput(const char file[]); 00069 00070 /* this methods does all the work */ 00071 vector<cluster>& findCluster(); 00072 00073 /* A function to display the two private members rel and revrel 00074 * used for debuging. */ 00075 void printMap(); 00076 00077 /* Display the result to an output stream. Default to stdout */ 00078 void displayClusters(ostream &os=cout); 00079 00080 /* clears the input data to release memory */ 00081 void clearMap() { rel.clear(); revrel.clear(); } 00082 00083 /* this methods loads the result into two database tables 00084 * update_tab = cds (update_col = pcluster) 00085 * clutab = pcluster or ncluster (id, member) will be 00086 * inserted 00087 * id is the key for pcluster or ncluster 00088 * cluster_id is the initial id number for naming clusters 00089 * it will be incremented as each cluster is inserted. 00090 * return true if successful 00091 * */ 00092 //bool loadTable(PgDatabase &orthodb, string update_tab, string update_col, 00093 bool loadTable(connection &orthodb, string update_tab, string update_col, 00094 string clutab, string clus_col, int &cluster_id); 00095 void dumpTable(const char ins[], const char upd[], int &cluster_id); // write result into files 00096 00097 int getClusterCount() { return allcl.size(); } 00098 00101 //friend set<int> grab(int k, multimap<int, int> &mm); 00102 00103 private: 00104 // helper for findCluster 00105 set<int> processTargets(const set<int> &tset); 00106 00107 multimap<int, int> rel; // forward relation 00108 multimap<int, int> revrel; // reverse relation 00109 //PgDatabase orthodb; // just make things more complicated 00110 vector<cluster> allcl; //store all the clusters; the result 00111 }; 00112 00113 #endif
1.5.6