more fs::native for user supplied paths
[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   MussaRef new_mussa(new Mussa);
46   opts.analysis = new_mussa;
47
48   // currently we can only have one analysis loaded, so 
49   // running trumps viewing.
50   if (vm.count("run-analysis")) {
51     fs::path analysis_path(vm["run-analysis"].as< std::string >(), fs::native);
52     opts.analysis->load_mupa_file( analysis_path );
53     std::cout << "I apologize for blocking the gui while running the analysis"
54               << std::endl;
55     opts.analysis->analyze();
56     if (opts.analysis->is_dirty())
57       opts.analysis->save();
58   }
59   else if (vm.count("view-analysis")) {
60     fs::path analysis_path(vm["view-analysis"].as< std::string >(), fs::native);
61     opts.analysis->load( analysis_path );
62   }
63   if (vm.count("motifs") and opts.analysis) {
64     fs::path motif_path(vm["motifs"].as< std::string >(), fs::native);
65     opts.analysis->load_motifs( motif_path );
66   }
67   if (vm.count("no-gui")) {
68     opts.useGUI=false;
69   }
70   if (vm.count("python")) {
71     opts.runAsPythonInterpeter = true;
72   }
73 }