Scaffolding  0.1
This program can assemble genome scaffolds using the pairing information in paired-end reads.
command_line.hpp
Go to the documentation of this file.
1 
2 
8 #ifndef COMMAND_LINE_HPP
9 #define COMMAND_LINE_HPP
10 
11 #include <string>
12 
13 #include <boost/program_options/variables_map.hpp>
14 #include <boost/program_options/parsers.hpp>
15 
16 #include "utils/utils.hpp"
17 #include "utils/exceptions.hpp"
18 
19 
20 namespace po = boost::program_options;
21 
22 
24 struct{
26  std::string in_graph_filename;
27 
29  std::string in_seq_filename;
30 
32  std::string out_model_filename;
33 
35  std::string out_graph_filename;
36 
38  std::string out_seq_filename;
39 
41  bool preprocess;
42 
44 
48 
50 
52 
54  unsigned objects;
56  unsigned paths;
58  unsigned cycles;
59 
61  unsigned cut_off;
62 
63 
65 
66  void sanity_check() const
67  {
68  if(!file_exists(in_graph_filename))
69  throw except::invalid_options("I have no input file to work with, use --fn <file> to give me a scaffold graph.");
70  if(out_seq_filename != "" && !file_exists(in_seq_filename))
71  throw except::invalid_options("I want to output fasta sequences to '" + out_seq_filename + "' but I cannot open the sequence database '" + in_seq_filename + "' (given with --is) for reading");
72  }
73 } options;
74 
76 template<typename T>
77 const T& get_option(const po::variables_map& vm, const std::string& option_name, const T& default_value){
78  if(vm.count(option_name))
79  return vm[option_name].as<T>();
80  else
81  return default_value;
82 }
83 
85 void handle_options(const int argc, const char** argv)
86 {
87  // Declare the supported options.
88  po::options_description desc((std::string)"syntax: " + argv[0] + " [options] --fn <scaffold graph file>\nwhere valid options are");
89  desc.add_options()
90  ("help", "produce help message")
91  ("fn", po::value<std::string>(), "file to read scaffold graph from")
92  ("is", po::value<std::string>(), "file to read contig sequences from (required for --os)")
93  ("os", po::value<std::string>(), "file to output solution sequences in fasta format (requires --is)")
94  ("og", po::value<std::string>(), "file to output solution graph in dot format")
95  ("om", po::value<std::string>(), "file to output CPLEX model to (see cplex::exportModel()) ")
96  ("o", po::value<unsigned>(), "allowed number of objects (paths or cycles) (default 6)")
97  ("p", po::value<unsigned>(), "allowed number of paths (default #objects (see -o))")
98  ("c", po::value<unsigned>(), "allowed number of cycles (default #objects (see -o))")
99  ("co", po::value<unsigned>(), "cut off all edges whose weight is strictly below the argument (default 0)")
100  ("ta", "let the solution take all weight of an edge when using it at least once, instead of gaining linearly (& scaling the weight)")
101  ("nj", "ignore contig jumps")
102  ("pp", "preprocess the input graph")
103  ;
104 
105  po::variables_map vm;
106  po::store(po::parse_command_line(argc, argv, desc), vm);
107  po::notify(vm);
108  if(vm.count("help") || !vm.count("fn")) { std::cout << desc << "\n"; exit(EXIT_SUCCESS); }
109 
110  options.in_graph_filename = get_option<std::string>(vm, "fn", "");
111  options.out_graph_filename = get_option<std::string>(vm, "og", "");
112  options.in_seq_filename = get_option<std::string>(vm, "is", "");
113  options.out_seq_filename = get_option<std::string>(vm, "os", "");
114  options.out_model_filename = get_option<std::string>(vm, "om", "");
115 
116  options.objects = get_option<unsigned>(vm, "o", 6);
117  options.paths = get_option<unsigned>(vm, "p", options.objects);
118  options.cycles = get_option<unsigned>(vm, "c", options.objects);
119  options.cut_off = get_option<unsigned>(vm, "co", 0);
120 
121  options.multi_take_all = vm.count("ta");
122  options.ignore_contig_jumps = vm.count("nj");
123  options.preprocess = vm.count("pp");
124 
125  try{
126  options.sanity_check();
127  } catch(except::invalid_options e){
128  std::cout << "Command line option error: "<<e.what() << std::endl;
129  std::cout << desc << std::endl;
130  exit(EXIT_FAILURE);
131  }
132 }
133 
134 
135 #endif
struct @3 options
options that configure the scaffolder
bool multi_take_all
bool indicating whether taking a contig-connection with multiplicity will gain all its weight ...
Definition: command_line.hpp:47
unsigned paths
maximum number of paths that a solution graph should consist of
Definition: command_line.hpp:56
unsigned cycles
maximum number of cycles that a solution graph should consist of
Definition: command_line.hpp:58
bool file_exists(const std::string &filename)
testing whether a file exists by trying to open it
Definition: utils.hpp:206
an exception for the case that the given program options are not valid
Definition: exceptions.hpp:41
bool preprocess
bool indicating whether to run preprocessing or not (currently defunct)
Definition: command_line.hpp:41
const T & get_option(const po::variables_map &vm, const std::string &option_name, const T &default_value)
return the value of an option or the given default if the value has not been supplied ...
Definition: command_line.hpp:77
std::string out_graph_filename
filename of a file to export the solution graph to
Definition: command_line.hpp:35
std::string in_seq_filename
filename of the input sequence file in fasta format
Definition: command_line.hpp:29
std::string in_graph_filename
filename of the input graph
Definition: command_line.hpp:26
unsigned cut_off
cut-off threshold: remove all links between contigs whose weight is strictly below this threshold ...
Definition: command_line.hpp:61
std::string out_model_filename
filename of a file to export the cplex model to
Definition: command_line.hpp:32
void handle_options(const int argc, const char **argv)
process the program options given on the command line
Definition: command_line.hpp:85
bool ignore_contig_jumps
bool incidating whether contig jumps should be considered
Definition: command_line.hpp:51
unsigned objects
maximum number of objects (paths or cycles) that a solution graph should consist of ...
Definition: command_line.hpp:54
std::string out_seq_filename
filename of a file to export solution sequences to
Definition: command_line.hpp:38