Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F75841180
ChIPPartitioningApplication.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
Sun, Aug 4, 15:15
Size
6 KB
Mime Type
text/x-c
Expires
Tue, Aug 6, 15:15 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
19616415
Attached To
R8820 scATAC-seq
ChIPPartitioningApplication.cpp
View Options
#include <ChIPPartitioningApplication.hpp>
#include <EMEngine.hpp>
#include <iostream>
#include <string>
#include <stdexcept>
// std::invalid_argument
#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>
//
namespace
po
=
boost
::
program_options
;
ChIPPartitioningApplication
::
ChIPPartitioningApplication
(
int
argn
,
char
**
argv
)
:
file_read
(
""
),
file_sequence
(
""
),
n_class
(
0
),
n_iter
(
0
),
n_shift
(
0
),
flip
(
false
),
n_threads
(
0
),
seeding
(
EMEngine
::
seeding_codes
::
RANDOM
),
seed
(
""
),
runnable
(
true
)
{
// parse command line options and set the fields
this
->
parseOptions
(
argn
,
argv
)
;
}
int
ChIPPartitioningApplication
::
run
()
{
if
(
this
->
runnable
)
{
// read data
std
::
vector
<
std
::
string
>
read_paths
;
boost
::
split
(
read_paths
,
this
->
file_read
,
[](
char
c
){
return
c
==
','
;});
std
::
vector
<
matrix2d_i
>
data_read
;
for
(
const
auto
&
path
:
read_paths
)
{
data_read
.
push_back
(
read_matrix2d_i
(
path
))
;
}
// sequence data
std
::
vector
<
matrix2d_i
>
data_seq
;
if
(
this
->
file_sequence
!=
""
)
{
data_seq
.
push_back
(
read_matrix2d_i
(
this
->
file_sequence
))
;
}
EMEngine
em
(
data_read
,
data_seq
,
this
->
n_class
,
this
->
n_iter
,
this
->
n_shift
,
this
->
flip
,
this
->
seeding
,
this
->
seed
,
this
->
n_threads
)
;
em
.
classify
()
;
std
::
cout
<<
em
.
get_post_prob
()
<<
std
::
endl
;
std
::
cerr
<<
em
.
get_post_class_prob
()
<<
std
::
endl
;
return
EXIT_SUCCESS
;
}
else
{
return
EXIT_FAILURE
;
}
}
void
ChIPPartitioningApplication
::
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
"
"ChIPPartitioning is a probabilistic partitioning algorithm that
\n
"
"sofetly assigns genomic regions to classes given their shape
\n
"
"of the signal over the region. The assignment probabilities
\n
"
"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
=
"A coma separated list of paths to the file containing the "
"read density data"
;
std
::
string
opt_seq_msg
=
"The path to the file containing the sequence 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. By default, shifting is "
"disabled (equivalent to --shift 1)."
;
std
::
string
opt_flip_msg
=
"Enables flipping."
;
std
::
string
opt_seeding_msg
=
"Specify which method should be used to initialise the "
"cluster references."
;
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
())
(
"seq"
,
po
::
value
<
std
::
string
>
(
&
(
this
->
file_sequence
)),
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
())
(
"seeding"
,
po
::
value
<
std
::
string
>
(
&
(
seeding_tmp
)),
opt_seeding_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 read density data were given (--read)!"
)
;
throw
std
::
invalid_argument
(
msg
)
;
}
else
if
((
seeding_tmp
!=
"random"
)
and
(
seeding_tmp
!=
"sampling"
)
and
(
seeding_tmp
!=
"toy"
)
and
(
not
help
))
{
std
::
string
msg
(
"Error! Unrecognized seeding method (--seeding)!"
)
;
throw
std
::
invalid_argument
(
msg
)
;
}
// no class 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 seeding
if
(
seeding_tmp
==
"random"
)
{
this
->
seeding
=
EMEngine
::
seeding_codes
::
RANDOM
;
}
else
if
(
seeding_tmp
==
"sampling"
)
{
this
->
seeding
=
EMEngine
::
seeding_codes
::
SAMPLING
;
}
else
if
(
seeding_tmp
==
"toy"
)
{
this
->
seeding
=
EMEngine
::
seeding_codes
::
TOY
;
}
// 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
)
{
ChIPPartitioningApplication
app
(
argn
,
argv
)
;
return
app
.
run
()
;
}
Event Timeline
Log In to Comment