36 if (!alignment_name) {
41 if (alignment_len<=0) {
48 const int MAXLETTER = 256;
49 const int FIRSTLETTER = 0;
51 typedef bool letterOccurs[MAXLETTER];
53 letterOccurs *occurs = ARB_alloc<letterOccurs>(alignment_len);
54 for (
int i = 0; i<MAXLETTER; ++i) {
55 for (
int p = 0; p<alignment_len; ++p) {
63 arb_progress progress(
"Counting different characters", all_marked);
75 for (
int i=0; i< alignment_len; ++i) {
76 unsigned char c = seq[i];
79 occurs[i][c-FIRSTLETTER] =
true;
91 if (is_amino)
for (
int c = 0; c<256; ++c) filter[c] = isupper(c) && !strchr(
"BJOUZ", c);
92 else for (
int c = 0; c<256; ++c) filter[c] =
bool(strchr(
"ACGTU", c));
94 char result[alignment_len+1];
95 for (
int i=0; i<alignment_len; i++) {
97 for (
int c =
'A'; c <
'Z'; ++c) {
99 sum += (occurs[i][c] || occurs[i][tolower(c)]);
102 result[i] = sum<10 ?
'0'+sum :
'A'-10+sum;
104 result[alignment_len] = 0;
120 free(alignment_name);
151 char *sai_name =
NULp;
152 char *sec_struct =
NULp;
153 bool canceled =
false;
159 error =
"Please select a species first.";
163 GBDATA *gb_species_sec_struct =
GB_entry(gb_species,
"sec_struct");
164 if (!gb_species_sec_struct) {
165 error =
"Field \"sec_struct\" not found or empty. Please select another species.";
168 error =
"Couldn't read field \"sec_struct\". Is it empty?";
173 char *sai_default_name =
GBS_global_string_copy(
"%s%s", species_name, strstr(species_name,
"_pfold") ?
"" :
"_pfold");
174 sai_name =
aw_input(
"Name of SAI to create:", sai_default_name);
175 free(sai_default_name);
181 else if (strspn(sai_name,
" ") == strlen(sai_name)) {
182 error =
"Name of SAI is empty. Please enter a valid name.";
189 error =
"SAI with the same name already exists. Please enter another name.";
201 while (gb_species_field && !error) {
205 if (strcmp(key,
"name") == 0) {
208 else if (strcmp(key,
"sec_struct") == 0) {
213 else if (strcmp(key,
"acc") != 0 && strcmp(key, ali_name) != 0) {
229 if (gb_sai_sec_struct)
GB_delete(gb_sai_sec_struct);
239 if (canceled) error =
"Aborted by user";
260 const char *species_name =
"";
270 if (!error && gbd && type ==
ADMVT_WWW) {
294 TEST_EXPECT_RESULT__NOERROREXPORTED(gb_sai =
GBT_expect_SAI(gb_main, SAI_COUNTED_CHARS));
295 TEST_EXPECT_RESULT__NOERROREXPORTED(gb_ali =
GB_entry(gb_sai, ali_name));
296 TEST_EXPECT_RESULT__NOERROREXPORTED(gb_counted_chars =
GB_entry(gb_ali,
"data"));
305 void TEST_count_chars() {
311 for (
int prot = 0; prot<2; ++prot) {
313 TEST_EXPECT_RESULT__NOERROREXPORTED(gb_main =
GB_open(prot ?
"TEST_prot.arb" :
"TEST_nuc.arb",
"rw"));
318 uint32_t expected = prot ? 0x9cad14cc : 0xefb05e4e;
324 void TEST_SLOW_count_chars() {
332 arb_unit_test::test_alignment_data data_source[] = {
334 { 1,
"s2",
"ACGTN" },
335 { 1,
"s3",
"NANNAN" },
336 { 1,
"s4",
"GATTACA" },
339 const int alilen = 50000;
342 char *longSeq[count];
343 for (
int c = 0; c<count; ++c) {
344 char *dest = longSeq[c] = ARB_alloc<char>(alilen+1);
346 const char *source = data_source[c].data;
347 int len = strlen(source);
349 for (
int p = 0; p<alilen; ++p) {
350 dest[p] = source[p%len];
354 data_source[c].data = dest;
358 GBDATA *gb_main = TEST_CREATE_DB(error,
"ali_test", data_source,
false);
368 for (
int c = 0; c<count; ++c) {
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)
void launch_MapViewer_cb(GBDATA *gbd, AD_MAP_VIEWER_TYPE type)
GBDATA * GBT_first_marked_species(GBDATA *gb_main)
char * GB_read_key(GBDATA *gbd)
GBDATA * GB_child(GBDATA *father)
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
long GBT_mark_all(GBDATA *gb_main, int flag)
AW_window * NT_create_extendeds_window(AW_root *aw_root)
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
void GB_end_transaction_show_error(GBDATA *gbd, GB_ERROR error, void(*error_handler)(GB_ERROR))
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
static char * alignment_name
GBDATA * GBT_expect_SAI(GBDATA *gb_main, const char *name)
bool GBT_is_alignment_protein(GBDATA *gb_main, const char *alignment_name)
#define ARRAY_ELEMS(array)
GBDATA * GB_get_father(GBDATA *gbd)
GB_ERROR GB_push_transaction(GBDATA *gbd)
GB_ERROR GB_delete(GBDATA *&source)
NOT4PERL GBDATA * GBT_add_data(GBDATA *species, const char *ali_name, const char *key, GB_TYPES type) __ATTR__DEPRECATED_TODO("better use GBT_create_sequence_data()")
GB_ERROR GB_await_error()
static AW_root * SINGLETON
GBDATA * GB_create_container(GBDATA *father, const char *key)
GB_TYPES GB_read_type(GBDATA *gbd)
void NT_create_sai_from_pfold(AW_window *aww)
static void error(const char *msg)
GBDATA * GBT_next_marked_species(GBDATA *gb_species)
void NT_count_different_chars(AW_window *, GBDATA *gb_main)
#define AWAR_SPECIES_NAME
GB_ERROR awt_openDefaultURL_with_item(AW_root *aw_root, GBDATA *gb_main, GBDATA *gb_item)
char * read_string() const
AW_awar * awar(const char *awar)
long GBT_count_marked_species(GBDATA *gb_main)
GB_ERROR GBT_write_string(GBDATA *gb_container, const char *fieldpath, const char *content)
char * GB_read_string(GBDATA *gbd)
GBDATA * GBT_gen_accession_number(GBDATA *gb_species, const char *ali_name)
uint32_t GBS_checksum(const char *seq, int ignore_case, const char *exclude)
#define TEST_EXPECT_NO_ERROR(call)
void aw_message(const char *msg)
GBDATA * GBT_find_species(GBDATA *gb_main, const char *name)
GB_ERROR write_string(const char *aw_string)
char * GBT_get_default_alignment(GBDATA *gb_main)
GBDATA * GBT_find_SAI_rel_SAI_data(GBDATA *gb_sai_data, const char *name)
GBDATA * GB_nextChild(GBDATA *child)
GBDATA * GBT_find_or_create_SAI(GBDATA *gb_main, const char *name)
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
GBDATA * GBT_get_SAI_data(GBDATA *gb_main)
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
char * aw_input(const char *title, const char *prompt, const char *default_input)
static const char *const SAI_COUNTED_CHARS
#define TEST_EXPECT_EQUAL(expr, want)
GBDATA * GB_entry(GBDATA *father, const char *key)
void inc_and_check_user_abort(GB_ERROR &error)
char * GBS_global_string_copy(const char *templat,...)
void GB_close(GBDATA *gbd)
GBDATA * GBT_get_species_data(GBDATA *gb_main)