47 char symbol2count[256];
53 if (err && !has_error()) error = err;
56 void init_bad_positions(
const char *species_list) {
57 bad_positions.clear();
62 for (
size_t i = 0; i<species.
size(); ++i) {
65 if (bad_positions.empty()) {
66 note_error(
"No species found");
70 void add_pair_position(
size_t pos,
size_t pair_pos) {
71 if (pos>pair_pos)
swap(pos, pair_pos);
73 if (paired_positions.find(pos) != paired_positions.end()) {
77 paired_positions[pos] = pair_pos;
80 void init_paired_positions(
const CharPtrArray& helices) {
81 paired_positions.clear();
83 if (helices.
size() == 1 && strcmp(helices[0],
"*") == 0) {
88 add_pair_position(pos, entry.
pair_pos);
93 for (
size_t i = 0; i<helices.
size() && !has_error(); ++i) {
102 for (
long pos = firstPos; pos<=lastPos && pos>0 && !has_error(); ) {
104 add_pair_position(pos, entry.
pair_pos);
111 if (paired_positions.empty()) {
112 note_error(
"List of helix positions to examine is empty");
116 void init_bad_symbol_table(
const char *bad_symbols) {
117 memset(symbol2count, 0, 256);
119 for (
int i = 0; bad_symbols[i]; ++i) {
120 if (bad_symbols[i] !=
' ') {
126 note_error(
"no 'bad' helix symbol defined");
130 long calculate_bad_positions(
const string& species) {
144 species.c_str(), ali.c_str()));
151 for (PairedPositions::const_iterator pp = paired_positions.begin(); pp != paired_positions.end(); ++pp) {
152 const size_t p1 = pp->first;
153 const size_t p2 = pp->second;
155 const char b1 = p1<seq_len ? sequence[p1] :
'.';
156 const char b2 = p2<seq_len ? sequence[p2] :
'.';
168 void update_bad_position_counts() {
169 for (BadPositionsForSpecies::iterator bp = bad_positions.begin(); bp != bad_positions.end(); ++bp) {
171 bp->second = calculate_bad_positions(bp->first);
178 const char *species_list,
180 const char *bad_symbols)
186 init_bad_positions(species_list);
187 init_paired_positions(helices);
188 init_bad_symbol_table(bad_symbols);
199 update_bad_position_counts();
200 return bad_positions;
215 long b1 = bad_pos.find(s1)->second;
216 long b2 = bad_pos.find(s2)->second;
218 if (!cmp) cmp = s1.compare(s2);
228 for (BadPositionsForSpeciesConst::const_iterator
s = bad_pos.begin();
s != bad_pos.end(); ++
s) {
229 long badCount =
long(
s->second);
230 if (badCount>0) result.push_back(
s->first);
240 for (
size_t i = 0; i<list_entries.
size(); ++i) {
241 const char *entry = list_entries[i];
242 if (strcmp(entry,
"*") == 0) {
243 result_helices.
erase();
244 result_helices.put(strdup(
"*"));
248 const char *minus = strchr(entry,
'-');
250 int h1 = atoi(entry);
251 int h2 = atoi(minus+1);
253 if (h1>h2)
swap(h1, h2);
255 for (
int h = h1; h<=h2; ++h) {
260 result_helices.put(strdup(entry));
266 #define StrArray_FROM_HELIXLIST(varname, helixlist) StrArray varname; parse_helix_list(varname, helixlist)
282 for (StringVector::const_iterator
s = sortedSpecies.begin();
s != sortedSpecies.end(); ++
s) {
283 const string& species = *
s;
284 long badCount = bad_pos.find(species)->second;
285 result.
ncat(species.c_str(), species.length());
297 void TEST_count_bad_ali_positions() {
300 AW_root aw_root(
"min_ascii.arb", UNITTEST_MOCK);
306 helix.init(gb_main, ali);
308 char *marked_species;
353 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(BadPositionsToString(marked_quality.results()),
"CorGluta=3,CorAquat=1,CytAquat=1");
354 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(BadPositionsToString(all_quality.results()),
"CloTyro3=7,CytAquat=7,CloInnoc=3,CorGluta=3,CloBifer=1,CloCarni=1,CloPaste=1,CloTyro2=1,CloTyro4=1,CloTyrob=1,CorAquat=1");
355 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(BadPositionsToString(all2_quality.results()),
"CloTyro3=10,CytAquat=8,CloTyro2=7,CloTyro4=7,CloTyrob=7,CorGluta=4,CloInnoc=3,CloBifer=2,CloButy2=1,CloButyr=1,CloCarni=1,CloPaste=1,CorAquat=1");
356 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(BadPositionsToString(all3_quality.results()),
"CloTyro3=10,CytAquat=8,CloTyro2=7,CloTyro4=7,CloTyrob=7,CorGluta=4,CloInnoc=3,CloBifer=2,CloButy2=1,CloButyr=1,CloCarni=1,CloPaste=1,CorAquat=1");
357 TEST_EXPECT_EQUAL_STRINGCOPY__NOERROREXPORTED(BadPositionsToString(all4_quality.results()),
"CytAquat=6,CloTyro3=5,CloInnoc=2,CloTyro2=2,CloTyro4=2,CloTyrob=2,CloBifer=1");
384 free(marked_species);
395 #define AWAR_BADALI_BASE "badali/"
396 #define AWAR_BADALI_HELIXLIST AWAR_BADALI_BASE "helixlist" // helix-numbers (comma-separated)
397 #define AWAR_BADALI_SYMBOLS AWAR_BADALI_BASE "symbols" // helix-symbols which count as "bad"
399 #define AWAR_BADALI_TEMP "tmp/" AWAR_BADALI_BASE
400 #define AWAR_BADALI_SPECIES AWAR_BADALI_TEMP "selected" // selected species
401 #define AWAR_BADALI_FIELD AWAR_BADALI_TEMP "field" // name of field to store bad positions
414 ED4_species_manager *species_manager = base->to_species_manager();
415 ED4_species_name_terminal *species_name_terminal = species_manager->search_spec_child_rek(
LEV_SPECIES_NAME)->to_species_name_terminal();
417 if (species_name_terminal->get_species_pointer() && !species_manager->is_SAI_manager()) {
418 char *species_name =
GB_read_as_string(species_name_terminal->get_species_pointer());
419 species->put(species_name);
442 const char *target_field;
470 if (!quality.has_error()) {
472 if (!quality.has_error()) {
473 const bool writeToField = target_field;
479 for (BadPositionsForSpeciesConst::const_iterator bp = bad_pos.begin(); bp != bad_pos.end() && !
error; ++bp) {
480 const char* species_name = bp->first.c_str();
481 long bad_positions = bp->second;
500 for (StringVector::const_iterator species = order.begin(); species != order.end(); ++species) {
501 const char *species_name = species->c_str();
502 size_t bad = bad_pos.find(*species)->second;
510 if (quality.has_error()) {
532 int current_helixnr = atoi(awar_helixnr->read_char_pntr());
533 int wanted_helixnr = 0;
534 int preference = current_helixnr>0 ? 1 : -1;
536 if (current_helixnr == 0) {
537 wanted_helixnr = atoi(helices[0]);
541 wanted_helixnr =
abs(current_helixnr);
544 wanted_helixnr = atoi(helices[0]);
545 for (
size_t i = 0; i<helices.size()-1; ++i) {
546 if (
abs(current_helixnr) ==
abs(atoi(helices[i]))) {
547 wanted_helixnr = atoi(helices[i+1]);
553 wanted_helixnr *= preference;
555 if (wanted_helixnr != 0) {
556 if (wanted_helixnr != current_helixnr || called ==
BY_BUTTON) {
570 static bool in_callback =
false;
579 swap(source_awar_name, dest_awar_name);
583 if (selected_species[0]) {
593 static AW_window_simple *aws =
NULp;
600 aws =
new AW_window_simple;
602 aws->init(aw_root,
"DETECT_BAD_ALI",
"Detect bad helix alignment");
603 aws->load_xfig(
"edit4/detect_bad_ali.fig");
605 aws->button_length(10);
609 aws->create_button(
"CLOSE",
"CLOSE",
"C");
613 aws->create_button(
"HELP",
"HELP",
"H");
621 aws->auto_space(5, 5);
622 aws->label_length(20);
624 aws->label(
"Helices to examine\n"
625 "(comma-separated list)");
629 aws->create_autosize_button(
"JUMP",
"Jump",
"J");
633 aws->label(
"Detected symbols");
636 aws->callback(*helixSettings_cb);
637 aws->create_autosize_button(
"HELIX_SETTINGS",
"Helix settings",
"H");
640 aws->label(
"Write to database field");
645 aws->create_button(
"CALCULATE",
"Calculate",
"C");
vector< string > StringVector
static void calc_and_update_alignment_errors_cb(AW_window *aww, AW_selection_list *sellst)
BadPositionsOrder(BadPositionsForSpeciesConst bad_pos_)
map< string, long > BadPositionsForSpecies
GBDATA * GB_open(const char *path, const char *opent)
void cut_tail(size_t byte_count)
AW_awar * set_srt(const char *srt)
const BI_helix_entry & entry(size_t pos) const
CONSTEXPR_INLINE unsigned char safeCharIndex(char c)
void insert_default(const char *displayed, const AW_scalar &value)
long GBT_mark_all(GBDATA *gb_main, int flag)
map< size_t, size_t > PairedPositions
BadPositionsForSpeciesConst results()
const long NOT_CALCULATED
static void selected_changed_cb(AW_root *aw_root, SelectedAwar whatChanged)
char * GB_read_as_string(GBDATA *gbd)
static void getSpeciesSortedByBadPositions(BadPositionsForSpeciesConst &bad_pos, StringVector &result)
long first_position(const char *helixNr) const
const char * GBS_global_string(const char *templat,...)
int is_species_manager() const
void AW_POPDOWN(AW_window *window)
AW_awar * add_callback(const RootCallback &cb)
void insert(const char *displayed, const AW_scalar &value)
void create_itemfield_selection_button(AW_window *aws, const FieldSelDef &selDef, const char *at)
long last_position(const char *helixNr) const
const char * read_char_pntr() const
#define AWAR_BADALI_SYMBOLS
size_t GB_read_string_count(GBDATA *gbd)
GB_ERROR GB_await_error()
WindowCallback makeHelpCallback(const char *helpfile)
static char * create_list_of_loaded_species()
static void parse_helix_list(StrArray &result_helices, const char *helix_list)
#define StrArray_FROM_HELIXLIST(varname, helixlist)
GBDATA * get_gb_main() const
long first_pair_position() const
static GB_ERROR get_error()
static ARB_ERROR add_species_to_list_cb(ED4_base *base, StrArray *species)
const BadPositionsForSpecies BadPositionsForSpeciesConst
static void error(const char *msg)
CONSTEXPR_INLINE_Cxx14 void swap(unsigned char &c1, unsigned char &c2)
ASSERTING_CONSTEXPR_INLINE int info2bio(int infopos)
GB_ERROR GB_write_lossless_int(GBDATA *gbd, int32_t i)
ED4_root_group_manager * root_group_man
long next_pair_position(size_t pos) const
#define AWAR_SPECIES_NAME
ARB_ERROR route_down_hierarchy(const ED4_route_cb &cb) FINAL_OVERRIDE
const char * prepare_and_get_selected_itemfield(AW_root *awr, const char *awar_name, GBDATA *gb_main, const ItemSelector &itemtype, FailIfField failIf)
GBDATA * GBT_find_species_rel_species_data(GBDATA *gb_species_data, const char *name)
GB_ERROR get_error() const
char * read_string() const
AW_awar * awar(const char *awar)
void ED4_popup_detect_bad_alignment_window(AW_window *editor_window, const WindowCallback *helixSettings_cb)
GBDATA * GBT_find_sequence(GBDATA *gb_species, const char *aliname)
void ED4_create_detect_bad_alignment_awars(AW_root *aw_root, AW_default aw_def)
char get_symbol(char left, char right) const
GBDATA * GBT_searchOrCreate_itemfield_according_to_changekey(GBDATA *gb_item, const char *field_name, const char *change_key_path)
char * GBT_join_strings(const CharPtrArray &strings, char separator)
void ncat(const char *from, size_t count)
static void jump_to_next_helix_cb(AW_window *, JumpWhy called)
#define AWAR_BADALI_HELIXLIST
char awar_path_for_helixNr[50]
const char * get_alignment_name() const
ED4_window * current_ed4w()
ItemSelector & SPECIES_get_selector()
#define TEST_EXPECT_NO_ERROR(call)
void aw_message(const char *msg)
void ED4_set_helixnr(AW_window *aww, const char *awar_name)
#define AWAR_BADALI_FIELD
GBDATA * GBT_find_species(GBDATA *gb_main, const char *name)
#define TEST_EXPECT_ERROR_CONTAINS(call, part)
GB_ERROR write_string(const char *aw_string)
void GBT_split_string(ConstStrArray &dest, const char *namelist, const char *separator, SplitMode mode)
char * GBT_get_default_alignment(GBDATA *gb_main)
char * GBT_store_marked_species(GBDATA *gb_main, bool unmark_all)
CONSTEXPR long FIELD_FILTER_INT_WRITEABLE
HelixAlignmentQuality(GBDATA *gb_main_, const AW_helix &helix_, const char *ali_, const char *species_list, const CharPtrArray &helices, const char *bad_symbols)
AW_window_menu_modes * aww
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
bool operator()(const string &s1, const string &s2) const
#define AWAR_BADALI_SPECIES
#define TEST_EXPECT_EQUAL(expr, want)
void aw_message_if(GB_ERROR error)
char * GBS_global_string_copy(const char *templat,...)
void GB_close(GBDATA *gbd)
GBDATA * GBT_get_species_data(GBDATA *gb_main)
GB_write_int const char s