Example #1
0
RootedSequenceTree::RootedSequenceTree(const RootedSequenceTree& T1, const RootedSequenceTree& T2)
  :RootedTree(T1,T2) 
{
  // We will create new names which will be the same as
  //  T1.order + T2.order
  for(int i=0;i<T1.get_sequences().size();i++) 
    sequences.push_back(T1.seq(i));
  for(int i=0;i<T2.get_sequences().size();i++) 
    sequences.push_back(T2.seq(i));
}
Example #2
0
int main(int argc,char* argv[]) 
{ 
  try {
    //---------- Parse command line  -------//
    variables_map args = parse_cmd_line(argc,argv);

    RootedSequenceTree T = load_T(args);
    
    int root=-1;
    if (args.count("outgroup")) 
    {
      string outgroup = args["outgroup"].as<string>();

      int leaf = find_leaf(T,outgroup);

      root = split_branch(T,leaf);
    }
    else if (args.count("taxa"))
    {
      string taxa = args["taxa"].as<string>();

      vector<string> taxon = split(taxa,',');
      
      if (taxon.size() != 3)
	throw myexception()<<"You must supply exactly 3 taxa, but you supplied "<<taxon.size();

      int n1 = find_leaf(T,taxon[0]);
      int n2 = find_leaf(T,taxon[1]);
      int n3 = find_leaf(T,taxon[2]);

      T.reroot(n1);

      root = T.common_ancestor(n2,n3);
    }
    else if (args.count("leaf"))
    {
      string leaf_name = args["leaf"].as<string>();

      root = find_leaf(T,leaf_name);
    }
    else if (args.count("parent-of"))
    {
      string leaf_name = args["parent-of"].as<string>();

      int leaf = find_leaf(T,leaf_name);

      root = T.branch(leaf).target();
    }
    else if (args.count("branch"))
    {
      string p = args["branch"].as<string>();
      vector<string> taxa = split(p,' ');

      dynamic_bitset<> mask(T.n_leaves());
      dynamic_bitset<> group1(T.n_leaves());

      int separator = find_index(taxa,string("|"));
      if (separator == -1)
	throw myexception()<<"Partition is missing a separator";

      for(int i=0;i<separator;i++) 
      {
	int ii = find_leaf(T,taxa[i]);
	mask[ii] = true;
	group1[ii] = true;
      }
      for(int i=separator+1;i<taxa.size();i++) 
      {
	int ii = find_leaf(T,taxa[i]);
	mask[ii] = true;
      }

      Partition P(T.get_sequences(),group1,mask);
      cerr<<P<<endl;
      int b = which_partition(T,P);
      cerr<<partition_from_branch(T,b)<<endl;
      root = split_branch(T,b);
    }
    else
      throw myexception("neither --outgroup nor --taxa nor --leaf specified!");

    
    T.reroot(root);
    std::cout<<T<<endl;
  }
  catch (std::exception& e) {
    std::cerr<<"tree-reroot: Error! "<<e.what()<<endl;
    exit(1);
  }
  return 0;

}
Example #3
0
 bool reader_t::next_tree(RootedSequenceTree& T)
 {
   T.get_sequences() = leaf_names;
   
   return next_tree(static_cast<RootedTree&>(T));
 }