]> ruin.nu Git - germs.git/blob - src/main.cpp
adding command line options
[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 int main(int argc, char** argv){
19
20         string ann = "default.ann";
21
22         int opt;
23         while ((opt = getopt(argc, argv, "n:h")) != -1) {
24                 switch (opt) {
25                         case 'n':
26                                 ann = optarg;
27                                 break;
28                         case 'h':
29                                 cout << "Usage: " << argv[0] << " [OPTION] [FILE]" << endl
30                                         << endl << "  -n <ann>   Specifies which artificial neural network to use for identification. '" << ann << "' is used by default"
31                                         << endl << "  -h         Prints this help message"
32                                         << endl << endl
33                                         << "With no FILE, or if FILE is '-', stdin will be used"
34                                         << endl;
35                                 exit(EXIT_SUCCESS);
36                                 break;
37                         default: /* '?' */
38                                 cerr << "Usage:  " << argv[0] << " [-n <ann>] [-h] [FILE]" << endl;
39                                 exit(EXIT_FAILURE);
40                 }
41         }
42
43         istream* in;
44         ifstream file;
45         if (optind == argc || *argv[optind] == '-'){
46                 in = &cin;
47         }else{
48                 file.open(argv[optind]);
49                 if (file.fail()){
50                         cerr << "Could not open file: '" << argv[optind] << "'" << endl;
51                         exit(EXIT_FAILURE);
52                 }
53                 in = &file;
54         }
55         //TODO: Parse
56         vector<Gene> g;
57         copy(istream_iterator<int>(*in), istream_iterator<int>(),
58                      back_inserter(g));   
59         GeneOrder go(g.begin(),g.end());
60
61         //TODO: Identify
62         ModelIdentifier mi(ann);
63         map<ModelIdentifier::Model,double> scores = mi.identify(go);
64         for (map<ModelIdentifier::Model,double>::iterator m = scores.begin();
65                         m != scores.end(); ++m){
66                 cout << "Model: " << m->first << " score: " << m->second << endl;
67         }
68
69         //TODO: Chose a sorter
70         GeneSorter so;
71         //TODO: Sort
72         GeneSorter::ActionList al = so.sort(go);
73         //TODO: Print result
74         return EXIT_SUCCESS;
75 }