31 #define AWAR_CON_SEQUENCE_TYPE "tmp/concat/sequence_type"
32 #define AWAR_CON_NEW_ALIGNMENT_NAME "tmp/concat/new_alignment_name"
33 #define AWAR_CON_ALIGNMENT_SEPARATOR "tmp/concat/alignment_separator"
34 #define AWAR_CON_SELECTED_ALI "tmp/concat/database_alignments"
35 #define AWAR_CON_MERGE_FIELD "tmp/concat/merge_field"
36 #define AWAR_CON_STORE_SIM_SP_NO "tmp/concat/store_sim_sp_no"
38 #define AWAR_CON_ALLOW_OVERWRITE_ALI "tmp/concat/overwrite"
39 #define AWAR_CON_INSGAPS_FOR_MISS_ALIS "tmp/concat/insgaps"
55 char *ali_type =
NULp;
101 static bool ran=
false;
131 int sep_len = strlen(ali_separator);
133 char *
info = ARB_alloc<char>(new_ali_length+1);
134 memset(info,
'=', new_ali_length);
137 int last_ali_idx = ali_names.size()-1;
139 for (
int a = 0; a <= last_ali_idx; ++a) {
140 const char *ali = ali_names[a];
143 int ali_str_len = strlen(ali);
146 char *my_info = info+
offset;
148 int half_ali_len = ali_len/2;
149 for (
int i = 0; i<5; ++i) {
150 if (i<half_ali_len) {
152 my_info[ali_len-i-1] =
'>';
156 if (ali_str_len<ali_len) {
157 int namepos = half_ali_len - ali_str_len/2;
158 memcpy(my_info+namepos, ali, ali_str_len);
162 if (a != last_ali_idx) {
163 memcpy(info+offset, ali_separator, sep_len);
169 info[new_ali_length] = 0;
192 arb_progress progress(
"Concatenating alignments", marked_species);
193 size_t ali_count = ali_names.size();
195 if (!error && ali_count<2) {
196 error =
"Not enough alignments selected for concatenation (need at least 2)";
199 int found[ali_count], missing[ali_count], ali_length[ali_count];
201 for (
size_t a = 0; a<ali_count; a++) {
206 if (ali_length[a]<=0) {
209 else if (strcmp(ali_names[a], new_ali_name) == 0) {
210 error =
"Target alignment may not be one of the source alignments";
216 const int sep_len = strlen(ali_separator);
218 long new_alignment_len = (ali_count-1)*sep_len;
219 for (
size_t a = 0; a<ali_count; ++a) {
220 new_alignment_len += ali_length[a];
228 if (gb_alignment_exists) {
235 error =
GBS_global_string(
"Target alignment '%s' already exists\n(check overwrite-toggle if you really want to overwrite)", new_ali_name);
247 free(source_alignments);
251 AW_repeated_question ask_about_missing_alignment;
255 gb_species && !error;
259 int data_inserted = 0;
261 for (
size_t a = 0; a<ali_count; ++a) {
262 if (a) concat_seq.
cat(ali_separator);
267 concat_seq.
cat(seq_data);
272 if (insertGaps) concat_seq.
nput(
'.', ali_length[a]);
277 if (!data_inserted) {
290 for (
size_t a = 0; a<ali_count; ++a) {
341 int doneLen = strlen(doneFields);
343 int sl_length = 0;
while (scl) { sl_length++; scl=scl->
next; }
344 int *fieldStat =
new int[sl_length];
346 while (sl && !error) {
348 char *fieldStart = newFields;
350 while (fieldStart[1] && !error) {
351 char *fieldEnd = strchr(fieldStart+1,
';');
353 char behind = fieldEnd[1]; fieldEnd[1] = 0;
355 if (!strstr(doneFields, fieldStart)) {
356 char *fieldName = fieldStart+1;
357 int fieldLen =
int(fieldEnd-fieldName);
366 int i;
int doneSpecies = 0;
int nextStat = 1;
368 for (i=0; i<sl_length; i++) { fieldStat[i] = 0; }
370 while (doneSpecies<sl_length) {
375 if (fieldStat[i]==0) {
380 fieldStat[i] = nextStat;
381 int j = i+1; doneSpecies++;
384 if (fieldStat[j]==0) {
388 if (strcmp(content, content2)==0) {
389 fieldStat[j] = nextStat;
399 sl3 = sl3->
next; j++;
401 free(content); nextStat++;
408 sl2 = sl2->
next; i++;
414 char *new_content =
NULp;
415 int new_content_len = 0;
423 new_content_len = strlen(new_content);
431 for (actualStat=1; actualStat<nextStat; actualStat++) {
435 char *content =
NULp;
439 if (fieldStat[i]==actualStat) {
447 sl2 = sl2->
next; i++;
450 int add_len = names_len+1+strlen(content);
451 char *whole = ARB_alloc<char>(new_content_len+1+add_len+1);
453 char *
add = new_content ? whole+sprintf(whole,
"%s ", new_content) : whole;
457 if (fieldStat[i]==actualStat) {
458 add += sprintf(add,
"%c%s", first ?
'{' :
';', sl2->
species_name);
461 sl2 = sl2->
next; i++;
463 add += sprintf(add,
"} %s", content);
466 freeset(new_content, whole);
467 new_content_len = strlen(new_content);
479 char *new_doneFields = ARB_alloc<char>(doneLen+fieldLen+1+1);
480 sprintf(new_doneFields,
"%s%s;", doneFields, fieldName);
481 doneLen += fieldLen+1;
482 freeset(doneFields, new_doneFields);
485 fieldEnd[1] = behind;
486 fieldStart = fieldEnd;
504 char *full_name =
NULp;
533 for (
int no_of_alignments = 0; ali_names[no_of_alignments]; no_of_alignments++) {
541 if (error) error =
GB_export_errorf(
"Can't create alignment '%s'", ali_names[no_of_alignments]);
555 char *new_species_name =
NULp;
572 if (!error) error =
GBT_write_string(gb_new_species,
"name", new_species_name);
574 free(new_species_name);
580 gb_new_species =
NULp;
587 return gb_new_species;
613 error =
"Please select database field for similarity detection";
622 gb_species && !error;
625 GBDATA *gb_species_field =
GB_entry(gb_species, merge_field_name);
627 if (!gb_species_field) {
629 error =
GBS_global_string(
"Species '%s' does not contain data in selected field '%s'",
635 int similar_species = 0;
638 gb_species_next && !
error;
641 GBDATA *gb_next_species_field =
GB_entry(gb_species_next, merge_field_name);
642 if (!gb_next_species_field) {
644 error =
GBS_global_string(
"Species '%s' does not contain data in selected field '%s'",
651 if (strcmp(gb_species_field_content, gb_next_species_field_content) == 0) {
657 free(gb_next_species_field_content);
661 if (similar_species > 0 && !error) {
669 if (new_species_created) {
673 if (report_field_name) {
681 free(gb_species_field_content);
690 int newSpeciesCount = 0;
692 for (; newSpeciesList; newSpeciesList = newSpeciesList->
next) {
700 free(merge_field_name);
713 AW_window_simple *aws =
new AW_window_simple;
717 const char *window_title =
NULp;
722 aws->init(aw_root, window_id, window_title);
725 aws->load_xfig(
"merge_species.fig");
729 aws->create_button(
"HELP",
"HELP",
"H");
735 const char *buttonText =
NULp;
743 aws->create_autosize_button(
"MERGE_SIMILAR_SPECIES", buttonText,
"M");
748 aws->create_button(
"CLOSE",
"CLOSE",
"C");
761 #if defined(ASSERTION_USED)
767 #if defined(ASSERTION_USED)
768 prev_selected_alis = selected_alis;
771 #if defined(ASSERTION_USED)
772 nt_assert(selected_alis == prev_selected_alis);
784 aw_message(
"Select alignment to use in the left alignment list");
790 AW_window_simple *aws =
new AW_window_simple;
792 aws->init(aw_root,
"CONCAT_ALIGNMENTS",
"Concatenate Alignments");
795 aws->auto_space(5, 5);
796 aws->button_length(8);
800 aws->create_button(
"HELP",
"HELP",
"H");
804 aws->create_button(
"CLOSE",
"CLOSE",
"C");
812 aws->insert_option(
"DNA",
"d",
"dna");
813 aws->insert_option(
"RNA",
"r",
"rna");
814 aws->insert_default_option(
"PROTEIN",
"p",
"ami");
815 aws->update_option_menu();
818 aws->at(
"aliSeparator");
823 aws->button_length(5);
825 aws->create_button(
"USE",
"Use");
827 aws->at(
"overwrite");
828 aws->label(
"Allow to overwrite an existing alignment?");
832 aws->label(
"Insert gaps for missing alignment data?");
835 aws->button_length(22);
839 aws->create_button(
"CONCATENATE",
"CONCATENATE",
"A");
842 aws->create_button(
"MERGE_SPECIES",
"MERGE SIMILAR SPECIES",
"M");
845 aws->create_button(
"MERGE_CONCATENATE",
"MERGE & CONCATENATE",
"S");
GB_ERROR GB_begin_transaction(GBDATA *gbd)
GB_ERROR GB_copy_dropProtectMarksAndTempstate(GBDATA *dest, GBDATA *source)
AW_awar * set_srt(const char *srt)
#define AWAR_CON_NEW_ALIGNMENT_NAME
GBDATA * GBT_first_marked_species(GBDATA *gb_main)
#define AWAR_CON_ALLOW_OVERWRITE_ALI
void NT_createConcatenationAwars(AW_root *aw_root, AW_default aw_def, GBDATA *gb_main)
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
void load_xfig(const char *file, bool resize=true)
static void useSelectedAlignment(AW_window *aww)
long GBT_mark_all(GBDATA *gb_main, int flag)
GB_ERROR GBT_check_alignment_name(const char *alignment_name)
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
AW_selection * awt_create_subset_selection_list(AW_window *aww, AW_selection_list *parent_selection, const char *at_box, const char *at_add, const char *at_sort, bool autocorrect_subselection, SubsetChangedCb subChanged_cb, AW_CL cl_user)
GBDATA * GBT_get_alignment(GBDATA *gb_main, const char *aliname)
GB_ERROR AWTC_generate_one_name(GBDATA *gb_main, const char *full_name, const char *acc, const char *addid, char *&new_name)
void GBT_get_alignment_names(ConstStrArray &names, GBDATA *gbd)
char * ARB_strdup(const char *str)
char * GB_read_as_string(GBDATA *gbd)
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)
#define AWAR_CON_MERGE_FIELD
void AW_POPDOWN(AW_window *window)
void nput(char c, size_t count)
void auto_subtitles(const char *prefix)
void cat(const char *from)
void get_values(StrArray &intoArray)
char * GBT_get_alignment_type_string(GBDATA *gb_main, const char *aliname)
GB_ERROR GB_push_transaction(GBDATA *gbd)
#define NO_FIELD_SELECTED
AW_window * NT_createMergeSimilarSpeciesWindow(AW_root *aw_root)
char * AWTC_makeUniqueShortName(const char *prefix, UniqueNameDetector &existingNames)
GB_ERROR GB_incur_error_if(bool error_may_occur)
AW_awar * add_callback(const RootCallback &cb)
GB_ERROR GBT_add_alignment_changekeys(GBDATA *gb_main, const char *ali)
static void addSpeciesToConcatenateList(SpeciesConcatenateList **sclp, GB_CSTR species_name)
void create_itemfield_selection_button(AW_window *aws, const FieldSelDef &selDef, const char *at)
const char * AW_get_nameserver_addid(GBDATA *gb_main)
static GBDATA * concatenateFieldsCreateNewSpecies(AW_window *, GBDATA *gb_species, SpeciesConcatenateList *scl)
const char * read_char_pntr() const
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()
GBDATA * GB_create_container(GBDATA *father, const char *key)
WindowCallback makeHelpCallback(const char *helpfile)
static GB_ERROR create_concatInfo_SAI(GBDATA *gb_main, const char *new_ali_name, const char *ali_separator, const StrArray &ali_names)
char * GBT_read_string(GBDATA *gb_container, const char *fieldpath)
GB_TYPES GB_read_type(GBDATA *gbd)
#define AWAR_CON_ALIGNMENT_SEPARATOR
static GB_ERROR checkAndMergeFields(GBDATA *gb_new_species, GB_ERROR error, SpeciesConcatenateList *scl)
char * GB_get_subfields(GBDATA *gbd)
static void error(const char *msg)
#define AWAR_CON_INSGAPS_FOR_MISS_ALIS
GBDATA * GBT_next_marked_species(GBDATA *gb_species)
static void concatenateAlignments(AW_window *aws, AW_selection *selected_alis)
GB_ERROR GB_write_lossless_int(GBDATA *gbd, int32_t i)
#define SRT_AUTOCORRECT_ALINAME
#define AWAR_CON_STORE_SIM_SP_NO
const char * prepare_and_get_selected_itemfield(AW_root *awr, const char *awar_name, GBDATA *gb_main, const ItemSelector &itemtype, FailIfField failIf)
#define AWAR_CON_SELECTED_ALI
GBDATA * GBT_find_species_rel_species_data(GBDATA *gb_species_data, const char *name)
char * read_string() const
AW_awar * awar(const char *awar)
GBDATA * GBT_find_sequence(GBDATA *gb_species, const char *aliname)
long GBT_count_marked_species(GBDATA *gb_main)
AW_DB_selection * awt_create_ALI_selection_list(GBDATA *gb_main, AW_window *aws, const char *varname, const char *ali_type_match)
GBDATA * GBT_searchOrCreate_itemfield_according_to_changekey(GBDATA *gb_item, const char *field_name, const char *change_key_path)
static void alitype_changed_cb(AW_root *aw_root, AW_DB_selection *db_sel)
char * GBT_join_strings(const CharPtrArray &strings, char separator)
GB_ERROR GB_export_errorf(const char *templat,...)
#define AWAR_CON_SEQUENCE_TYPE
static void mergeSimilarSpecies(AW_window *aws, MergeSpeciesType mergeType, AW_selection *selected_alis)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
SpeciesConcatenateList * next
void GB_write_flag(GBDATA *gbd, long flag)
GB_ERROR GBT_write_string(GBDATA *gb_container, const char *fieldpath, const char *content)
char * get_alitype_eval(AW_root *aw_root)
ItemSelector & SPECIES_get_selector()
void awt_reconfigure_ALI_selection_list(AW_DB_selection *dbsel, const char *ali_type_match)
uint32_t GBS_checksum(const char *seq, int ignore_case, const char *exclude)
void aw_message(const char *msg)
GBDATA * GB_find_string(GBDATA *gbd, const char *key, const char *str, GB_CASE case_sens, GB_SEARCH_TYPE gbs)
GBDATA * GBT_create_alignment(GBDATA *gb_main, const char *name, long len, long aligned, long security, const char *type, const char *why_created)
AW_window * NT_createConcatenationWindow(AW_root *aw_root)
static AW_window * createMergeSimilarSpeciesWindow(AW_root *aw_root, MergeSpeciesType mergeType, AW_selection *selected_alis)
GB_ERROR write_string(const char *aw_string)
static AW_window * NT_createMergeSimilarSpeciesAndConcatenateWindow(AW_root *aw_root, AW_selection *selected_alis)
char * GBT_get_default_alignment(GBDATA *gb_main)
const char * get_data() const
CONSTEXPR long FIELD_FILTER_INT_WRITEABLE
GBDATA * GBT_find_or_create_SAI(GBDATA *gb_main, const char *name)
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
GB_ERROR GBT_check_data(GBDATA *Main, const char *alignment_name)
GBDATA * GBT_get_presets(GBDATA *gb_main)
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
static int info[maxsites+1]
GBDATA * GB_entry(GBDATA *father, const char *key)
void inc_and_check_user_abort(GB_ERROR &error)
AW_selection_list * get_sellist()
CONSTEXPR long FIELD_FILTER_STRING_READABLE
char * GBS_global_string_copy(const char *templat,...)
static AW_DB_selection * createSelectionList(GBDATA *gb_main, AW_window *aws, const char *awarName)
static void freeSpeciesConcatenateList(SpeciesConcatenateList *scl)
GBDATA * GBT_get_species_data(GBDATA *gb_main)