22 #define FIELD_FILTER_RESORT (1<<GB_STRING)|(1<<GB_INT)|(1<<GB_FLOAT) // field types supported by cmpByKey()
24 #define CUSTOM_CRITERIA 3
62 cmp = f1<f2 ? -1 : (f1>f2 ? 1 : 0);
81 else cmp = gb_field2 ? 1 : 0;
114 cmp =
cmpByKey(gbd1, gbd2, sortBy[c]);
147 free(gb_resort_data_list);
160 if (!error_or_warning) {
161 if (!
customDefinesOrder) error_or_warning =
"Warning: No order is defined by the specified fields";
162 else if (!
customOrderIsStrict) error_or_warning =
"Note: The specified fields do not define a strict order";
164 return error_or_warning;
172 if (!tree) error =
"Please select/build a tree first";
177 #define AWAR_TREE_SORT1 "db_sort/sort_1"
178 #define AWAR_TREE_SORT2 "db_sort/sort_2"
179 #define AWAR_TREE_SORT3 "db_sort/sort_3"
181 #define AWAR_TREE_REV1 "db_sort/rev1"
182 #define AWAR_TREE_REV2 "db_sort/rev2"
183 #define AWAR_TREE_REV3 "db_sort/rev3"
196 if (error_or_warning)
aw_message(error_or_warning);
210 AW_window_simple *aws =
new AW_window_simple;
211 aws->init(awr,
"SORT_DB_ENTRIES",
"SORT DATABASE");
216 aws->create_button(
"CLOSE",
"CLOSE",
"C");
220 aws->create_button(
"HELP",
"HELP",
"H");
226 aws->at(
"rev1"); aws->label(
"Reverse"); aws->create_toggle(
AWAR_TREE_REV1);
227 aws->at(
"rev2"); aws->label(
"Reverse"); aws->create_toggle(
AWAR_TREE_REV2);
228 aws->at(
"rev3"); aws->label(
"Reverse"); aws->create_toggle(
AWAR_TREE_REV3);
232 aws->create_button(
"GO",
"GO",
"G");
245 #define TEST_EXPECT_DATABASE_ORDER(expected_order) do{ \
246 GB_transaction ta1(gb_main); \
247 char *got_order = GBT_store_marked_species(gb_main, false); \
248 TEST_EXPECT_EQUAL(got_order, expected_order); \
252 #define TEST_EXPECT_ANNOTATD_ORDER(expected_order,expected_values,key) do{ \
253 GB_transaction ta2(gb_main); \
254 TEST_EXPECT_DATABASE_ORDER(expected_order); \
255 char *aci = GBS_global_string_copy("split(\";\")|findspec(readdb(%s))|merge(\";\")", key); \
256 char *gen_values = GB_command_interpreter(expected_order, aci, gb_main); \
257 if (!gen_values) TEST_EXPECT_NO_ERROR(GB_await_error()); \
258 TEST_EXPECT_EQUAL(gen_values, expected_values); \
263 void TEST_resort_database() {
269 const char *
const BYNAME_ORDER =
"AcsCell2;AgrSp148;BurCalid;ClaMich8;CytHutc2;DstHafn2;ErwOleae;GlmApico;HrpAura2;IlyPoly2;MhyPalud;MtpKand2;OcgTerie;PesPropi;PslBats2;PurGergo;SrrAquat;StxAceti;TreIsopt;VibJapon;XanCucur;YerKrist";
270 const char *
const PHYLO_ORDER =
"ErwOleae;PurGergo;YerKrist;SrrAquat;GlmApico;VibJapon;MhyPalud;BurCalid;StxAceti;XanCucur;AgrSp148;PslBats2;MtpKand2;OcgTerie;PesPropi;DstHafn2;ClaMich8;AcsCell2;HrpAura2;CytHutc2;TreIsopt;IlyPoly2";
271 const char *
const INITIAL_ORDER =
"ErwOleae;PurGergo;YerKrist;SrrAquat;GlmApico;VibJapon;MhyPalud;BurCalid;StxAceti;XanCucur;AgrSp148;PslBats2;TreIsopt;IlyPoly2;CytHutc2;ClaMich8;AcsCell2;HrpAura2;PesPropi;DstHafn2;OcgTerie;MtpKand2";
274 TEST_EXPECT_DATABASE_ORDER(INITIAL_ORDER);
289 TEST_EXPECT_DATABASE_ORDER(PHYLO_ORDER);
300 TEST_EXPECT_DATABASE_ORDER(BYNAME_ORDER);
309 TEST_EXPECT_ANNOTATD_ORDER(
"AcsCell2;MtpKand2;ClaMich8;AgrSp148;BurCalid;PslBats2;ErwOleae;GlmApico;XanCucur;YerKrist;IlyPoly2;PurGergo;StxAceti;PesPropi;VibJapon;SrrAquat;DstHafn2;TreIsopt;MhyPalud;HrpAura2;OcgTerie;CytHutc2",
310 "124;124;122;121;121;121;120;119;119;118;117;117;117;116;116;115;114;113;112;111;105;101",
311 "align_bp_score_slv");
316 TEST_EXPECT_ANNOTATD_ORDER(
"MtpKand2;AcsCell2;ClaMich8;AgrSp148;PslBats2;BurCalid;ErwOleae;GlmApico;XanCucur;YerKrist;IlyPoly2;StxAceti;PurGergo;PesPropi;VibJapon;SrrAquat;DstHafn2;TreIsopt;MhyPalud;HrpAura2;OcgTerie;CytHutc2",
318 "91;96;99;95;96;97;97;92;99;99;87;93;99;86;99;99;91;72;92;83;82;88",
319 "align_quality_slv");
328 TEST_EXPECT_ANNOTATD_ORDER(
"DstHafn2;XanCucur;AgrSp148;GlmApico;IlyPoly2;PesPropi;ClaMich8;StxAceti;OcgTerie;MhyPalud;CytHutc2;AcsCell2;BurCalid;PslBats2;ErwOleae;YerKrist;PurGergo;SrrAquat;TreIsopt;VibJapon;HrpAura2;MtpKand2",
329 "0.12;0.13;0.2;0.2;0.2;0.2;0.27;0.27;0.27;0.28;0.29;0.33;0.33;0.35;0.4;0.41;0.41;0.41;0.41;0.47;0.68;1.6",
335 TEST_EXPECT_ANNOTATD_ORDER(
"OcgTerie;HrpAura2;TreIsopt;IlyPoly2;PesPropi;MtpKand2;DstHafn2;CytHutc2;StxAceti;MhyPalud;BurCalid;GlmApico;AgrSp148;AcsCell2;PslBats2;ErwOleae;ClaMich8;PurGergo;SrrAquat;VibJapon;YerKrist;XanCucur",
336 "69.761269;73.481384;74.731186;76.5748;77.514793;79.776756;79.802635;82.919708;87.339195;87.470451;89.498642;89.625168;89.759888;90.149460;92.114960;94.846054;95.121948;97.172417;97.569443;99.170128;99.247093;100",
GB_ERROR GB_begin_transaction(GBDATA *gbd)
customCriterion(const customCriterion &other)
GBDATA * GB_open(const char *path, const char *opent)
static void NT_resort_data_base_by_tree(TreeNode *tree, GBDATA *gb_species_data)
long GB_read_int(GBDATA *gbd)
#define implicated(hypothesis, conclusion)
#define FIELD_FILTER_RESORT
void load_xfig(const char *file, bool resize=true)
GBDATA ** GBT_gen_species_array(GBDATA *gb_main, long *speciesCountPtr)
long GBT_mark_all(GBDATA *gb_main, int flag)
void GB_sort(void **array, size_t first, size_t behind_last, gb_compare_function compare, void *client_data)
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
void NT_create_resort_awars(AW_root *awr, AW_default aw_def)
char * ARB_strdup(const char *str)
TreeNode * GBT_read_tree(GBDATA *gb_main, const char *tree_name, TreeRoot *troot)
void AW_POPDOWN(AW_window *window)
GB_ERROR GBT_link_tree(TreeNode *tree, GBDATA *gb_main, bool show_status, int *zombies, int *duplicates)
#define NO_FIELD_SELECTED
customCriterion(const char *key_, bool reverse_)
void create_itemfield_selection_button(AW_window *aws, const FieldSelDef &selDef, const char *at)
const char * read_char_pntr() const
GB_ERROR GB_await_error()
static bool customOrderIsStrict
TreeNode * NT_get_tree_root_of_canvas(TREE_canvas *ntw)
WindowCallback makeHelpCallback(const char *helpfile)
GB_TYPES GB_read_type(GBDATA *gbd)
static GBDATA ** gb_resort_data_list
static void NT_resort_data_by_user_criteria(AW_window *aw)
void NT_resort_data_by_phylogeny(AW_window *, TREE_canvas *ntw)
static bool customDefinesOrder
#define TEST_REJECT_NULL(n)
static void error(const char *msg)
float GB_read_float(GBDATA *gbd)
static long gb_resort_data_count
static SearchTree * tree[SEARCH_PATTERNS]
int GB_nsons(GBDATA *gbd)
AW_awar * awar(const char *awar)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
TYPE * ARB_calloc(size_t nelem)
static int resort_data_by_customOrder(const void *v1, const void *v2, void *cd_sortBy)
ItemSelector & SPECIES_get_selector()
#define TEST_EXPECT_NO_ERROR(call)
void aw_message(const char *msg)
static int cmpByKey(GBDATA *gbd1, GBDATA *gbd2, const customCriterion &by)
#define TEST_EXPECT_ERROR_CONTAINS(call, part)
static GB_ERROR strict_resort_data_base(GBDATA *gb_main, const customCriterion *sortBy)
GB_transaction ta(gb_var)
void destroy(TreeNode *that)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
GB_ERROR GB_resort_data_base(GBDATA *gb_main, GBDATA **new_order_list, long listsize)
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
DECLARE_ASSIGNMENT_OPERATOR(customCriterion)
GBDATA * GB_entry(GBDATA *father, const char *key)
static GB_ERROR resort_data_base(GBDATA *gb_main, TreeNode *tree, const customCriterion *sortBy)
void GB_close(GBDATA *gbd)
AW_window * NT_create_resort_window(AW_root *awr)
GBDATA * GBT_get_species_data(GBDATA *gb_main)