38 columnBlockUsed(
false)
44 void autocorrect_type();
62 res = get_colblock_range();
87 SeqPart(
const char *seq_,
int offset_,
int len_)
98 char gap = to_gap(seq[offset]);
99 if (!gap && offset) gap = to_gap(seq[offset-1]);
104 char gap = to_gap(seq[offset+len-1]);
105 if (!gap) gap = to_gap(seq[offset+len]);
116 if (colStatTerm) colStatTerm->request_refresh();
122 ED4_species_name_terminal *name_term = listElem->
elem()->object;
128 listElem = listElem->
next();
139 columnBlockUsed =
true;
151 if (columnBlockUsed) {
155 aw_message(
"No columnblock marked so far - I can't guess the column range");
205 char *new_seq = block_operator.
operate(
SeqPart(seq, 0, len), new_len);
210 memcpy(seq, new_seq, new_len);
213 for (l=new_len; l<len; l++) {
218 else if (new_len>len) {
219 for (
int l=new_len-1; l>=len; l--) {
221 error =
"Result of block-operation to large (not enough gaps at end of sequence data)";
227 memcpy(seq, new_seq, len);
231 memcpy(seq, new_seq, len);
257 int len_part = range.
size();
258 char *seq_part = seq+range.start();
260 char *new_seq_part = block_operator.
operate(
SeqPart(seq, range.start(), len_part), new_len);
264 if (new_len<len_part) {
265 memcpy(seq_part, new_seq_part, new_len);
267 if (seq_part[len_part-1] ==
'.' || seq_part[len_part] ==
'.') gap =
'.';
269 for (
int l=new_len; l<len_part; l++) {
273 else if (new_len>len_part) {
274 for (
int l=new_len-1; l>=len_part; l--) {
276 error =
"Result of block-operation to large (not enough gaps at end of marked columnblock)";
282 memcpy(seq_part, new_seq_part, len_part);
286 memcpy(seq_part, new_seq_part, len_part);
306 typedef map<ED4_window*, int> CursorPositions;
307 CursorPositions at_base;
317 aw_message(
"No block marked -- use right mouse button");
324 while (listElem && !error) {
325 ED4_species_name_terminal *nameTerm = listElem->
elem()->object;
332 listElem = listElem->
next();
337 error =
"Illegal blocktype";
348 for (CursorPositions::iterator ab = at_base.begin(); ab != at_base.end(); ++ab) {
408 if (seq_term==last_term1) {
411 if (seq_term==last_term2) {
416 ED4_species_manager *species_man = name_term->containing_species_manager();
417 if (species_man->is_highlighted()) {
423 if (!species_man->is_consensus_manager()) {
439 if (species_man->is_highlighted() && !species_man->is_consensus_manager()) {
443 if (term==last_term2)
break;
450 while (term && term!=term1) {
453 if (species_man->is_highlighted() && !species_man->is_consensus_manager()) {
488 switch (event->
type) {
520 AW_pos min_term_y = LONG_MAX;
521 AW_pos max_term_y = LONG_MIN;
522 ED4_species_name_terminal *min_term =
NULp;
523 ED4_species_name_terminal *max_term =
NULp;
527 ED4_species_name_terminal *name_term = listElem->elem()->object;
528 name_term->calc_world_coords(&xpos, &ypos);
530 if (ypos<min_term_y) {
532 min_term = name_term;
534 if (ypos>max_term_y) {
536 max_term = name_term;
539 listElem = listElem->next();
543 ED4_species_name_terminal *fix_name_term;
544 if (fabs(ypos-min_term_y)<fabs(ypos-max_term_y)) {
545 fix_name_term = max_term;
548 fix_name_term = min_term;
551 fix_term = fix_name_term->corresponding_sequence_terminal();
575 if (block_visible_part.
is_empty()) {
576 if (scr_pos>block_screen_range.
end()) {
585 int dist_left =
abs(scr_pos-block_visible_part.
start());
586 int dist_right =
abs(scr_pos-block_visible_part.
end());
588 if (dist_left < dist_right) {
622 for (
int i = 0; i<len && !
cmp; ++i) {
623 cmp =
int(s1[i])-
int(s2[i]);
624 if (cmp && s2[i] ==
'?') cmp = 0;
631 const char *oldString;
632 const char *newString;
639 : oldString(oldString_),
640 newString(newString_)
642 olen = strlen(oldString);
643 nlen = strlen(newString);
648 int len = part.length();
649 int max_o = len-olen;
655 maxlen = (len/olen+1)*nlen;
658 char *new_seq = ARB_alloc<char>(maxlen+1);
663 const char *sequence = part.data();
666 memcpy(new_seq+n, newString, nlen);
672 new_seq[n++] = sequence[o++];
696 AW_window_simple *aws =
new AW_window_simple;
698 aws->init(root,
"REPLACE",
"Search & Replace");
703 aws->create_button(
"CLOSE",
"Close",
"C");
707 aws->create_button(
"HELP",
"Help",
"H");
717 aws->create_button(
"GO",
"Go",
"G");
727 if (new_len == part.
length()) {
728 if (memcmp(result, part.
data(), new_len) == 0) {
739 case_op(
bool to_upper_) : to_upper(to_upper_) {}
742 int len = part.length();
743 const char *
seq = part.data();
744 char *new_seq = ARB_alloc<char>(len+1);
747 for (
int i=0; i<len; i++) new_seq[i] = toupper(seq[i]);
750 for (
int i=0; i<len; i++) new_seq[i] = tolower(seq[i]);
767 complement(complement_),
778 int len = part.length();
798 int len = part.length();
799 const char *
seq = part.data();
800 char *
result = ARB_alloc<char>(len+1);
811 int gapcount = len-n;
814 memmove(result+gapcount, result, n);
815 memset(result, part.left_gap(), gapcount);
818 int leftgaps = gapcount/2;
819 int rightgaps = gapcount-leftgaps;
821 memmove(result+leftgaps, result, n);
822 memset(result, part.left_gap(), leftgaps);
823 memset(result+leftgaps+n, part.right_gap(), rightgaps);
828 memset(result+n, part.right_gap(), gapcount);
844 char *shift_left_sequence(
const SeqPart& part,
int& new_len)
const {
849 error =
"Need a gap at block start for shifting left";
857 memcpy(result, seq+1, len-1);
862 char *shift_right_sequence(
const SeqPart& part,
int& new_len)
const {
868 error =
"Need a gap at block end for shifting right";
875 memcpy(result+1, seq, len-1);
882 shift_op(
int direction_) : direction(direction_) {}
885 char *
result = direction<0
886 ? shift_left_sequence(part, new_len)
887 : shift_right_sequence(part, new_len);
893 switch (operationType) {
918 #define AWAR_MOD_SAI_SCRIPT "modsai/script"
927 error =
"Please select the SAI you like to modify";
930 error =
"Please highlight the range where the SAI shall be modified";
960 int reslen = strlen(result);
961 if (reslen>range.size()) {
962 error =
GBS_global_string(
"Cannot insert modified range (result too long; %i>%i)", reslen, range.size());
965 memcpy(seq+range.start(),
result, reslen);
966 int rest = range.size()-reslen;
967 if (rest>0) memset(seq+range.start()+reslen,
'-', rest);
979 error = ta.
close(error);
988 AW_window_simple *aws =
new AW_window_simple;
989 aws->init(root,
"modsai",
"Modify SAI range");
990 aws->load_xfig(
"edit4/modsai.fig");
994 aws->create_button(
"CLOSE",
"Close",
"C");
998 aws->create_button(
"HELP",
"Help",
"H");
1010 aws->create_button(
"go",
"GO");
1024 int whole_len = strlen(oversized_input);
1025 SeqPart part(oversized_input, 1, whole_len-2);
1032 expectations.
add(part_of_error
1040 return all().ofgroup(expectations);
1043 #define TEST_EXPECT_BLOCKOP_PERFORMS(oversized_input,blockop,expected) TEST_EXPECTATION(blockop_expected_io(blockop, oversized_input, expected, NULp))
1044 #define TEST_EXPECT_BLOCKOP_PERFORMS__BROKEN(oversized_input,blockop,expected) TEST_EXPECTATION__BROKEN(blockop_expected_io(blockop, oversized_input, expected, NULp))
1045 #define TEST_EXPECT_BLOCKOP_ERRORHAS(oversized_input,blockop,expected) TEST_EXPECTATION(blockop_expected_io(blockop, oversized_input, NULp, expected))
1046 #define TEST_EXPECT_BLOCKOP_ERRORHAS__BROKEN(oversized_input,blockop,expected) TEST_EXPECTATION__BROKEN(blockop_expected_io(blockop, oversized_input, NULp, expected))
1048 void TEST_block_operators() {
1054 TEST_EXPECT_BLOCKOP_PERFORMS(
"-A-C--",
replace_op(
"-",
"."),
"A.C.");
1055 TEST_EXPECT_BLOCKOP_PERFORMS(
"-A-C--",
replace_op(
"?",
"."),
"....");
1056 TEST_EXPECT_BLOCKOP_PERFORMS(
"AACAG-",
replace_op(
"AC",
"CA"),
"CAAG");
1057 TEST_EXPECT_BLOCKOP_PERFORMS(
"-ACAG-",
replace_op(
"A?",
"Ax"),
"AxAx");
1059 TEST_EXPECT_BLOCKOP_PERFORMS(
"GACAG-",
replace_op(
"GA",
"AG"),
NULp);
1060 TEST_EXPECT_BLOCKOP_PERFORMS(
"GAGAGA",
replace_op(
"GA",
"AG"),
"AAGG");
1061 TEST_EXPECT_BLOCKOP_PERFORMS(
"GACAGA",
replace_op(
"GA",
"AG"),
NULp);
1062 TEST_EXPECT_BLOCKOP_PERFORMS(
"AGAGAG",
replace_op(
"GA",
"AG"),
"AGAG");
1065 TEST_EXPECT_BLOCKOP_PERFORMS(
"-AcGuT-",
case_op(
true),
"ACGUT");
1066 TEST_EXPECT_BLOCKOP_PERFORMS(
"-AcGuT-",
case_op(
false),
"acgut");
1067 TEST_EXPECT_BLOCKOP_PERFORMS(
"-acgut-",
case_op(
false),
NULp);
1068 TEST_EXPECT_BLOCKOP_PERFORMS(
"-------",
case_op(
false),
NULp);
1080 TEST_EXPECT_BLOCKOP_PERFORMS(
"-AR-DQF-",
revcomp_op(
GB_AT_AA,
true,
false),
"FQD-RA");
1081 TEST_EXPECT_BLOCKOP_ERRORHAS(
"-AR-DQF-",
revcomp_op(
GB_AT_AA,
false,
true),
"complement not available");
1082 TEST_EXPECT_BLOCKOP_ERRORHAS(
"-AR-DQF-",
revcomp_op(
GB_AT_AA,
true,
true),
"reverse-complement not available");
1085 TEST_EXPECT_BLOCKOP_PERFORMS(
"-A-c-G--T-",
unalign_op(-1),
"AcGT----");
1086 TEST_EXPECT_BLOCKOP_PERFORMS(
"-A-c-G-T-T",
unalign_op(-1),
"AcGT----");
1087 TEST_EXPECT_BLOCKOP_PERFORMS(
"-A-c-G--TT",
unalign_op(-1),
"AcGT----");
1088 TEST_EXPECT_BLOCKOP_PERFORMS(
"-A-c-G--T.",
unalign_op(-1),
"AcGT....");
1089 TEST_EXPECT_BLOCKOP_PERFORMS(
"-A-c-G-T.T",
unalign_op(-1),
"AcGT....");
1091 TEST_EXPECT_BLOCKOP_PERFORMS(
"A-Ac-G--T-",
unalign_op(+1),
"----AcGT");
1092 TEST_EXPECT_BLOCKOP_PERFORMS(
"-A-c-G--T-",
unalign_op(+1),
"----AcGT");
1093 TEST_EXPECT_BLOCKOP_PERFORMS(
"A.Ac-G--T-",
unalign_op(+1),
"....AcGT");
1094 TEST_EXPECT_BLOCKOP_PERFORMS(
".A-c-G--T-",
unalign_op(+1),
"....AcGT");
1095 TEST_EXPECT_BLOCKOP_PERFORMS(
"AA-c-G--T-",
unalign_op(+1),
"----AcGT");
1097 TEST_EXPECT_BLOCKOP_PERFORMS(
"AA-c-G--TT",
unalign_op(0),
"--AcGT--");
1098 TEST_EXPECT_BLOCKOP_PERFORMS(
".A-c-G--T-",
unalign_op(0),
"..AcGT--");
1099 TEST_EXPECT_BLOCKOP_PERFORMS(
".A-c-G--T.",
unalign_op(0),
"..AcGT..");
1100 TEST_EXPECT_BLOCKOP_PERFORMS(
"-A-c-G--T.",
unalign_op(0),
"--AcGT..");
1101 TEST_EXPECT_BLOCKOP_PERFORMS(
"-A-c-Gc-T.",
unalign_op(0),
"-AcGcT..");
1105 TEST_EXPECT_BLOCKOP_PERFORMS(
"--AcGcT.",
unalign_op(0),
"AcGcT.");
1112 TEST_EXPECT_BLOCKOP_PERFORMS(
"-A-C--",
shift_op(+1),
"-A-C");
1113 TEST_EXPECT_BLOCKOP_PERFORMS(
".A-C--",
shift_op(+1),
".A-C");
1114 TEST_EXPECT_BLOCKOP_PERFORMS(
"-.AC--",
shift_op(+1),
"..AC");
1116 TEST_EXPECT_BLOCKOP_PERFORMS(
"--A-C-",
shift_op(-1),
"A-C-");
1117 TEST_EXPECT_BLOCKOP_PERFORMS(
"--A-C.",
shift_op(-1),
"A-C.");
1118 TEST_EXPECT_BLOCKOP_PERFORMS(
"--AC..",
shift_op(-1),
"AC..");
1119 TEST_EXPECT_BLOCKOP_PERFORMS(
"------",
shift_op(-1),
NULp);
1121 TEST_EXPECT_BLOCKOP_PERFORMS(
"G-TTAC",
shift_op(-1),
"TTA-");
1123 TEST_EXPECT_BLOCKOP_ERRORHAS(
"GATTAC",
shift_op(-1),
"Need a gap at block");
1124 TEST_EXPECT_BLOCKOP_ERRORHAS(
"GATTAC",
shift_op(+1),
"Need a gap at block");
1127 #endif // UNIT_TESTS
unalign_op(int direction_)
GB_ERROR GB_begin_transaction(GBDATA *gbd)
char * operate(const SeqPart &part, int &new_len) const OVERRIDE
int screen_to_sequence(int screen_pos) const
static GB_ERROR perform_block_operation_on_whole_sequence(const ED4_block_operator&block_operator, ED4_sequence_terminal *term)
#define ED4_AWAR_REP_REPLACE_PATTERN
AW_window * ED4_create_modsai_window(AW_root *root)
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
void load_xfig(const char *file, bool resize=true)
PosRange intersection(PosRange r1, PosRange r2)
GBDATA * get_species_pointer() const
const char * data() const
char * operate(const SeqPart &part, int &new_len) const OVERRIDE
char * operate(const SeqPart &part, int &new_len) const OVERRIDE
char * GBT_complementNucSequence(const char *s, int len, char T_or_U)
ED4_columnStat_terminal * corresponding_columnStat_terminal() const
ExplicitRange clip_screen_range(PosRange screen_range) const
static void ED4_with_whole_block(const ED4_block_operator&block_operator)
void ED4_setBlocktype(ED4_blocktype bt)
char * dont_return_unchanged(char *result, int &new_len, const SeqPart &part)
ED4_returncode get_area_rectangle(AW_screen_area *rect, AW_pos x, AW_pos y)
char * GBT_reverseNucSequence(const char *s, int len)
void GB_end_transaction_show_error(GBDATA *gbd, GB_ERROR error, void(*error_handler)(GB_ERROR))
const char * GBS_global_string(const char *templat,...)
ED4_highlighted_list * highlighted_objects
void AW_POPDOWN(AW_window *window)
ED4_terminal * owner_of_cursor
int get_base_position() const
static void highlight_and_update(ED4_sequence_terminal *term1, ED4_sequence_terminal *term2, ED4_index pos1, ED4_index pos2, int initial_call)
bool in_SAI_terminal() const
virtual char * operate(const SeqPart &part, int &new_len) const =0
void world_to_win_coords(AW_pos *xPtr, AW_pos *yPtr) const
GBDATA * GBT_find_SAI(GBDATA *gb_main, const char *name)
const char * read_char_pntr() const
PosRange get_range_according_to_type()
size_t GB_read_string_count(GBDATA *gbd)
GB_ERROR GB_await_error()
WindowCallback makeHelpCallback(const char *helpfile)
TYPE * ARB_alloc(size_t nelem)
#define is_equal_to_NULL()
void set_type(ED4_blocktype bt)
bool matchesUsingWildcard(GB_CSTR s1, GB_CSTR s2, int len)
static void col_block_refresh_on_seq_term(ED4_sequence_terminal *seq_term)
ED4_blocktype get_type() const
void jump_base_pos(int base_pos, ED4_CursorJumpType jump_type)
GBDATA * get_gb_main() const
int sequence_to_screen(int sequence_pos) const
void ED4_toggle_block_type()
static void modsai_cb(AW_window *aww)
void remove_from_highlighted(ED4_species_name_terminal *object)
ED4_returncode add_to_highlighted(ED4_species_name_terminal *object)
ED4_window * first_window
ED4_terminal * get_next_terminal()
SeqPart(const char *seq_, int offset_, int len_)
static void error(const char *msg)
expectation_group & add(const expectation &e)
ASSERTING_CONSTEXPR_INLINE int info2bio(int infopos)
ED4_root_group_manager * root_group_man
PosRange calc_interval_displayed_in_rectangle(AW_screen_area *area_rect)
void calc_world_coords(AW_pos *x, AW_pos *y) const
replace_op(const char *oldString_, const char *newString_)
char * read_string() const
GB_CSTR GB_path_in_ARBLIB(const char *relative_path)
AW_awar * awar(const char *awar)
GBDATA * GBT_find_sequence(GBDATA *gb_species, const char *aliname)
ED4_list_elem * next() const
GB_alignment_type alignment_type
char * operate(const SeqPart &part, int &new_len) const OVERRIDE
ED4_blocktype ED4_getBlocktype()
AW_selection_list * awt_create_selection_list_with_input_field(AW_window *aww, const char *awar_name, const char *at_box, const char *at_field)
#define does_contain(val)
bool is_consensus_terminal() const
ED4_cursor & current_cursor()
GB_ERROR get_error() const
ED4_species_name_terminal * corresponding_species_name_terminal() const
int MAXSEQUENCECHARACTERLENGTH
GB_ERROR close(GB_ERROR error)
static GB_ERROR perform_block_operation_on_part_of_sequence(const ED4_block_operator&block_operator, ED4_sequence_terminal *term)
void ED4_setColumnblockCorner(AW_event *event, ED4_sequence_terminal *seq_term)
const char * get_alignment_name() const
char * GB_read_string(GBDATA *gbd)
ED4_window * current_ed4w()
ED4_list_elem< T > * head() const
revcomp_op(GB_alignment_type aliType, bool reverse_, bool complement_)
bool ED4_is_gap_character(char chr)
void request_refresh(int clear=1) FINAL_OVERRIDE
void aw_message(const char *msg)
ED4_index pixel2pos(AW_pos click_x)
void set_range(const PosRange &new_range)
ED4_species_manager * containing_species_manager() const
bool ED4_get_highlighted_range(ED4_terminal *term, PosRange &range)
const ED4_remap * remap() const
const PosRange & get_colblock_range() const
GB_ERROR write_string(const char *aw_string)
char * dup_corresponding_part(const char *source, size_t source_len) const
int is_sequence_terminal() const
void ED4_setup_gaps_and_alitype(const char *gap_chars, GB_alignment_type alitype)
NOT4PERL char * GB_command_interpreter_in_env(const char *str, const char *commands, const GBL_call_env &callEnv)
static void refresh_highlighted(bool refresh_name_terminals)
void ED4_correctBlocktypeAfterModification()
GB_ERROR load(const char *filemask, bool append) const
GB_transaction ta(gb_var)
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
#define ED4_AWAR_REP_SEARCH_PATTERN
#define AWAR_MOD_SAI_SCRIPT
AW_window * ED4_create_replace_window(AW_root *root)
char * operate(const SeqPart &part, int &new_len) const OVERRIDE
void ED4_perform_block_operation(ED4_blockoperation_type operationType)
int is_species_name_terminal() const
void aw_message_if(GB_ERROR error)
NOT4PERL GB_ERROR GBT_determine_T_or_U(GB_alignment_type alignment_type, char *T_or_U, const char *supposed_target)
static void replace_in_block(AW_window *)
GB_ERROR GB_write_autoconv_string(GBDATA *gbd, const char *val)