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;
191 error =
"Your template DB has no default alignment";
195 if (error) error =
GBS_global_string(
"Failed to format alignments (Reason: %s)", error);
200 if (!error &&
GB_save_as(gbdst, filename.c_str(),
"b")) {
201 error =
"Unable to save to output file";
217 const char* out,
int c)
218 : gbmain(_gbmain), dbname(_dbname), formname(eft), outname(out), compress(c)
227 const int cut_stop_codon = 0;
228 const int multiple = 0;
232 char *real_outname =
NULp;
235 &filter, cut_stop_codon, compress,
236 dbname, formname,
NULp,
237 outname, multiple, &real_outname);
250 "Exports sequences from an ARB database."
253 " --source <FILE> source file\n"
254 " --dest <FILE> destination file\n"
255 " --format <ARG> 'ARB', 'FASTA' or path to ARB EFT file\n"
256 " --accs <FILE> export only sequences matching these accessions\n"
258 "only for EFT output format:\n"
259 " --eft-compress-gaps <ARG> 'none', 'vertical' or 'all' (default none)\n"
261 "required for ARB output format:\n"
262 " --arb-template <FILE> template (empty) arb file\n"
268 set<string> accessions;
273 getline(ifs,linestring);
274 if (!linestring.empty()) {
275 stringstream
line(linestring);
278 getline(line,item,
',');
279 item.erase(item.find_last_not_of(
" \n,\t")+1);
280 item.erase(0,item.find_first_not_of(
" \n,\t"));
282 accessions.insert(item);
283 }
while(line.good());
290 int main(
int argc,
char** argv) {
311 for (
int i = 1; i < argc; i++) {
313 if (!strcmp(argv[i],
"--source")) {
315 }
else if (!strcmp(argv[i],
"--dest")) {
317 }
else if (!strcmp(argv[i],
"--arb-template")) {
319 }
else if (!strcmp(argv[i],
"--accs")) {
321 }
else if (!strcmp(argv[i],
"--format")) {
322 if (!strcmp(argv[++i],
"ARB")) {
324 }
else if (!strcmp(argv[i],
"FASTA")) {
330 }
else if (!strcmp(argv[i],
"--eft-compress-gaps")) {
331 if (!strcmp(argv[++i],
"none")) {
333 }
else if (!strcmp(argv[i],
"vertical")) {
335 }
else if (!strcmp(argv[i],
"all")) {
338 cerr <<
"missing argument to --eft-compress-gaps?";
342 cerr <<
"ignoring malformed argument: '" << argv[i] <<
"'" << endl;
345 cerr <<
"ignoring malformed argument: '" << argv[i] <<
"'" << endl;
350 cerr <<
"need '--source' parameter" << endl;
354 cerr <<
"need '--dest' parameter" << endl;
358 cerr <<
"need '--format' parameter" << endl;
361 if (
format == FMT_ARB && !tmpl) {
362 cerr <<
"need '--arb-template' parameter for output type ARB'" << endl;
366 set<string> accessions;
369 cerr <<
"unable to open accession number file '" << accs <<
'\'' << endl;
380 error =
"unable to open source file";
389 count_max = accessions.size();
401 writer =
new ArbWriter(tmpl, dest, count_max);
410 writer =
new AwtiExportWriter(gbsrc, src, eft, dest, compress);
414 error =
"internal error";
422 gbspec && writer->
ok();
428 if (!accs || accessions.count(name)) {
445 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