ARB
Classes | Macros | Functions
adtree.cxx File Reference
#include <arb_progress.h>
#include "gb_local.h"
#include <arb_strarray.h>
#include <set>
#include <limits.h>
#include <arb_global_defs.h>
#include <arb_strbuf.h>
#include <arb_diff.h>
#include <arb_defs.h>
#include <arb_match.h>
#include <arb_msg_nospam.h>
#include "TreeNode.h"
Include dependency graph for adtree.cxx:

Go to the source code of this file.

Classes

struct  link_tree_data
 
struct  indexed_name
 

Macros

#define GBT_PUT_DATA   1
 
#define GBT_GET_SIZE   0
 

Functions

GBDATAGBT_get_tree_data (GBDATA *gb_main)
 
TreeNodeGBT_remove_leafs (TreeNode *tree, GBT_TreeRemoveType mode, const GB_HASH *species_hash, int *removed, int *groups_removed)
 
int get_tree_idx (GBDATA *gb_tree)
 
int get_max_tree_idx (GBDATA *gb_treedata)
 
GBDATAget_tree_with_idx (GBDATA *gb_treedata, int at_idx)
 
GBDATAget_tree_infrontof_idx (GBDATA *gb_treedata, int infrontof_idx)
 
GBDATAget_tree_behind_idx (GBDATA *gb_treedata, int behind_idx)
 
GB_ERROR set_tree_idx (GBDATA *gb_tree, int idx)
 
static GB_ERROR reserve_tree_idx (GBDATA *gb_treedata, int idx)
 
static void ensure_trees_have_order (GBDATA *gb_treedata)
 
static void tree_set_default_order (GBDATA *gb_tree)
 
GB_ERROR GBT_write_group_name (GBDATA *gb_group_name, const char *new_group_name, bool pedantic)
 
GB_ERROR GBT_write_name_to_groupData (GBDATA *gb_group, bool createNameEntry, const char *new_group_name, bool pedantic)
 
static GB_ERROR gbt_write_tree_nodes (GBDATA *gb_tree, TreeNode *node, long *startid)
 
static chargbt_write_tree_rek_new (const TreeNode *node, char *dest, long mode)
 
static GB_ERROR gbt_write_tree (GBDATA *gb_main, GBDATA *gb_tree, const char *tree_name, TreeNode *tree)
 
GB_ERROR GBT_write_tree (GBDATA *gb_main, const char *tree_name, TreeNode *tree)
 
GB_ERROR GBT_overwrite_tree (GBDATA *gb_tree, TreeNode *tree)
 
static GB_ERROR write_tree_remark (GBDATA *gb_tree, const char *remark)
 
GB_ERROR GBT_write_tree_remark (GBDATA *gb_main, const char *tree_name, const char *remark)
 
GB_ERROR GBT_log_to_tree_remark (GBDATA *gb_tree, const char *log_entry, bool stamp)
 
GB_ERROR GBT_log_to_named_trees_remark (GBDATA *gb_main, const char *tree_name, const char *log_entry, bool stamp)
 
GB_ERROR GBT_write_tree_with_remark (GBDATA *gb_main, const char *tree_name, TreeNode *tree, const char *remark)
 
static TreeNodegbt_read_tree_rek (char **data, long *startid, GBDATA **gb_tree_nodes, TreeRoot *troot, int size_of_tree, GB_ERROR &error)
 
static TreeNoderead_tree_and_size_internal (GBDATA *gb_tree, GBDATA *gb_ctree, TreeRoot *troot, int node_count, GB_ERROR &error)
 
TreeNodeGBT_read_tree_and_size (GBDATA *gb_main, const char *tree_name, TreeRoot *troot, int *tree_size)
 
TreeNodeGBT_read_tree (GBDATA *gb_main, const char *tree_name, TreeRoot *troot)
 
size_t GBT_count_leafs (const TreeNode *tree)
 
static GB_ERROR gbt_invalid_because (const TreeNode *tree, const char *reason)
 
bool has_son (const TreeNode *father, const TreeNode *son)
 
static GB_ERROR gbt_is_invalid (bool is_root, const TreeNode *tree)
 
GB_ERROR GBT_is_invalid (const TreeNode *tree)
 
static GB_ERROR gbt_link_tree_to_hash_rek (TreeNode *tree, link_tree_data *ltd)
 
static GB_ERROR GBT_link_tree_using_species_hash (TreeNode *tree, bool show_status, GB_HASH *species_hash, int *zombies, int *duplicates)
 
GB_ERROR GBT_link_tree (TreeNode *tree, GBDATA *gb_main, bool show_status, int *zombies, int *duplicates)
 
