|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file.
54 #include <unordered_map>
65 auto node_comparator = [] (
71 if( l_ptr ==
nullptr || r_ptr ==
nullptr ) {
74 return ( l_ptr->name == r_ptr->name) && ( node_l.
index() == node_r.index() );
77 auto edge_comparator = [] (
83 if( l_ptr ==
nullptr || r_ptr ==
nullptr ) {
86 return ( l_ptr->edge_num() == r_ptr->edge_num() ) &&
92 lhs, rhs, node_comparator, edge_comparator
110 node_data->
name = source_data.name;
135 double pendant_work = 0.0;
137 for(
auto const& pqry : smp.
pqueries() ) {
140 for(
auto const& place : pqry.placements() ) {
141 auto& edge = target.
edge_at( place.edge().index() );
147 = place.proximal_length
162 += sign * place.like_weight_ratio * multiplicity / scaler
167 pendant_work += place.like_weight_ratio * multiplicity * place.pendant_length / scaler;
179 sample, +1.0, scaler, mass_tree
181 return { std::move( mass_tree ), pend_work };
184 std::pair< tree::TreeSet, std::vector<double> >
192 for(
auto const& smp : sample_set ) {
193 avg_tree_set.
add( smp.tree() );
198 avg_tree_set.
clear();
205 for(
size_t i = 0; i < sample_set.size(); ++i ) {
206 mass_trees.add( mass_tree, sample_set.name_at(i) );
208 assert( mass_trees.size() == sample_set.size() );
211 auto pend_works = std::vector<double>( sample_set.size(), 0.0 );
214 #pragma omp parallel for schedule( dynamic )
215 for(
size_t i = 0; i < sample_set.size(); ++i ) {
224 sample_set[i], +1.0, scaler, mass_trees[i]
228 pend_works[ i ] = pend_work;
231 return { std::move( mass_trees ), std::move( pend_works ) };
243 table.add_column(
"#").justify(kRight);
244 table.add_column(
"name");
245 table.add_column(
"edge_num").justify(kRight);
246 table.add_column(
"likelihood").justify(kRight);
247 table.add_column(
"like_weight_ratio").justify(kRight);
248 table.add_column(
"proximal_length").justify(kRight);
249 table.add_column(
"pendant_length").justify(kRight);
252 for(
auto const& pqry : smp.
pqueries() ) {
253 std::string name = pqry.name_size() > 0 ? pqry.name_at(0).name :
"";
254 if( pqry.name_size() > 1 ) {
258 for(
auto const& p : pqry.placements() ) {
285 +
std::to_string( place_map[ edge.index() ].size() ) +
" placements";
void add(Tree const &tree, std::string const &name="")
Add a Tree with a name to the TreeSet.
double total_placement_mass_with_multiplicities(Sample const &smp)
Get the mass of all PqueryPlacements of the Sample, using the multiplicities as factors.
PlacementTree & tree()
Get the PlacementTree of this Sample.
Tree convert(Tree const &source, std::function< std::unique_ptr< BaseNodeData >(BaseNodeData const &node_data)> node_data_converter, std::function< std::unique_ptr< BaseEdgeData >(BaseEdgeData const &edge_data)> edge_data_converter)
Create a tree with the same topology as the source tree, while converting its data.
Store a set of Samples with associated names.
EdgeNumType edge_num() const
Return the edge_num of this edge. This value is defined by the jplace standard.
std::pair< tree::MassTree, double > convert_sample_to_mass_tree(Sample const &sample, bool normalize)
Convert a Sample to a tree::MassTree.
Print a Tree in a compact form, i.e., each node and edge on one line.
Data class for MassTreeEdges. Stores the branch length and a list of masses with their positions alon...
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on.
Base class for storing data on Edges of a Tree.
TreeEdge & edge_at(size_t index)
Return the TreeEdge at a certain index.
static std::unique_ptr< PlacementEdgeData > create()
void clear()
Clear the TreeSet and destroy all contained Trees.
Provides functions for working with Placements and Pqueries.
bool equal(Tree const &lhs, Tree const &rhs, std::function< bool(TreeNode const &, TreeNode const &) > node_comparator, std::function< bool(TreeEdge const &, TreeEdge const &) > edge_comparator)
Compare two trees for equality given binary comparator functionals for their nodes and edges.
TreeNode & secondary_node()
Return the TreeNode of this TreeEdge that points away from the root.
std::string to_string(GenomeLocus const &locus)
double add_sample_to_mass_tree(Sample const &smp, double const sign, double const scaler, tree::MassTree &target)
Helper function to copy masses from a Sample to a MassTree.
Data class for PlacementTreeEdges. Stores the branch length of the edge, and the edge_num,...
Class for representing phylogenetic trees.
Data class for PlacementTreeNodes. Stores a node name.
double branch_length
Branch length of the edge.
std::string name
Name of the node.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Base class for storing data on Nodes of a Tree.
TreeNode & primary_node()
Return the TreeNode of this TreeEdge that points towards the root.
BaseEdgeData * data_ptr()
Return a pointer to the data.
TableLayout simple_layout(bool condensed)
MassTree convert_common_tree_to_mass_tree(CommonTree const &source)
Helper function that takes a CommonTree (or any Tree with Node and Edge data derived from it) and tur...
std::pair< tree::TreeSet, std::vector< double > > convert_sample_set_to_mass_trees(SampleSet const &sample_set, bool normalize)
Convert all Samples in a SampleSet to tree::MassTrees.
Common class containing the commonly needed data for tree edges.
void reset_edge_nums(PlacementTree &tree)
Reset all edge nums of a PlacementTree.
std::string print_tree(Sample const &smp)
Return a simple view of the Tree of a Sample with information about the Pqueries on it.
Tree average_branch_length_tree(std::vector< Tree > const &tset)
Return a Tree where the branch lengths are the average of the Trees in the given vector of Trees or T...
PlacementTree convert_common_tree_to_placement_tree(tree::CommonTree const &source_tree)
Convert a CommonTree into a PlacementTree.
Common class containing the commonly needed data for tree nodes.
std::vector< std::vector< PqueryPlacement const * > > placements_per_edge(Sample const &smp, bool only_max_lwr_placements)
Return a mapping from each PlacementTreeEdges to the PqueryPlacements that are placed on that edge.
size_t index() const
Return the index of this Node.
BaseNodeData * data_ptr()
Return a pointer to the data.
void print(std::ostream &out, Tree const &tree, std::function< std::string(TreeNode const &node, TreeEdge const &edge)> const print_line)
Print a compact representation of a Tree to an output stream, using a given function for output of th...
utils::Range< iterator_pqueries > pqueries()
Return a Range iterator to the Pqueries .
void normalize(Histogram &h, double total)
double total_multiplicity(Pquery const &pqry)
Return the sum of all multiplicities of the Pquery.
std::ostream & operator<<(std::ostream &out, Sample const &smp)
Print a table of all Pqueries with their Placements and Names to the stream.
bool compatible_trees(PlacementTree const &lhs, PlacementTree const &rhs)
Return whether two PlacementTrees are compatible.
static std::unique_ptr< PlacementNodeData > create()