22 ID Cluster::unused_id = 1;
32 if (leafs.
first() == distance_to || leafs.
second() == distance_to) {
58 min_dist = max_dist = dist->second;
61 AP_FLOAT min_mean_dist = 9999999999.0;
62 representative =
NULp;
64 for (; dist != dist_end; ++dist) {
68 if (di<min_dist) min_dist = di;
69 if (di>max_dist) max_dist = di;
73 for (
int i = 0; i<2; ++i) {
74 const ClusterTree *member = i ? leafs.
first() : leafs.
second();
75 GBDATA *gb_species = member->gb_node;
78 if (members.find(gb_species) == members.end()) {
79 members.insert(gb_species);
82 if (mean_dist_to_member<min_mean_dist) {
83 representative = gb_species;
84 min_mean_dist = mean_dist_to_member;
91 cl_assert(members.size() == ct->get_leaf_count());
93 min_bases = ct->get_min_bases();
95 ClusterTree *root = ct->get_root_node();
96 size_t allSize = root->get_leaf_count();
97 size_t size = ct->get_leaf_count();
98 size_t first = ct->relative_position_in(root);
99 size_t last = first+size-1;
101 rel_tree_pos = ((double(first)+last)/2) / allSize;
103 mean_dist /= distances->size();
105 desc = create_description(ct);
116 if (group_name && keep_group_name.
selects(*ct)) {
119 else result =
new string(group_name);
122 string *leftgroups =
get_downgroups(ct->get_leftson(), keep_group_name, group_members);
123 size_t right_members;
124 string *rightgroups =
get_downgroups(ct->get_rightson(), keep_group_name, right_members);
126 group_members += right_members;
128 if (leftgroups || rightgroups) {
129 if (!leftgroups) { result = rightgroups; rightgroups =
NULp; }
130 else if (!rightgroups) { result = leftgroups; leftgroups =
NULp; }
131 else result =
new string(*leftgroups+
"+"+*rightgroups);
145 static SmartCharPtr
result;
150 else if (group_name && keep_group_name.
selects(*ct)) {
156 group_name =
get_upgroup(father, keep_group_name, upgroupPtr, reuse_original_name);
160 group_name =
"<WHOLE TREE>";
178 const char *upgroup_name =
get_upgroup(ct, use_any_upgroup, upgroup,
false);
185 if (upgroup_members == cluster_members) {
186 name =
string(
"[G] ")+upgroup_name;
189 size_t downgroup_members;
190 string *downgroup_names =
get_downgroups(ct, use_any_upgroup, downgroup_members);
195 if (up_rel>down_rel) {
199 if (downgroup_members == cluster_members) {
200 name = downgroup_names->c_str();
207 delete downgroup_names;
217 const char *upgroup_name =
get_upgroup(ct, keep_group_name, upgroup,
true);
219 size_t upgroup_members = upgroup->get_leaf_count();
222 const char *upgroup_info;
223 if (upgroup_members == cluster_members) {
224 upgroup_info = upgroup_name;
228 size_t cluster_posN = cluster_pos1+cluster_members-1;
230 upgroup_info =
GBS_global_string(
"%zu.%zu[%zu]%s%s", cluster_pos1, cluster_posN, upgroup_members, separator.c_str(), upgroup_name);
243 mutable char *format_string;
245 static char *make_format(
size_t val) {
250 static void calc_float_format(
AP_FLOAT val,
int&
all,
int& afterdot) {
252 afterdot = digits <=3 ? 5-digits-1 : 0;
254 all = digits+(afterdot ? (afterdot+1) : 0);
257 static char *make_format(
AP_FLOAT val) {
259 calc_float_format(val, all, afterdot);
277 max_count =
std::max(max_count, count);
278 max_dist =
std::max(max_dist, maxDist);
279 max_minBases =
std::max(max_minBases, minBases);
281 freenull(format_string);
286 int distSize, baseSize;
289 calc_float_format(max_dist, distSize, afterdot);
290 calc_float_format(max_minBases, baseSize, afterdot);
294 countSize, countSize<5 ?
"#" :
"Count",
295 distSize,
"Mean [min-max] dist",
300 if (!format_string) {
302 char *count_part = make_format(max_count);
303 char *dist_part = make_format(max_dist);
304 char *bases_part = make_format(max_minBases);
308 dist_part, dist_part, dist_part,
315 return format_string;
327 const char *format_string;
328 if (format) format_string = format->
get_format();
329 else format_string =
"%zu %.3f [%.3f-%.3f] %.1f %s";
345 known_clusters[clus->
get_ID()] = clus;
346 get_subset(subset).push_back(clus->
get_ID());
350 int pos = get_pos(clus, subset);
353 ClusterIDs::iterator toRemove = ids.begin();
354 advance(toRemove, pos);
356 known_clusters.erase(clus->
get_ID());
364 known_clusters.erase(*
id);
376 copy(shown.begin(), shown.end(), back_insert_iterator<ClusterIDs>(stored));
382 copy(stored.begin(), stored.end(), back_insert_iterator<ClusterIDs>(shown));
400 primary_order(primary),
401 secondary_order(secondary)
412 bool equal = !cl2->
lessByOrder(*cl1, primary_order);
431 sort(shown.begin(), shown.end(), sortBy);
437 for (
int pass = 1; pass <= 2; ++pass) {
464 known_clusters.clear();
468 char *original =
NULp;
469 const char *was = strstr(groupname,
" {was:");
470 const char *closing = strchr(groupname,
'}');
471 if (was && closing) {
475 if (sub) freeset(original, sub);
const ClusterTree * second() const
AliDataPtr format(AliDataPtr data, const size_t wanted_len, GB_ERROR &error)
const char * get_list_display(const DisplayFormat *format) const
char * originalGroupName(const char *groupname)
return string(buffer, length)
void insert_default(const char *displayed, const AW_scalar &value)
const ClusterTree * first() const
void update_cluster_selection_list()
static const char * get_upgroup(const ARB_countedTree *ct, const ARB_tree_predicate &keep_group_name, const ARB_countedTree *&upgroupPtr, bool reuse_original_name)
const char * GBS_global_string(const char *templat,...)
bool isNull() const
test if SmartPtr is NULp
char * ARB_strpartdup(const char *start, const char *end)
LeafRelations::const_iterator LeafRelationCIter
bool operator()(ID id1, ID id2) const
void insert(const char *displayed, const AW_scalar &value)
void add(ClusterPtr clus, ClusterSubset subset)
std::string get_upgroup_info(const ARB_countedTree *ct, const ARB_tree_predicate &keep_group_name, const std::string &separator)
size_t relative_position_in(const ARB_countedTree *upgroup) const
void scan_display_widths(DisplayFormat &format) const
CONSTEXPR_INLINE int digits(int parts)
virtual bool selects(const ARB_seqtree &tree) const =0
std::vector< ID > ClusterIDs
bool less(const copy< T > &t1, const copy< T > &t2)
std::map< TwoLeafs, AP_FLOAT > LeafRelations
CONSTEXPR_INLINE_Cxx14 void swap(unsigned char &c1, unsigned char &c2)
bool is_keeled_group() const
SortClusterIDsBy(const KnownClusters &known_, ClusterOrder primary, ClusterOrder secondary)
virtual unsigned get_leaf_count() const =0
void clear(ClusterSubset subset)
void remove(ClusterPtr clus, ClusterSubset subset)
std::map< ID, ClusterPtr > KnownClusters
static void copy(double **i, double **j)
static AP_FLOAT calc_mean_dist_to(const ClusterTree *distance_to, const LeafRelations *distances)
ClusterIDs::const_iterator ClusterIDsIter
bool is_inside(const TreeNode *subtree) const
ClusterPtr clusterWithID(ID id) const
size_t get_member_count() const
bool lessByOrder(const Cluster &other, ClusterOrder sortBy) const
AW_selection_list * clusterList
const char * get_group_name() const
char * GBS_global_string_copy(const char *templat,...)
static string * get_downgroups(const ARB_countedTree *ct, const ARB_tree_predicate &keep_group_name, size_t &group_members)