]> ruin.nu Git - germs.git/blob - src/main.cpp
Only show models with positive score, and convert the enum to strings
[germs.git] / src / main.cpp
1 #include <iostream>
2 #include <vector>
3 #include <queue>
4 #include <iterator>
5 #include <fstream>
6
7 using namespace std;
8
9 #include <unistd.h>
10
11 #include "geneorder.h"
12 #include "modelidentifier.h"
13 #include "genesorter.h"
14 #include "sortaction.h"
15
16 typedef pair<ModelIdentifier::Model,double> modelpair;
17
18 struct ScoreCmp {
19         template<typename T>
20         bool operator()(T s1, T s2){
21                 return s1.first < s2.first;
22         }
23 };
24
25 int main(int argc, char** argv){
26
27         string ann = "default.ann";
28
29         int opt;
30         while ((opt = getopt(argc, argv, "n:h")) != -1) {
31                 switch (opt) {
32                         case 'n':
33                                 ann = optarg;
34                                 break;
35                         case 'h':
36                                 cout << "Usage: " << argv[0] << " [OPTION] [FILE]" << endl
37                                         << endl << "  -n <ann>   Specifies which artificial neural network to use for identification. '" << ann << "' is used by default"
38                                         << endl << "  -h         Prints this help message"
39                                         << endl << endl
40                                         << "With no FILE, or if FILE is '-', stdin will be used"
41                                         << endl;
42                                 exit(EXIT_SUCCESS);
43                                 break;
44                         default: /* '?' */
45                                 cerr << "Usage:  " << argv[0] << " [-n <ann>] [-h] [FILE]" << endl;
46                                 exit(EXIT_FAILURE);
47                 }
48         }
49
50         istream* in;
51         ifstream file;
52         if (optind == argc || *argv[optind] == '-'){
53                 in = &cin;
54         }else{
55                 file.open(argv[optind]);
56                 if (file.fail()){
57                         cerr << "Could not open file: '" << argv[optind] << "'" << endl;
58                         exit(EXIT_FAILURE);
59                 }
60                 in = &file;
61         }
62         //TODO: Parse
63         vector<Gene> g;
64         copy(istream_iterator<int>(*in), istream_iterator<int>(),
65                      back_inserter(g));   
66         GeneOrder go(g.begin(),g.end());
67
68         //TODO: Identify
69         ModelIdentifier mi(ann);
70         map<ModelIdentifier::Model,double> scores = mi.identify(go);
71         priority_queue<pair<double,ModelIdentifier::Model>,vector<pair<double,ModelIdentifier::Model> >, ScoreCmp > pq;
72         for (map<ModelIdentifier::Model,double>::iterator m = scores.begin();
73                         m != scores.end(); ++m){
74                 if (m->second > 0){
75                         pq.push(pair<double,ModelIdentifier::Model>(m->second,m->first));
76                 }
77         }
78         while (pq.size() > 0){
79                 cout << "Model: " << mi.modelName(pq.top().second) << " score: " << pq.top().first << endl;
80                 pq.pop();
81         }
82
83         //TODO: Chose a sorter
84         GeneSorter so;
85         //TODO: Sort
86         GeneSorter::ActionList al = so.sort(go);
87         //TODO: Print result
88         return EXIT_SUCCESS;
89 }