Update mussa to build on ubuntu 10.04 with qt 4.6.2 +boost 1.40.0.1
[mussa.git] / alg / parse_options.cpp
1 #include <boost/program_options.hpp>
2 namespace po = boost::program_options;
3 #include <boost/filesystem/path.hpp>
4 namespace fs = boost::filesystem;
5
6 #include <string>
7 #include <iostream>
8
9 #include "alg/mussa.hpp"
10 #include "alg/parse_options.hpp"
11
12 MussaOptions::MussaOptions()
13   : useGUI(true),
14     runAsPythonInterpeter(false)
15 {
16 }
17
18 void initialize_mussa(MussaOptions& opts, int argc, char **argv)
19 {
20   po::options_description options("Mussa options");
21   po::positional_options_description pos_options;
22   pos_options.add("run-analysis", -1);
23
24   options.add_options()
25     ("help", "help message")
26     ("run-analysis,p", po::value<std::string>(), 
27      "run an analysis defined by the mussa parameter file")
28     ("view-analysis", po::value<std::string>(),
29      "load a previously run analysis")
30     ("motifs", po::value<std::string>(),
31      "annotate analysis with motifs from this file")
32     ("no-gui", "terminate without running an analysis")
33     ("python", "launch as a python interpreter")
34   ;
35
36   po::variables_map vm;
37   po::store(po::command_line_parser(argc, argv).options(options).positional(pos_options).run(), vm);
38   po::notify(vm);
39
40   if (vm.count("help")) {
41     std::cout << options << std::endl;
42     return;
43   }
44   
45   opts.analysis = Mussa::init();
46
47   // currently we can only have one analysis loaded, so 
48   // running trumps viewing.
49   if (vm.count("run-analysis")) {
50     fs::path analysis_path(vm["run-analysis"].as< std::string >(), fs::native);
51     opts.analysis->load_mupa_file( analysis_path );
52     std::cout << "I apologize for blocking the gui while running the analysis"
53               << std::endl;
54     opts.analysis->analyze();
55     if (opts.analysis->is_dirty())
56       opts.analysis->save();
57   }
58   else if (vm.count("view-analysis")) {
59     fs::path analysis_path(vm["view-analysis"].as< std::string >(), fs::native);
60     opts.analysis->load( analysis_path );
61   }
62   if (vm.count("motifs") and opts.analysis) {
63     fs::path motif_path(vm["motifs"].as< std::string >(), fs::native);
64     opts.analysis->load_motifs( motif_path );
65   }
66   if (vm.count("no-gui")) {
67     opts.useGUI=false;
68   }
69   if (vm.count("python")) {
70     opts.runAsPythonInterpeter = true;
71   }
72 }