38 "Primer (local)",
"Primer (region)",
"Primer (global)",
39 "Signature (local)",
"Signature (region)",
"Signature (global)",
98 aw_message(
"Search for complement is not supported for this alignment type (has been disabled)");
132 static int start_offset;
134 static int min_mismatches;
135 static int max_mismatches;
136 static int *uni2real;
153 min_mismatches = minMis;
154 max_mismatches = maxMis;
161 int SearchTreeNode::start_offset;
163 int SearchTreeNode::min_mismatches;
164 int SearchTreeNode::max_mismatches;
165 int *SearchTreeNode::uni2real;
177 comment = nulldup(pattern_comment);
184 comment = nulldup(pattern_comment);
190 if (brother!=&FOUND)
delete brother;
191 if (son!=&FOUND)
delete son;
201 neu->brother = &FOUND;
225 if (brother!=&FOUND) {
240 int matches = c==
'?' || c==seq[0];
241 int use_mismatch = 0;
243 if (!matches && mismatches<max_mismatches) {
247 if (c_is_gap==seq_is_gap) {
248 mismatch_list[mismatches] = uni2real[off];
257 if (mismatches>=min_mismatches) {
258 report(uni2real[start_offset], uni2real[off], comment, mismatch_list);
262 son->
findMatches(off+1, seq+1, len-1, mismatches, mismatch_list);
267 mismatch_list[mismatches] = -1;
272 if (brother==&FOUND) {
273 if (mismatches>=min_mismatches) {
274 report(uni2real[start_offset], uni2real[off-1], comment, mismatch_list);
278 brother->
findMatches(off, seq, len, mismatches, mismatch_list);
287 unsigned char unified[256];
290 static char unify_char(
char c,
int case_sensitive,
int T_equal_U);
292 char *unify_str(
const char *data,
int len,
ED4_SEARCH_GAPS gaps,
int *new_len,
int **uni2real);
293 char *unify_pattern(
const char *
pattern,
int *new_len);
294 char *unify_sequence(
const char *sequence,
int len,
int *new_len,
int **uni2real);
308 char *end = strchr(s,
'\0');
310 while (end>s && isspace(end[-1])) {
313 while (isspace(s[0])) {
321 char *num = strchr(*tok,
'#');
337 char *
s = ARB_alloc<char>(l1+1+l2+1);
339 sprintf(s,
"%s %s", s1, s2);
349 shortestPattern = INT_MAX;
356 for (i=0; i<256; i++) {
357 unified[i] = unify_char(i, case_sensitive, T_equal_U);
361 #define INSERT_ROOT_PATTERN(tok, com) \
364 root = root->insert_unified_pattern(tok, com); \
367 root = new SearchTreeNode(tok, com); \
374 const char *trenner =
"\n,";
375 char *tok = strtok(pattern, trenner);
379 bool show_T_or_U_error =
false;
384 char *uni_tok = unify_pattern(tok, &uni_tok_len);
391 if (uni_tok_len<shortestPattern) {
392 shortestPattern = uni_tok_len;
395 if (!s_exact || (!s_reverse && !s_complement)) {
400 int commentLen = comment ? strlen(comment) : 0;
405 if (!s_exact || !s_complement) {
406 char *reverseComment =
appendComment(comment, commentLen,
"(reverse)");
409 free(reverseComment);
415 char *revcompComment =
appendComment(comment, commentLen,
"(reverse complement)");
416 char *uni_revcomp = unify_pattern(revcomp,
NULp);
421 free(revcompComment);
425 show_T_or_U_error =
true;
436 if (!s_exact || !s_reverse) {
438 char *complementComment =
appendComment(comment, commentLen,
"(complement)");
439 char *uni_complement = unify_pattern(complement,
NULp);
443 free(uni_complement);
444 free(complementComment);
449 show_T_or_U_error =
true;
455 tok = strtok(
NULp, trenner);
460 if (show_T_or_U_error && T_or_U_error)
aw_message(T_or_U_error);
463 #undef INSERT_ROOT_PATTERN
470 char SearchTree::unify_char(
char c,
int case_sensitive,
int T_equal_U) {
471 if (!case_sensitive) {
491 char *SearchTree::unify_str(
const char *data,
int len,
ED4_SEARCH_GAPS gaps,
int *new_len,
int **uni2real) {
492 char *p = ARB_alloc<char>(len+1);
498 int *u2r = *uni2real;
501 while (realPos<len) {
502 *pp++ = unified[(
unsigned char)data[realPos]];
503 u2r[nlen++] = realPos++;
507 while (realPos<len) {
508 unsigned char c = data[realPos];
512 u2r[nlen++] = realPos;
520 while (realPos<len) {
521 *pp++ = unified[(
unsigned char)data[realPos++]];
526 while (realPos<len) {
527 unsigned char c = data[realPos++];
546 char *SearchTree::unify_pattern(
const char *
pattern,
int *new_len) {
547 int len = strlen(pattern);
551 char *SearchTree::unify_sequence(
const char *sequence,
int len,
int *new_len,
int **uni2real) {
552 return unify_str(sequence, len, sett->
get_seq_gaps(), new_len, uni2real);
558 int *uni2real = ARB_alloc<int>(len);
559 char *uni_seq = unify_sequence(seq, len, &new_len, &uni2real);
562 char *useq = uni_seq;
566 mismatch_list[off] = -1;
572 for (off=0; off<new_len; off++, useq++) {
574 root->
findMatches(off, useq, new_len-off, 0, mismatch_list);
584 #define AWAR_NAME(t, s) ED4_AWAR_##t##_SEARCH_##s
586 #define AWAR_LIST(t) \
587 AWAR_NAME(t, PATTERN), \
588 AWAR_NAME(t, MIN_MISMATCHES), \
589 AWAR_NAME(t, MAX_MISMATCHES), \
590 AWAR_NAME(t, CASE), \
592 AWAR_NAME(t, PAT_GAPS), \
593 AWAR_NAME(t, SEQ_GAPS), \
594 AWAR_NAME(t, REVERSE), \
595 AWAR_NAME(t, COMPLEMENT), \
596 AWAR_NAME(t, EXACT), \
597 AWAR_NAME(t, SHOW), \
598 AWAR_NAME(t, OPEN_FOLDED), \
599 AWAR_NAME(t, AUTO_JUMP)
653 if (!settings[type])
return;
665 if (patLen < 3*maxMis) {
670 root->
awar(awar_list[type].max_mismatches)->
write_int(maxMaxMis);
684 if (settings[type]->get_autoJump() && (action &
DO_AUTO_JUMP)) {
709 if (
abs(pos-next_pos)<
abs(pos-bestPos)) {
716 if (bestPos == pos) {
736 #define cb(action) add_callback(makeRootCallback(searchParamsChanged, ED4_SearchPositionType(i), search_params_changed_action(action)));
773 char *ED4_SearchPosition::lastShownComment =
NULp;
781 comment = found_comment;
782 memcpy(mismatch, mismatches,
sizeof(*mismatch)*MAX_MISMATCHES);
785 start_pos = other.start_pos;
786 end_pos = other.end_pos;
787 whatsFound = other.whatsFound;
790 memcpy(mismatch, other.mismatch,
sizeof(mismatch[0])*
MAX_MISMATCHES);
799 if (toAdd->cmp(*
self)<=0) {
801 if (last) last->next = toAdd;
821 if (self->whatsFound == typeToRemove) {
824 *ptrToMe =
self->next;
838 #ifdef TEST_SEARCH_POSITION
839 int ED4_SearchPosition::ok()
const {
845 printf(
"ED4_SearchPosition: list not sorted\n");
857 if (!comment)
return NULp;
858 if (lastShownComment && strcmp(lastShownComment, comment)==0)
return NULp;
860 delete lastShownComment;
862 return lastShownComment;
869 if (self->start_pos > pos)
break;
870 if (self->containsPos(pos))
return self;
878 int ED4_SearchResults::initialized = 0;
882 int ED4_SearchResults::bufferSize;
883 char *ED4_SearchResults::buffer;
890 timeOfLastSearch[i] = 0;
891 timeOfNextSearch[i] = 1;
933 first = first->
insert(pos);
934 #ifdef TEST_SEARCH_POSITION
949 if (timeOf[i]<timeOfNextSearch[i]) {
950 timeOf[i] = timeOfNextSearch[i];
951 timeOfLastSearch[i] = timeOfNextSearch[i];
959 #if defined TEST_SEARCH_POSITION
974 reportToResult =
this;
984 reportToResult =
NULp;
1030 pos = array[best_m];
1087 int next_unused_stamp = timeOfLastSearch[
type] + 1;
1090 if (timeOfNextSearch[type]!=next_unused_stamp) {
1091 timeOfNextSearch[
type] = next_unused_stamp;
1125 int needed_size = end-start+1;
1126 if (needed_size>bufferSize) {
1128 bufferSize = needed_size;
1132 memset(
buffer, 0,
sizeof(
char)*needed_size);
1140 int correct_neg_values = 0;
1150 for (i=s; i<=e; i++) {
1158 for (i=0; i<5 && mismatches[i]>=0; i++) {
1159 int mpos = mismatches[i];
1161 if (mpos>=start && mpos<=end) {
1162 int rpos = mpos-
start;
1163 if (
buffer[rpos]==color) {
1165 correct_neg_values = 1;
1173 if (correct_neg_values) {
1174 for (i=end-start; i>=0; i--) {
1201 if (!best || type<best->get_whatsFound()) {
1211 void ED4_SearchResults::to_array() {
1217 int a_arraySize = 0;
1223 arraySize = a_arraySize;
1229 for (
int e=0; e<arraySize; e++) {
1238 void ED4_SearchResults::to_list() {
1249 *direction = descriptor&1 ? 1 : -1;
1256 if (last_searchDescriptor==-1) {
1257 return GBS_global_string(
"You have to search first, before you can repeat a search.");
1267 last_searchDescriptor = searchDescriptor;
1297 int start_pos = pos;
1307 results.
search(seq_terminal);
1318 if (terminal==start_terminal && pos==start_pos) {
1319 if (searchOnlyForShownPatterns) {
1320 aw_message(
"There are no other shown patterns");
1323 aw_message(
"This is the only occurrence of the search pattern");
1331 else if (last_loop) {
1332 if (searchOnlyForShownPatterns) {
1336 aw_message(
"Search pattern was not found in any sequence");
1354 if (terminal==start_terminal) {
1369 results.
search(seq_terminal);
1374 if (species_man->is_species_seq_manager()) {
1375 GBDATA *gbd = species_man->get_species_pointer();
1453 FILE *in = fopen(filename,
"rt");
1458 if (
aw_question(
"overwrite_search_params", question,
"Overwrite,Cancel") != 0) {
1459 error =
"Wont overwrite existing file";
1465 FILE *out = fopen(filename,
"wt");
1468 error =
GBS_global_string(
"Can't write file '%s' (%s)", filename, strerror(errno));
1516 FILE *in = fopen(filename,
"rt");
1527 if (!fgets(buffer, BUFFERSIZE, in))
break;
1529 char *content = strchr(buffer,
'=');
1536 if (strcmp(buffer,
"pattern")==0) {
1541 int value = atoi(content);
1546 else if (strcmp(buffer,
"tu")==0) root->
awar(al->
tu)->
write_int(value);
1575 aws->init(root, window_id, window_title);
1578 free(window_id_src);
1593 AW_window_simple *aws =
new AW_window_simple;
1596 aws_init_localized(root, aws,
"load_%s_search_para_%i",
"Load %s Search Parameters", ED4_SearchPositionTypeId[param->
type], param->
winNum);
1599 aws_init_localized(root, aws,
"save_%s_search_para_%i",
"Save %s Search Parameters", ED4_SearchPositionTypeId[param->
type], param->
winNum);
1602 aws->load_xfig(
"edit4/save_search.fig");
1606 aws->create_button(
"CLOSE",
"CLOSE",
"C");
1610 aws->create_button(
"HELP",
"HELP",
"H");
1616 aws->create_button(
"CANCEL",
"CANCEL",
"C");
1621 aws->create_button(
"LOAD",
"LOAD",
"L");
1625 aws->create_button(
"SAVE",
"SAVE",
"S");
1634 cdef.
add(awarList->
show,
"show");
1642 cdef.
add(awarList->
tu,
"tu");
1646 cdef.
add(awarList->
exact,
"exact");
1660 static search_window_map swm;
1662 search_window_map::iterator sw4win = swm.find(ed4w);
1674 aws->load_xfig(
"edit4/search.fig");
1678 aws->create_button(
"CLOSE",
"CLOSE",
"C");
1682 aws->create_button(
"HELP",
"HELP",
"H");
1688 aws->create_button(
"LOAD",
"LOAD",
"L");
1692 aws->create_button(
"SAVE",
"SAVE",
"S");
1696 aws->create_button(
"SEARCH_NEXT",
"#edit/next.xpm",
"N");
1698 aws->at(
"previous");
1700 aws->create_button(
"SEARCH_LAST",
"#edit/last.xpm",
"L");
1704 aws->create_autosize_button(
"MARK_SPECIES",
"Mark species with matches",
"M");
1707 aws->create_toggle(awarList->
show);
1713 aws->create_toggle(awarList->
autoJump);
1716 aws->create_text_field(awarList->
pattern, 28, 17);
1720 aws->insert_default_toggle(
"0",
"0", 0);
1721 aws->insert_toggle(
"1",
"1", 1);
1722 aws->insert_toggle(
"2",
"2", 2);
1723 aws->update_toggle_field();
1727 aws->insert_default_toggle(
"0",
"0", 0);
1728 aws->insert_toggle(
"1",
"1", 1);
1729 aws->insert_toggle(
"2",
"2", 2);
1730 aws->insert_toggle(
"3",
"3", 3);
1731 aws->insert_toggle(
"4",
"4", 4);
1732 aws->insert_toggle(
"5",
"5", 5);
1733 aws->update_toggle_field();
1735 aws->at(
"seq_gaps");
1736 aws->create_toggle(awarList->
seq_gaps);
1737 aws->at(
"pat_gaps");
1738 aws->create_toggle(awarList->
pat_gaps);
1740 aws->create_toggle(awarList->
tu);
1744 aws->create_toggle(awarList->
reverse);
1745 aws->at(
"complement");
1748 aws->create_toggle(awarList->
exact);
static void set_mismatches(int minMis, int maxMis)
static void str2pattern(char *s)
static char * appendComment(const char *s1, int l1, const char *s2)
ED4_SEARCH_CASE get_case_sensitive() const
static void set_report(reportMatch r, int *u2r)
ED4_SEARCH_GAPS get_pat_gaps() const
void add(const char *awar_name, const char *config_name)
GB_CSTR GB_path_in_arbprop(const char *relative_path)
ED4_SearchPosition * get_next() const
ED4_SEARCH_GAPS get_seq_gaps() const
std::map< ED4_window *, SmartPtr< search_windows > > search_window_map
ED4_terminal * get_first_terminal(int start_index=0) const
static void setNewSearch(ED4_SearchPositionType type)
static char * pattern2str(GB_CSTR p)
AW_window_simple * windows[SEARCH_PATTERNS]
ED4_group_manager * is_in_folded_group() const
ED4_SearchResults & results() const
char * GBT_complementNucSequence(const char *s, int len, char T_or_U)
GB_CSTR get_comment() const
ED4_SearchPosition * get_first_at(ED4_SearchPositionType type, int start, int end) const
const char * case_sensitive
void AW_create_standard_fileselection(AW_window *aws, const char *awar_prefix)
void ED4_create_search_awars(AW_root *root)
void ED4_search_cb(UNFIXED, int searchDescriptor, ED4_window *ed4w)
int get_open_folded() const
char * ARB_strdup(const char *str)
char * GBT_reverseNucSequence(const char *s, int len)
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)
static ED4_SearchResults * reportToResult
SearchSettings(SearchAwarList *awarList)
const int * getMismatches() const
const char * GBS_global_string(const char *templat,...)
void AW_POPDOWN(AW_window *window)
char * GBS_string_2_key(const char *str)
ED4_terminal * owner_of_cursor
static void load_search_paras_from_file(AW_window *aw, ED4_SearchPositionType type)
char buffer[MESSAGE_BUFFERSIZE]
struct Unfixed_cb_parameter * UNFIXED
static HelixNrInfo * start
void ED4_popup_search_window(AW_window *aww, ED4_SearchPositionType type)
const char * max_mismatches
static int resultsAreShown(ED4_SearchPositionType type)
WindowCallback makeHelpCallback(const char *helpfile)
int containsPos(int pos) const
ED4_SearchPosition * get_first() const
static AW_window * loadsave_search_parameters(AW_root *root, const LoadSaveSearchParam *param, bool load)
ED4_SearchPosition * insert(ED4_SearchPosition *toAdd)
static void searchParamsChanged(AW_root *root, ED4_SearchPositionType type, search_params_changed_action action)
GBDATA * get_gb_main() const
static SearchSettings * settings[SEARCH_PATTERNS]
ED4_terminal * get_last_terminal(int start_index=-1) const
ED4_SearchPosition(int sp, int ep, ED4_SearchPositionType wf, GB_CSTR found_comment, int mismatches[MAX_MISMATCHES])
GB_BUFFER GB_give_buffer(size_t size)
#define ED4_AWAR_SEARCH_RESULT_CHANGED
ED4_SearchPositionType get_whatsFound() const
static void save_search_paras_to_file(AW_window *aw, ED4_SearchPositionType type)
ED4_window * first_window
ED4_SearchPosition * get_first_starting_after(ED4_SearchPositionType type, int pos, int mustBeShown) const
ED4_terminal * get_next_terminal()
SearchTreeNode * insert_unified_pattern(GB_CSTR pattern, GB_CSTR pattern_comment)
static void error(const char *msg)
int get_complement() const
void AW_create_fileselection_awars(AW_root *awr, const char *awar_base, const char *directories, const char *filter, const char *file_name)
char * buildColorString(const ED4_sequence_terminal *seq_terminal, int start, int end)
ED4_root_group_manager * root_group_man
void addSearchPosition(ED4_SearchPosition *pos)
ED4_SEARCH_TU get_tu() const
int get_start_pos() const
GB_CSTR get_pattern() const
GB_ERROR ED4_repeat_last_search(ED4_window *ed4w)
static int last_searchDescriptor
char * read_string() const
int get_max_mismatches() const
void search(const ED4_sequence_terminal *seq_terminal)
AW_awar * awar(const char *awar)
static void set_start_offset(int off)
SearchTree(const SearchSettings *s)
GB_alignment_type alignment_type
bool setCursorTo(ED4_cursor *cursor, int seq_pos, bool unfoldGroups, ED4_CursorJumpType jump_type)
ED4_SearchPositionType type
static ED4_SearchPositionType reportType
ED4_window * get_ed4w() const
int aw_question(const char *unique_id, const char *question, const char *buttons, bool sameSizeButtons, const char *helpfile)
ED4_cursor & current_cursor()
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 void aws_init_localized(AW_root *root, AW_window_simple *aws, GB_CSTR id_format, GB_CSTR title_format, GB_CSTR typeId, int winNum)
void GB_write_flag(GBDATA *gbd, long flag)
ED4_SearchPosition * get_shown_at(int pos) const
int ED4_encodeSearchDescriptor(int direction, ED4_SearchPositionType pattern)
void findMatches(int off, GB_CSTR seq, int len, int mismatches, int mismatch_list[MAX_MISMATCHES])
ED4_window * current_ed4w()
static void setup_search_config(AWT_config_definition &cdef, ED4_SearchPositionType search_type)
static void ED4_mark_matching_species(AW_window *, ED4_SearchPositionType pattern)
bool ED4_is_gap_character(char chr)
void aw_message(const char *msg)
ED4_SearchPosition * get_last_starting_before(ED4_SearchPositionType type, int pos, int mustBeShown) const
static int pattern[maxsites+1]
#define ED4_SEARCH_SAVE_BASE
void request_refresh_for_sequence_terminals()
#define INSERT_ROOT_PATTERN(tok, com)
static void splitTokComment(char **tok, char **commentP)
GB_ERROR write_string(const char *aw_string)
int is_sequence_terminal() const
static void reportSearchPosition(int start, int end, GB_CSTR comment, int mismatches[MAX_MISMATCHES])
int get_min_mismatches() const
char * resolve_pointer_to_string_copy(int *str_len=NULp) const FINAL_OVERRIDE
int get_sequence_pos() const
static char * shortenString(char *s)
GB_transaction ta(gb_var)
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
void(* reportMatch)(int start, int end, GB_CSTR comment, int mismatches[MAX_MISMATCHES])
search_params_changed_action
ED4_terminal * get_prev_terminal()
void update(SearchAwarList *awarList)
ED4_manager * get_parent(ED4_level lev) const
ED4_SearchPosition * remove(ED4_SearchPositionType typeToRemove)
ED4_SearchPosition * get_next_at(int pos) const
LoadSaveSearchParam(ED4_SearchPositionType type_, int winNum_)
GB_ERROR write_int(long aw_int)
const char * ED4_SearchPositionTypeId[SEARCH_PATTERNS+1]
int get_shortestPattern() const
SearchTreeNode(GB_CSTR pattern, GB_CSTR comment)
void findMatches(const char *seq, int len, reportMatch report)
char * GBS_global_string_copy(const char *templat,...)
void decodeSearchDescriptor(int descriptor, int *direction, ED4_SearchPositionType *pattern)
NOT4PERL GB_ERROR GBT_determine_T_or_U(GB_alignment_type alignment_type, char *T_or_U, const char *supposed_target)
static struct SearchAwarList awar_list[SEARCH_PATTERNS]
const char * min_mismatches
GB_write_int const char s