Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F122203296
EMReadApplication.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jul 16, 14:35
Size
4 KB
Mime Type
text/x-c
Expires
Fri, Jul 18, 14:35 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
27449384
Attached To
R8820 scATAC-seq
EMReadApplication.cpp
View Options
#include <EMReadApplication.hpp>
#include <EMRead.hpp>
#include <iostream>
#include <string>
#include <stdexcept> // std::invalid_argument
#include <boost/program_options.hpp>
#include <Matrix2D.hpp>
namespace po = boost::program_options ;
EMReadApplication::EMReadApplication(int argn, char** argv)
: file_read(""), n_class(0), n_iter(0), n_shift(0), flip(false),
n_threads(0), seed(""), runnable(true)
{
// parse command line options and set the fields
this->parseOptions(argn, argv) ;
}
int EMReadApplication::run()
{ if(this->runnable)
{ EMRead em(Matrix2D<int>(this->file_read),
this->n_class,
this->n_iter,
this->n_shift,
this->flip,
this->seed,
this->n_threads) ;
em.classify() ;
std::cout << em.get_post_prob() << std::endl ;
return EXIT_SUCCESS ;
}
else
{ return EXIT_FAILURE ; }
}
void EMReadApplication::parseOptions(int argn, char** argv)
{
// no option to parse
if(argv == nullptr)
{ std::string message = "no options to parse!" ;
throw std::invalid_argument(message) ;
}
// help messages
std::string desc_msg = "\n"
"EMRead is a probabilistic partitioning algorithm that \n"
"sofetly assigns genomic regions to classes given the shape \n"
"of the read density over the region. The assignment \n"
"probabilities are returned through stdout.\n\n" ;
std::string opt_help_msg = "Produces this help message." ;
std::string opt_thread_msg = "The number of threads dedicated to parallelize the computations,\n "
"by default 0 (no parallelization)." ;
std::string opt_read_msg = "The path to the file containing the read density data" ;
std::string opt_iter_msg = "The number of iterations." ;
std::string opt_class_msg = "The number of classes to find." ;
std::string opt_shift_msg = "Enables this number of column of shifting "
"freedom to realign the data. By default, shifting is "
"disabled (equivalent to --shift 1)." ;
std::string opt_flip_msg = "Enables flipping to realign the data.";
std::string opt_seed_msg = "A value to seed the random number generator.";
// option parser
boost::program_options::variables_map vm ;
boost::program_options::options_description desc(desc_msg) ;
std::string seeding_tmp ;
desc.add_options()
("help,h", opt_help_msg.c_str())
("read", po::value<std::string>(&(this->file_read)), opt_read_msg.c_str())
("iter,i", po::value<size_t>(&(this->n_iter)), opt_iter_msg.c_str())
("class,c", po::value<size_t>(&(this->n_class)), opt_class_msg.c_str())
("shift,s", po::value<size_t>(&(this->n_shift)), opt_shift_msg.c_str())
("flip", opt_flip_msg.c_str())
("seed", po::value<std::string>(&(this->seed)), opt_seed_msg.c_str())
("thread", po::value<std::size_t>(&(this->n_threads)), opt_thread_msg.c_str()) ;
// parse
try
{ po::store(po::parse_command_line(argn, argv, desc), vm) ;
po::notify(vm) ;
}
catch(std::invalid_argument& e)
{ std::string msg = std::string("Error! Invalid option given!\n") + std::string(e.what()) ;
throw std::invalid_argument(msg) ;
}
catch(...)
{ throw std::invalid_argument("An unknown error occured while parsing the options") ; }
bool help = vm.count("help") ;
// checks unproper option settings
if(this->file_read == "" and
(not help))
{ std::string msg("Error! No data were given (--read)!") ;
throw std::invalid_argument(msg) ;
}
// no iter given -> 1 iter
if(this->n_iter == 0)
{ this->n_iter = 1 ; }
// no shift class given -> 1 class
if(this->n_class == 0)
{ this->n_class = 1 ; }
// no shift given, value of 1 -> no shift
if(this->n_shift == 0)
{ this->n_shift = 1 ; }
// set flip
if(vm.count("flip"))
{ this->flip = true ; }
// help invoked, run() cannot be invoked
if(help)
{ std::cout << desc << std::endl ;
this->runnable = false ;
return ;
}
// everything fine, run() can be called
else
{ this->runnable = true ;
return ;
}
}
int main(int argn, char** argv)
{ EMReadApplication app(argn, argv) ;
return app.run() ;
}
Event Timeline
Log In to Comment