53 #include <unordered_map> 64 auto node_comparator = [] (
70 if( l_ptr ==
nullptr || r_ptr ==
nullptr ) {
73 return ( l_ptr->name == r_ptr->name) && ( node_l.
index() == node_r.index() );
76 auto edge_comparator = [] (
82 if( l_ptr ==
nullptr || r_ptr ==
nullptr ) {
85 return ( l_ptr->edge_num() == r_ptr->edge_num() ) &&
91 lhs, rhs, node_comparator, edge_comparator
109 node_data->
name = source_data.name;
134 double pendant_work = 0.0;
136 for(
auto const& pqry : smp.
pqueries() ) {
139 for(
auto const& place : pqry.placements() ) {
140 auto& edge = target.
edge_at( place.edge().index() );
145 = place.proximal_length
151 += sign * place.like_weight_ratio * multiplicity / scaler;
155 pendant_work += place.like_weight_ratio * multiplicity * place.pendant_length / scaler;
167 sample, +1.0, scaler, mass_tree
169 return { std::move( mass_tree ), pend_work };
172 std::pair< tree::TreeSet, std::vector<double> >
180 for(
auto const& smp : sample_set ) {
181 avg_tree_set.
add( smp.tree() );
186 avg_tree_set.
clear();
193 for(
size_t i = 0; i < sample_set.size(); ++i ) {
194 mass_trees.add( mass_tree, sample_set.name_at(i) );
196 assert( mass_trees.size() == sample_set.size() );
199 auto pend_works = std::vector<double>( sample_set.size(), 0.0 );
202 #pragma omp parallel for schedule( dynamic ) 203 for(
size_t i = 0; i < sample_set.size(); ++i ) {
205 double const scaler = normalize
212 sample_set[i], +1.0, scaler, mass_trees[i]
216 pend_works[ i ] = pend_work;
219 return { std::move( mass_trees ), std::move( pend_works ) };
231 table.add_column(
"#").justify(kRight);
232 table.add_column(
"name");
233 table.add_column(
"edge_num").justify(kRight);
234 table.add_column(
"likelihood").justify(kRight);
235 table.add_column(
"like_weight_ratio").justify(kRight);
236 table.add_column(
"proximal_length").justify(kRight);
237 table.add_column(
"pendant_length").justify(kRight);
240 for(
auto const& pqry : smp.
pqueries() ) {
241 std::string name = pqry.name_size() > 0 ? pqry.name_at(0).name :
"";
242 if( pqry.name_size() > 1 ) {
246 for(
auto const& p : pqry.placements() ) {
273 +
std::to_string( place_map[ edge.index() ].size() ) +
" placements";
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.
void add(Tree const &tree, std::string const &name="")
Add a Tree with a name to the TreeSet.
Data class for PlacementTreeEdges. Stores the branch length of the edge, and the edge_num, as defined in the jplace standard.
PlacementTree & tree()
Get the PlacementTree of this Sample.
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...
TableLayout simple_layout(bool condensed)
Base class for storing data on Nodes of a Tree.
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...
Provides functions for working with Placements and Pqueries.
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...
TreeNode & secondary_node()
Return the TreeNode of this TreeEdge that points away from the root.
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
void clear()
Clear the TreeSet and destroy all contained Trees.
utils::Range< iterator_pqueries > pqueries()
Return a Range iterator to the Pqueries .
TreeNode & primary_node()
Return the TreeNode of this TreeEdge that points towards the root.
void reset_edge_nums(PlacementTree &tree)
Reset all edge nums of a PlacementTree.
BaseEdgeData * data_ptr()
Return a pointer to the data.
std::pair< tree::MassTree, double > convert_sample_to_mass_tree(Sample const &sample, bool normalize)
Convert a Sample to a tree::MassTree.
Class for representing phylogenetic trees.
PlacementTree convert_common_tree_to_placement_tree(tree::CommonTree const &source_tree)
Convert a CommonTree into a PlacementTree.
Store a set of Samples with associated names.
double total_multiplicity(Pquery const &pqry)
Return the sum of all multiplicities of the Pquery.
double total_placement_mass_with_multiplicities(Sample const &smp)
Get the mass of all PqueryPlacements of the Sample, using the multiplicities as factors.
TreeEdge & edge_at(size_t index)
Return the TreeEdge at a certain index.
std::string name
Name of the node.
static std::unique_ptr< PlacementEdgeData > create()
double branch_length
Branch length of the edge.
Data class for PlacementTreeNodes. Stores a node name.
void normalize(Histogram &h, double total)
Manage a set of Pqueries along with the PlacementTree where the PqueryPlacements are placed on...
Common class containing the commonly needed data for tree nodes.
bool compatible_trees(PlacementTree const &lhs, PlacementTree const &rhs)
Return whether two PlacementTrees are compatible.
std::shared_ptr< BaseOutputTarget > to_string(std::string &target_string)
Obtain an output target for writing to a string.
static std::unique_ptr< PlacementNodeData > create()
size_t index() const
Return the index of this Node.
EdgeNumType edge_num() const
Return the edge_num of this edge. This value is defined by the jplace standard.
Base class for storing data on Edges of a Tree.
Common class containing the commonly needed data for tree edges.
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...
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...
std::string print_tree(Sample const &smp)
Return a simple view of the Tree of a Sample with information about the Pqueries on it...
BaseNodeData * data_ptr()
Return a pointer to the data.
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.
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.
std::ostream & operator<<(std::ostream &out, Sample const &smp)
Print a table of all Pqueries with their Placements and Names to the stream.