31 error =
GBS_global_string(
"SAI '%s' has no data in alignment '%s'", sai_name.c_str(), aliName);
34 #if defined(ASSERTION_USED)
42 bool blockChars = (type ==
BLOCK) != inverse;
45 filter =
new AP_filter(sai_data, crt.expandedRange(), aliSize);
48 AP_filter inv_filt(sai_data, crt.expandedRange(), aliSize);
64 aliname(nulldup(aliname_)),
66 accept_missing_data(
false),
67 header_ACI(strdup(
"readdb(name)")),
101 int FilteredExport::count_bases(
const char *
seq)
const {
103 for (
int p = 0; seq[p]; ++p) {
104 count += count_table.
isSet(seq[p]);
109 char *FilteredExport::get_filtered_sequence(
GBDATA *gb_species,
const char*& reason)
const {
130 if (accept_missing_data) {
131 reason =
"has no data";
147 int count = count_bases(seq);
148 if (count<minCount) {
150 reason =
"not enough base-characters left";
156 if (seq && sequence_ACI) {
158 if (seq_postprocessed) {
159 freeset(seq, seq_postprocessed);
175 char *FilteredExport::get_fasta_header(
GBDATA *gb_species)
const {
188 gb_species && !
error;
192 char *filt_seq = get_filtered_sequence(gb_species, reason);
198 char *header = get_fasta_header(gb_species);
209 fputs(filt_seq, out);
226 if (error) progress.
done();
231 fprintf(stderr,
"Summary: %i species exported", exported);
232 if (skipped) fprintf(stderr,
", %i species skipped", skipped);
236 fprintf(stderr,
"Summary: all %i species skipped (warning: generated empty file)\n", skipped);
250 #define TEST_EXPECT_CRT_DEFINES(arg,expected) TEST_EXPECT_EQUAL(CharRangeTable(arg).expandedRange(), expected)
252 #define ABC "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
253 #define abc "abcdefghijklmnopqrstuvwxyz"
255 void TEST_CharRangeTable() {
256 TEST_EXPECT_CRT_DEFINES(
"abc",
"abc");
257 TEST_EXPECT_CRT_DEFINES(
"cba",
"abc");
258 TEST_EXPECT_CRT_DEFINES(
"c-a",
"-ac");
259 TEST_EXPECT_CRT_DEFINES(
"a-c",
"abc");
261 TEST_EXPECT_CRT_DEFINES(
"a-db-e",
"abcde");
262 TEST_EXPECT_CRT_DEFINES(
"a-de-b",
"-abcde");
264 TEST_EXPECT_CRT_DEFINES(
"-ab",
"-ab");
265 TEST_EXPECT_CRT_DEFINES(
"a-b",
"ab");
266 TEST_EXPECT_CRT_DEFINES(
"ab-",
"-ab");
268 TEST_EXPECT_CRT_DEFINES(
"a-ac-c",
"ac");
270 TEST_EXPECT_CRT_DEFINES(
"a-zA-Z", ABC abc);
273 TEST_EXPECT_CRT_DEFINES(
".-=",
"-.=");
274 TEST_EXPECT_CRT_DEFINES(
"=-.",
"-.=");
276 TEST_EXPECT_CRT_DEFINES(
"a-Z",
"-Za");
277 TEST_EXPECT_CRT_DEFINES(
"A-z",
"-Az");
283 #define TEST_EXPECT_SEQWITHLENGTH__NOERROREXPORTED(create_seqcopy, expected_length) do { \
285 TEST_EXPECT_RESULT__NOERROREXPORTED(seqcopy = create_seqcopy); \
286 TEST_EXPECT_EQUAL(strlen(seqcopy), expected_length); \
290 void TEST_FilteredExport() {
299 char *ali_name =
NULp;
312 FilteredExport exporter_incomplete(gb_main,
"ali_dna_incomplete", ali_size);
328 TEST_EXPECT_SEQWITHLENGTH__NOERROREXPORTED(exporter.get_filtered_sequence(gb_spec1, reason), ali_size);
329 TEST_EXPECT_SEQWITHLENGTH__NOERROREXPORTED(exporter.get_filtered_sequence(gb_spec2, reason), ali_size);
331 TEST_EXPECT_NORESULT__ERROREXPORTED_CONTAINS(exporter_incomplete.get_filtered_sequence(gb_spec3, reason),
"has no data in 'ali_dna_incomplete'");
334 exporter_incomplete.do_accept_missing_data();
336 TEST_EXPECT_NORESULT__NOERROREXPORTED(exporter_incomplete.get_filtered_sequence(gb_spec3, reason));
339 TEST_EXPECT_SEQWITHLENGTH__NOERROREXPORTED(exporter.get_filtered_sequence(gb_spec4, reason), ali_size);
342 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(exporter.get_fasta_header(gb_spec1),
"StrRamo3");
343 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(exporter.get_fasta_header(gb_spec2),
"MucRacem");
345 exporter.set_header_ACI(
"readdb(name);\",\";readdb(full_name)");
346 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(exporter.get_fasta_header(gb_spec3),
"BctFra12,Bacteroides fragilis");
348 exporter.set_header_ACI(
"readdb(name);\",\";readdb(ali_dna);\",\";readdb(nosuchfield);\",\";readdb(full_name)");
349 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(exporter.get_fasta_header(gb_spec4),
"CytLyti6,,,Cytophaga lytica");
351 exporter.set_header_ACI(
"readdb(name);\",\";bugme");
352 TEST_EXPECT_NORESULT__ERROREXPORTED_CONTAINS(exporter.get_fasta_header(gb_spec4),
"Unknown command 'bugme'");
355 exporter.set_required_baseCount(
"ACGT", 185);
356 TEST_EXPECT_NORESULT__NOERROREXPORTED(exporter.get_filtered_sequence(gb_spec1, reason));
358 exporter.reset_required_baseCount();
372 TEST_EXPECT_RESULT__NOERROREXPORTED(filt_blck_variab = pvp_blck_variab.make_filter(gb_main, ali_name, ali_size));
373 TEST_EXPECT_RESULT__NOERROREXPORTED(filt_pass_variab = pvp_pass_variab.make_filter(gb_main, ali_name, ali_size));
374 TEST_EXPECT_RESULT__NOERROREXPORTED(filt_blck_cnsrvd = pvp_blck_cnsrvd.make_filter(gb_main, ali_name, ali_size));
375 TEST_EXPECT_RESULT__NOERROREXPORTED(filt_pass_cnsrvd = pvp_pass_cnsrvd.make_filter(gb_main, ali_name, ali_size));
387 delete filt_pass_cnsrvd;
388 delete filt_blck_cnsrvd;
389 delete filt_pass_variab;
390 delete filt_blck_variab;
395 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(exporter.get_filtered_sequence(gb_spec1, reason),
"TCCACGCACCAAGTCCT--GGACTTTG--GACCGGGTCCCTGACG-ATG-CCGGGGACG---GACTGG--TC--GGGCCGCT-ACGG---CGCTCGGCCGCG-------GCCG-CTGGG----CCGCCGT.....");
397 exporter.clear_SAI_filters();
400 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(exporter.get_filtered_sequence(gb_spec1, reason),
"TCACCAAGTTGGGTCGACCGGGAATGGGCCAGCCCGCGCTGGCCC");
402 exporter.clear_SAI_filters();
406 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(exporter.get_filtered_sequence(gb_spec1, reason),
"CGCACCC--ACTTTG--GACCGGCCTCG-ATG-GCG---GCG--TC--GCGT-CG---CGTCGG-------GCG-CG----GCGT.....");
409 exporter.set_sequence_ACI(
":.=-");
410 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(exporter.get_filtered_sequence(gb_spec1, reason),
"CGCACCC--ACTTTG--GACCGGCCTCG-ATG-GCG---GCG--TC--GCGT-CG---CGTCGG-------GCG-CG----GCGT-----");
412 exporter.set_sequence_ACI(
":bad");
413 TEST_EXPECT_NORESULT__ERROREXPORTED_CONTAINS(exporter.get_filtered_sequence(gb_spec1, reason),
"SRT ERROR: no '=' found in command 'bad'");
GBDATA * GB_open(const char *path, const char *opent)
#define implicated(hypothesis, conclusion)
char * GB_read_as_string(GBDATA *gbd)
const char * GBS_global_string(const char *templat,...)
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
GBDATA * GBT_expect_SAI(GBDATA *gb_main, const char *name)
AP_filter * make_filter(GBDATA *gb_main, const char *aliName, size_t aliSize) const
GB_ERROR write_fasta(FILE *out)
FilteredExport(GBDATA *gb_main_, const char *aliname_, size_t alisize_)
GB_ERROR GB_export_error(const char *error)
GB_ERROR GB_await_error()
long GB_read_count(GBDATA *gbd)
char * filter_string(const char *fulllen_string) const
#define TEST_REJECT(cond)
#define TEST_REJECT_NULL(n)
static void error(const char *msg)
size_t get_length() const
FilterDefType get_type() const
bool isSet(uint8_t i) const
GBDATA * GBT_find_sequence(GBDATA *gb_species, const char *aliname)
size_t get_filtered_length() const
fputs(TRACE_PREFIX, stderr)
GB_ERROR GB_export_errorf(const char *templat,...)
#define TEST_EXPECT_NULL(n)
GB_ERROR GB_failedTo_error(const char *do_something, const char *special, GB_ERROR error)
GBDATA * GBT_first_species(GBDATA *gb_main)
GB_ERROR is_invalid() const
#define TEST_EXPECT_NO_ERROR(call)
GBDATA * GBT_next_species(GBDATA *gb_species)
GBDATA * GBT_find_species(GBDATA *gb_main, const char *name)
char * GBT_get_default_alignment(GBDATA *gb_main)
NOT4PERL char * GB_command_interpreter_in_env(const char *str, const char *commands, const GBL_call_env &callEnv)
GB_ERROR add_SAI_filter(const FilterDefinition &filterDef) __ATTR__USERESULT
long GBT_get_species_count(GBDATA *gb_main)
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
#define TEST_EXPECT_EQUAL(expr, want)
void GB_close(GBDATA *gbd)