27 #define AWAR_CS2GP "tmp/ntree/colstat_2_gnuplot"
29 #define AWAR_CS2GP_NAME AWAR_CS2GP "/name"
30 #define AWAR_CS2GP_SUFFIX AWAR_CS2GP "/filter"
31 #define AWAR_CS2GP_DIRECTORY AWAR_CS2GP "/directory"
32 #define AWAR_CS2GP_FILENAME AWAR_CS2GP "/file_name"
34 #define AWAR_CS2GP_SMOOTH_VALUES AWAR_CS2GP "/smooth_values"
35 #define AWAR_CS2GP_SMOOTH_GNUPLOT AWAR_CS2GP "/smooth_gnuplot"
36 #define AWAR_CS2GP_GNUPLOT_OVERLAY_PREFIX AWAR_CS2GP "/gnuplot_overlay_prefix"
37 #define AWAR_CS2GP_GNUPLOT_OVERLAY_POSTFIX AWAR_CS2GP "/gnuplot_overlay_postfix"
38 #define AWAR_CS2GP_FILTER_NAME AWAR_CS2GP "/ap_filter/name"
47 *name_prefixPtr =
NULp;
48 *name_postfixPtr =
NULp;
50 const char *lslash = strrchr(fname,
'/');
54 dir[lslash-fname] = 0;
57 char *name_postfix =
NULp;
58 char *ldot = strrchr(name_prefix,
'.');
64 if (!ldot || name_prefix[0] == 0) freedup(name_prefix,
"*");
65 if (!name_postfix || name_postfix[0] == 0) freedup(name_postfix,
"*_gnu");
71 *name_prefixPtr = name_prefix;
72 *name_postfixPtr = name_postfix;
83 char *dir, *name_prefix, *name_postfix;
86 char *found_files =
NULp;
88 char *found_prefix_files =
NULp;
89 char *found_postfix_files =
NULp;
91 if (overlay_prefix || overlay_postfix) {
102 if (overlay_postfix) {
111 if (found_prefix_files) {
112 if (found_postfix_files) {
116 found_files = found_prefix_files;
117 found_prefix_files =
NULp;
121 found_files = found_postfix_files;
122 found_postfix_files =
NULp;
126 free(found_postfix_files);
127 free(found_prefix_files);
177 "Most frequent base",
180 "Least frequent base",
190 if (strcmp(type, plotTypeName[pt]) == 0) {
199 const char *rslash = strrchr(fname,
'/');
200 if (rslash) rslash++;
204 char *rdot = strrchr(name,
'.');
250 for (
int i = 0; i<4; ++i) {
251 freq[i] =
new float[len];
252 for (
size_t p = 0; p<len; ++p) freq[i][p] = 0.0;
255 for (
unsigned int c = 0; c<256; ++c) {
258 for (
size_t p = 0; p<len; ++p) {
259 if (freq[3][p] < cfreq[p]) {
260 freq[3][p] = cfreq[p];
262 for (
int i = 3; i > 0; --i) {
263 if (freq[i-1][p] >= freq[i][p])
break;
265 float f = freq[i][p];
266 freq[i][p] = freq[i-1][p];
275 for (
size_t p = 0; p<len; ++p) {
283 for (
int i = 0; i<4; ++i)
delete [] freq[i];
295 size_t wrap(
size_t idx) {
return idx >= size ? idx-size : idx; }
299 : size(smooth_range),
307 value =
new double[size];
308 index =
new size_t[size];
310 for (
size_t i = 0; i<size; ++i) value[i] = 0.0;
317 void print(FILE *out,
size_t i,
double v) {
318 sum = sum+v-value[next];
325 if (added<size) ++added;
327 size_t printNext = wrap(next+halfsize);
328 fprintf(out,
"%zu %f\n", index[printNext], sum/size);
345 filterdef(filterdef_)
360 if (alignment_length<=0) {
362 error =
"Please select a valid alignment";
365 AP_filter filter(filterstring,
"0", alignment_length);
369 if (!error && !column_stat->
get_length()) error =
"Please select column statistic";
372 free(alignment_name);
380 if (strlen(fname) < 1) error =
"Please enter file name";
387 for (
char *name = strtok(found_files,
"*"); name; name = strtok(
NULp,
"*")) {
388 printf(
"Deleting gnuplot file '%s'\n", name);
389 if (unlink(name) != 0) printf(
"Can't delete '%s'\n", name);
399 out = fopen(fname,
"w");
416 } stat_type = STAT_UNKNOWN;
424 const float *floatVals;
425 const bool *boolVals;
429 data.amount.A =
NULp;
430 data.amount.C =
NULp;
431 data.amount.G =
NULp;
432 data.amount.TU =
NULp;
442 stat_type = STAT_AMOUNT;
451 stat_type = STAT_SIMPLE_FLOAT;
452 data.floatVals = column_stat->
get_rates();
456 stat_type = STAT_SIMPLE_FLOAT;
461 stat_type = STAT_SIMPLE_BOOL;
469 stat_type = STAT_SORT;
475 error =
"Please select what to plot";
484 for (
size_t j=0; j<columns; ++j) {
485 if (!weights[j])
continue;
490 float A = data.amount.A[j];
491 float C = data.amount.C[j];
492 float G = data.amount.G[j];
493 float TU = data.amount.TU[j];
495 float amount = A+C+G+TU;
509 case STAT_SIMPLE_FLOAT: val = data.floatVals[j];
break;
510 case STAT_SIMPLE_BOOL: val = data.boolVals[j];
break;
511 case STAT_SORT: val = data.sorted->get(plot_type, j);
break;
516 smoother.
print(out, j, val);
520 if (stat_type == STAT_SORT)
delete data.sorted;
542 fprintf(out,
"set samples 1000\n");
544 bool plotted =
false;
545 const char *plot_command[] = {
"plot",
"replot" };
548 for (
char *name = strtok(found_files,
"*"); name; name = strtok(
NULp,
"*")) {
549 if (strcmp(name, fname) != 0) {
550 fprintf(out,
"%s \"%s\" %s title \"%s\"\n", plot_command[
int(plotted)], name, smooth,
makeTitle(name));
557 fprintf(out,
"%s \"%s\" %s title \"%s\"\n", plot_command[
int(plotted)], fname, smooth,
makeTitle(fname));
558 fprintf(out,
"pause mouse any \"Any key or button will terminate gnuplot\"\n");
583 smooth_max = INT_MAX;
595 AW_window_simple *aws =
new AW_window_simple;
597 aws->init(root,
"EXPORT_CSP_TO_GNUPLOT",
"Export Column statistic to GnuPlot");
598 aws->load_xfig(
"cpro/csp_2_gnuplot.fig");
609 aws->create_button(
"CLOSE",
"CLOSE",
"C");
612 aws->create_button(
"HELP",
"HELP",
"H");
622 plotTypeList->
insert(plotTypeDescription[pt], plotTypeName[pt]);
635 aws->at(
"ap_filter");
644 aws->insert_default_toggle(
"None",
"N",
"");
645 aws->insert_toggle(
"Unique",
"U",
"smooth unique");
646 aws->insert_toggle(
"CSpline",
"S",
"smooth cspline");
647 aws->insert_toggle(
"Bezier",
"B",
"smooth bezier");
648 aws->update_toggle_field();
650 aws->auto_space(10, 10);
651 aws->button_length(13);
657 aws->create_button(
"SAVE",
"Save");
661 aws->create_button(
"SAVE_AND_VIEW",
"Save & View");
664 aws->label(
"Overlay statistics with same prefix?");
668 aws->label(
"Overlay statistics with same postfix?");
671 aws->at(
"del_overlays");
673 aws->create_autosize_button(
"DEL_OVERLAYS",
"Delete currently overlayed files",
"D", 2);
void awt_create_filter_awars(AW_root *aw_root, AW_default aw_def, const char *awar_filtername, const char *awar_mapto_alignment)
#define AWAR_CS2GP_FILTER_NAME
const float * get_frequencies(unsigned char c) const
static GB_ERROR split_stat_filename(const char *fname, char **dirPtr, char **name_prefixPtr, char **name_postfixPtr)
void insert_default(const char *displayed, const AW_scalar &value)
char * GB_find_all_files(const char *dir, const char *mask, bool filename_only)
void AW_create_standard_fileselection(AW_window *aws, const char *awar_prefix)
#define AWAR_CS2GP_DIRECTORY
static PlotType string2PlotType(const char *type)
char * ARB_strdup(const char *str)
#define AWAR_DEFAULT_ALIGNMENT
static void colstat_2_gnuplot_cb(AW_window *aww, PlotParam *param, PlotMode mode)
Smoother(size_t smooth_range)
AW_awar * set_minmax(float min, float max)
void COLSTAT_create_selection_list(AW_window *aws, ColumnStat *column_stat)
long GBT_get_alignment_len(GBDATA *gb_main, const char *aliname)
static char * alignment_name
void AW_POPDOWN(AW_window *window)
GB_ERROR ARB_system(const char *cmd, XCmdType boundExectype)
AW_awar * add_callback(const RootCallback &cb)
void insert(const char *displayed, const AW_scalar &value)
const char * read_char_pntr() const
GB_ERROR GB_await_error()
WindowCallback makeHelpCallback(const char *helpfile)
const float * get_rates() const
const float * get_ttratio() const
#define AWAR_CS2GP_SMOOTH_VALUES
static int weights[MAX_BASETYPES][MAX_BASETYPES]
static void error(const char *msg)
FILE * GB_fopen_tempfile(const char *filename, const char *fmode, char **res_fullname)
void AW_create_fileselection_awars(AW_root *awr, const char *awar_base, const char *directories, const char *filter, const char *file_name)
#define AWAR_CS2GP_SUFFIX
__ATTR__USERESULT GB_ERROR calculate(AP_filter *filter)
adfiltercbstruct * awt_create_select_filter(AW_root *aw_root, GBDATA *gb_main, const char *def_name)
AW_window * awt_create_select_filter_win(AW_root *aw_root, adfiltercbstruct *acbs)
char * read_string() const
AW_awar * awar(const char *awar)
void print(FILE *out, size_t i, double v)
#define AWAR_CS2GP_FILENAME
char * GB_unique_filename(const char *name_prefix, const char *suffix)
AW_window * NT_create_colstat_2_gnuplot_window(AW_root *root)
GB_ERROR GB_export_errorf(const char *templat,...)
#define AWAR_CS2GP_GNUPLOT_OVERLAY_PREFIX
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
#define AWAR_CS2GP_GNUPLOT_OVERLAY_POSTFIX
const GB_UINT4 * get_weights() const
static char * get_overlay_files(AW_root *awr, const char *fname, GB_ERROR &error)
void aw_message(const char *msg)
SortedFreq(const ColumnStat *column_stat)
adfiltercbstruct * filterdef
size_t get_length() const
PlotParam(ColumnStat *colstat_, adfiltercbstruct *filterdef_)
static const char * plotTypeName[PT_PLOT_TYPES]
static void colstat_ali_changed_cb(AW_root *root, AW_awar *awar_ali)
GB_transaction ta(gb_var)
static const char * plotTypeDescription[PT_PLOT_TYPES]
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
static const char * makeTitle(const char *fname)
#define AWAR_CS2GP_SMOOTH_GNUPLOT
const bool * get_is_helix() const
char * GBS_global_string_copy(const char *templat,...)