28 memset ((
char *)
this, 0,
sizeof(
PH_filter));
33 filter =
new char[size];
34 real_len = filter_len = size;
35 for (
int i = 0; i < size; i++) {
47 for (
int i = 0; s[i]; ++i) {
53 long i, j,
max, num_all_chars;
55 char delete_when_max[100], get_maximum_from[100], all_chars[100], max_char;
56 long reference_table[256], **chars_counted;
57 char real_chars[100], low_chars[100];
58 char rest_chars[40], upper_rest_chars[20], low_rest_chars[20];
59 unsigned char *sequence_buffer;
77 strcpy(real_chars,
"ACGTU");
78 strcpy(upper_rest_chars,
"MRWSYKVHDBXN");
81 strcpy(real_chars,
"ABCDEFGHIKLMNPQRSTVWYZ");
82 strcpy(upper_rest_chars,
"X");
86 strcpy(low_chars, real_chars);
strlwr(low_chars);
88 strcpy(low_rest_chars, upper_rest_chars);
90 strcpy(rest_chars, upper_rest_chars);
91 strcat(rest_chars, low_rest_chars);
94 strcpy(all_chars, real_chars);
95 strcat(all_chars, low_chars);
96 strcat(all_chars, rest_chars);
98 strcpy(get_maximum_from, real_chars);
99 strcat(all_chars,
".-");
101 num_all_chars = strlen(all_chars);
116 delete_when_max[0] =
'\0';
118 long len = stopcol - startcol;
125 for (i=0; i<len; i++) {
126 ARB_calloc(chars_counted[i], num_all_chars+2);
127 for (j=0; j<num_all_chars+2; j++) chars_counted[i][j] = 0;
131 for (i=0; i<256; i++) {
133 reference_table[i] = num_all_chars;
137 for (i=0; i<num_all_chars; i++) {
138 mask[(
unsigned char)all_chars[i]] =
true;
139 reference_table[(
unsigned char)all_chars[i]] = i;
144 reference_table[(
unsigned char)
'U'] = reference_table[(
unsigned char)
'T'];
145 reference_table[(
unsigned char)
'u'] = reference_table[(
unsigned char)
't'];
146 reference_table[(
unsigned char)
'N'] = reference_table[(
unsigned char)
'X'];
147 reference_table[(
unsigned char)
'n'] = reference_table[(
unsigned char)
'x'];
152 switch (filter_dot) {
154 mask[(
unsigned char)
'.'] =
false;
158 strcat(delete_when_max,
".");
159 strcat(get_maximum_from,
".");
163 reference_table[(
unsigned char)
'.']=num_all_chars;
176 switch (filter_minus) {
178 mask[(
unsigned char)
'-'] =
false;
182 strcat(delete_when_max,
"-");
183 strcat(get_maximum_from,
"-");
187 reference_table[(
unsigned char)
'-']=num_all_chars;
200 bool mapRestToX =
false;
201 switch (filter_ambig) {
203 for (i=0; rest_chars[i]; i++) mask[(
unsigned char)rest_chars[i]] =
false;
207 strcat(delete_when_max,
"X");
208 strcat(get_maximum_from,
"X");
213 reference_table[(
unsigned char)
'X'] = num_all_chars;
223 strcat(get_maximum_from, upper_rest_chars);
233 for (i=0; rest_chars[i]; i++) {
234 reference_table[(
unsigned char)rest_chars[i]] = reference_table[(
unsigned char)
'X'];
238 switch (filter_lower) {
240 for (i=0; low_chars[i]; i++) mask[(
unsigned char)low_chars[i]] =
false;
245 for (i=0; low_chars[i]; i++) reference_table[(
unsigned char)low_chars[i]] = reference_table[(
unsigned char)
'a'];
246 strcat(delete_when_max,
"a");
247 strcat(get_maximum_from,
"a");
251 for (i=0; low_chars[i]; i++) reference_table[(
unsigned char)low_chars[i]] = num_all_chars;
260 for (i=0; low_chars[i]; i++) reference_table[(
unsigned char)low_chars[i]] = reference_table[toupper(low_chars[i])];
261 for (i=0; low_rest_chars[i]; i++) reference_table[(
unsigned char)low_rest_chars[i]] = reference_table[toupper(low_rest_chars[i])];
276 if (slen< send) send = slen;
277 for (j=startcol; j<send; j++) {
278 if (mask[sequence_buffer[j]]) {
279 chars_counted[j-startcol][reference_table[sequence_buffer[j]]]++;
282 chars_counted[j-startcol][num_all_chars+1]++;
291 for (i=0; i<len && !
error; i++) {
292 if (chars_counted[i][num_all_chars]==0) {
294 for (j=0; get_maximum_from[j]!=
'\0'; j++) {
295 if (max<chars_counted[i][reference_table[(
unsigned char)get_maximum_from[j]]]) {
296 max_char = get_maximum_from[j];
297 max = chars_counted[i][reference_table[(
unsigned char)max_char]];
300 if ((max!=0) && !strchr(delete_when_max, max_char)) {
302 for (j=0; delete_when_max[j]!=
'\0'; j++) {
303 chars_counted[i][num_all_chars+1] += chars_counted[i][reference_table[(
unsigned char)delete_when_max[j]]];
304 chars_counted[i][reference_table[(
unsigned char)delete_when_max[j]]]=0;
306 mline[i+startcol] = (max/
308 (
float) chars_counted[i][num_all_chars+1]))*100.0;
316 for (i=0; i<len; i++) {
317 free(chars_counted[i]);
324 filt[i] = minhom<=mline[i] && maxhom>=mline[i] ?
'1' :
'0';
350 int startcol = awar_startcol->
read_int();
351 int stopcol = awar_stopcol->
read_int();
353 if (startcol>stopcol) {
354 if (start_changed) awar_stopcol ->
write_int(startcol);
362 int minhom = awar_minhom->
read_int();
363 int maxhom = awar_maxhom->
read_int();
366 if (min_changed) awar_maxhom->
write_int(minhom);
417 AW_window_simple *aws =
new AW_window_simple;
418 aws->init(aw_root,
"PHYL_FILTER",
"PHYL FILTER");
420 aws->button_length(10);
424 aws->create_button(
"CLOSE",
"CLOSE",
"C");
426 const int SCALERWIDTH = 200;
427 aws->auto_space(5, 5);
441 aws->label_length(20);
443 aws->at(
"point_opts");
450 aws->update_option_menu();
452 aws->at(
"minus_opts");
455 aws->insert_option(
filter_text[DONT_COUNT],
"0", DONT_COUNT);
456 aws->insert_option(
filter_text[SKIP_COLUMN_IF_MAX],
"0", SKIP_COLUMN_IF_MAX);
457 aws->insert_option(
filter_text[SKIP_COLUMN_IF_OCCUR],
"0", SKIP_COLUMN_IF_OCCUR);
458 aws->insert_option(
filter_text[COUNT_DONT_USE_MAX],
"0", COUNT_DONT_USE_MAX);
459 aws->update_option_menu();
461 aws->at(
"rest_opts");
462 aws->label(
"ambiguity codes");
464 aws->insert_option(
filter_text[DONT_COUNT],
"0", DONT_COUNT);
465 aws->insert_option(
filter_text[SKIP_COLUMN_IF_MAX],
"0", SKIP_COLUMN_IF_MAX);
466 aws->insert_option(
filter_text[SKIP_COLUMN_IF_OCCUR],
"0", SKIP_COLUMN_IF_OCCUR);
467 aws->insert_option(
filter_text[COUNT_DONT_USE_MAX],
"0", COUNT_DONT_USE_MAX);
469 aws->update_option_menu();
471 aws->at(
"lower_opts");
472 aws->label(
"lowercase chars");
474 aws->insert_option(
filter_text[DONT_COUNT],
"0", DONT_COUNT);
475 aws->insert_option(
filter_text[SKIP_COLUMN_IF_MAX],
"0", SKIP_COLUMN_IF_MAX);
476 aws->insert_option(
filter_text[SKIP_COLUMN_IF_OCCUR],
"0", SKIP_COLUMN_IF_OCCUR);
477 aws->insert_option(
filter_text[COUNT_DONT_USE_MAX],
"0", COUNT_DONT_USE_MAX);
479 aws->update_option_menu();
485 aws->label(
"Auto recalculate?");
const char * filter_text[]
#define AWAR_PHYLO_FILTER_STARTCOL
#define AWAR_PHYLO_FILTER_AMBIG
AW_window * phylo_main_window
void load_xfig(const char *file, bool resize=true)
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)
AW_window * PH_create_filter_window(AW_root *aw_root)
AW_awar * set_minmax(float min, float max)
static void correct_minmaxhom_cb(AW_root *aw_root, bool min_changed)
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
void AW_POPDOWN(AW_window *window)
bool GBT_is_alignment_protein(GBDATA *gb_main, const char *alignment_name)
#define AWAR_PHYLO_FILTER_DOT
AW_awar * add_callback(const RootCallback &cb)
static void correct_startstop_cb(AW_root *aw_root, bool start_changed)
size_t GB_read_string_count(GBDATA *gbd)
GB_ERROR GB_await_error()
#define AWAR_PHYLO_FILTER_STOPCOL
#define AWAR_PHYLO_FILTER_LOWER
static PH_used_windows * windowList
float * calculate_column_homology()
static void error(const char *msg)
static void update_on_config_change_cb(AW_root *aw_root)
void PH_create_filter_variables(AW_root *aw_root, AW_default default_file, GBDATA *gb_main)
#define AWAR_PHYLO_FILTER_MAXHOM
AW_awar * awar(const char *awar)
#define AWAR_PHYLO_FILTER_MINHOM
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)
#define AWAR_PHYLO_FILTER_MINUS
static AWT_config_mapping_def phyl_filter_config_mapping[]
#define AWAR_PHYLO_FILTER_AUTOCALC
GB_ERROR write_string(const char *aw_string)
char * GBT_get_default_alignment(GBDATA *gb_main)
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
GBDATA * get_gb_main(DbSel db)
#define AWAR_PHYLO_FILTER_FILTER
GB_ERROR write_int(long aw_int)
void inc_and_check_user_abort(GB_ERROR &error)
void aw_message_if(GB_ERROR error)
GB_write_int const char s