|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file.
71 throw std::invalid_argument(
"Serialization failed.");
75 char magic[] =
"BPLACE\0\0";
83 nw.enable_names(
true);
84 nw.enable_branch_lengths(
true);
94 ser.
put_int(pqry.placement_size());
95 for(
auto const& place : pqry.placements() ) {
98 ser.
put_int (place.edge().index());
101 ser.
put_float( place.like_weight_ratio );
108 for(
auto const& name : pqry.names() ) {
130 throw std::invalid_argument(
"Deserialization failed: Cannot open file." );
135 if (strncmp (magic.c_str(),
"BPLACE\0\0", 8) != 0) {
136 throw std::invalid_argument(
"Wrong file format: \"" + magic +
"\".");
138 auto ver = des.
get_int<
unsigned char>();
140 throw std::invalid_argument(
"Wrong serialization version: " +
std::to_string(ver));
148 size_t num_pqueries = des.
get_int<
size_t>();
149 for (
size_t i = 0; i < num_pqueries; ++i) {
153 size_t num_place = des.
get_int<
size_t>();
154 for (
size_t p = 0; p < num_place; ++p) {
156 size_t edge_idx = des.
get_int<
size_t>();
161 place.like_weight_ratio = des.
get_float<
double>();
162 place.proximal_length = des.
get_float<
double>();
163 place.pendant_length = des.
get_float<
double>();
167 size_t num_names = des.
get_int<
size_t>();
168 for (
size_t n = 0; n < num_names; ++n) {
175 throw std::invalid_argument(
"Deserialization failed: File longer than expected.");
184 load( file_names, sample_set );
190 #if defined( GENESIS_OPENMP )
194 auto tmp = std::vector<Sample>( file_names.size() );
197 #pragma omp parallel for
198 for(
size_t i = 0; i < file_names.size(); ++i ) {
199 tmp[ i ] =
load( file_names[i] );
203 for(
size_t i = 0; i < file_names.size(); ++i ) {
205 sample_set.
add( std::move( tmp[i] ), name );
210 for(
auto const& fn : file_names ) {
212 sample_set.
add(
load( fn ), name );
PlacementTree & tree()
Get the PlacementTree of this Sample.
std::shared_ptr< BaseOutputTarget > to_string(std::string &target_string)
Obtain an output target for writing to a string.
Store a set of Samples with associated names.
size_t size() const
Return the number of Pqueries that are stored in this Sample.
T get_float()
Read a floating point number from the stream and return it.
void add(Sample const &smp, std::string const &name="")
Add a Sample with a name to the SampleSet.
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on.
std::string get_raw_string(size_t n)
Read n bytes from the stream and return them as a string.
TreeEdge & edge_at(size_t index)
Return the TreeEdge at a certain index.
std::string get_string()
Read a string from the stream, provided that its length it written preceding it, as done by put_strin...
Pquery & add()
Create an empty Pquery, add it to the Sample and return it.
Header of Serializer and Deserializer class.
std::shared_ptr< BaseInputSource > from_string(std::string const &input_string)
Obtain an input source for reading from a string.
std::string to_string(GenomeLocus const &locus)
std::string file_filename(std::string const &filename)
Remove extension if present.
static unsigned char version
Version of this serialization helper. Is written to the stream and read again to make sure that diffe...
static Sample load(std::string const &file_name)
Loads a Sample from a binary file that was written by using save().
double multiplicity
Multiplicity of the name.
A pquery holds a set of PqueryPlacements and a set of PqueryNames.
T get_int()
Read an integer number from the stream and return it.
static void save(Sample const &map, std::string const &file_name)
Saves the Sample to a binary file that can later be read by using load().
PqueryName & add_name(std::string name="", double multiplicity=1.0)
Create a new PqueryName using the provided parameters, add it to the Pquery and return it.
void put_raw(char const *data, size_t n)
Write raw data, provided as a char array of length n, to the stream.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
void put_string(const std::string &v)
Write a string, preceded by its length, to the stream. Use get_string() to read it.
double likelihood
Total likelihood of the tree with this placement attached to it.
std::string file_basename(std::string const &filename)
Remove directory name from file name if present.
Header of Serializer and Deserializer class.
PqueryPlacement & add_placement(PlacementTreeEdge &edge)
Create a new PqueryPlacement at a given PlacementTreeEdge, add it to the Pquery and return it.
Tree read(std::shared_ptr< utils::BaseInputSource > source) const
Read a single Tree from an input source containing a Newick tree.
void put_int(const T v)
Write an integer number to the stream.
utils::Range< iterator_pqueries > pqueries()
Return a Range iterator to the Pqueries .
void put_float(const T v)
Write a floating point number to the stream.