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