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