]> ruin.nu Git - germs.git/blobdiff - src/main.cpp
Only show models with positive score, and convert the enum to strings
[germs.git] / src / main.cpp
index 5e6a5c99902915cd28e344b4d63eecec0ed8f375..1c6a85ecc85790716e6a8559e1ea86117d716922 100644 (file)
@@ -2,8 +2,12 @@
 #include <vector>
 #include <queue>
 #include <iterator>
+#include <fstream>
+
 using namespace std;
 
+#include <unistd.h>
+
 #include "geneorder.h"
 #include "modelidentifier.h"
 #include "genesorter.h"
@@ -11,20 +15,69 @@ using namespace std;
 
 typedef pair<ModelIdentifier::Model,double> modelpair;
 
-int main(){
+struct ScoreCmp {
+       template<typename T>
+       bool operator()(T s1, T s2){
+               return s1.first < s2.first;
+       }
+};
+
+int main(int argc, char** argv){
+
+       string ann = "default.ann";
 
+       int opt;
+       while ((opt = getopt(argc, argv, "n:h")) != -1) {
+               switch (opt) {
+                       case 'n':
+                               ann = optarg;
+                               break;
+                       case 'h':
+                               cout << "Usage: " << argv[0] << " [OPTION] [FILE]" << endl
+                                       << endl << "  -n <ann>   Specifies which artificial neural network to use for identification. '" << ann << "' is used by default"
+                                       << endl << "  -h         Prints this help message"
+                                       << endl << endl
+                                       << "With no FILE, or if FILE is '-', stdin will be used"
+                                       << endl;
+                               exit(EXIT_SUCCESS);
+                               break;
+                       default: /* '?' */
+                               cerr << "Usage:  " << argv[0] << " [-n <ann>] [-h] [FILE]" << endl;
+                               exit(EXIT_FAILURE);
+               }
+       }
+
+       istream* in;
+       ifstream file;
+       if (optind == argc || *argv[optind] == '-'){
+               in = &cin;
+       }else{
+               file.open(argv[optind]);
+               if (file.fail()){
+                       cerr << "Could not open file: '" << argv[optind] << "'" << endl;
+                       exit(EXIT_FAILURE);
+               }
+               in = &file;
+       }
        //TODO: Parse
        vector<Gene> g;
-       copy(istream_iterator<int>(cin), istream_iterator<int>(),
+       copy(istream_iterator<int>(*in), istream_iterator<int>(),
                     back_inserter(g));   
        GeneOrder go(g.begin(),g.end());
 
        //TODO: Identify
-       ModelIdentifier mi("default.ann");
+       ModelIdentifier mi(ann);
        map<ModelIdentifier::Model,double> scores = mi.identify(go);
+       priority_queue<pair<double,ModelIdentifier::Model>,vector<pair<double,ModelIdentifier::Model> >, ScoreCmp > pq;
        for (map<ModelIdentifier::Model,double>::iterator m = scores.begin();
                        m != scores.end(); ++m){
-               cout << "Model: " << m->first << " score: " << m->second << endl;
+               if (m->second > 0){
+                       pq.push(pair<double,ModelIdentifier::Model>(m->second,m->first));
+               }
+       }
+       while (pq.size() > 0){
+               cout << "Model: " << mi.modelName(pq.top().second) << " score: " << pq.top().first << endl;
+               pq.pop();
        }
 
        //TODO: Chose a sorter
@@ -32,5 +85,5 @@ int main(){
        //TODO: Sort
        GeneSorter::ActionList al = so.sort(go);
        //TODO: Print result
-       return 0;
+       return EXIT_SUCCESS;
 }