void GBT_unlink_tree (TreeNode *tree)
 
GBDATAGBT_find_tree (GBDATA *gb_main, const char *tree_name)
 
bool is_tree (GBDATA *gb_tree)
 
GBDATAget_first_tree (GBDATA *gb_main)
 
GBDATAget_next_tree (GBDATA *gb_tree)
 
static GBDATAfind_largest_tree (GBDATA *gb_main)
 
GBDATAGBT_tree_infrontof (GBDATA *gb_tree)
 
GBDATAGBT_tree_behind (GBDATA *gb_tree)
 
GBDATAGBT_find_top_tree (GBDATA *gb_main)
 
GBDATAGBT_find_bottom_tree (GBDATA *gb_main)
 
const charGBT_existing_tree (GBDATA *gb_main, const char *tree_name)
 
GBDATAGBT_find_next_tree (GBDATA *gb_tree)
 
const charGBT_get_tree_name (GBDATA *gb_tree)
 
GB_ERROR GBT_check_tree_name (const char *tree_name)
 
const charGBT_name_of_largest_tree (GBDATA *gb_main)
 
const charGBT_name_of_bottom_tree (GBDATA *gb_main)
 
const charGBT_tree_info_string (GBDATA *gb_main, const char *tree_name, int maxTreeNameLen)
 
long GBT_size_of_tree (GBDATA *gb_main, const char *tree_name)
 
void GBT_get_tree_names (ConstStrArray &names, GBDATA *gb_main, bool sorted)
 
NOT4PERL GB_ERROR GBT_move_tree (GBDATA *gb_moved_tree, GBT_ORDER_MODE mode, GBDATA *gb_target_tree)
 
static GBDATAget_source_and_check_target_tree (GBDATA *gb_main, const char *source_tree, const char *dest_tree, GB_ERROR &error)
 
static GBDATAcopy_tree_container (GBDATA *gb_source_tree, const char *newName, GB_ERROR &error)
 
GB_ERROR GBT_copy_tree (GBDATA *gb_main, const char *source_name, const char *dest_name)
 
GB_ERROR GBT_rename_tree (GBDATA *gb_main, const char *source_name, const char *dest_name)
 
static GB_CSTRfill_species_name_array (GB_CSTR *current, const TreeNode *tree)
 
GB_CSTRGBT_get_names_of_species_in_tree (const TreeNode *tree, size_t *count)
 
static void tree2newick (const TreeNode *tree, GBS_strstruct &out, NewickFormat format, int indent)
 
charGBT_tree_2_newick (const TreeNode *tree, NewickFormat format, bool compact)
 

Macro Definition Documentation

#define GBT_PUT_DATA   1

Definition at line 24 of file adtree.cxx.

Referenced by gbt_write_tree(), and gbt_write_tree_rek_new().

#define GBT_GET_SIZE   0

Definition at line 25 of file adtree.cxx.

Referenced by gbt_write_tree().

Function Documentation

GBDATA* GBT_get_tree_data ( GBDATA gb_main)
TreeNode* GBT_remove_leafs ( TreeNode tree,
GBT_TreeRemoveType  mode,
const GB_HASH species_hash,
int removed,
int groups_removed 
)

Remove leafs from given 'tree'.

Parameters
treetree from which species will be removed
modedefines what to remove
species_hashhash translation from leaf-name to species-dbnode (not needed if tree is linked; see GBT_link_tree)
removedwill be incremented for each removed leaf (if !NULp)
groups_removedwill be incremented for each removed group (if !NULp)
Returns
new root node

if 'species_hash' is not provided and tree is not linked, the function will silently act strange:

  • GBT_REMOVE_MARKED and GBT_REMOVE_UNMARKED will remove any leaf
  • GBT_REMOVE_ZOMBIES and GBT_KEEP_MARKED will remove all leafs

Definition at line 34 of file adtree.cxx.

References destroy(), TreeNode::fixDeletedSon(), TreeNode::forget_origin(), TreeNode::forget_relatives(), gb_assert, TreeNode::gb_node, GB_read_flag(), GBS_read_hash(), GBT_REMOVE_MARKED, GBT_REMOVE_UNMARKED, GBT_REMOVE_ZOMBIES, TreeNode::get_tree_root(), TreeNode::is_leaf(), TreeNode::is_root_node(), TreeNode::leftson, TreeNode::name, NULp, TreeNode::rightson, and tree.

Referenced by NT_alltree_remove_leafs(), and sq_calc_seq_quality_cb().

