74 char *textvalue =
NULp;
75 const char *labelvalue =
NULp;
79 const char *symbol = currArg.
symbol;
104 for (
int c = 0; c<currArg.
numchoices && !labelvalue; ++c) {
107 if (strcmp(choice.
method, textvalue) == 0) {
108 labelvalue = choice.
label;
116 if (!symbol) symbol =
"";
118 set<string>warned_about;
119 int conversion_warning = 0;
121 const int symLen = strlen(symbol);
122 int actlen = strlen(Action);
124 for (
int i, j = 0; (i=
Find2(Action+j, symbol)) != -1;) {
127 if (i>0 && Action[i-1] ==
'$') {
128 const char *replaceBy = textvalue;
131 if (i>1 && Action[i-2] ==
'!') {
133 replaceBy = labelvalue;
142 int repLen = strlen(replaceBy);
143 int remLen = skip+symLen;
147 temp.
ncat(Action, i-skip);
148 temp.
ncat(replaceBy, repLen);
149 temp.
cat(Action+i+symLen);
152 freeset(Action, temp.
release());
155 if (warned_about.find(symbol) == warned_about.end()) {
157 "old arb version converted '%s' to '%s' (now only '$%s' is converted)\n",
158 symbol, textvalue, symbol);
159 conversion_warning++;
160 warned_about.insert(symbol);
165 if (conversion_warning) {
167 "Conversion warnings occurred in Action:\n'%s'\n",
176 size_t oldslen = strlen(olds);
177 size_t newslen = strlen(news);
178 size_t actlen = strlen(Action);
181 for (; (i=
Find2(Action, olds)) != -1;) {
184 temp.
ncat(Action, i);
185 temp.
ncat(news, newslen);
186 temp.
cat(Action+i+oldslen);
189 freeset(Action, temp.
release());
201 bool hadAndSign =
false;
202 char *andSign = strrchr(Action, 0);
203 while (andSign>Action) {
205 if (!isspace(andSign[0])) {
207 if (andSign[0] ==
'&') {
263 int part_len = seq_len;
264 if (seq_len > ali_len) {
266 int oversize = seq_len-ali_len;
267 int irrelevant = strspn(sequence+ali_len,
"-.nN");
268 int relevant_oversize = oversize-irrelevant;
270 part_len = ali_len+relevant_oversize;
272 if (relevant_oversize) {
273 int new_ali_len = part_len;
280 ali_len = new_ali_len;
285 if (part_len<seq_len) {
300 inline bool isTU(
char c) {
return c ==
'T' || c ==
'U'; }
306 if (
isgap(seq[index])) {
307 char gap = seq[index++];
308 while (
isgap(seq[index])) ++index;
322 char TU = ali_type ==
GB_AT_RNA ?
'U' :
'T';
323 char tu = tolower(TU);
329 if (og && ng && og != ng) memset(fixed+f, og, n-f);
332 char oc = old_seq[o++];
333 char nc = new_seq[n++];
336 char oC = toupper(oc);
337 char nC = toupper(nc);
339 if (fixTU &&
isTU(nC) &&
isTU(oC)) fixed[f] = (oc == oC) ? TU : tu;
340 else if (oc != nc && oC == nC) fixed[f] = oc;
362 if (maxalignlen <= 0 && !error) {
379 const long oldalignlen = maxalignlen;
380 bool auto_format =
false;
382 AW_repeated_question overwrite_question;
383 AW_repeated_question checksum_change_question;
386 for (i = oldnumelements; !error && i < dataset.
numelements; i++) {
388 int seqtyp, issame = 0;
391 if ((seqtyp == lotyp) || ((seqtyp ==
DNA) && (lotyp ==
RNA)) || ((seqtyp ==
RNA) && (lotyp ==
DNA))) {
399 for (
long j = 0; j < sequ->
seqlen; j++) {
409 const char *new_seq = (
const char *)sequ->
sequence;
410 int new_seq_len = sequ->
seqlen;
413 gde_assert((
int)strlen(new_seq) == new_seq_len);
426 if (new_seq_len<maxalignlen) auto_format =
true;
435 bool fix_data_changes =
false;
440 enum ReplaceMode { REPLACE_SPEC = 0, REIMPORT_SEQ = 1, SKIP_IMPORT = 2 } replace_mode;
443 replace_mode = REIMPORT_SEQ;
446 const char *question =
448 "That species already exists in your database!\n"
450 "Possible actions:\n"
452 " - overwrite existing species (all fields)\n"
453 " - overwrite the sequence (does not change other fields)\n"
454 " - skip import of the species\n",
457 replace_mode = (ReplaceMode)overwrite_question.get_answer(
"GDE_overwrite", question,
"Overwrite species,Overwrite sequence only,Skip entry",
"all",
false);
460 switch (replace_mode) {
475 fix_data_changes = replace_mode == REIMPORT_SEQ;
493 bool writeSequence =
true;
497 long old_checksum = 0;
498 long new_checksum = 0;
499 bool calcStdChecksum =
true;
500 if (fix_data_changes) {
523 if (new_checksum == old_checksum) {
526 new_seq = new_seq_fixed;
527 calcStdChecksum =
false;
530 fprintf(stderr,
"Checksum changed for '%s':\nold='%s'\nfix='%s' (failed)\nnew='%s'\n", savename, old_seq, new_seq_fixed, new_seq);
534 if (calcStdChecksum) {
539 if (old_checksum != new_checksum) {
540 if (!fix_data_changes) {
541 fprintf(stderr,
"Checksum changed for '%s':\nold='%s'\nnew='%s'\n", savename, old_seq, new_seq);
545 "This should NOT happen if you aligned sequences!\n"
546 "(see console for changes to sequence)", savename);
548 const char *questionID = aligned_data ?
"GDE_accept_aligner_seqchange" :
"GDE_accept_seqchange";
553 } change_mode = (ChangeMode)checksum_change_question.get_answer(questionID, question,
"Accept change,Reject",
"all",
false);
555 if (change_mode == REJECT_CHANGE) writeSequence =
false;
558 savename, writeSequence ?
"accepted" :
"rejected"));
564 if (new_seq_len<maxalignlen) auto_format =
true;
574 if (!auto_format) auto_format = oldalignlen != maxalignlen;
597 static const char *
jobLabel(
const char *itemLabel) {
600 fprintf(stderr,
"error generating jobLabel: %s\n",
GB_await_error());
601 jlab = strdup(
"someJob");
620 for (
int j=0; j<current_item->
numinputs; j++) {
623 aw_message(
"'intyped' must be same for all inputs (config error in GDE menu file)");
643 progress.
subtitle(
"reading database");
649 stop =
ReadArbdb2(DataSet, filter2, compress, cutoff_stop_codon, typeinfo);
652 stop =
ReadArbdb(DataSet, marked, filter2, compress, cutoff_stop_codon, typeinfo);
668 static int fileindx = 0;
669 for (
int j=0; j<current_item->
numinputs; j++) {
673 sprintf(buffer,
"gde%d_%d", pid, fileindx++);
684 for (
int j=0; j<current_item->
numoutputs; j++) {
686 sprintf(buffer,
"gde%d_%d", pid, fileindx++);
697 for (
int j=0; j<current_item->
numargs; j++) Action =
ReplaceArgs(aw_root, Action, gmenuitem, j);
698 bool changed = strcmp(oldAction, Action) != 0;
707 if (
Find(Action,
"$FILTER") ==
true) {
713 static int jobCounter = 1;
716 if (
Find(Action,
"$AGDE_JOBID") ==
true) {
723 progress.
subtitle(
"calling external program");
724 fprintf(stderr,
"---------------------------------------- [executing %s]\n", jobID);
730 if (playback)
GB_setenv(
"ARB_WAIT_TIMEOUT",
"7");
737 if (playback)
GB_setenv(
"ARB_WAIT_TIMEOUT",
"");
739 fprintf(stderr,
"---------------------------------------- [done with %s]\n", jobID);
747 for (
int j=0; j<current_item->
numoutputs; j++) {
759 for (
int j=0; j<current_item->
numoutputs; j++) {
765 for (
int j=0; j<current_item->
numinputs; j++) {
792 #define TEST_FIX_ALIGNED(t,o,f,a) TEST_EXPECTATION(fixed_as(t,o,f,a))
793 #define TEST_FIX_ALIGNED__BROKEN(t,o,fw,fg,a) TEST_EXPECTATION__BROKEN(fixed_as(t,o,fw,a), fixed_as(t,o,fg,a))
795 void TEST_fix_aligned_data() {
797 "...A---CG..G--U.....",
807 "...A---CG..G--U.....",
GB_ERROR GB_begin_transaction(GBDATA *gbd)
void LoadData(char *filen, NA_Alignment &dataset)
char short_name[SIZE_SHORT_NAME]
static void GDE_freesequ(NA_Sequence *sequ)
AliDataPtr format(AliDataPtr data, const size_t wanted_len, GB_ERROR &error)
static char * fix_aligned_data(const char *old_seq, const char *new_seq, GB_alignment_type ali_type)
#define AWAR_GDE_COMPRESSION
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
int ReadArbdb2(NA_Alignment &dataset, AP_filter *filter, GapCompression compress, bool cutoff_stop_codon, TypeInfo typeinfo)
char * ARB_strdup(const char *str)
void GB_end_transaction_show_error(GBDATA *gbd, GB_ERROR error, void(*error_handler)(GB_ERROR))
const char * GBS_global_string(const char *templat,...)
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
char * AW_get_selected_fullname(AW_root *awr, const char *awar_prefix)
char * GBS_string_eval(const char *insource, const char *icommand)
char eatgaps(const char *seq, int &index)
char * GBS_string_2_key(const char *str)
void cat(const char *from)
int ReadArbdb(NA_Alignment &dataset, bool marked, AP_filter *filter, GapCompression compress, bool cutoff_stop_codon, TypeInfo typeinfo)
char buffer[MESSAGE_BUFFERSIZE]
GBDATA * GB_get_father(GBDATA *gbd)
GB_ERROR ARB_system(const char *cmd, XCmdType boundExectype)
GB_ERROR GB_delete(GBDATA *&source)
char * GDE_maketmpawarname(GmenuItem *gmenuitem, long i)
NOT4PERL GBDATA * GBT_add_data(GBDATA *species, const char *ali_name, const char *key, GB_TYPES type) __ATTR__DEPRECATED_TODO("better use GBT_create_sequence_data()")
GB_ERROR GB_await_error()
char * GB_create_tempfile(const char *name)
#define AWAR_GDE_CUTOFF_STOPCODON
NA_Alignment(GBDATA *gb_main_)
void GDE_startaction_cb(AW_window *aw, GmenuItem *gmenuitem)
GB_CSTR GB_read_key_pntr(GBDATA *gbd)
const char * awarname(const char *awarname_template, int idx)
GDE_get_sequences_cb get_sequences
struct gde_database_access db_access
char * GDE_makeawarname(GmenuItem *gmenuitem, long i)
static bool FindAndRemoveAsyncAndSign(char *&Action)
void GB_setenv(const char *var, const char *value)
GB_ERROR GBT_set_alignment_len(GBDATA *gb_main, const char *aliname, long new_len)
static void error(const char *msg)
GBDATA * GB_get_root(GBDATA *gbd)
GBDATA * GBT_find_or_create_species_rel_species_data(GBDATA *gb_species_data, const char *name, bool markCreated)
char * read_as_string() const
#define RETURN_LOCAL_ALLOC(mallocation)
GB_alignment_type GBT_get_alignment_type(GBDATA *gb_main, const char *aliname)
GBDATA * GBT_find_species_rel_species_data(GBDATA *gb_species_data, const char *name)
char * read_string() const
GDE_format_alignment_cb format_ali
AW_awar * awar(const char *awar)
static void export_to_DB(NA_Alignment &dataset, size_t oldnumelements, bool aligned_data)
static GB_ERROR write_sequence_autoinc_alisize(GBDATA *gb_data, long &ali_len, const char *sequence, int seq_len)
GBDATA * GBT_find_sequence(GBDATA *gb_species, const char *aliname)
GB_alignment_type alignment_type
static char * preCreateTempfile(const char *name)
AP_filter * awt_get_filter(adfiltercbstruct *acbs)
void ncat(const char *from, size_t count)
int WriteGen(NA_Alignment &aln, char *filename, int method)
TYPE * ARB_calloc(size_t nelem)
char * ARB_strndup(const char *start, int len)
void subtitle(const char *stitle)
static void ReplaceString(char *&Action, const char *olds, const char *news)
static void ReplaceFile(char *&Action, GfileFormat file)
#define AWAR_PREFIX_GDE_TEMP
bool is_executing_macro(AW_root *root)
GB_ERROR awt_invalid_filter(AP_filter *filter)
uint32_t GBS_checksum(const char *seq, int ignore_case, const char *exclude)
void aw_message(const char *msg)
int WriteGDE(NA_Alignment &aln, char *filename, int method)
bool is_std_gap(const char c)
char * GBT_get_default_alignment(GBDATA *gb_main)
char * GB_command_interpreter(const char *str, const char *commands, GBDATA *gb_main)
GBDATA * GBT_find_or_create_SAI(GBDATA *gb_main, const char *name)
char * AWT_get_combined_filter_name(AW_root *aw_root, GB_CSTR prefix)
GB_transaction ta(gb_var)
adfiltercbstruct * agde_filter
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
static char * ReplaceArgs(AW_root *awr, char *Action, GmenuItem *gmenuitem, int number)
static const char * jobLabel(const char *itemLabel)
void inc_and_check_user_abort(GB_ERROR &error)
size_t get_position() const
void aw_message_if(GB_ERROR error)
char * GBS_global_string_copy(const char *templat,...)
int WriteNA_Flat(NA_Alignment &aln, char *filename, int method)
GBDATA * GBT_get_species_data(GBDATA *gb_main)