| 1 | // ============================================================= // |
|---|
| 2 | // // |
|---|
| 3 | // File : AWTI_export.cxx // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // ============================================================= // |
|---|
| 10 | |
|---|
| 11 | #include "awti_export.hxx" |
|---|
| 12 | |
|---|
| 13 | #include <seqio.hxx> |
|---|
| 14 | #include <awt_filter.hxx> |
|---|
| 15 | #include <AP_filter.hxx> |
|---|
| 16 | #include <aw_awars.hxx> |
|---|
| 17 | #include <aw_file.hxx> |
|---|
| 18 | #include <aw_window.hxx> |
|---|
| 19 | #include <aw_msg.hxx> |
|---|
| 20 | #include <arb_progress.h> |
|---|
| 21 | #include <aw_root.hxx> |
|---|
| 22 | #include <arbdbt.h> |
|---|
| 23 | #include <arb_str.h> |
|---|
| 24 | #include <arb_file.h> |
|---|
| 25 | |
|---|
| 26 | #define AWAR_EXPORT_FILE "tmp/export_db/file" |
|---|
| 27 | #define AWAR_EXPORT_FORM "export/form" |
|---|
| 28 | #define AWAR_EXPORT_ALI "tmp/export/alignment" |
|---|
| 29 | #define AWAR_EXPORT_MULTIPLE_FILES "tmp/export/multiple_files" |
|---|
| 30 | #define AWAR_EXPORT_MARKED "export/marked" |
|---|
| 31 | #define AWAR_EXPORT_COMPRESS "export/compress" |
|---|
| 32 | #define AWAR_EXPORT_FILTER_PREFIX "export/filter" |
|---|
| 33 | #define AWAR_EXPORT_FILTER_NAME AWAR_EXPORT_FILTER_PREFIX "/name" |
|---|
| 34 | #define AWAR_EXPORT_FILTER_FILTER AWAR_EXPORT_FILTER_PREFIX "/filter" |
|---|
| 35 | #define AWAR_EXPORT_FILTER_ALI AWAR_EXPORT_FILTER_PREFIX "/alignment" |
|---|
| 36 | #define AWAR_EXPORT_CUTSTOP "export/cutstop" |
|---|
| 37 | |
|---|
| 38 | static void AWTC_export_go_cb(AW_window *aww, AW_CL cl_gb_main, AW_CL res_from_awt_create_select_filter) { |
|---|
| 39 | GBDATA *gb_main = (GBDATA*)cl_gb_main; |
|---|
| 40 | GB_transaction dummy(gb_main); |
|---|
| 41 | adfiltercbstruct *acbs = (adfiltercbstruct*)res_from_awt_create_select_filter; |
|---|
| 42 | |
|---|
| 43 | arb_progress progress("Exporting data"); |
|---|
| 44 | |
|---|
| 45 | AW_root *awr = aww->get_root(); |
|---|
| 46 | char *formname = awr->awar(AWAR_EXPORT_FORM"/file_name")->read_string(); |
|---|
| 47 | int multiple = awr->awar(AWAR_EXPORT_MULTIPLE_FILES)->read_int(); |
|---|
| 48 | int marked_only = awr->awar(AWAR_EXPORT_MARKED)->read_int(); |
|---|
| 49 | int cut_stop_codon = awr->awar(AWAR_EXPORT_CUTSTOP)->read_int(); |
|---|
| 50 | int compress = awr->awar(AWAR_EXPORT_COMPRESS)->read_int(); |
|---|
| 51 | GB_ERROR error = 0; |
|---|
| 52 | |
|---|
| 53 | char *outname = awr->awar(AWAR_EXPORT_FILE"/file_name")->read_string(); |
|---|
| 54 | char *real_outname = 0; // with suffix (name of first file if multiple) |
|---|
| 55 | |
|---|
| 56 | AP_filter *filter = awt_get_filter(acbs); |
|---|
| 57 | char *db_name = awr->awar(AWAR_DB_NAME)->read_string(); |
|---|
| 58 | |
|---|
| 59 | error = SEQIO_export_by_format(gb_main, marked_only, filter, cut_stop_codon, compress, |
|---|
| 60 | db_name, formname, outname, multiple, &real_outname); |
|---|
| 61 | free(db_name); |
|---|
| 62 | if (error) aw_message(error); |
|---|
| 63 | |
|---|
| 64 | if (real_outname) awr->awar(AWAR_EXPORT_FILE"/file_name")->write_string(real_outname); |
|---|
| 65 | |
|---|
| 66 | AW_refresh_fileselection(awr, AWAR_EXPORT_FILE); |
|---|
| 67 | |
|---|
| 68 | free(real_outname); |
|---|
| 69 | free(outname); |
|---|
| 70 | free(formname); |
|---|
| 71 | |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | static void AWTC_create_export_awars(AW_root *awr, AW_default def) { |
|---|
| 75 | AW_create_fileselection_awars(awr, AWAR_EXPORT_FORM, GB_path_in_ARBLIB("export"), ".eft", "*", AW_ROOT_DEFAULT, true); |
|---|
| 76 | AW_create_fileselection_awars(awr, AWAR_EXPORT_FILE, "", "", "noname"); |
|---|
| 77 | |
|---|
| 78 | awr->awar_string(AWAR_EXPORT_ALI, "16s", def); |
|---|
| 79 | awr->awar_int(AWAR_EXPORT_MULTIPLE_FILES, 0, def); |
|---|
| 80 | |
|---|
| 81 | awr->awar_int(AWAR_EXPORT_MARKED, 1, def); // marked only |
|---|
| 82 | awr->awar_int(AWAR_EXPORT_COMPRESS, 1, def); // vertical gaps |
|---|
| 83 | awr->awar_string(AWAR_EXPORT_FILTER_NAME, "none", def); // no default filter |
|---|
| 84 | awr->awar_string(AWAR_EXPORT_FILTER_FILTER, "", def); |
|---|
| 85 | AW_awar *awar_ali = awr->awar_string(AWAR_EXPORT_FILTER_ALI, "", def); |
|---|
| 86 | awar_ali->map("presets/use"); // map to default alignment |
|---|
| 87 | |
|---|
| 88 | awr->awar_int(AWAR_EXPORT_CUTSTOP, 0, def); // don't cut stop-codon |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | static void export_form_changed_cb(AW_root *aw_root) { |
|---|
| 93 | // called when selected export format changes |
|---|
| 94 | // -> automatically correct filename suffix |
|---|
| 95 | // -> restrict view to suffix |
|---|
| 96 | |
|---|
| 97 | static char *previous_suffix = 0; |
|---|
| 98 | |
|---|
| 99 | GB_ERROR error = 0; |
|---|
| 100 | AW_awar *awar_form = aw_root->awar(AWAR_EXPORT_FORM"/file_name"); |
|---|
| 101 | char *current_format = awar_form->read_string(); |
|---|
| 102 | |
|---|
| 103 | if (current_format) { |
|---|
| 104 | if (GB_is_regularfile(current_format)) { |
|---|
| 105 | char *current_suffix = SEQIO_exportFormat_get_outfile_default_suffix(current_format, error); |
|---|
| 106 | if (!error) { |
|---|
| 107 | // Note: current_suffix may be NULL.. is that ok? |
|---|
| 108 | |
|---|
| 109 | // modify export filename and view |
|---|
| 110 | |
|---|
| 111 | AW_awar *awar_filter = aw_root->awar(AWAR_EXPORT_FILE"/filter"); |
|---|
| 112 | AW_awar *awar_export = aw_root->awar(AWAR_EXPORT_FILE"/file_name"); |
|---|
| 113 | |
|---|
| 114 | awar_filter->write_string(""); |
|---|
| 115 | |
|---|
| 116 | char *exportname = awar_export->read_string(); |
|---|
| 117 | |
|---|
| 118 | { |
|---|
| 119 | char *path, *nameOnly, *suffix; |
|---|
| 120 | GB_split_full_path(exportname, &path, NULL, &nameOnly, &suffix); |
|---|
| 121 | |
|---|
| 122 | if (suffix) { |
|---|
| 123 | if (previous_suffix && ARB_stricmp(suffix, previous_suffix) == 0) freedup(suffix, current_suffix); // remove old suffix |
|---|
| 124 | else freedup(suffix, GB_append_suffix(suffix, current_suffix)); // don't know existing suffix -> append |
|---|
| 125 | } |
|---|
| 126 | else suffix = strdup(current_suffix); |
|---|
| 127 | |
|---|
| 128 | const char *new_exportname = GB_concat_path(path, GB_append_suffix(nameOnly, suffix)); |
|---|
| 129 | if (new_exportname) awar_export->write_string(new_exportname); |
|---|
| 130 | |
|---|
| 131 | free(suffix); |
|---|
| 132 | free(nameOnly); |
|---|
| 133 | free(path); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | free(exportname); |
|---|
| 137 | |
|---|
| 138 | awar_filter->write_string(current_suffix); |
|---|
| 139 | |
|---|
| 140 | // remember last applied suffix |
|---|
| 141 | reassign(previous_suffix, current_suffix); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | free(current_suffix); |
|---|
| 145 | } |
|---|
| 146 | free(current_format); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | if (error) aw_message(error); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | AW_window *open_AWTC_export_window(AW_root *awr, GBDATA *gb_main) |
|---|
| 153 | { |
|---|
| 154 | static AW_window_simple *aws = 0; |
|---|
| 155 | if (aws) return aws; |
|---|
| 156 | |
|---|
| 157 | AWTC_create_export_awars(awr, AW_ROOT_DEFAULT); |
|---|
| 158 | |
|---|
| 159 | aws = new AW_window_simple; |
|---|
| 160 | |
|---|
| 161 | aws->init(awr, "ARB_EXPORT", "ARB EXPORT"); |
|---|
| 162 | aws->load_xfig("awt/export_db.fig"); |
|---|
| 163 | |
|---|
| 164 | aws->at("close"); |
|---|
| 165 | aws->callback(AW_POPDOWN); |
|---|
| 166 | aws->create_button("CLOSE", "CLOSE", "C"); |
|---|
| 167 | |
|---|
| 168 | aws->at("help"); |
|---|
| 169 | aws->callback(AW_POPUP_HELP, (AW_CL)"arb_export.hlp"); |
|---|
| 170 | aws->create_button("HELP", "HELP", "H"); |
|---|
| 171 | |
|---|
| 172 | AW_create_fileselection(aws, AWAR_EXPORT_FILE, "f"); |
|---|
| 173 | |
|---|
| 174 | AW_create_fileselection(aws, AWAR_EXPORT_FORM, "", "ARBHOME", false); |
|---|
| 175 | |
|---|
| 176 | aws->get_root()->awar(AWAR_EXPORT_FORM"/file_name")->add_callback(export_form_changed_cb); |
|---|
| 177 | |
|---|
| 178 | aws->at("allmarked"); |
|---|
| 179 | aws->create_option_menu(AWAR_EXPORT_MARKED); |
|---|
| 180 | aws->insert_option("all", "a", 0); |
|---|
| 181 | aws->insert_option("marked", "m", 1); |
|---|
| 182 | aws->update_option_menu(); |
|---|
| 183 | |
|---|
| 184 | aws->at("compress"); |
|---|
| 185 | aws->create_option_menu(AWAR_EXPORT_COMPRESS); |
|---|
| 186 | aws->insert_option("no", "n", 0); |
|---|
| 187 | aws->insert_option("vertical gaps", "v", 1); |
|---|
| 188 | aws->insert_option("all gaps", "a", 2); |
|---|
| 189 | aws->update_option_menu(); |
|---|
| 190 | |
|---|
| 191 | aws->at("seqfilter"); |
|---|
| 192 | adfiltercbstruct *filtercd = awt_create_select_filter(aws->get_root(), gb_main, AWAR_EXPORT_FILTER_NAME); |
|---|
| 193 | aws->callback(AW_POPUP, (AW_CL)awt_create_select_filter_win, (AW_CL)filtercd); |
|---|
| 194 | aws->create_button("SELECT_FILTER", AWAR_EXPORT_FILTER_NAME); |
|---|
| 195 | |
|---|
| 196 | aws->at("cutstop"); |
|---|
| 197 | aws->create_toggle(AWAR_EXPORT_CUTSTOP); |
|---|
| 198 | |
|---|
| 199 | aws->at("multiple"); |
|---|
| 200 | aws->create_toggle(AWAR_EXPORT_MULTIPLE_FILES); |
|---|
| 201 | |
|---|
| 202 | aws->at("go"); |
|---|
| 203 | aws->highlight(); |
|---|
| 204 | aws->callback(AWTC_export_go_cb, (AW_CL)gb_main, (AW_CL)filtercd); |
|---|
| 205 | aws->create_button("GO", "GO", "G"); |
|---|
| 206 | |
|---|
| 207 | return aws; |
|---|
| 208 | } |
|---|