int get_tree_idx ( GBDATA gb_tree)
inline
int get_max_tree_idx ( GBDATA gb_treedata)
inline

Definition at line 123 of file adtree.cxx.

References GB_child(), GB_nextChild(), and get_tree_idx().

Referenced by ensure_trees_have_order(), and tree_set_default_order().

GBDATA* get_tree_with_idx ( GBDATA gb_treedata,
int  at_idx 
)
inline

Definition at line 132 of file adtree.cxx.

References GB_child(), GB_nextChild(), get_tree_idx(), and NULp.

Referenced by GBT_find_top_tree(), and reserve_tree_idx().

GBDATA* get_tree_infrontof_idx ( GBDATA gb_treedata,
int  infrontof_idx 
)
inline

Definition at line 143 of file adtree.cxx.

References gb_assert, GB_child(), GB_nextChild(), get_tree_idx(), and NULp.

Referenced by GBT_find_bottom_tree(), and GBT_tree_infrontof().

GBDATA* get_tree_behind_idx ( GBDATA gb_treedata,
int  behind_idx 
)
inline

Definition at line 159 of file adtree.cxx.

References gb_assert, GB_child(), GB_nextChild(), get_tree_idx(), and NULp.

Referenced by GBT_find_top_tree(), and GBT_tree_behind().

GB_ERROR set_tree_idx ( GBDATA gb_tree,
int  idx 
)
inline
static GB_ERROR reserve_tree_idx ( GBDATA gb_treedata,
int  idx 
)
static

Definition at line 186 of file adtree.cxx.

References error(), get_tree_with_idx(), NULp, and set_tree_idx().

Referenced by GBT_copy_tree(), GBT_get_tree_names(), and GBT_move_tree().

static void ensure_trees_have_order ( GBDATA gb_treedata)
static
static void tree_set_default_order ( GBDATA gb_tree)
static

Definition at line 220 of file adtree.cxx.

References GB_get_father(), get_max_tree_idx(), get_tree_idx(), and set_tree_idx().

Referenced by gbt_write_tree().

GB_ERROR GBT_write_group_name ( GBDATA gb_group_name,
const char new_group_name,
bool  pedantic 
)
GB_ERROR GBT_write_name_to_groupData ( GBDATA gb_group,
bool  createNameEntry,
const char new_group_name,
bool  pedantic 
)
static GB_ERROR gbt_write_tree_nodes ( GBDATA gb_tree,
TreeNode node,
long startid 
)
static
static char* gbt_write_tree_rek_new ( const TreeNode node,
char dest,
long  mode 
)
static
static GB_ERROR gbt_write_tree ( GBDATA gb_main,
GBDATA gb_tree,
const char tree_name,
TreeNode tree 
)
static

writes a tree to the database.

If tree is loaded by function GBT_read_tree(..) then 'tree_name' should be NULp else 'gb_tree' should be set to NULp

To copy a tree call GBT_copy_tree() or copy_tree_container() or set recursively all tree->gb_node variables to zero (that unlinks the tree),

Definition at line 441 of file adtree.cxx.

References error(), GB_allow_compression(), gb_assert, GB_await_error(), GB_CREATE_CONTAINER, GB_delete(), GB_entry(), GB_nextEntry(), GB_raise_user_flag(), GB_search(), GB_user_flag(), GB_USERFLAG_GHOSTNODE, GBS_global_string(), GBT_check_tree_name(), GBT_GET_SIZE, GBT_get_tree_data(), GBT_PUT_DATA, GBT_write_int(), GBT_write_string(), gbt_write_tree_nodes(), gbt_write_tree_rek_new(), NULp, and tree_set_default_order().

Referenced by GBT_overwrite_tree(), and GBT_write_tree().

GB_ERROR GBT_write_tree ( GBDATA gb_main,
const char tree_name,
TreeNode tree 
)
GB_ERROR GBT_overwrite_tree ( GBDATA gb_tree,
TreeNode tree 
)

Definition at line 526 of file adtree.cxx.

References GB_get_root(), gbt_write_tree(), and NULp.

Referenced by adjustTreeRoot(), NTREE_move_tree_info(), and ARB_seqtree_root::saveToDB().

static GB_ERROR write_tree_remark ( GBDATA gb_tree,
const char remark 
)
static

Definition at line 530 of file adtree.cxx.

References GBT_write_string().

Referenced by GBT_log_to_tree_remark(), and GBT_write_tree_remark().

GB_ERROR GBT_write_tree_remark ( GBDATA gb_main,
const char tree_name,
const char remark 
)

Definition at line 533 of file adtree.cxx.

