| 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 | // @@@ let awt_create_select_filter create filter awars and automatically map it to awar_default_alignment |
|---|
| 23 | // (see [6476] for changes done for ColumnStat) |
|---|
| 24 | |
|---|
| 25 | adfilter = awt_create_select_filter(aw_root, gb_main, awar_filter_name); |
|---|
| 26 | column_stat = awar_columnStat_name ? new ColumnStat(gb_main, aw_root, awar_columnStat_name, awar_default_alignment) : NULp; |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | WeightedFilter::~WeightedFilter() { |
|---|
| 30 | delete column_stat; |
|---|
| 31 | // @@@ leak: adfilter (no destruction implemented) |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | AP_filter *WeightedFilter::create_filter() const { |
|---|
| 35 | return awt_get_filter(adfilter); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | AP_weights *WeightedFilter::create_weights(const AP_filter *filter, GB_ERROR& error) const { |
|---|
| 39 | ga_assert(!error); |
|---|
| 40 | |
|---|
| 41 | AP_weights *weights = NULp; |
|---|
| 42 | bool haveRates = false; |
|---|
| 43 | |
|---|
| 44 | if (column_stat) { |
|---|
| 45 | error = column_stat->calculate(NULp); |
|---|
| 46 | if (error) error = GBS_global_string("Failed to calculate weights (Reason: %s)", error); |
|---|
| 47 | |
|---|
| 48 | haveRates = column_stat->has_rates(); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | if (!error) { |
|---|
| 52 | if (haveRates) { |
|---|
| 53 | column_stat->weight_by_inverseRates(); |
|---|
| 54 | weights = new AP_weights(column_stat->get_weights(), column_stat->get_length(), filter); |
|---|
| 55 | } |
|---|
| 56 | else { |
|---|
| 57 | weights = new AP_weights(filter); |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | if (column_stat) column_stat->forget(); |
|---|
| 61 | |
|---|
| 62 | ga_assert(contradicted(error, weights)); |
|---|
| 63 | return weights; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | AliView *WeightedFilter::create_aliview(const char *aliname, GB_ERROR& error) const { |
|---|
| 67 | ga_assert(!error); |
|---|
| 68 | ga_assert(!GB_have_error()); |
|---|
| 69 | |
|---|
| 70 | AliView *aliview = NULp; |
|---|
| 71 | { |
|---|
| 72 | AP_filter *filter = create_filter(); |
|---|
| 73 | error = filter->is_invalid(); |
|---|
| 74 | |
|---|
| 75 | if (!error) { |
|---|
| 76 | AP_weights *weights = create_weights(filter, error); |
|---|
| 77 | aliview = error ? NULp : new AliView(adfilter->gb_main, *filter, *weights, aliname); |
|---|
| 78 | delete weights; |
|---|
| 79 | } |
|---|
| 80 | delete filter; |
|---|
| 81 | } |
|---|
| 82 | ga_assert(contradicted(error, aliview)); |
|---|
| 83 | ga_assert(!GB_have_error()); // @@@ should be returned via 'error' |
|---|
| 84 | return aliview; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | GBDATA *WeightedFilter::get_gb_main() const { |
|---|
| 88 | return adfilter->gb_main; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | AW_root *WeightedFilter::get_aw_root() const { |
|---|
| 92 | return adfilter->awr; |
|---|
| 93 | } |
|---|
| 94 | |
|---|