本文整理汇总了C++中SequenceTree::n_leaves方法的典型用法代码示例。如果您正苦于以下问题:C++ SequenceTree::n_leaves方法的具体用法?C++ SequenceTree::n_leaves怎么用?C++ SequenceTree::n_leaves使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SequenceTree
的用法示例。
在下文中一共展示了SequenceTree::n_leaves方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_As_and_random_T
/// \brief Load a collection of alignments based on command line parameters and generate a random tree.
///
/// \param args The command line parameters.
/// \param alignments The alignments.
/// \param T The leaf-labelled tree.
/// \param internal_sequences Should each resulting alignment have sequences for internal nodes on the tree?
///
void load_As_and_random_T(const variables_map& args,vector<alignment>& alignments,SequenceTree& T,const vector<bool>& internal_sequences)
{
alignments = load_As(args);
//------------- Load random tree ------------------------//
SequenceTree TC = star_tree(sequence_names(alignments[0]));
if (args.count("t-constraint"))
TC = load_constraint_tree(args["t-constraint"].as<string>(),sequence_names(alignments[0]));
T = TC;
RandomTree(T,1.0);
//-------------- Link --------------------------------//
link(alignments,T,internal_sequences);
//---------------process----------------//
for(int i=0;i<alignments.size();i++)
{
//---------------- Randomize alignment? -----------------//
if (args.count("randomize-alignment"))
alignments[i] = randomize(alignments[i],T.n_leaves());
//------------------ Analyze 'internal'------------------//
if ((args.count("internal") and args["internal"].as<string>() == "+")
or args.count("randomize-alignment"))
for(int column=0;column< alignments[i].length();column++) {
for(int j=T.n_leaves();j<alignments[i].n_sequences();j++)
alignments[i](column,j) = alphabet::not_gap;
}
//---- Check that internal sequence satisfy constraints ----//
check_alignment(alignments[i],T,internal_sequences[i]);
}
}
示例2: load_As_and_T
/// \brief Load a tree and a collection of alignments based on command line parameters.
///
/// \param args The command line parameters.
/// \param alignments The alignments.
/// \param T The leaf-labelled tree.
/// \param internal_sequences Should each resulting alignment have sequences for internal nodes on the tree?
///
void load_As_and_T(const variables_map& args,vector<alignment>& alignments,SequenceTree& T,const vector<bool>& internal_sequences)
{
alignments = load_As(args);
T = load_T(args);
link(alignments,T,internal_sequences);
for(int i=0;i<alignments.size();i++)
{
//---------------- Randomize alignment? -----------------//
if (args.count("randomize-alignment"))
alignments[i] = randomize(alignments[i],T.n_leaves());
//------------------ Analyze 'internal'------------------//
if ((args.count("internal") and args["internal"].as<string>() == "+")
or args.count("randomize-alignment"))
for(int column=0;column< alignments[i].length();column++) {
for(int j=T.n_leaves();j<alignments[i].n_sequences();j++)
alignments[i](column,j) = alphabet::not_gap;
}
//---- Check that internal sequence satisfy constraints ----//
check_alignment(alignments[i],T,internal_sequences[i]);
}
}
示例3: load_A_and_random_T
/// \brief Load an alignment based on command line parameters and generate a random tree.
///
/// \param args The command line parameters.
/// \param alignments The alignments.
/// \param T The leaf-labelled tree.
/// \param internal_sequences Should each resulting alignment have sequences for internal nodes on the tree?
///
void load_A_and_random_T(const variables_map& args,alignment& A,SequenceTree& T,bool internal_sequences)
{
// NO internal sequences, yet!
A = load_A(args,internal_sequences);
//------------- Load random tree ------------------------//
SequenceTree TC = star_tree(sequence_names(A));
if (args.count("t-constraint"))
TC = load_constraint_tree(args["t-constraint"].as<string>(),sequence_names(A));
T = TC;
RandomTree(T,1.0);
//------------- Link Alignment and Tree -----------------//
link(A,T,internal_sequences);
//---------------- Randomize alignment? -----------------//
if (args.count("randomize-alignment"))
A = randomize(A,T.n_leaves());
//------------------ Analyze 'internal'------------------//
if ((args.count("internal") and args["internal"].as<string>() == "+")
or args.count("randomize-alignment"))
for(int column=0;column< A.length();column++) {
for(int i=T.n_leaves();i<A.n_sequences();i++)
A(column,i) = alphabet::not_gap;
}
//---- Check that internal sequence satisfy constraints ----//
check_alignment(A,T,internal_sequences);
}
示例4: add_internal
alignment add_internal(alignment A,const SequenceTree& T)
{
// Complain if A and T don't correspond
if (A.n_sequences() != T.n_leaves())
throw myexception()<<"Number of sequence in alignment doesn't match number of leaves in tree"
<<"- can't add internal sequences";
// Add empty sequences
vector<sequence> S;
for(int i=T.n_leaves();i<T.n_nodes();i++)
{
sequence s;
if (T.label(i) == "")
throw myexception()<<"Adding internal sequences: Tree has missing internal node name!";
s.name = T.label(i);
S.push_back(s);
}
A.add_sequences(S);
return A;
}
示例5: peel_n_mutations
void peel_n_mutations(const alphabet& a, const vector<int>& letters, const SequenceTree& T,
const ublas::matrix<B>& cost,ublas::matrix<B>& n_muts,
const vector<const_branchview>& branches)
{
const int A = a.size();
assert(letters.size() == T.n_leaves());
assert(cost.size1() == A);
assert(cost.size2() == A);
// we need a scratch row in the matrix
assert(n_muts.size1() == T.n_nodes());
assert(n_muts.size2() == A);
// compute the max cost -- is this approach a good idea?
// Well... this apparently doesn't work.
B max_cost = 0;
for(int i=0;i<A;i++)
for(int j=0;j<A;j++)
max_cost = std::max(cost(i,j)+1, max_cost);
// clear the length matrix.
for(int i=0;i<n_muts.size1();i++)
for(int j=0;j<n_muts.size2();j++)
n_muts(i,j)=0;
// set the leaf costs
for(int s=0;s<T.n_leaves();s++)
{
int L = letters[s];
if (a.is_letter_class(L))
for(int l=0;l<A;l++)
if (a.matches(l,L))
n_muts(s,l) = 0;
else
n_muts(s,l) = max_cost;
}
// compute the costs for letters at each node
for(int i=0;i<branches.size();i++)
{
int s = branches[i].source();
int t = branches[i].target();
// for each letter l of node target...
for(int l=0;l<A;l++)
{
// compute minimum treelength for data behind source.
B temp = n_muts(s,0)+cost(0,l);
for(int k=1;k<A;k++)
temp = min(temp, n_muts(s,k)+cost(k,l) );
// add it to treelengths for data behind target
n_muts(t,l) += temp;
}
}
}
示例6: link
/// \brief Remap the leaf indices of tree \a T to match the alignment \a A: check the result
///
/// \param A The alignment.
/// \param T The tree.
/// \param internal_sequences Should the resulting alignment have sequences for internal nodes on the tree?
///
void link(alignment& A,SequenceTree& T,bool internal_sequences)
{
check_names_unique(A);
// Later, might we WANT sub-branches???
if (has_sub_branches(T))
remove_sub_branches(T);
if (internal_sequences and not is_Cayley(T) and T.n_leaves() > 1) {
assert(has_polytomy(T));
throw myexception()<<"Cannot link a multifurcating tree to an alignment with internal sequences.";
}
//------ IF sequences < leaf nodes THEN complain ---------//
if (A.n_sequences() < T.n_leaves())
throw myexception()<<"Tree has "<<T.n_leaves()<<" leaves but Alignment only has "
<<A.n_sequences()<<" sequences.";
//----- IF sequences = leaf nodes THEN maybe add internal sequences.
else if (A.n_sequences() == T.n_leaves())
{
A = remap_A_indices(A,T);
if (internal_sequences)
{
add_internal_labels(T);
A = add_internal(A,T);
connect_leaf_characters(A,T);
}
}
//----- IF sequences > leaf nodes THEN maybe complain -------//
else if (A.n_sequences() > T.n_nodes())
throw myexception()<<"More alignment sequences ("<<A.n_sequences()<<") than tree nodes ("<<T.n_nodes()<<")!";
else if (A.n_sequences() < T.n_nodes())
throw myexception()<<"Fewer alignment sequences ("<<A.n_sequences()<<") than tree nodes ("<<T.n_nodes()<<")!";
else
{
A = remap_A_indices(A,T);
if (not internal_sequences)
A = chop_internal(A);
}
//---------- double-check that we have the right number of sequences ---------//
if (internal_sequences)
assert(A.n_sequences() == T.n_nodes());
else
assert(A.n_sequences() == T.n_leaves());
//----- Check that each alignment sequence maps to a corresponding name in the tree -----//
for(int i=0;i<A.n_sequences();i++)
assert(T.get_label(i) == A.seq(i).name);
//---- Check to see that internal nodes satisfy constraints ----//
check_alignment(A,T,internal_sequences);
}
示例7: link
/// \brief Remap the leaf indices of tree \a T to match the alignment \a A: check the result
///
/// \param A The alignment.
/// \param T The tree.
/// \param internal_sequences Should the resulting alignment have sequences for internal nodes on the tree?
///
void link(alignment& A,SequenceTree& T,bool internal_sequences)
{
check_names_unique(A);
// Later, might we WANT sub-branches???
if (has_sub_branches(T))
remove_sub_branches(T);
if (internal_sequences and not is_Cayley(T)) {
assert(has_polytomy(T));
throw myexception()<<"Cannot link a multifurcating tree to an alignment with internal sequences.";
}
//------ IF sequences < leaf nodes THEN complain ---------//
if (A.n_sequences() < T.n_leaves())
throw myexception()<<"Tree has "<<T.n_leaves()<<" leaves but Alignment only has "
<<A.n_sequences()<<" sequences.";
//----- IF sequences = leaf nodes THEN maybe add internal sequences.
else if (A.n_sequences() == T.n_leaves()) {
if (internal_sequences)
A = add_internal(A,T);
}
//----- IF sequences > leaf nodes THEN maybe complain -------//
else {
if (not internal_sequences) {
alignment A2 = chop_internal(A);
if (A2.n_sequences() == T.n_leaves()) {
A = A2;
}
else
throw myexception()<<"More alignment sequences than leaf nodes!";
}
else if (A.n_sequences() > T.n_nodes())
throw myexception()<<"More alignment sequences than tree nodes!";
else if (A.n_sequences() < T.n_nodes())
throw myexception()<<"Fewer alignment sequences than tree nodes!";
}
//---------- double-check that we have the right number of sequences ---------//
if (internal_sequences)
assert(A.n_sequences() == T.n_nodes());
else
assert(A.n_sequences() == T.n_leaves());
//----- Remap leaf indices for T onto A's leaf sequence indices -----//
remap_T_indices(T,A);
if (internal_sequences)
connect_leaf_characters(A,T);
//---- Check to see that internal nodes satisfy constraints ----//
check_alignment(A,T,internal_sequences);
}
示例8: operator
void accum_branch_lengths_same_topology::operator()(const SequenceTree& T)
{
if (not n_samples) {
if (T.n_leaves() != Q.n_leaves())
throw myexception()<<"Query tree has "<<Q.n_leaves()<<" leaves, but tree sample has "<<T.n_leaves()<<" leaves.";
}
n_samples++;
if (update_lengths(Q,T,m1,m2,n1))
n_matches++;
}
示例9: 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;
}
示例10: operator
void count_pair_distances::operator()(const SequenceTree& T)
{
if (not initialized) {
N = T.n_leaves();
names = T.get_leaf_labels();
m1.resize(N*(N-1)/2);
m2.resize(N*(N-1)/2);
m1 = 0;
m2 = 0;
initialized = true;
}
n_samples++;
// Theoretically, we could do this much faster, I think.
// vector<vector<int> > leaf_sets = partition_sets(T);
int k=0;
for(int i=0;i<N;i++)
for(int j=0;j<i;j++,k++)
{
double D = 0;
if (RF)
D = T.edges_distance(i,j);
else
D = T.distance(i,j);
m1[k] += D;
m2[k] += D*D;
}
}
示例11: 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;
}
示例12: getSimilarity
Matrix getSimilarity(const SequenceTree& T,substitution::MultiModel& SM) {
int n = T.n_leaves();
Matrix S(n,n);
for(int i=0;i<n;i++)
for(int j=0;j<i;j++)
S(i,j) = S(j,i) = getSimilarity(T.distance(i,j),SM);
return S;
}
示例13: remap_T_indices
/// \brief Re-index the leaves of tree \a T1 so that the labels have the same ordering as in \a T2.
///
/// \param T1 The leaf-labelled tree to re-index.
/// \param T2 The leaf-labelled tree to match.
///
void remap_T_indices(SequenceTree& T1,const SequenceTree& T2)
{
if (T1.n_leaves() != T2.n_leaves())
throw myexception()<<"Trees do not correspond: different numbers of leaves.";
//----- Remap leaf indices for T onto A's leaf sequence indices -----//
try {
remap_T_indices(T1,T2.get_sequences());
}
catch(const bad_mapping<string>& b)
{
bad_mapping<string> b2(b.missing,b.from);
if (b.from == 0)
b2<<"Couldn't find leaf sequence \""<<b2.missing<<"\" in second tree.";
else
b2<<"Couldn't find leaf sequence \""<<b2.missing<<"\" in first tree.";
throw b2;
}
}
示例14: partition_from_branch
Partition partition_from_branch(const SequenceTree& T,int b)
{
dynamic_bitset<> group(T.n_leaves());
const dynamic_bitset<>& with_internal = T.partition(b);
for(int i=0;i<group.size();i++)
group[i] = with_internal[i];
return Partition(T.get_leaf_labels(), group);
}
示例15: remap_A_indices
/// \brief Re-index the leaves of tree \a T so that the labels have the same ordering as in \a A.
///
/// \param T The leaf-labelled tree.
/// \param A A multiple sequence alignment.
///
alignment remap_A_indices(alignment& A, const SequenceTree& T)
{
vector<string> labels = T.get_labels();
if (A.n_sequences() == T.n_leaves())
{
labels.resize(T.n_leaves());
}
else if (A.n_sequences() != T.n_nodes())
throw myexception()<<"Cannot map alignment onto tree:\n Alignment has "<<A.n_sequences()<<" sequences.\n Tree has "<<T.n_leaves()<<" leaves and "<<T.n_nodes()<<" nodes.";
for(int i=0;i<labels.size();i++)
if (labels[i] == "")
{
if (i<T.n_leaves())
throw myexception()<<"Tree has empty label for a leaf node: not allowed!";
else
throw myexception()<<"Alignment has internal node information, but tree has empty label for an internal node: not allowed!";
}
assert(A.n_sequences() == labels.size());
//----- Remap leaf indices for T onto A's leaf sequence indices -----//
try {
vector<int> mapping = compute_mapping(labels, sequence_names(A));
return reorder_sequences(A,mapping);
}
catch(const bad_mapping<string>& b)
{
bad_mapping<string> b2 = b;
b2.clear();
if (b.from == 0)
b2<<"Couldn't find sequence \""<<b2.missing<<"\" in alignment.";
else
b2<<"Alignment sequence '"<<b2.missing<<"' not found in the tree.";
throw b2;
}
}