References GBT_find_tree(), and write_tree_remark().

Referenced by di_calculate_tree_cb(), GBT_write_tree_with_remark(), and main().

GB_ERROR GBT_log_to_tree_remark ( GBDATA gb_tree,
const char log_entry,
bool  stamp 
)

append 'log_entry' to tree comment

Parameters
gb_treethe tree
log_entrytext to append
stamptrue -> prefix date before 'log_entry'
Returns
error in case of failure

Definition at line 537 of file adtree.cxx.

References error(), GB_await_error(), GB_have_error(), GBS_log_action_to(), GBT_read_char_pntr(), NULp, and write_tree_remark().

Referenced by adjustTreeRoot(), GBT_log_to_named_trees_remark(), and NTREE_move_tree_info().

GB_ERROR GBT_log_to_named_trees_remark ( GBDATA gb_main,
const char tree_name,
const char log_entry,
bool  stamp 
)

append 'log_entry' to tree comment

Parameters
gb_maindatabase
tree_namename of tree
log_entrytext to append
stamptrue -> prefix date before 'log_entry'
Returns
error in case of failure

Definition at line 556 of file adtree.cxx.

References GBS_global_string(), GBT_find_tree(), and GBT_log_to_tree_remark().

Referenced by di_calculate_tree_cb(), and main().

GB_ERROR GBT_write_tree_with_remark ( GBDATA gb_main,
const char tree_name,
TreeNode tree,
const char remark 
)
static TreeNode* gbt_read_tree_rek ( char **  data,
long startid,
GBDATA **  gb_tree_nodes,
TreeRoot troot,
int  size_of_tree,
GB_ERROR error 
)
static
static TreeNode* read_tree_and_size_internal ( GBDATA gb_tree,
GBDATA gb_ctree,
TreeRoot troot,
int  node_count,
GB_ERROR error 
)
static
TreeNode* GBT_read_tree_and_size ( GBDATA gb_main,
const char tree_name,
TreeRoot troot,
int tree_size 
)

Loads a tree from DB into any user defined structure.

Parameters
gb_mainDB root node
tree_nameis the name of the tree in the db
trootconstructs the tree-node instances
tree_sizeif specified -> will be set to "size of tree" (aka number of leafs minus 1)
Returns
  • NULp if any error occurs (which is exported then)
  • root of loaded tree (dynamic type depends on 'nodeFactory')

Definition at line 770 of file adtree.cxx.

References TreeNode::announce_tree_constructed(), TreeRoot::delete_by_node(), error(), gb_assert, GB_entry(), GB_export_errorf(), GB_FIND, GB_read_int(), GB_search(), GBT_check_tree_name(), GBT_find_tree(), TreeNode::is_normal_group(), NULp, read_tree_and_size_internal(), and tree.

Referenced by GBT_read_tree(), and MatrixOrder::MatrixOrder().

TreeNode* GBT_read_tree ( GBDATA gb_main,
const char tree_name,
TreeRoot troot 
)
size_t GBT_count_leafs ( const TreeNode tree)
static GB_ERROR gbt_invalid_because ( const TreeNode tree,
const char reason 
)
static

Definition at line 849 of file adtree.cxx.

References GBS_global_string().

Referenced by gbt_is_invalid(), and GBT_is_invalid().

bool has_son ( const TreeNode father,
const TreeNode son 
)
inline

Definition at line 853 of file adtree.cxx.

References TreeNode::is_leaf(), TreeNode::leftson, and TreeNode::rightson.

Referenced by gbt_is_invalid().

static GB_ERROR gbt_is_invalid ( bool  is_root,
const TreeNode tree 
)
static
GB_ERROR GBT_is_invalid ( const TreeNode tree)
static GB_ERROR gbt_link_tree_to_hash_rek ( TreeNode tree,
link_tree_data ltd 
)
static
static GB_ERROR GBT_link_tree_using_species_hash ( TreeNode tree,
bool  show_status,
GB_HASH species_hash,
int zombies,
int duplicates 
)
static
GB_ERROR GBT_link_tree ( TreeNode tree,
GBDATA gb_main,
bool  show_status,
int zombies,
int duplicates 
)

Link a given tree to the database. That means that for all tips the member 'gb_node' is set to the database container holding the species data.

Parameters
treewhich will be linked to DB
gb_mainDB root node
show_statusshow a progress indicator?
zombiesif specified -> set to number of zombies (aka non-existing species) in tree
duplicatesif specified -> set to number of duplicated species in tree
Returns
error on failure
See also
GBT_unlink_tree()

Definition at line 953 of file adtree.cxx.

