26 #define AWAR_CS2GP "tmp/ntree/colstat_2_gnuplot"
28 #define AWAR_CS2GP_NAME AWAR_CS2GP "/name"
29 #define AWAR_CS2GP_SUFFIX AWAR_CS2GP "/filter"
30 #define AWAR_CS2GP_DIRECTORY AWAR_CS2GP "/directory"
31 #define AWAR_CS2GP_FILENAME AWAR_CS2GP "/file_name"
33 #define AWAR_CS2GP_SMOOTH_VALUES AWAR_CS2GP "/smooth_values"
34 #define AWAR_CS2GP_SMOOTH_GNUPLOT AWAR_CS2GP "/smooth_gnuplot"
35 #define AWAR_CS2GP_GNUPLOT_OVERLAY_PREFIX AWAR_CS2GP "/gnuplot_overlay_prefix"
36 #define AWAR_CS2GP_GNUPLOT_OVERLAY_POSTFIX AWAR_CS2GP "/gnuplot_overlay_postfix"
37 #define AWAR_CS2GP_FILTER_NAME AWAR_CS2GP "/ap_filter/name"
46 *name_prefixPtr =
NULp;
47 *name_postfixPtr =
NULp;
49 const char *lslash = strrchr(fname,
'/');
53 dir[lslash-fname] = 0;
56 char *name_postfix =
NULp;
57 char *ldot = strrchr(name_prefix,
'.');
63 if (!ldot || name_prefix[0] == 0) freedup(name_prefix,
"*");
64 if (!name_postfix || name_postfix[0] == 0) freedup(name_postfix,
"*_gnu");
70 *name_prefixPtr = name_prefix;
71 *name_postfixPtr = name_postfix;
82 char *dir, *name_prefix, *name_postfix;
85 char *found_files =
NULp;
87 char *found_prefix_files =
NULp;
88 char *found_postfix_files =
NULp;
90 if (overlay_prefix || overlay_postfix) {
101 if (overlay_postfix) {
110 if (found_prefix_files) {
111 if (found_postfix_files) {
115 found_files = found_prefix_files;
116 found_prefix_files =
NULp;
120 found_files = found_postfix_files;
121 found_postfix_files =
NULp;
125 free(found_postfix_files);
126 free(found_prefix_files);
176 "Most frequent base",
179 "Least frequent base",
189 if (strcmp(type, plotTypeName[pt]) == 0) {
198 const char *rslash = strrchr(fname,
'/');
199 if (rslash) rslash++;
203 char *rdot = strrchr(name,
'.');
249 for (
int i = 0; i<4; ++i) {
250 freq[i] =
new float[len];
251 for (
size_t p = 0; p<len; ++p) freq[i][p] = 0.0;
254 for (
unsigned int c = 0; c<256; ++c) {
257 for (
size_t p = 0; p<len; ++p) {
258 if (freq[3][p] < cfreq[p]) {
259 freq[3][p] = cfreq[p];
261 for (
int i = 3; i > 0; --i) {
262 if (freq[i-1][p] >= freq[i][p])
break;
264 float f = freq[i][p];
265 freq[i][p] = freq[i-1][p];
274 for (
size_t p = 0; p<len; ++p) {
282 for (
int i = 0; i<4; ++i)
delete [] freq[i];
294 size_t wrap(
size_t idx) {
return idx >= size ? idx-size : idx; }
298 : size(smooth_range),
306 value =
new double[size];
307 index =
new size_t[size];
309 for (
size_t i = 0; i<size; ++i) value[i] = 0.0;
316 void print(FILE *out,
size_t i,
double v) {
317 sum = sum+v-value[next];
324 if (added<size) ++added;
326 size_t printNext = wrap(next+halfsize);
327 fprintf(out,
"%zu %f\n", index[printNext], sum/size);
344 filterdef(filterdef_)
359 if (alignment_length<0) {
361 error =
"Please select a valid alignment";
364 AP_filter filter(filterstring,
"0", alignment_length);
368 if (!error && !column_stat->
get_length()) error =
"Please select column statistic";
371 free(alignment_name);
379 if (strlen(fname) < 1) error =
"Please enter file name";
386 for (
char *name = strtok(found_files,
"*"); name; name = strtok(
NULp,
"*")) {
387 printf(
"Deleting gnuplot file '%s'\n", name);
388 if (unlink(name) != 0) printf(
"Can't delete '%s'\n", name);
398 out = fopen(fname,
"w");
415 } stat_type = STAT_UNKNOWN;
423 const float *floatVals;
424 const bool *boolVals;
428 data.amount.A =
NULp;
429 data.amount.C =
NULp;
430 data.amount.G =
NULp;
431 data.amount.TU =
NULp;
441 stat_type = STAT_AMOUNT;
450 stat_type = STAT_SIMPLE_FLOAT;
451 data.floatVals = column_stat->
get_rates();
455 stat_type = STAT_SIMPLE_FLOAT;
460 stat_type = STAT_SIMPLE_BOOL;
468 stat_type = STAT_SORT;
474 error =
"Please select what to plot";
483 for (
size_t j=0; j<columns; ++j) {
484 if (!weights[j])
continue;
489 float A = data.amount.A[j];
490 float C = data.amount.C[j];
491 float G = data.amount.G[j];
492 float TU = data.amount.TU[j];
494 float amount = A+C+G+TU;
508 case STAT_SIMPLE_FLOAT: val = data.floatVals[j];
break;
509 case STAT_SIMPLE_BOOL: val = data.boolVals[j];
break;
510 case STAT_SORT: val = data.sorted->get(plot_type, j);
break;
515 smoother.
print(out, j, val);
519 if (stat_type == STAT_SORT)
delete data.sorted;
541 fprintf(out,
"set samples 1000\n");
543 bool plotted =
false;
544 const char *plot_command[] = {
"plot",
"replot" };
547 for (
char *name = strtok(found_files,
"*"); name; name = strtok(
NULp,
"*")) {
548 if (strcmp(name, fname) != 0) {
549 fprintf(out,
"%s \"%s\" %s title \"%s\"\n", plot_command[
int(plotted)], name, smooth,
makeTitle(name));
556 fprintf(out,
"%s \"%s\" %s title \"%s\"\n", plot_command[
int(plotted)], fname, smooth,
makeTitle(fname));
557 fprintf(out,
"pause mouse any \"Any key or button will terminate gnuplot\"\n");
582 smooth_max = INT_MAX;
594 AW_window_simple *aws =
new AW_window_simple;
596 aws->init(root,
"EXPORT_CSP_TO_GNUPLOT",
"Export Column statistic to GnuPlot");
597 aws->load_xfig(
"cpro/csp_2_gnuplot.fig");
608 aws->create_button(
"CLOSE",
"CLOSE",
"C");
611 aws->create_button(
"HELP",
"HELP",
"H");
621 plotTypeList->
insert(plotTypeDescription[pt], plotTypeName[pt]);
634 aws->at(
"ap_filter");
643 aws->insert_default_toggle(
"None",
"N",
"");
644 aws->insert_toggle(
"Unique",
"U",
"smooth unique");
645 aws->insert_toggle(
"CSpline",
"S",
"smooth cspline");
646 aws->insert_toggle(
"Bezier",
"B",
"smooth bezier");
647 aws->update_toggle_field();
649 aws->auto_space(10, 10);
650 aws->button_length(13);
656 aws->create_button(
"SAVE",
"Save");
660 aws->create_button(
"SAVE_AND_VIEW",
"Save & View");
663 aws->label(
"Overlay statistics with same prefix?");
667 aws->label(
"Overlay statistics with same postfix?");
670 aws->at(
"del_overlays");
672 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)
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)
NOT4PERL GB_ERROR GB_xcmd(const char *cmd, XCMD_TYPE exectype) __ATTR__USERESULT_TODO
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,...)