72 char *textvalue =
NULp;
73 const char *labelvalue =
NULp;
77 const char *symbol = currArg.
symbol;
102 for (
int c = 0; c<currArg.
numchoices && !labelvalue; ++c) {
105 if (strcmp(choice.
method, textvalue) == 0) {
106 labelvalue = choice.
label;
114 if (!symbol) symbol =
"";
116 set<string>warned_about;
117 int conversion_warning = 0;
119 const int symLen = strlen(symbol);
120 int actlen = strlen(Action);
122 for (
int i, j = 0; (i=
Find2(Action+j, symbol)) != -1;) {
125 if (i>0 && Action[i-1] ==
'$') {
126 const char *replaceBy = textvalue;
129 if (i>1 && Action[i-2] ==
'!') {
131 replaceBy = labelvalue;
140 int repLen = strlen(replaceBy);
141 int remLen = skip+symLen;
145 temp.
ncat(Action, i-skip);
146 temp.
ncat(replaceBy, repLen);
147 temp.
cat(Action+i+symLen);
150 freeset(Action, temp.
release());
153 if (warned_about.find(symbol) == warned_about.end()) {
155 "old arb version converted '%s' to '%s' (now only '$%s' is converted)\n",
156 symbol, textvalue, symbol);
157 conversion_warning++;
158 warned_about.insert(symbol);
163 if (conversion_warning) {
165 "Conversion warnings occurred in Action:\n'%s'\n",
174 size_t oldslen = strlen(olds);
175 size_t newslen = strlen(news);
176 size_t actlen = strlen(Action);
179 for (; (i=
Find2(Action, olds)) != -1;) {
182 temp.
ncat(Action, i);
183 temp.
ncat(news, newslen);
184 temp.
cat(Action+i+oldslen);
187 freeset(Action, temp.
release());
241 int part_len = seq_len;
242 if (seq_len > ali_len) {
244 int oversize = seq_len-ali_len;
245 int irrelevant = strspn(sequence+ali_len,
"-.nN");
246 int relevant_oversize = oversize-irrelevant;
248 part_len = ali_len+relevant_oversize;
250 if (relevant_oversize) {
251 int new_ali_len = part_len;
258 ali_len = new_ali_len;
263 if (part_len<seq_len) {
278 inline bool isTU(
char c) {
return c ==
'T' || c ==
'U'; }
284 if (
isgap(seq[index])) {
285 char gap = seq[index++];
286 while (
isgap(seq[index])) ++index;
300 char TU = ali_type ==
GB_AT_RNA ?
'U' :
'T';
301 char tu = tolower(TU);
307 if (og && ng && og != ng) memset(fixed+f, og, n-f);
310 char oc = old_seq[o++];
311 char nc = new_seq[n++];
314 char oC = toupper(oc);
315 char nC = toupper(nc);
317 if (fixTU &&
isTU(nC) &&
isTU(oC)) fixed[f] = (oc == oC) ? TU : tu;
318 else if (oc != nc && oC == nC) fixed[f] = oc;
340 if (maxalignlen <= 0 && !error) {
357 const long oldalignlen = maxalignlen;
358 bool auto_format =
false;
360 AW_repeated_question overwrite_question;
361 AW_repeated_question checksum_change_question;
364 for (i = oldnumelements; !error && i < dataset.
numelements; i++) {
366 int seqtyp, issame = 0;
369 if ((seqtyp == lotyp) || ((seqtyp ==
DNA) && (lotyp ==
RNA)) || ((seqtyp ==
RNA) && (lotyp ==
DNA))) {
377 for (
long j = 0; j < sequ->
seqlen; j++) {
387 const char *new_seq = (
const char *)sequ->
sequence;
388 int new_seq_len = sequ->
seqlen;
391 gde_assert((
int)strlen(new_seq) == new_seq_len);
404 if (new_seq_len<maxalignlen) auto_format =
true;
413 bool fix_data_changes =
false;
418 enum ReplaceMode { REPLACE_SPEC = 0, REIMPORT_SEQ = 1, SKIP_IMPORT = 2 } replace_mode;
421 replace_mode = REIMPORT_SEQ;
424 const char *question =
426 "That species already exists in your database!\n"
428 "Possible actions:\n"
430 " - overwrite existing species (all fields)\n"
431 " - overwrite the sequence (does not change other fields)\n"
432 " - skip import of the species\n",
435 replace_mode = (ReplaceMode)overwrite_question.get_answer(
"GDE_overwrite", question,
"Overwrite species,Overwrite sequence only,Skip entry",
"all",
false);
438 switch (replace_mode) {
453 fix_data_changes = replace_mode == REIMPORT_SEQ;
471 bool writeSequence =
true;
475 long old_checksum = 0;
476 long new_checksum = 0;
477 bool calcStdChecksum =
true;
478 if (fix_data_changes) {
501 if (new_checksum == old_checksum) {
504 new_seq = new_seq_fixed;
505 calcStdChecksum =
false;
508 fprintf(stderr,
"Checksum changed for '%s':\nold='%s'\nfix='%s' (failed)\nnew='%s'\n", savename, old_seq, new_seq_fixed, new_seq);
512 if (calcStdChecksum) {
517 if (old_checksum != new_checksum) {
518 if (!fix_data_changes) {
519 fprintf(stderr,
"Checksum changed for '%s':\nold='%s'\nnew='%s'\n", savename, old_seq, new_seq);
523 "This should NOT happen if you aligned sequences!\n"
524 "(see console for changes to sequence)", savename);
526 const char *questionID = aligned_data ?
"GDE_accept_aligner_seqchange" :
"GDE_accept_seqchange";
531 } change_mode = (ChangeMode)checksum_change_question.get_answer(questionID, question,
"Accept change,Reject",
"all",
false);
533 if (change_mode == REJECT_CHANGE) writeSequence =
false;
536 savename, writeSequence ?
"accepted" :
"rejected"));
542 if (new_seq_len<maxalignlen) auto_format =
true;
552 if (!auto_format) auto_format = oldalignlen != maxalignlen;
575 static const char *
jobLabel(
const char *itemLabel) {
578 fprintf(stderr,
"error generating jobLabel: %s\n",
GB_await_error());
579 jlab = strdup(
"someJob");
598 for (
int j=0; j<current_item->
numinputs; j++) {
601 aw_message(
"'intyped' must be same for all inputs (config error in GDE menu file)");
621 progress.
subtitle(
"reading database");
627 stop =
ReadArbdb2(DataSet, filter2, compress, cutoff_stop_codon, typeinfo);
630 stop =
ReadArbdb(DataSet, marked, filter2, compress, cutoff_stop_codon, typeinfo);
646 static int fileindx = 0;
647 for (
int j=0; j<current_item->
numinputs; j++) {
651 sprintf(buffer,
"gde%d_%d", pid, fileindx++);
662 for (
int j=0; j<current_item->
numoutputs; j++) {
664 sprintf(buffer,
"gde%d_%d", pid, fileindx++);
675 for (
int j=0; j<current_item->
numargs; j++) Action =
ReplaceArgs(aw_root, Action, gmenuitem, j);
676 bool changed = strcmp(oldAction, Action) != 0;
685 if (
Find(Action,
"$FILTER") ==
true) {
691 static int jobCounter = 1;
694 if (
Find(Action,
"$AGDE_JOBID") ==
true) {
699 progress.
subtitle(
"calling external program");
700 fprintf(stderr,
"---------------------------------------- [executing %s]\n", jobID);
702 fprintf(stderr,
"---------------------------------------- [done with %s]\n", jobID);
710 for (
int j=0; j<current_item->
numoutputs; j++) {
722 for (
int j=0; j<current_item->
numoutputs; j++) {
728 for (
int j=0; j<current_item->
numinputs; j++) {
755 #define TEST_FIX_ALIGNED(t,o,f,a) TEST_EXPECTATION(fixed_as(t,o,f,a))
756 #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))
758 void TEST_fix_aligned_data() {
760 "...A---CG..G--U.....",
770 "...A---CG..G--U.....",
GB_ERROR GB_begin_transaction(GBDATA *gbd)
GB_ERROR GBK_system(const char *system_command)
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 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)
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
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)