1 #ifndef SEAVIEW_H
2 #define SEAVIEW_H
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <limits.h>
7 #include <FL/Fl.H>
8 #if 100*FL_MAJOR_VERSION + 10*FL_MINOR_VERSION + FL_PATCH_VERSION < 134
9 // because of Fl_Graphics_Driver::draw_scaled() introduced 1.3.4 used by Fl_SVG_Image
10 #error Seaview requires FLTK version 1.3.4 or higher
11 #endif
12 #include <FL/Fl_Window.H>
13 #include <FL/Fl_Menu_Item.H>
14 #include <FL/Fl_Menu_Bar.H>
15 #include <FL/Fl_Browser.H>
16 #include <FL/Fl_Input.H>
17 #include <FL/Fl_Box.H>
18 #include <FL/Fl_Return_Button.H>
19 #include <FL/Fl_Repeat_Button.H>
20 #include <FL/Fl_Choice.H>
21 #include <FL/fl_draw.H>
22 #include <FL/fl_ask.H>
23 #include <FL/Fl_Native_File_Chooser.H>
24 #ifndef FALSE
25 #define FALSE 0
26 #define TRUE (!FALSE)
27 #endif
28 
29 #if defined(__APPLE__) || defined(WIN32)
30 #define MICRO
31 #endif
32 
33 #ifdef NO_PDF
34 #define PDF_OR_PS "PostScript"
35 #define PDF_OR_PS_EXT "ps"
36 #else
37 #define PDF_OR_PS "PDF"
38 #define PDF_OR_PS_EXT "pdf"
39 #endif
40 
41 #define fgets(a,b,c) my_fgets(a,b,c)
42 extern char *my_fgets(char *s, int n, FILE *f);
43 
44 // FL_COMMAND is the modifier for menu shortcuts (Meta on Apple and Ctrl otherwise)
45 #ifndef FL_COMMAND
46 #if defined(__APPLE__)
47 #define FL_COMMAND FL_META
48 #else
49 #define FL_COMMAND FL_CTRL
50 #endif
51 #endif
52 
53 #ifdef WIN32
54 extern void my_bell(void);
55 #define fopen(a,b) fl_fopen(a, b)
56 #define memccpy _memccpy
57 #elif defined __APPLE__
58 #else
59 #include "FL/x.H"
60 #endif
61 #define FL_max(a,b)      ( (a) > (b) ? (a):(b) )
62 #define FL_min(a,b)      ( (a) < (b) ? (a):(b) )
63 #ifdef __APPLE__
64 #define PREPARE_LABEL(p) mac_fname_to_roman(p)
65 extern void set_seaview_modified(struct _SEA_VIEW *view, int ismodified);
66 #else
67 #if defined(WIN32)
68 extern const char *win32_UTF8_to_CP1252(const char *in);
69 #define PREPARE_LABEL(p) win32_UTF8_to_CP1252(p)
70 #else
71 #define PREPARE_LABEL(p) p
72 #endif
73 #define set_seaview_modified(view, ismodif) view->modif_but_not_saved = ismodif
74 #endif
75 typedef struct _user_data_plus {
76 	void *p;
77 	int value;
78 	} user_data_plus;
79 extern void fl_reset_cursor(Fl_Window *win);
80 
81 
82 #define MAXLENCOM 50000 /* long max des commentaires sous mase */
83 #define MAX_SPECIES_SETS 50 /* nbre max de species sets */
84 #define MSF_WID_NAME 15
85 #define CLU_BLOCK_LEN 5000 /* block pour allocation mem format Clustal */
86 #define MAX_GAP_SITES 1000
87 #define MOVEKEYS_DEFAULT "][><"
88 
89 typedef struct _list_segments { /* one segment + pointer to its successor */
90 	int debut, fin;
91 	struct _list_segments *next;
92 	} list_segments;
93 
94 typedef struct { /* one region = name + pointer to list of segments */
95   char *name;
96   int hide_when_viewasprots; /* TRUE iff this region shd not be enabled in view as protein mode */
97   list_segments *list;
98   } region;
99 
100 typedef struct _list_regions { /* region list = pointer to region +
101 				pointer to successor in list */
102 	region *element;
103 	struct _list_regions *next;
104 	} list_regions;
105 
106 typedef struct {
107 	int pos;
108 	int l[2];
109 	} gap_site;
110 
111 typedef enum {MASE_FORMAT, PHYLIP_FORMAT, CLUSTAL_FORMAT, MSF_FORMAT,
112 	FASTA_FORMAT, NEXUS_FORMAT }
113 	known_format;
114 
115 typedef enum {OPEN_ANY, OPEN_MASE, OPEN_PHYLIP, OPEN_CLUSTAL, OPEN_MSF, OPEN_FASTA,
116 	OPEN_NEXUS, ACNUC_IMPORT, SAVE, SAVE_AS, SAVE_REGIONS, SAVE_PROT_ALIGN, SAVE_BOOTSTRAPS, PRINTOUT,
117 #if !defined(__APPLE__)
118 	PDFOPTIONS,
119 #endif
120 	CONCATENATE, NEW_WINDOW, CLOSE_WINDOW,QUIT
121 	} file_menu_choice;
122 
123 typedef enum {NO_ALT_COLORS, USING_STANDARD_COLORS, USING_ALT_COLORS}
124 	color_choice;
125 
126 typedef enum {COPY_SEQS, PASTE_SEQS, SELECT_ALL, RENAME_SEQ, EDIT_COMMENTS, EDIT_SEQ, DELETE_SEQ, CREATE_SEQ,
127 	LOAD_SEQ, DUPLICATE_SEQ,
128 	COMPLEMENT_SEQ, REVERSE_SEQ, EXCHANGE_UT, DOT_PLOT,
129 	CONSENSUS_SEQ, DELETE_GAP_ONLY_SITES, SET_GCODE}
130 	edit_choice;
131 
132 typedef enum { ALIGN_ALL, ALIGN_SELECTED_SEQS, ALIGN_SITES, PROFILE, UNALIGN, ALIGN_OPTIONS } align_choice;
133 
134 typedef enum {SHOW_HIDE_FOOTERS, CREATE_FOOTER, DELETE_FOOTER }
135 	footers_menu_choice;
136 
137 typedef enum {PDF_COLOR, PDF_BW, TEXT_ONLY, SVG} pdf_kind;
138 
139 class vlength_menu // an FL_SUBMENU_POINTER-attached variable-length series of Fl_Menu_Item's
140 {
141   int offset; // # of fixed items
142   int vlen; // # of variable items
143   Fl_Menu_Item *items; // array of fixed + variable menu items
144   Fl_Menu_ *menu_; // menu of which this is a submenu
145   int rank; // rank of menu item to which this is a submenu
146   int val; // rank (from 1) of currently selected variable item
147 public:
148   vlength_menu(Fl_Menu_ *m, const char *name, const Fl_Menu_Item *init, int clength);
vlength()149   int vlength() {return vlen;} // lenth of variable part
value()150   int value() { return val; } // 0 if unset, >=1 if one if set
151   void value(int v); // 0 to clear, >=1 to set one
get_menu()152   Fl_Menu_Item *get_menu() {return items;} // fixed + variable parts
153   void add(const char *txt, Fl_Callback *cb, void *data, int flags); // add at end of variable part
vitem(int r)154   Fl_Menu_Item* vitem(int r) { return items + offset + r; } // one of the variable items
bar_item()155   Fl_Menu_Item* bar_item() { return (Fl_Menu_Item*)menu_->menu() + rank; }
156   void remove(int rank); // remove variable item of rank (from 0)
157   Fl_Menu_Item* find_item(const char*txt);
158   void vclear(); // remove all the variable part
159   ~vlength_menu();
160 };
161 
162 #define TREE_WINDOW "Tree"
163 #define SEAVIEW_WINDOW "Seaview"
164 
165 typedef struct _SEA_VIEW {
166   Fl_Widget *DNA_obj; /* free object for names + seqs */
167   Fl_Scrollbar *horsli; /* horizontal scrollbar */
168   Fl_Scrollbar *vertsli; /* vertical scrollbar */
169   Fl_Widget *right_screen_move, *left_screen_move, *up_screen_move,
170 		  *down_screen_move; /* 4 big jump arrows */
171   Fl_Widget *multipl; /* box displaying the multiplier value */
172   Fl_Menu_Bar *menubar;
173   const Fl_Menu_Item *menu_file; /* menu items of file operations */
174   const Fl_Menu_Item *menu_edit; /* menu items of edit operations */
175   const Fl_Menu_Item *menu_align; /* menu of align operations */
176   const Fl_Menu_Item *menu_props; /* menu of properties */
177   vlength_menu *menu_sites; /* menu of site operations */
178   vlength_menu *menu_species; /* menu of species */
179   const Fl_Menu_Item *menu_footers; /* menu of footers */
180   vlength_menu *menu_trees; /* menu of trees */
181   Fl_Widget *bouton_reference; /* bouton_reference */
182   char **sequence; /* array of sequences */
183   char **comments; /* array of sequence comments */
184   char *header; /* header of mase file */
185   char **col_rank; /* array of color ranks of sequence sites */
186   char **alt_col_rank; /* alternate array of color ranks of sequence sites for by reference */
187   char **seqname; /* array of sequence names */
188   char *masename; /* mase file name */
189   int protein; /* TRUE iff protein data */
190   known_format format_for_save; /* what file format used when saving */
191   int wid_names; /* width of largest sequence name */
192   int first_seq, first_site; /* first seq and site currently displayed */
193   int tot_seqs; /* total number of sequences in memory */
194   int seq_length; /* current length of longest sequence */
195   int max_seq_length; /*max length allowed for longest sequence to grow */
196   int *each_length; /* array of each individual sequence length */
197   int tot_sites, tot_lines; /* sites and lines fitting in DNA_obj */
198   int x_name, y_name, x_seq, y_seq; /* top left to start writing
199 					  names and sequences */
200   int draw_names; /*controle ecriture noms 0: pas ecrits;
201 		  -1: tous ecrits puis aussi les seqs;
202 		  -2: tous ecrits mais pas les seqs;
203 		  >=1: 1 seul ecrit et pas de seq ni de curseur ecrit*/
204   int mod_seq; /* -1: seqs selectionnees;
205 		  0: normal;
206 		  >= 1: 1 seul seq ecrite */
207   int mod_cursor; /* FALSE: cursor ancien ignore; TRUE: ancien efface */
208 #if (100*FL_MAJOR_VERSION + FL_MINOR_VERSION >= 104) && !defined(__APPLE__)
209   float scale; /* scaling factor used to compute char_width */
210 #endif
211   float char_width; /* largeur en pixels des caracteres */
212   int line_height; /* hauteur en pixels des lignes */
213   int cursor_seq, cursor_site; /* position courante du curseur */
214   int old_cursor_seq, old_cursor_site; /* position precedente du curseur*/
215   int tot_sel_seqs; /* nbre courant de seqs selectionnees */
216   int *sel_seqs; /* tableau des seqs selectionnees: T/F pour chacune */
217   int *curr_colors; /*tableau des couleurs pour chaque valeur col_rank */
218   int inverted_colors; /* TRUE iff use black letters on colored square */
219   int namecolor; /* couleur utilisee pour les noms */
220   int numb_gc; /* 1 en N&B, >1 en couleurs */
221   int *dnacolors; /* tableau des couleurs pour DNA/RNA */
222   int numb_dnacolors; /* nbre de couleurs pour DNA/RNA */
223   int *stdprotcolors; /*tableau des couleurs standard pour prots*/
224   int numb_stdprotcolors; /* nbre de couleurs standard pour prots */
225   int *altprotcolors;/*tableau des couleurs alternatives pour prots*/
226   int numb_altprotcolors; /*nbre de couleurs alternatives pour prots*/
227   int *codoncolors; /*tableau des couleurs standard pour codons*/
228   color_choice alt_colors; /* current aa color use */
229   list_regions *regions; /* list of known regions */
230   region *active_region; /* active region (NULL when none) */
231   char *region_line; /* region line (of length region_length) */
232   int region_color; /* color used to display region line */
233   int region_length; /* length of region_line (==seq_length) */
234   int mod_region_line; /* TRUE region line changed=>redraw only it */
235   int numb_species_sets; /* number of known species sets */
236   int *list_species_sets[MAX_SPECIES_SETS];/*list of known species sets*/
237   char *name_species_sets[MAX_SPECIES_SETS];/*names of species sets*/
238   int allow_seq_edit; /* when TRUE can type sequence data in */
239   void *viewasprots; /* !=NULL when DNA displayed as proteins */
240   int hjkl; /* when TRUE, keys hjklHJKL produce TCGA */
241   int modif_but_not_saved; /* set/unset through function set_seaview_modified */
242   Fl_Window *dnawin; /* full seaview window */
243   int double_buffer; /* true iff DNA_obj is double buffered */
244   int alignment_algorithm; /* rank (from 0) of chosen alignment algorithm */
245   int count_msa_algos; /* number of usable alignment algorithms */
246   char *clustal_options; /* options for clustalw if != NULL */
247   int consensus_threshold; /* min threshold (%) for residue in consensus*/
248   int consensus_allowgaps; /* TRUE iff gaps count as residue for consensus*/
249   int consensus_allowiupac; /* TRUE iff IUPAC codes are used in consensus DNA sequences */
250   int tot_comment_lines; /* number of comment lines */
251   char **comment_line; /* array of comment lines */
252   char **comment_name; /* array of comment names */
253   int *comment_length; /* array of comment lengths */
254   int show_comment_lines; /* TRUE when displayed */
255   int pos_first_comment_line; /* rank on screen of this line */
256   int mod_comment_line; /* 0: normal, >=1 celle-ci ecrite */
257   int active_comment_line; /* 0: none, >=1 target of keyboard */
258   int cursor_in_comment; /* TRUE when cursor is in comments not in seqs */
259   int old_cursor_in_comment; /*previous place of cursor seq vs. comments*/
260   char *movekeys; /* default ][><  keys to move seq right or left */
261   int allow_lower; /* TRUE iff lowercase displayed in seqs */
262   int phylipwidnames; /* max name length when writing PHYLIP files */
263   int spaces_in_fasta_names; //TRUE iff spaces dont mark end of seq name n FASTA format
264   int tot_trees; /* number of trees in next array */
265   char **trees; /* array of trees */
266 } SEA_VIEW;
267 
268 
269 typedef struct _props_menu_parts {
270 	int colors, viewasprots, inverted, edit, reference, keys,
271 		consensusopt, slow_fast, allow_lower;
272 	int usingcodoncolors;
273 	} props_menu_parts;
274 
275 extern void update_treerecs_prog_path(const char* str);
276 extern void out_of_memory(void);
277 extern "C" void majuscules(char *s);
278 extern void init_dna_scroller(SEA_VIEW *view, int totseqs,
279 	const char *masename, int protein, char *header);
280 extern const char *extract_filename(const char *fname);
281 extern const char *extract_dirname(const char *pathname);
282 extern void draw_region_line(Fl_Widget *ob, SEA_VIEW *view);
283 extern void props_button_callback(Fl_Widget *ob, long mainpop);
284 extern void regions_menu_callback(Fl_Widget *ob, void *extra);
285 extern void species_menu_callback(Fl_Widget *ob, void *extra);
286 extern void footers_menu_callback(Fl_Widget *ob, void *extra);
287 extern int suppr_segment(region *maregion, int site, char *line);
288 extern int begin_change_segment(SEA_VIEW *view, int new_site);
289 extern int continue_change_segment(SEA_VIEW *view, int new_site);
290 extern void end_change_segment(SEA_VIEW *view);
291 extern int extend_segment_at_left(SEA_VIEW *view, int new_site);
292 extern void delete_region_part(SEA_VIEW *view, int numsite, int total);
293 extern void insert_region_part(SEA_VIEW *view, int numsite, int total);
294 extern void delete_region(SEA_VIEW *view, int rang);
295 extern list_regions *parse_regions_from_header(char *header);
296 extern int parse_species_sets_from_header(char *header, int **list_species_sets,
297 	char **name_species_sets, int totseqs);
298 extern void set_tot_lines(SEA_VIEW *view, int new_val);
299 extern int read_mase_seqs_header(const char *, char ***pseq,char ***pseqname,
300 		char ***pcomments, char **pheader, char **err_message);
301 extern int read_fasta_align(const char *fname, char ***pseq, char ***pseqname,
302 		char ***pcomments, char **pheader,  char **err_message, int spaces_in_names);
303 extern int read_phylip_align(const char *fname, char ***pseq, char ***pseqname,
304 		char ***pcomments, char **pheader, char **);
305 extern int read_clustal_align(const char *fname, char ***pseq, char ***pseqname,
306 		char ***pcomments, char **pheader, char **err_message);
307 extern int read_msf_align(const char *fname, char ***pseq, char ***pseqname,
308 		char ***pcomments, char **pheader, char **err_message);
309 extern int read_nexus_align(char *fname, char ***pseqs, char ***pseqnames,
310 	char ***pcomments, char **pheader, char **err_message,
311 	list_regions **charsets, int *pnum_species_sets,
312 	int ***list_species_sets, char ***name_species_sets,
313 	int *ptot_comment_lines, char ***comment_name, char ***comment_line,
314 	int **comment_length, int *protein, SEA_VIEW *view);
315 extern char *save_alignment_or_region(const char *fname, char **seq,
316 	char **comments,
317 	char *header, char **seqname, int totseqs, int *eachlength,
318 	list_regions *regions, region *region_used, known_format format,
319 	int numb_species_sets, int **list_species_sets,
320 	char **name_species_sets, int *sel_seqs, int tot_sel_seqs, int protein,
321 	int tot_comment_lines, char **comment_name, char **comment_line, int phylipwidnames,
322 	int tot_trees, char **trees, const Fl_Menu_Item *menu_tree_items, int spaces_in_fasta_names);
323 extern Fl_Window *load_alignment_file(SEA_VIEW *view, char *filename,
324 	const char *message, known_format file_format, int doing_dnd);
325 extern int is_a_protein_seq(char *seq);
326 extern int is_a_protein_alignment(SEA_VIEW *view);
327 extern char *get_full_path(const char *fname);
328 extern void draw_region_background(SEA_VIEW *view, int f_seq0, int l_seq0);
329 extern void load_seq_dialog(SEA_VIEW *view);
330 extern void edit_comments_dialog(SEA_VIEW *view);
331 extern void edit_sequence_dialog(SEA_VIEW *view);
332 extern int add_seq_to_align(SEA_VIEW *view, char *newname, char *newseq, int lenseq, bool no_gui = false);
333 extern int get_color_for_base( int key );
334 extern int get_color_for_aa( int key );
335 extern char **prepcolranks(char **seq, int totseqs, int maxlen, int *eachlength,
336 	int (*calc_color_function)( int ), int numb_gc, int allow_lower);
337 extern char complement_base(char old);
338 extern void select_deselect_seq(SEA_VIEW *view, int new_seq, int from_tree = 0);
339 extern void save_active_region(SEA_VIEW *view);
340 extern void align_selected_parts(SEA_VIEW *view, align_choice my_align_choice, bool no_gui = false);
341 extern void free_region(region *reg);
342 extern void my_watch_cursor(Fl_Window *win);
343 extern void update_current_seq_length(int newlength, SEA_VIEW *view);
344 extern char *cre_consensus(SEA_VIEW *view, char *newname);
345 extern int parse_comment_lines_from_header(char *header, char ***plines,
346 	char ***pnames, int **plengths, int *pmax_seq_length);
347 extern int insert_char_in_comment(int key, int num, SEA_VIEW *view);
348 extern int delete_char_in_comment(SEA_VIEW *view, int count, int comnum,
349 	int depart, int protect);
350 extern void update_menu_footers(SEA_VIEW *view);
351 extern int insert_gap_all_comments(int numgaps, int pos,  SEA_VIEW *view);
352 extern int delete_in_all_comments(int numdels, int pos,  SEA_VIEW *view);
353 extern char* fl_file_chooser(const char* message, const char* pat, const char* fname, int);
354 extern char *run_and_close_native_file_chooser(Fl_Native_File_Chooser *chooser, int keepalive=0);
355 extern void trees_callback(Fl_Widget *ob, void *data);
356 extern int save_fasta_file(const char *fname, char **seq, char **comments,
357 		    char **seqname, int totseqs, int *eachlength, region *region_used,
358 		    int *sel_seqs, int tot_sel_seqs, int spaces_in_names, int pad_to_max_length=FALSE);
359 #ifdef __APPLE__
360 extern char *mac_fname_to_roman(const char *in);
361 #endif
362 
363 #endif
364