26 #define SRT_AWARCOLSTAT_NAME "/name=/name"
27 #define SRT_AWARCOLSTAT_ALIGNMENT "/name=/alignment"
28 #define SRT_AWARCOLSTAT_SMOOTH "/name=/smooth"
29 #define SRT_AWARCOLSTAT_ENABLE_HELIX "/name=/enable_helix"
65 memset(frequency, 0,
ARRAY_ELEMS(frequency)*
sizeof(*frequency));
72 ga_assert(strcmp(awar_name, awar_alignment) != 0);
84 delete [] weights; weights =
NULp;
85 delete [] rates; rates =
NULp;
86 delete [] ttratio; ttratio =
NULp;
87 delete [] is_helix; is_helix =
NULp;
88 delete [] mut_sum; mut_sum =
NULp;
89 delete [] freq_sum; freq_sum =
NULp;
90 delete desc; desc =
NULp;
92 for (
int i=0; i<256; i++) {
93 delete [] frequency[i];
102 delete awar_alignment;
104 delete awar_enable_helix;
112 size_t alignment_length = 0;
116 if (alignment_length_l<=0) {
119 else if (alignment_length_l == 1) {
123 alignment_length = alignment_length_l;
124 if (filter && filter->
get_length() != alignment_length) {
125 error =
GBS_global_string(
"Incompatible filter (filter=%zu bp, alignment=%zu bp)",
137 if (strcmp(sai_name,
"") != 0) {
146 gb_ali =
GB_entry(gb_sai, alignment_name);
147 if (!gb_ali) error =
GBS_global_string(
"SAI '%s' does not exist in alignment '%s'", sai_name, alignment_name);
150 gb_freqs =
GB_entry(gb_ali,
"FREQUENCIES");
151 if (!gb_freqs) error =
GBS_global_string(
"Column statistic '%s' is invalid (has no FREQUENCIES)", sai_name);
157 delete [] weights; weights =
new GB_UINT4[seq_len];
158 delete [] rates; rates =
new float[seq_len];
159 delete [] ttratio; ttratio =
new float[seq_len];
160 delete [] is_helix; is_helix =
new bool[seq_len];
161 delete [] mut_sum; mut_sum =
new GB_UINT4[seq_len];
162 delete [] freq_sum; freq_sum =
new GB_UINT4[seq_len];
164 delete desc; desc =
NULp;
168 for (i=0; i<256; i++) {
delete frequency[i]; frequency[i]=
NULp; }
170 long use_helix = awr->
awar(awar_enable_helix)->
read_int();
172 for (i=0; i<seq_len; i++) {
177 if (!error && use_helix) {
179 error = helix.
init(this->gb_main, alignment_name);
186 for (j=i=0; i<alignment_length; i++) {
202 for (i=0; i<seq_len; i++) freq_sum[i] = 0;
206 for (i=0; i<256; i++) freqi[i] =
NULp;
211 if (key[0] ==
'N' && key[1] && !key[2]) {
223 if (!gb_minmut) error =
GBS_global_string(
"Column statistic '%s' is invalid (has no FREQUENCIES/TRANSITIONS)", sai_name);
224 if (!gb_transver) error =
GBS_global_string(
"Column statistic '%s' is invalid (has no FREQUENCIES/TRANSVERSIONS)", sai_name);
232 if (!transver) error =
GBS_global_string(
"Column statistic '%s' is invalid (error reading FREQUENCIES/TRANSVERSIONS: %s)", sai_name,
GB_await_error());
236 unsigned long max_freq_sum = 0;
237 for (wf = 0; wf<256; wf++) {
238 if (!freqi[wf])
continue;
239 for (j=i=0; i<alignment_length; i++) {
241 freq_sum[j] += freqi[wf][i];
242 mut_sum[j] = minmut[i];
246 for (i=0; i<seq_len; i++)
247 if (freq_sum[i] > max_freq_sum)
248 max_freq_sum = freq_sum[i];
249 unsigned long min_freq_sum =
DIST_MIN_SEQ(max_freq_sum);
251 for (wf = 0; wf<256; wf++) {
252 if (!freqi[wf])
continue;
253 frequency[wf] =
new float[seq_len];
254 for (j=i=0; i<alignment_length; i++) {
256 if (freq_sum[j] > min_freq_sum) {
257 frequency[wf][j] = freqi[wf][i]/(float)freq_sum[j];
260 frequency[wf][j] = 0;
267 for (j=i=0; i<alignment_length; i++) {
275 rates[j] = (mut_sum[j] / (float)freq_sum[j]);
276 if (transver[i] > 0) {
277 ttratio[j] = (minmut[i] - transver[i]) / (
float)transver[i];
282 if (ttratio[j] < 0.05) ttratio[j] = 0.05;
283 if (ttratio[j] > 5.0) ttratio[j] = 5.0;
289 double sum_rates = 0;
290 for (i=0; i<seq_len; i++) sum_rates += rates[i];
291 sum_rates /= seq_len;
292 for (i=0; i<seq_len; i++) rates[i] /= sum_rates;
297 for (i=0; i<256; i++) free(freqi[i]);
307 for (
size_t i = 0; i<seq_len; ++i) {
308 if (rates[i]>0.0000001) {
309 weights[i] *= (
int)(2.0 / rates[i]);
318 double sum_rates[2] = { 0.0, 0.0 };
319 double sum_tt[2] = { 0.0, 0.0 };
320 long count[2] = { 0, 0 };
322 for (
unsigned j=0; j<seq_len; j++) {
324 fputc(
".#"[is_helix[j]], stdout);
325 printf(
"%u: minmut %5i freqs %5i rates %5f tt %5f ",
326 j, mut_sum[j], freq_sum[j], rates[j], ttratio[j]);
327 for (
int wf = 0; wf<256; wf++) {
328 if (frequency[wf]) printf(
"%c:%5f ", wf, frequency[wf][j]);
330 sum_rates[is_helix[j]] += rates[j];
331 sum_tt[is_helix[j]] += ttratio[j];
332 count[is_helix[j]]++;
333 printf(
"w: %i\n", weights[j]);
336 printf(
"Helical Rates %5f Non Hel. Rates %5f\n",
337 sum_rates[1]/count[1], sum_rates[0]/count[0]);
338 printf(
"Helical TT %5f Non Hel. TT %5f\n",
339 sum_tt[1]/count[1], sum_tt[0]/count[0]);
378 AW_window_simple *aws =
new AW_window_simple;
379 aws->init(aw_root,
"SELECT_CSP",
"Select Column Statistic");
380 aws->load_xfig(
"awt/col_statistic.fig");
384 aws->create_button(
"CLOSE",
"CLOSE",
"C");
387 aws->create_button(
"HELP",
"HELP",
"H");
394 aws->insert_toggle(
"Calculate each column (nearly) independently",
"D", 0);
395 aws->insert_toggle(
"Smooth parameter estimates a little",
"M", 1);
396 aws->insert_toggle(
"Smooth parameter estimates across columns",
"S", 2);
397 aws->update_toggle_field();
400 aws->label(
"Use Helix Information (SAI 'HELIX')");
const char * get_awar_smooth() const
bool is_pairpos(size_t pos) const
AW_DB_selection * awt_create_SAI_selection_list(GBDATA *gb_main, AW_window *aws, const char *varname, const SaiSelectionlistFilterCallback &fcb)
char * GB_read_key(GBDATA *gbd)
GBDATA * GB_child(GBDATA *father)
const char * get_type_path() const
GB_ERROR GB_append_exportedError(GB_ERROR error)
AW_window * COLSTAT_create_selection_window(AW_root *aw_root, ColumnStat *column_stat)
const char * get_awar_enable_helix() const
void COLSTAT_create_selection_list(AW_window *aws, ColumnStat *column_stat)
const char * GBS_global_string(const char *templat,...)
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
static char * alignment_name
char * GBS_string_eval(const char *insource, const char *icommand)
void AW_POPDOWN(AW_window *window)
#define SRT_AWARCOLSTAT_ENABLE_HELIX
void cat(const char *from)
#define SRT_AWARCOLSTAT_ALIGNMENT
#define ARRAY_ELEMS(array)
AW_awar * add_callback(const RootCallback &cb)
ColumnStat(GBDATA *gb_main_, AW_root *awr_, const char *awar_template, AW_awar *awar_used_alignment)
GBDATA * GBT_find_SAI(GBDATA *gb_main, const char *name)
void refresh_sai_selection_list()
GB_ERROR GB_await_error()
WindowCallback makeHelpCallback(const char *helpfile)
void create_sai_selection_list(AW_window *aww)
static int weights[MAX_BASETYPES][MAX_BASETYPES]
static void error(const char *msg)
#define SRT_AWARCOLSTAT_NAME
size_t get_length() const
__ATTR__USERESULT GB_ERROR calculate(AP_filter *filter)
GB_UINT4 * GB_read_ints(GBDATA *gbd)
char * read_string() const
AW_awar * awar(const char *awar)
bool has_valid_alignment() const
size_t get_filtered_length() const
GBDATA * get_gb_main() const
#define DIST_MIN_SEQ(seq_anz)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
AW_awar * map(const char *awarn)
GB_ERROR is_invalid() const
static char * filter_columnstat_SAIs(GBDATA *gb_extended, ColumnStat *column_stat)
void aw_message(const char *msg)
#define SRT_AWARCOLSTAT_SMOOTH
void weight_by_inverseRates() const
GBDATA * GB_nextChild(GBDATA *child)
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 GBS_string_matches(const char *str, const char *expr, GB_CASE case_sens)
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
bool use_position(size_t pos) const
GB_ERROR init(GBDATA *gb_main)
GBDATA * GB_entry(GBDATA *father, const char *key)
static void refresh_columnstat_selection(AW_root *, ColumnStat *column_stat)