28 #define AWAR_SC_BASE "sai/calc/"
29 #define AWAR_SC_TEMP "tmp/" AWAR_SC_BASE
30 #define AWAR_SC_TRANSLATE_BASE AWAR_SC_BASE "translate/"
31 #define AWAR_SC_TRANSLATE_TEMP AWAR_SC_TEMP "translate/"
32 #define AWAR_SC_MATRIX_BASE AWAR_SC_BASE "matrix/"
33 #define AWAR_SC_MATRIX_TEMP AWAR_SC_TEMP "matrix/"
34 #define AWAR_SC_BOOL_BASE AWAR_SC_BASE "bool/"
35 #define AWAR_SC_BOOL_TEMP AWAR_SC_TEMP "bool/"
36 #define AWAR_SC_ACI_BASE AWAR_SC_BASE "aci/"
37 #define AWAR_SC_ACI_TEMP AWAR_SC_TEMP "aci/"
39 #define AWAR_SC_TARGET_SAI AWAR_SC_BASE "target"
40 #define AWAR_SC_SOURCE_SAI_LIST AWAR_SC_BASE "sources" // format = "name1;name2;..."
41 #define AWAR_SC_METHOD AWAR_SC_BASE "method" // = SaiOperatorType
42 #define AWAR_SC_SCOPE AWAR_SC_BASE "scope" // = SaiAliScope
43 #define AWAR_SC_METHOD_CONFIG AWAR_SC_TEMP "config" // mapped to config of currently selected SaiOperatorType
45 #define AWAR_SC_TRANSLATE_CONFIG AWAR_SC_TRANSLATE_BASE "config"
46 #define AWAR_SC_TRANSLATE_DEFAULT AWAR_SC_TRANSLATE_TEMP "default"
47 #define AWAR_SC_TRANSLATE_IO_TEMPL AWAR_SC_TRANSLATE_TEMP "%c%i"
49 #define AWAR_SC_MATRIX_CONFIG AWAR_SC_MATRIX_BASE "config"
50 #define AWAR_SC_MATRIX_CELL_TEMPL AWAR_SC_MATRIX_TEMP "m%i_%i"
52 #define AWAR_SC_BOOL_CONFIG AWAR_SC_BOOL_BASE "config"
53 #define AWAR_SC_BOOL_IN1 AWAR_SC_BOOL_TEMP "in1"
54 #define AWAR_SC_BOOL_IN0 AWAR_SC_BOOL_TEMP "in0"
55 #define AWAR_SC_BOOL_OP AWAR_SC_BOOL_TEMP "op"
56 #define AWAR_SC_BOOL_OUT1 AWAR_SC_BOOL_TEMP "out1"
57 #define AWAR_SC_BOOL_OUT0 AWAR_SC_BOOL_TEMP "out0"
58 #define AWAR_SC_BOOL_SEL_RULE AWAR_SC_BOOL_TEMP "selrule"
59 #define AWAR_SC_BOOL_RULES AWAR_SC_BOOL_TEMP "rules"
61 #define AWAR_SC_ACI_CONFIG AWAR_SC_ACI_BASE "config"
62 #define AWAR_SC_ACI AWAR_SC_ACI_TEMP "aci"
64 #define TRANSLATION_RULES 10
66 #define MATRIX_RULES (7+1) // includes default translation rule
67 #define MATRIX_AWARS (MATRIX_RULES+1)
80 {
"*diff2",
"Compares 2 SAI.\nResult: '-' where equal\n 'x' where different",
"method='0';target='diff';~config='aci=\\'colsplit|compare|plus(1)|translate(\"012\",\"x-x\")\\''" },
81 {
"*diff2_ignCase",
"Compares 2 SAI (ignoring case).\nResult: '-' where equal \n 'x' where different",
"method='0';target='idiff';~config='aci=\\'upper|colsplit|compare|plus(1)|translate(\"012\",\"x-x\")\\''" },
82 {
"*count_x",
"Count 'x' in multiple SAI (up to 9).",
"method='0';target='x-count';~config='aci=\\'keep(\"x\")|len|translate(\"0\",\"-\")\\''" },
83 {
"*sum_up_2",
"Sum up 2 SAI containing digits and gaps\n(raises error if result overflows 9).",
"method='0';target='sum';~config='aci=\\'translate(\"-=\",\"00\")|colsplit|plus\\''" },
84 {
"*cutByTermini",
"Sai1: termini (containing 'x' in region)\nSai2: any\n=> same as Sai2 at all 'x' in Sai1\n else same as Sai1 (normally gap).",
"method='0';sources='termini';~config='aci=\\'command(\"/^x//\")|head(1)\\''" },
85 {
"*invert_binary",
"inverts binary SAI\n(works with binary source and/or target)",
"method='0';~config='aci=\\'translate(\"01\",\"10\")\\''" },
109 static SmartCharPtr
result;
115 AW_window_simple *aws =
new AW_window_simple;
117 aws->init(awr,
"SAI_TRANSLATOR",
"SAI translator configuration");
120 aws->auto_space(5, 5);
121 aws->button_length(8);
125 aws->create_button(
"CLOSE",
"CLOSE",
"O");
128 aws->create_button(
"HELP",
"HELP");
130 aws->at(
"target");
int x2 = aws->get_at_xposition();
131 aws->at(
"source");
int x1 = aws->get_at_xposition();
144 aws->label(
"Default:");
164 if ((x == 0 && (y == 0 || y == 1))
171 static SmartCharPtr awarName;
182 AW_window_simple *aws =
new AW_window_simple;
184 aws->init(awr,
"SAI_MATRIX_TRANSLATOR",
"SAI matrix translator configuration");
187 aws->auto_space(5, 5);
188 aws->button_length(8);
192 aws->create_button(
"CLOSE",
"CLOSE",
"O");
195 aws->create_button(
"HELP",
"HELP");
201 aws->at(
"col1"); aws->get_at_position(&xpos[1], &ypos[0]);
202 aws->at(
"col2"); aws->get_at_position(&xpos[2], &ycheck);
204 aws->at(
"row1"); aws->get_at_position(&xpos[0], &ypos[1]);
205 aws->at(
"row2"); aws->get_at_position(&xcheck, &ypos[2]);
209 int xdiff = xpos[2]-xpos[1];
210 int ydiff = ypos[2]-ypos[1];
212 bool figConsistent = (xpos[0] == xcheck) && (ypos[0] == ycheck) && xdiff>0 && ydiff>0;
215 xpos[p] = xpos[p-1] + xdiff;
216 ypos[p] = ypos[p-1] + ydiff;
221 aw_message(
"internal error: invalid position values");
229 aws->at(xpos[x], ypos[
y]);
231 aws->create_input_field(awar_name, 5);
239 aws->create_autosize_button(
"NORMALIZE",
"Normalize");
245 AW_window_simple *aws =
new AW_window_simple;
247 aws->init(awr,
"SAI_ACI_CONFIG",
"SAI ACI configuration");
250 aws->auto_space(5, 5);
251 aws->button_length(8);
255 aws->create_button(
"CLOSE",
"CLOSE",
"O");
258 aws->create_button(
"HELP",
"HELP");
274 if (boolrule_sellst) {
275 boolrule_sellst->
clear();
276 for (
int r = 0; ruleArray[r]; ++r) {
277 boolrule_sellst->
insert(ruleArray[r], ruleArray[r]);
279 if (ruleArray.
empty()) {
285 boolrule_sellst->
update();
296 bool seenDelimiter =
false;
297 for (
int i = 0; ruleArray[i] && !seenDelimiter; ++i) {
298 seenDelimiter = strchr(ruleArray[i], RULELIST_DELIMITER[0]);
305 srt[1] = RULELIST_DELIMITER[0];
307 for (
int i = 0; ruleArray[i]; ++i) {
309 if (strlen(copy[i]) != strlen(ruleArray[i])) {
311 int(RULELIST_DELIMITER[0]), ruleArray[i]));
329 if (boolrule_sellst) {
340 if (createFirstRule) {
351 bool specifiedChars = trueChars[0];
354 return new SaiBoolRule(op, specifiedChars, specifiedChars ? trueChars : falseChars);
363 const bool first = ruleArray.
empty();
366 ruleArray.
put(rule->to_string().c_str());
377 const bool first = selIdx == 0;
380 ruleArray.
replace(selIdx, rule->to_string().c_str());
385 aw_message(
"No operation selected to modify.");
397 if (selIdx == 0 && !ruleArray.
empty()) {
409 ruleArray.
replace(0, replaced.c_str());
416 aw_message(
"No operation selected to delete.");
421 AW_window_simple *aws =
new AW_window_simple;
423 aws->init(awr,
"SAI_BOOLCHAIN_CONFIG",
"SAI boolchain configuration");
426 aws->auto_space(5, 5);
427 aws->button_length(8);
431 aws->create_button(
"CLOSE",
"CLOSE",
"O");
434 aws->create_button(
"HELP",
"HELP");
441 aws->insert_default_option(
"AND",
"A",
SBO_AND);
442 aws->insert_option (
"OR",
"O",
SBO_OR);
443 aws->insert_option (
"XOR",
"X",
SBO_XOR);
444 aws->insert_option (
"NAND",
"D",
SBO_NAND);
445 aws->insert_option (
"NOR",
"N",
SBO_NOR);
446 aws->insert_option (
"XNOR",
"R",
SBO_XNOR);
447 aws->update_option_menu();
458 aws->callback(
mod_boolrule_cb); aws->create_button(
"UPDATE",
"UPDATE");
459 aws->callback(
del_boolrule_cb); aws->create_button(
"DELETE",
"DELETE");
475 if (aw_visible && aw_visible != aww[type]) {
476 if (aw_visible->
is_shown()) forcePopup =
true;
481 if (!forcePopup)
return;
505 aw_message(
"cannot edit this type of calculation method (yet)");
509 aw_visible = aww[
type];
543 const SaiTranslator *translator =
DOWNCAST(SaiTranslator*, &*saiOp);
545 translator->deduceTranslations(cmap);
557 for (
int k = 0; keys[k]; ++k) {
558 const char *value = cmap.
get_entry(keys[k]);
559 bool accepted =
false;
560 if (strncmp(keys[k],
"trans", 5) == 0) {
561 const int num = atoi(keys[k]+5);
564 firstChar[0] = value[0];
571 else if (strcmp(keys[k],
"default") == 0) {
592 SaiTranslator translator(translate_default[0] ? translate_default[0] :
'-');
597 if (translate_from[0] && translate_to[0]) {
598 translator.addTranslation(translate_from, translate_to[0]);
603 string cfg = translator.get_config();
622 const bool globalIsDefined = globalDefTrans && globalDefTrans[0];
625 bool isDefined = defTrans && defTrans[0];
627 char defResChar = isDefined ? defTrans[0] : (globalIsDefined ? globalDefTrans[0] :
'-');
628 SaiTranslator *colTrans =
new SaiTranslator(defResChar);
634 if (cellTrans && cellTrans[0]) {
635 if (from && from[0]) {
636 colTrans->addTranslation(from, cellTrans[0]);
643 if (!isDefined && !returnDefault) {
657 bool check_row[255], check_col[255];
658 for (
int i = 0; i<255; ++i) {
659 check_row[i] = check_col[i] =
true;
663 for (
int x1 = 0; x1<255; ++x1) {
665 string c(1,
char(x1+1));
666 for (
int x2 = x1+1; x2<255; ++x2) {
669 for (
int y = 0;
y<255 && equal; ++
y) {
670 equal = out[
y*255+x1] == out[
y*255+x2];
674 check_col[x2] =
false;
678 check_col[x1] =
false;
684 for (
int y1 = 0; y1<255; ++y1) {
686 string r(1,
char(y1+1));
687 for (
int y2 = y1+1; y2<255; ++y2) {
690 for (
int x = 0; x<255 && equal; ++x) {
691 equal = out[y1*255+x] == out[y2*255+x];
695 check_row[y2] =
false;
699 check_row[y1] =
false;
708 StringVector::iterator r2nd = row.begin(); ++r2nd;
709 StringVector::iterator c2nd = col.begin(); ++c2nd;
722 const SaiMatrixTranslator *matrix =
DOWNCAST(SaiMatrixTranslator*, &*saiOp);
733 const int MSIZE = 255*255;
737 char *
buffer = ARB_alloc<char>(2*(MSIZE+1));
741 char *in2 = buffer+(MSIZE+1);
743 for (
int y = 0;
y<255; ++
y) {
744 for (
int x = 0; x<255; ++x) {
775 for (
size_t r = 1; r<row.size(); ++r) {
780 for (
size_t c = 1; c<col.size(); ++c) {
786 char globalDefault = 0;
788 for (
size_t c = 0; c<col.size(); ++c) {
791 char defaultOfColumn = 0;
793 for (
size_t r = 0; r<row.size(); ++r) {
798 to[0] = out[y*255+x];
800 if (to[0] != globalDefault && to[0] != defaultOfColumn) {
807 defaultOfColumn = to[0];
808 if (c == 0) globalDefault = to[0];
829 SaiMatrixTranslator matrixTranslator(columnTranslator);
833 if (from && from[0]) {
835 if (columnTranslator.
isSet()) {
836 matrixTranslator.addOperator(from, columnTranslator);
842 string cfg = matrixTranslator.get_config();
893 vector<string> ruleString;
894 ruleString.reserve(ruleCount);
897 for (
size_t r = 0; r<ruleCount; ++r) {
899 ruleArray.
put(ruleString.back().c_str());
928 for (
size_t r = 0; r<ruleArray.
size() && !
error; ++r) {
957 if (selRule && selRule[0]) {
970 const char *trueChars =
"";
971 const char *falseChars =
"";
1004 if (saiOp.
isSet()) {
1033 const char *currCfg =
NULp;
1052 if (awar_specific_cfg) {
1053 awar_cfg->
map(awar_specific_cfg);
1054 awar_specific_cfg->
touch();
1067 if (saiOp.isSet()) {
1072 SaiCalculator calculator(gb_main, inputSaiName, *saiOp, targetSaiName, scope);
1142 AW_window_simple *aws =
new AW_window_simple;
1147 aws->init(awr,
"SAI_CALC",
"SAI calculator");
1148 aws->load_xfig(
"saicalc.fig");
1150 aws->button_length(8);
1154 aws->create_button(
"CLOSE",
"CLOSE",
"O");
1158 aws->create_button(
"HELP",
"HELP");
1162 SmartCharPtr source_sai_list = awar_source_sai->
read_string();
1170 aws->at(
"overwrite");
1172 aws->create_button(
"OVERWRITE",
"Overwrite");
1176 aws->insert_default_option(
"Selected alignment",
"S",
SAS_SELECTED);
1177 aws->insert_option (
"Existing alignments",
"E",
SAS_ALL);
1178 aws->insert_option (
"Common alignments",
"C",
SAS_COMMON);
1179 aws->insert_option (
"Target alignments",
"C",
SAS_TARGET);
1180 aws->update_option_menu();
1191 aws->update_option_menu();
1195 aws->create_button(
"EDIT",
"EDIT");
1200 aws->create_autosize_button(
"CALC",
"Calculate");
static void boolchain_rulesAwar_changed_cb(AW_root *awr)
vector< string > StringVector
static const char * type_name(SaiOperatorType type)
#define SAI_OPERATOR_TYPES
AW_DB_selection * awt_create_SAI_selection_list(GBDATA *gb_main, AW_window *aws, const char *varname, const SaiSelectionlistFilterCallback &fcb)
void put(const char *elem)
#define implicated(hypothesis, conclusion)
void select_element_at(int wanted_index)
static bool in_boolchain_awar_callback
void load_xfig(const char *file, bool resize=true)
void insert_default(const char *displayed, const AW_scalar &value)
static void SAI_init_calculator_awars(AW_root *awr)
static void normalize_matrix_cb(AW_window *aww)
static SaiOperatorPtr createOpFromConfigAwar(SaiOperatorType type, AW_awar *awar_config)
static void refill_boolrules_sellist(const ConstStrArray &ruleArray)
static SaiOperatorPtr buildColumnTranslatorFromAwars(int x, bool returnDefault)
AW_selection * awt_create_subset_selection_list(AW_window *aww, AW_selection_list *parent_selection, const char *at_box, const char *at_add, const char *at_sort, bool autocorrect_subselection, SubsetChangedCb subChanged_cb, AW_CL cl_user)
static bool in_translate_awar_callback
static void translate_gui_changed_cb(AW_root *awr, bool, int)
#define AWAR_SC_TARGET_SAI
static AWT_predefined_config saicalc_predefined_configs[]
vector< string > StringVector
void AWT_insert_config_manager(AW_window *aww, AW_default default_file_, const char *id, const StoreConfigCallback &store_cb, const RestoreConfigCallback &load_or_reset_cb, const char *macro_id, const AWT_predefined_config *predef)
bool operator()(const string &s1, const string &s2) const
#define AWAR_SC_TRANSLATE_DEFAULT
#define AWAR_SC_SOURCE_SAI_LIST
const char * GBS_global_string(const char *templat,...)
#define AWAR_SC_BOOL_SEL_RULE
const char * firstChar(const char *s)
static void translate_config_changed_cb(AW_root *awr)
static void fill_boolrules_array_from_AWAR(AW_root *awr, ConstStrArray &ruleArray)
char * GBS_string_eval(const char *insource, const char *icommand)
void AW_POPDOWN(AW_window *window)
static void use_selected_as_target_cb(AW_window *aww)
static void saicalc_edit_method_cb(AW_root *awr, bool forcePopup)
char getOutTrans(bool i) const
int get_index_of_selected()
static void matrix_gui_changed_cb(AW_root *awr, int, int)
static WindowCallback reuse(const RootCallback &rcb)
void set_memblock(char *block)
void get_values(StrArray &intoArray)
static void fill_with_source_sais(ConstStrArray &sainame, AW_root *awr)
#define AWAR_SC_METHOD_CONFIG
#define AWAR_SC_MATRIX_CONFIG
static AW_window * create_aciapp_config_window(AW_root *awr)
void setNull()
set SmartPtr to NULp
char buffer[MESSAGE_BUFFERSIZE]
#define DOWNCAST(totype, expr)
#define AWAR_SC_ACI_CONFIG
void SAI_popup_calculator_window(AW_window *awp, GBDATA *gb_main)
AW_awar * add_callback(const RootCallback &cb)
void insert(const char *displayed, const AW_scalar &value)
const char * read_char_pntr() const
static AW_selection_list * boolrule_sellst
static AW_root * SINGLETON
static const char *const RULELIST_DELIMITER
#define AWAR_SC_BOOL_OUT1
WindowCallback makeHelpCallback(const char *helpfile)
const char * awarname(const char *awarname_template, int idx)
bool isSet() const
test if SmartPtr is not NULp
void get_entries(class ConstStrArray &to_array)
static ErrorOrSaiOperatorPtr make(SaiOperatorType type, const char *config)
static void detectEqualRowsAndColumns(const string &out, StringVector &row, StringVector &col)
static void matrix_config_changed_cb(AW_root *awr)
bool operator()(const string &s1, const string &s2) const
static AW_window * create_matrix_config_window(AW_root *awr)
ARB_ERROR getError() const
static const char * awar_translate(bool in, int num)
static void error(const char *msg)
#define AWAR_SC_MATRIX_CELL_TEMPL
const SaiBoolRule & getRule(size_t idx) const
#define AWAR_SC_BOOL_RULES
static AW_window * create_translator_config_window(AW_root *awr)
std::string get_config() const OVERRIDE
size_t count_rules() const
static void mod_boolrule_cb(AW_window *aww)
static const char * content_matrix_cell(int x, int y)
GB_ERROR reset_to_default()
static AW_window * create_boolchain_config_window(AW_root *awr)
static void del_boolrule_cb(AW_window *aww)
char * read_string() const
AW_awar * awar_no_error(const char *awar)
end timer stuff
static void calculate_sai_cb(AW_window *aww, GBDATA *gb_main)
AW_awar * awar(const char *awar)
void awt_set_subset_selection_content(AW_selection *subset_sel_, const CharPtrArray &values)
#define AWAR_SC_BOOL_OUT0
#define AWAR_SC_TRANSLATE_CONFIG
static void source_sai_list_changed_cb(AW_root *awr, AW_selection *sel_sai)
std::string get_config() const OVERRIDE
char * GBT_join_strings(const CharPtrArray &strings, char separator)
static void copy(double **i, double **j)
static void add_boolrule_cb(AW_window *aww)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
static char firstCharOfAwarOrDefault(AW_root *awr, const char *awarname)
const char * get_chars() const
static void update_rulesAwar(AW_root *awr, const CharPtrArray &ruleArray)
static const char * awar_matrix_cell(int x, int y)
static bool in_aci_awar_callback
void addRule(const SaiBoolRule &r)
AW_awar * map(const char *awarn)
#define AWAR_SC_BOOL_CONFIG
std::string to_string() const
static void bool_config_changed_cb(AW_root *awr)
const char * get_entry(const char *entry) const
void aw_message(const char *msg)
static void boolchain_gui_changed_cb(AW_root *awr)
static SaiBoolRulePtr build_rule_from_AWARs(AW_root *awr, bool createFirstRule)
GB_ERROR write_string(const char *aw_string)
static AWT_config_mapping_def saicalc_config_mapping[]
static void inputCharsetChanged_cb(AW_root *awr, bool defTrue)
static void refill_boolrules_sellist_from_AWAR(AW_root *awr)
ARB_ERROR getError() const
#define AWAR_SC_TRANSLATE_IO_TEMPL
bool specifiesTrueChars() const
#define TRANSLATION_RULES
static bool in_matrix_awar_callback
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
static void display_selected_rule_cb(AW_root *awr)
static void calc_method_changed_cb(AW_root *awr)
void GBT_splitNdestroy_string(ConstStrArray &names, char *&namelist, const char *separator, SplitMode mode)
const char * replace(int i, const char *elem)
const std::string get_aci() const
GB_ERROR write_int(long aw_int)
static void sai_seletion_changed_cb(AW_selection *sel_sai, bool, AW_CL)
static void aci_gui_changed_cb(AW_root *awr)
AW_selection_list * get_sellist()
static bool in_boolchain_inputCharset_awar_callback
void aw_message_if(GB_ERROR error)
char * GBS_global_string_copy(const char *templat,...)
static ErrorOrSaiBoolRulePtr make(const char *fromString)
static void aci_config_changed_cb(AW_root *awr)