12 #include "geneorder.h"
13 #include "modelidentifier.h"
14 #include "genesorter.h"
15 #include "threadgenesorter.h"
16 #include "sortaction.h"
17 #include "genealgorithms.h"
20 int main(int argc, char** argv){
22 string ann = "default.ann";
24 bool detectModel = true;
25 bool onlyIdentify = false;
26 bool printPerm = false;
28 //Parse command line arguments
31 while ((opt = getopt(argc, argv, "im:n:t:hp")) != -1) {
34 model = Model::modelFactory(optarg);
41 threads = atoi(optarg);
50 cout << "Usage: " << argv[0] << " [OPTION] [FILE]" << endl
51 << endl << " -m <model> Specifies which model to use for sorting: Whirl, X, Zipper, FatX or Cloud "
52 << endl << " -n <ann> Specifies which artificial neural network to use for identification. '" << ann << "' is used by default"
53 << endl << " -i Only identify the model, don't try to sort it"
54 << endl << " -p Print the resulting permutation at each sorting step"
55 << endl << " -h Prints this help message"
57 << "With no FILE, or if FILE is '-', stdin will be used"
62 cerr << "Usage: " << argv[0] << " [-n <ann>] [-h] [FILE]" << endl;
70 if (optind == argc || *argv[optind] == '-'){
73 file.open(argv[optind]);
75 cerr << "Could not open file: '" << argv[optind] << "'" << endl;
81 //Parse the gene order permutation
83 copy(istream_iterator<int>(*in), istream_iterator<int>(),
85 GeneOrder go(g.begin(),g.end());
88 ModelIdentifier mi(ann);
89 priority_queue<pair<double,Model> > pq = mi.identify(go);
91 model = pq.top().second;
93 while (pq.size() > 0){
94 cout << "Model: " << pq.top().second.name() << " score: " << pq.top().first << endl;
97 cout << "Using model: " << model.name() << endl;
99 cout << "Distance: " << inversionDistance(go) << endl;
100 //copy(go.begin(), go.end(), ostream_iterator<int>(cout, " "));
107 ThreadGeneSorter so(model, threads);
111 ThreadGeneSorter::SolutionsQueue solutions = so.solutions();
113 while (solutions.size() > 0){
114 pair<double,GeneSorter::ActionList> s = solutions.top();
118 for (GeneSorter::ActionList::iterator sa = s.second.begin(); sa != s.second.end(); ++sa){
119 cout << sa->toString() << " ";
122 cout << endl << "Score: " << s.first << endl;
128 GeneSorter::ActionList al = so.sort(go,model);
134 for (GeneSorter::ActionList::iterator sa = al.begin(); sa != al.end(); ++sa){
135 cout << "Action: " << sa->toString() << " model score: " << model.score(*sa,temp) << endl;
137 score += model.score(*sa,temp);
140 copy(temp.begin(), temp.end(), ostream_iterator<int>(cout, " "));
144 cout << "Avg score: " << score / al.size() << endl;