31 using std::stringstream;
45 cerr <<
"aw_status_fraction: " << d << endl;
55 if (!err_state.empty()) {
56 cerr <<
"ERROR: " << err_state << endl;
68 return err_state.empty() ?
NULp : err_state.c_str();
76 double count, count_max;
81 count(0), count_max(c)
86 if (!gbd)
return string(
"<empty>");
88 if (!str)
return string(
"<empty>");
96 if (!gbd)
return string(
"<empty>");
110 std::replace_if(tmp.begin(),tmp.end(),
equals<char>(
'.'),
'-');
113 for (i=0; i+70<tmp.size(); i+=70)
114 file << tmp.substr(i,70) <<
"\n";
115 file << tmp.substr(i) <<
"\n";
123 double count, count_max;
124 GBDATA *gbdst, *gbdst_spec;
145 gbdst =
GB_open(template_arb.c_str(),
"rw");
146 if (!gbdst)
set_error(
"Unable to open template file");
149 cerr <<
"WARN: Unable to disable undo buffer";
163 unlink(filename.c_str());
187 cerr <<
"Compressing..." << endl;
192 error =
"Your template DB has no default alignment";
196 if (error) error =
GBS_global_string(
"Failed to format alignments (Reason: %s)", error);
201 if (!error &&
GB_save_as(gbdst, filename.c_str(),
"b")) {
202 error =
"Unable to save to output file";
218 const char* out,
int c)
219 : gbmain(_gbmain), dbname(_dbname), formname(eft), outname(out), compress(c)
228 const int cut_stop_codon = 0;
229 const int multiple = 0;
243 char *real_outname =
NULp;
246 &filter, cut_stop_codon, compress,
247 dbname, formname,
NULp,
248 outname, multiple, &real_outname);
262 "Exports sequences from an ARB database."
265 " --source <FILE> source file\n"
266 " --dest <FILE> destination file\n"
267 " --format <ARG> 'ARB', 'FASTA' or path to ARB EFT file\n"
268 " --accs <FILE> export only sequences matching these accessions\n"
270 "only for EFT output format:\n"
271 " --eft-compress-gaps <ARG> 'none', 'vertical' or 'all' (default none)\n"
273 "required for ARB output format:\n"
274 " --arb-template <FILE> template (empty) arb file\n"
280 set<string> accessions;
285 getline(ifs,linestring);
286 if (!linestring.empty()) {
287 stringstream
line(linestring);
290 getline(line,item,
',');
291 item.erase(item.find_last_not_of(
" \n,\t")+1);
292 item.erase(0,item.find_first_not_of(
" \n,\t"));
294 accessions.insert(item);
295 }
while(line.good());
302 int main(
int argc,
char** argv) {
323 for (
int i = 1; i < argc; i++) {
325 if (!strcmp(argv[i],
"--source")) {
327 }
else if (!strcmp(argv[i],
"--dest")) {
329 }
else if (!strcmp(argv[i],
"--arb-template")) {
331 }
else if (!strcmp(argv[i],
"--accs")) {
333 }
else if (!strcmp(argv[i],
"--format")) {
334 if (!strcmp(argv[++i],
"ARB")) {
336 }
else if (!strcmp(argv[i],
"FASTA")) {
342 }
else if (!strcmp(argv[i],
"--eft-compress-gaps")) {
343 if (!strcmp(argv[++i],
"none")) {
345 }
else if (!strcmp(argv[i],
"vertical")) {
347 }
else if (!strcmp(argv[i],
"all")) {
350 cerr <<
"missing argument to --eft-compress-gaps?";
354 cerr <<
"ignoring malformed argument: '" << argv[i] <<
"'" << endl;
357 cerr <<
"ignoring malformed argument: '" << argv[i] <<
"'" << endl;
362 cerr <<
"need '--source' parameter" << endl;
366 cerr <<
"need '--dest' parameter" << endl;
370 cerr <<
"need '--format' parameter" << endl;
373 if (
format == FMT_ARB && !tmpl) {
374 cerr <<
"need '--arb-template' parameter for output type ARB'" << endl;
378 set<string> accessions;
381 cerr <<
"unable to open accession number file '" << accs <<
'\'' << endl;
392 error =
"unable to open source file";
401 count_max = accessions.size();
413 writer =
new ArbWriter(tmpl, dest, count_max);
427 writer =
new AwtiExportWriter(gbsrc, src, eft, dest, compress);
431 error =
"internal error";
439 gbspec && writer->
ok();
445 if (!accs || accessions.count(name)) {
462 if (error) cerr <<
"ERROR: " << error << endl;
GB_ERROR GB_begin_transaction(GBDATA *gbd)
GB_ERROR GB_copy_dropProtectMarksAndTempstate(GBDATA *dest, GBDATA *source)
GBDATA * GB_open(const char *path, const char *opent)
GB_ERROR GB_commit_transaction(GBDATA *gbd)
virtual bool ok() const =0
string readData(GBDATA *spec)
AliDataPtr format(AliDataPtr data, const size_t wanted_len, GB_ERROR &error)
return string(buffer, length)
void addSequence(GBDATA *gbspec) OVERRIDE
GBDATA * GB_find(GBDATA *gbd, const char *key, GB_SEARCH_TYPE gbs)
long GBT_mark_all(GBDATA *gb_main, int flag)
virtual void addSequence(GBDATA *)=0
AwtiExportWriter(GBDATA *_gbmain, const char *_dbname, const char *eft, const char *out, int c)
char * GB_read_as_string(GBDATA *gbd)
static set< string > read_accession_file(const char *file)
ArbWriter(string ta, string f, int c)
const char * GBS_global_string(const char *templat,...)
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
void addSequence(GBDATA *spec) OVERRIDE
GB_ERROR GB_release(GBDATA *gbd)
GB_ERROR GB_await_error()
GBDATA * GB_create_container(GBDATA *father, const char *key)
GB_ERROR ARB_format_alignment(GBDATA *Main, const char *alignment_name)
GB_ERROR GB_save_as(GBDATA *gbd, const char *path, const char *savetype)
static void error(const char *msg)
GB_ERROR export_by_format(GBDATA *gb_main, ExportWhich which, const char *one_species, AP_filter *filter, int cut_stop_codon, int compress, const char *dbname, const char *formname, const char *field_transfer_set, const char *outname, int multiple, char **real_outname)
int main(int argc, char **argv)
static void aw_status(double d)
string readString(GBDATA *spec, const char *key)
void GB_write_flag(GBDATA *gbd, long flag)
const struct formatTable formname[]
GBDATA * GBT_first_species(GBDATA *gb_main)
MultiFastaWriter(string s, const char *a, int c)
const char * GBS_static_string(const char *str)
GBDATA * GBT_next_species(GBDATA *gb_species)
virtual void set_error(const char *error)
bool GB_is_regularfile(const char *path)
const char * get_error() const
char * GBT_get_default_alignment(GBDATA *gb_main)
GB_ERROR GB_request_undo_type(GBDATA *gb_main, GB_UNDO_TYPE type) __ATTR__USERESULT_TODO
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
void GB_close(GBDATA *gbd)
bool operator()(const T &_t)
GB_write_int const char s