本文整理汇总了C++中SequenceTree::n_branches方法的典型用法代码示例。如果您正苦于以下问题:C++ SequenceTree::n_branches方法的具体用法?C++ SequenceTree::n_branches怎么用?C++ SequenceTree::n_branches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SequenceTree
的用法示例。
在下文中一共展示了SequenceTree::n_branches方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update_lengths
bool update_lengths(const SequenceTree& Q,const SequenceTree& T,
valarray<double>& branch_lengths,
valarray<double>& branch_lengths_squared,
valarray<double>& node_lengths)
{
// map branches from Q -> T
vector<int> branches_map = extends_map(T,Q);
if (not branches_map.size())
return false;
// incorporate lengths of branches that map to Q
for(int b=0;b<Q.n_branches();b++)
{
int b2 = branches_map[b];
double L = T.directed_branch(b2).length();
branch_lengths[b] += L;
branch_lengths_squared[b] += L*L;
}
// map nodes from T -> Q
vector<int> nodes_map = get_nodes_map(Q,T,branches_map);
// incorprate lengths of branches that map to nodes in Q
for(int i=T.n_leafbranches();i<T.n_branches();i++)
{
const_branchview b = T.branch(i);
int n1 = nodes_map[b.source()];
int n2 = nodes_map[b.target()];
if (n1 == n2)
node_lengths[n1] += T.branch(i).length();
}
return true;
}
示例2: estimate_tree
void estimate_tree(const alignment& A,
SequenceTree& T,
substitution::MultiModel& smodel,
const vector<int>& parameters)
{
//------- Estimate branch lengths -------------//
log_branch_likelihood score2(A,smodel,T,parameters);
// Initialize starting point
optimize::Vector start(0.1, T.n_branches() + parameters.size());
for(int b=0;b<T.n_branches();b++)
start[b] = log(T.branch(b).length());
for(int i=0;i<parameters.size();i++)
start[i+T.n_branches()] = smodel.get_parameter_value_as<Double>( parameters[i] );
// optimize::Vector end = search_gradient(start,score);
// optimize::Vector end = search_basis(start,score);
optimize::Vector end = search_gradient(start,score2,1e-3);
for(int b=0;b<T.n_branches();b++)
T.branch(b).set_length(exp(end[b]));
for(int i=0;i<parameters.size();i++)
smodel.set_parameter_value(parameters[i], end[i+T.n_branches()]);
smodel.set_rate(1);
}
示例3: operator
void accum_branch_lengths_ignore_topology::operator()(const SequenceTree& T)
{
n_samples++;
for(int b1=0;b1<Q.n_branches();b1++)
{
// this is a complete waste of CPU time.
dynamic_bitset<> bp1 = branch_partition(Q,b1);
if (not bp1[0]) bp1.flip();
// search for Q.branch(b1) in tree T
int b2 = -1;
for(int i=0;i<T.n_branches();i++)
{
dynamic_bitset<> bp2 = branch_partition(T,i);
if (not bp2[0]) bp2.flip();
if (bp1 == bp2) {
b2 = i;
break;
}
}
if (b2 != -1) {
double L = T.branch(b2).length();
m1[b1] += L;
m2[b1] += L*L;
n_matches[b1]++;
}
}
}
示例4: Q
accum_branch_lengths_ignore_topology(const SequenceTree& T)
:
n_samples(0),
n_matches(0, T.n_branches()),
Q(T),
m1(0.0, Q.n_branches()),
m2(0.0, Q.n_branches())
{}
示例5: choose_SPR_target
int choose_SPR_target(SequenceTree& T1, int b1_)
{
const_branchview b1 = T1.directed_branch(b1_);
//----- Select the branch to move to ------//
dynamic_bitset<> subtree_nodes = T1.partition(b1.reverse());
subtree_nodes[b1.target()] = true;
vector<int> branches;
vector<double> lengths;
for(int i=0; i<T1.n_branches(); i++)
{
const_branchview bi = T1.branch(i);
// skip branch if its contained in the subtree
if (subtree_nodes[bi.target()] and
subtree_nodes[bi.source()])
continue;
double L = 1.0;
// down-weight branch if it is one of the subtree's 2 neighbors
if (subtree_nodes[bi.target()] or
subtree_nodes[bi.source()])
L = 0.5;
branches.push_back(i);
lengths.push_back(L);
}
int b2 = branches[ choose(lengths) ];
return b2;
}
示例6: which_partition
int which_partition(const SequenceTree& T, const Partition& p) {
for(int b=0; b<T.n_branches(); b++) {
dynamic_bitset<> bp = branch_partition(T,b);
if( implies(bp,p) )
return b;
}
throw myexception(string("Partition not found in tree!"));
}
示例7:
vector<Partition> all_partitions_from_tree(const SequenceTree& T)
{
vector<Partition> partitions;
for(int b=0;b<T.n_branches();b++)
partitions.push_back(partition_from_branch(T,b));
return partitions;
}
示例8: implies
/// Does any branch in T imply the partition p?
bool implies(const SequenceTree& T,const Partition& p) {
bool result = false;
for(int b=0;b<T.n_branches() and not result;b++) {
dynamic_bitset<> bp = branch_partition(T,b);
if (implies(bp,p)) return true;
}
return false;
}
示例9: which_branch
int which_branch(const SequenceTree& T, const Partition& p)
{
for(int b=0; b<2*T.n_branches(); b++) {
dynamic_bitset<> bp = branch_partition(T,b);
if( directed_implies(bp,p) )
return b;
}
return -1;
}
示例10: A
data_partition::data_partition(const string& n, const alignment& a,const SequenceTree& t,
const substitution::MultiModel& SM)
:SModel_(SM),
partition_name(n),
cached_alignment_prior_for_branch(t.n_branches()),
cached_alignment_counts_for_branch(t.n_branches(),ublas::matrix<int>(5,5)),
cached_sequence_lengths(a.n_sequences()),
branch_mean_(1.0),
smodel_full_tree(true),
A(a),
T(t),
MC(t,SM),
LC(t,SModel()),
branch_HMMs(t.n_branches()),
branch_HMM_type(t.n_branches(),0),
beta(2, 1.0)
{
for(int b=0;b<cached_alignment_counts_for_branch.size();b++)
cached_alignment_counts_for_branch[b].invalidate();
}
示例11: get_mf_tree
SequenceTree get_mf_tree(const std::vector<std::string>& names,
const std::vector<dynamic_bitset<> >& partitions)
{
SequenceTree T = star_tree(names);
for(int i=0;i<partitions.size();i++)
T.induce_partition(partitions[i]);
for(int i=0;i<T.n_branches();i++)
T.branch(i).set_length(1.0);
return T;
}
示例12: prior_exponential
/// Tree prior: topology & branch lengths (exponential)
efloat_t prior_exponential(const SequenceTree& T,double branch_mean)
{
efloat_t p = 1;
// --------- uniform prior on topologies --------//
if (T.n_leaves()>3)
p /= num_topologies(T.n_leaves());
// ---- Exponential prior on branch lengths ---- //
for(int i=0;i<T.n_branches();i++)
p *= exponential_pdf(T.branch(i).length(), branch_mean);
return p;
}
示例13: prior_gamma
/// Tree prior: topology & branch lengths (gamma)
efloat_t prior_gamma(const SequenceTree& T,double branch_mean)
{
efloat_t p = 1;
// --------- uniform prior on topologies --------//
if (T.n_leaves()>3)
p /= num_topologies(T.n_leaves());
// ---- Exponential prior on branch lengths ---- //
double a = 0.5;
double b = branch_mean*2;
for(int i=0;i<T.n_branches();i++)
p *= gamma_pdf(T.branch(i).length(), a, b);
return p;
}
示例14: main
int main(int argc,char* argv[])
{
try {
//---------- Parse command line -------//
variables_map args = parse_cmd_line(argc,argv);
//----------- Load alignment and tree ---------//
alignment A;
SequenceTree T;
if (args.count("tree"))
load_A_and_T(args,A,T,false);
else
A = load_A(args,false);
const alphabet& a = A.get_alphabet();
//------- Load groups and find branches -------//
vector<sequence_group> groups;
if (args.count("groups"))
groups = load_groups(A,args["groups"].as<string>());
for(int i=0;i<groups.size();i++) {
cerr<<groups[i].name<<": ";
for(int j=0;j<groups[i].taxa.size();j++)
cerr<<A.seq(groups[i].taxa[j]).name<<" ";
cerr<<endl;
}
vector<int> group_branches;
if (args.count("tree"))
{
for(int i=0;i<groups.size();i++)
{
dynamic_bitset<> p(T.n_leaves());
for(int j=0;j<groups[i].taxa.size();j++)
p[groups[i].taxa[j]] = true;
int found = -1;
for(int b=0;b<2*T.n_branches() and found == -1;b++)
if (p == branch_partition(T,b))
found = b;
if (found == -1)
throw myexception()<<"I can't find group "<<i+1<<" on the tree!";
group_branches.push_back(found);
}
}
vector<string> group_names;
for(int i=0;i<groups.size();i++)
group_names.push_back(groups[i].name);
vector<Partition> splits;
if (args.count("split"))
{
vector<string> split = args["split"].as<vector<string> >();
for(int i=0;i<split.size();i++)
splits.push_back(Partition(group_names,split[i]));
}
//-------------------------------------------//
Matrix C(A.length(),A.n_sequences()+1);
for(int i=0;i<C.size1();i++)
for(int j=0;j<C.size2();j++)
C(i,j) = 0;
// yes but, how much more conservation THAN EXPECTED do we see?
for(int c=0;c<C.size1();c++)
{
vector<bool> interesting(groups.size(), true);
//-------------------------------------------------------//
vector<int> leaf_letters( T.n_leaves() );
for(int j=0;j<leaf_letters.size();j++)
leaf_letters[j] = A(c,j);
vector<vector<int> > node_letters = get_all_parsimony_letters(a,leaf_letters,T,unit_cost_matrix(a));
vector<vector<int> > initial_value(groups.size());
for(int g=0;g<groups.size();g++)
{
int n = T.directed_branch(group_branches[g]).target();
initial_value[g] = node_letters[n];
}
//------------ find 'group conserved at' values ----------//
vector<int> value(groups.size(),alphabet::gap);
for(int g=0;g<groups.size();g++)
{
vector<int> temp;
for(int i=0;i<groups[g].taxa.size();i++)
temp.push_back(A(c,groups[g].taxa[i]));
int best = most_common(temp);
int count = number_of(temp,best);
if (count >= groups[g].taxa.size()-1 and count >=3 and count> groups[g].taxa.size()/2)
value[g] = best;
//.........这里部分代码省略.........
示例15: assert
// mark nodes in T according to what node of Q they map to
vector<int> get_nodes_map(const SequenceTree& Q,const SequenceTree& T,
const vector<int>& branches_map)
{
assert(branches_map.size() == Q.n_branches() * 2);
vector<int> nodes_map(T.n_nodes(),-1);
// map nodes from T -> Q that are in both trees
for(int b=0;b<Q.n_branches();b++)
{
int Q_source = Q.branch(b).source();
int Q_target = Q.branch(b).target();
int b2 = branches_map[b];
int T_source = T.directed_branch(b2).source();
int T_target = T.directed_branch(b2).target();
if (nodes_map[T_source] == -1)
nodes_map[T_source] = Q_source;
else
assert(nodes_map[T_source] == Q_source);
if (nodes_map[T_target] == -1)
nodes_map[T_target] = Q_target;
else
assert(nodes_map[T_target] == Q_target);
}
// map the rest of the nodes from T -> Q
for(int i=Q.n_leaves();i<Q.n_nodes();i++)
{
unsigned D = Q[i].degree();
if (D <= 3) continue;
// get a branch of Q pointing into the node
const_branchview outside = *(Q[i].branches_in());
// get a branch of T pointing into the node
outside = T.directed_branch(branches_map[outside.name()]);
list<const_branchview> branches;
typedef list<const_branchview>::iterator list_iterator;
append(outside.branches_after(),branches);
for(list_iterator b = branches.begin() ; b != branches.end();)
{
int node = (*b).target();
if (nodes_map[node] == -1)
nodes_map[node] = i;
if (nodes_map[node] == i) {
append((*b).branches_after(),branches);
b++;
}
else {
list_iterator prev = b;
b++;
branches.erase(prev);
}
}
assert(branches.size() == D-3);
}
for(int i=0;i<nodes_map.size();i++)
assert(nodes_map[i] != -1);
return nodes_map;
}