| 1 | // ================================================================ // |
|---|
| 2 | // // |
|---|
| 3 | // File : GUI_aliview.cxx // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Coded by Ralf Westram (coder@reallysoft.de) in November 2009 // |
|---|
| 7 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 8 | // http://www.arb-home.de/ // |
|---|
| 9 | // // |
|---|
| 10 | // ================================================================ // |
|---|
| 11 | |
|---|
| 12 | #include "gui_aliview.hxx" |
|---|
| 13 | #include "awt_filter.hxx" |
|---|
| 14 | #include "ColumnStat.hxx" |
|---|
| 15 | #include "ga_local.h" |
|---|
| 16 | |
|---|
| 17 | #include <AliView.hxx> |
|---|
| 18 | #include <AP_filter.hxx> |
|---|
| 19 | #include <arb_msg.h> |
|---|
| 20 | |
|---|
| 21 | WeightedFilter::WeightedFilter(GBDATA *gb_main, AW_root *aw_root, const char *awar_filter_name, const char *awar_columnStat_name, AW_awar *awar_default_alignment) { |
|---|
| 22 | #if defined(WARN_TODO) |
|---|
| 23 | #warning let awt_create_select_filter create filter awars and automatically map it to awar_default_alignment \ |
|---|
| 24 | // (see [6476] for changes done for ColumnStat) |
|---|
| 25 | #endif |
|---|
| 26 | adfilter = awt_create_select_filter(aw_root, gb_main, awar_filter_name); |
|---|
| 27 | column_stat = awar_columnStat_name ? new ColumnStat(gb_main, aw_root, awar_columnStat_name, awar_default_alignment) : NULp; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | WeightedFilter::~WeightedFilter() { |
|---|
| 31 | delete column_stat; |
|---|
| 32 | // @@@ leak: adfilter (no destruction implemented) |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | AP_filter *WeightedFilter::create_filter() const { |
|---|
| 36 | return awt_get_filter(adfilter); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | AP_weights *WeightedFilter::create_weights(const AP_filter *filter, GB_ERROR& error) const { |
|---|
| 40 | ga_assert(!error); |
|---|
| 41 | |
|---|
| 42 | AP_weights *weights = NULp; |
|---|
| 43 | bool haveRates = false; |
|---|
| 44 | |
|---|
| 45 | if (column_stat) { |
|---|
| 46 | error = column_stat->calculate(NULp); |
|---|
| 47 | if (error) error = GBS_global_string("Failed to calculate weights (Reason: %s)", error); |
|---|
| 48 | |
|---|
| 49 | haveRates = column_stat->has_rates(); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | if (!error) { |
|---|
| 53 | if (haveRates) { |
|---|
| 54 | column_stat->weight_by_inverseRates(); |
|---|
| 55 | weights = new AP_weights(column_stat->get_weights(), column_stat->get_length(), filter); |
|---|
| 56 | } |
|---|
| 57 | else { |
|---|
| 58 | weights = new AP_weights(filter); |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | if (column_stat) column_stat->forget(); |
|---|
| 62 | |
|---|
| 63 | ga_assert(contradicted(error, weights)); |
|---|
| 64 | return weights; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | AliView *WeightedFilter::create_aliview(const char *aliname, GB_ERROR& error) const { |
|---|
| 68 | ga_assert(!error); |
|---|
| 69 | ga_assert(!GB_have_error()); |
|---|
| 70 | |
|---|
| 71 | AliView *aliview = NULp; |
|---|
| 72 | { |
|---|
| 73 | AP_filter *filter = create_filter(); |
|---|
| 74 | error = filter->is_invalid(); |
|---|
| 75 | |
|---|
| 76 | if (!error) { |
|---|
| 77 | AP_weights *weights = create_weights(filter, error); |
|---|
| 78 | aliview = error ? NULp : new AliView(adfilter->gb_main, *filter, *weights, aliname); |
|---|
| 79 | delete weights; |
|---|
| 80 | } |
|---|
| 81 | delete filter; |
|---|
| 82 | } |
|---|
| 83 | ga_assert(contradicted(error, aliview)); |
|---|
| 84 | ga_assert(!GB_have_error()); // @@@ should be returned via 'error' |
|---|
| 85 | return aliview; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | GBDATA *WeightedFilter::get_gb_main() const { |
|---|
| 89 | return adfilter->gb_main; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | AW_root *WeightedFilter::get_aw_root() const { |
|---|
| 93 | return adfilter->awr; |
|---|
| 94 | } |
|---|
| 95 | |
|---|