References error(), GBS_free_hash(), GBT_create_species_hash(), and GBT_link_tree_using_species_hash().

Referenced by ST_ML::calc_st_ml(), compress_sequence_tree(), GBT_compress_sequence_tree2(), get_cached_taxonomy(), ARB_seqtree_root::linkToDB(), PVP_calculate(), AP_tree::relink(), sq_calc_seq_quality_cb(), TREE_write_Newick(), and TREE_write_XML().

void GBT_unlink_tree ( TreeNode tree)

Definition at line 986 of file adtree.cxx.

References TreeNode::unlink_from_DB().

Referenced by ARB_seqtree_root::unlinkFromDB().

GBDATA* GBT_find_tree ( GBDATA gb_main,
const char tree_name 
)
bool is_tree ( GBDATA gb_tree)
inline

Definition at line 1001 of file adtree.cxx.

References GB_get_father(), and GB_has_key().

Referenced by GBT_get_tree_name(), get_next_tree(), and NT_jump_cb().

GBDATA* get_first_tree ( GBDATA gb_main)
inline

Definition at line 1007 of file adtree.cxx.

References GB_child(), and GBT_get_tree_data().

Referenced by find_largest_tree(), and GBT_existing_tree().

GBDATA* get_next_tree ( GBDATA gb_tree)
inline

Definition at line 1011 of file adtree.cxx.

References gb_assert, GB_nextChild(), is_tree(), and NULp.

Referenced by find_largest_tree().

static GBDATA* find_largest_tree ( GBDATA gb_main)
static

Definition at line 1017 of file adtree.cxx.

References GBT_read_int(), get_first_tree(), get_next_tree(), and NULp.

Referenced by GBT_name_of_largest_tree().

GBDATA* GBT_tree_infrontof ( GBDATA gb_tree)
GBDATA* GBT_tree_behind ( GBDATA gb_tree)
GBDATA* GBT_find_top_tree ( GBDATA gb_main)
GBDATA* GBT_find_bottom_tree ( GBDATA gb_main)
const char* GBT_existing_tree ( GBDATA gb_main,
const char tree_name 
)

Definition at line 1056 of file adtree.cxx.

References GBT_find_tree(), GBT_get_tree_name(), and get_first_tree().

Referenced by popup_new_main_window().

GBDATA* GBT_find_next_tree ( GBDATA gb_tree)
const char* GBT_get_tree_name ( GBDATA gb_tree)
GB_ERROR GBT_check_tree_name ( const char tree_name)
const char* GBT_name_of_largest_tree ( GBDATA gb_main)
const char* GBT_name_of_bottom_tree ( GBDATA gb_main)

Definition at line 1107 of file adtree.cxx.

References GBT_find_bottom_tree(), and GBT_get_tree_name().

Referenced by NT_select_bottom_tree().

const char* GBT_tree_info_string ( GBDATA gb_main,
const char tree_name,
int  maxTreeNameLen 
)
long GBT_size_of_tree ( GBDATA gb_main,
const char tree_name 
)

Definition at line 1162 of file adtree.cxx.

References GB_entry(), GB_read_int(), and GBT_find_tree().

Referenced by pars_check_size().

void GBT_get_tree_names ( ConstStrArray names,
GBDATA gb_main,
bool  sorted 
)
NOT4PERL GB_ERROR GBT_move_tree ( GBDATA gb_moved_tree,
GBT_ORDER_MODE  mode,
GBDATA gb_target_tree 
)
static GBDATA* get_source_and_check_target_tree ( GBDATA gb_main,
const char source_tree,
const char dest_tree,
GB_ERROR error 
)
static
static GBDATA* copy_tree_container ( GBDATA gb_source_tree,
const char newName,
GB_ERROR error 
)
static
GB_ERROR GBT_copy_tree ( GBDATA gb_main,
const char source_name,
const char dest_name 
)
GB_ERROR GBT_rename_tree ( GBDATA gb_main,
const char source_name,
const char dest_name 
)
static GB_CSTR* fill_species_name_array ( GB_CSTR current,
const TreeNode tree 
)
static

Definition at line 1340 of file adtree.cxx.

References TreeNode::is_leaf(), and TreeNode::name.

Referenced by GBT_get_names_of_species_in_tree().

GB_CSTR* GBT_get_names_of_species_in_tree ( const TreeNode tree,
size_t count 
)
static void tree2newick ( const TreeNode tree,
GBS_strstruct out,
NewickFormat  format,
int  indent 
)
static
char* GBT_tree_2_newick ( const TreeNode tree,
NewickFormat  format,
bool  compact 
)