File: seqed.c

package info (click to toggle)
staden 2.0.0%2Bb11-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 21,568 kB
  • sloc: ansic: 240,605; tcl: 65,360; cpp: 12,854; makefile: 11,201; sh: 2,952; fortran: 2,033; perl: 63; awk: 46
file content (307 lines) | stat: -rw-r--r-- 6,972 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#include <string.h>
#include "xalloc.h"
#include "tkSeqed.h"
#include "seq_results.h"
#include "seqed.h"
#include "seq_reg.h"
#include "tkSeqedUtils.h"
#include "tcl_utils.h"
#include "seqed_restriction_enzymes.h"
#include "text_output.h"
#include "seq_raster.h"
#include "spin_globals.h"

int seqed_reg(Tcl_Interp *interp, char *seqed_win, int seq_num, tkSeqed *se);

void seqed_shutdown(Tcl_Interp *interp,
		    SeqedResult *result)
{
    Tcl_CmdInfo info;
    tkSeqed *se;
    char *tmp;

#ifdef DEBUG
    printf("seqed shutdown \n");
#endif

    Tcl_GetCommandInfo(interp, result->seqed_win, &info);
    se = (tkSeqed*)info.clientData;

   if (se->renzDisplayed) {
	free_lines();
	free_r_enzyme(se->r_enzyme, se->num_enzymes);
    }

    /* destroy toplevel seqed window */
    Tcl_VarEval(interp, "winfo toplevel ", result->seqed_win, NULL);
    Tcl_VarEval(interp, "destroy ", Tcl_GetStringResult(interp), NULL);

    tmp = get_default_string(interp, tk_utils_defs, w("RASTER.RESULTS.WIN"));
    if (TCL_OK != Tcl_VarEval(interp, "seq_result_list_update ", 
			      tmp, NULL)){
	verror(ERR_WARN, "seqed shutdown", "%s \n", Tcl_GetStringResult(interp));
    }

    xfree(result);
}

tkSeqed *seqed_id_to_se(Tcl_Interp *interp,
			 int seqed_id)
{
    Tcl_CmdInfo info;
    tkSeqed *se;
    seq_reg_info info1;
    char *seqed_win;
    
    info1.job = SEQ_RESULT_INFO;
    info1.op = WINDOW;
    info1.result = NULL;

    seq_result_notify(seqed_id, (seq_reg_data *)&info1, 0);
    seqed_win = (char *)info1.result;
    Tcl_GetCommandInfo(interp, seqed_win, &info);
    se = (tkSeqed*)info.clientData;
    return(se);
}

/*
 * add sequence to seqed widget
 */
int add_seq_seqed(Tcl_Interp *interp,
		  char *sequence,
		  char *seqed_win,
		  int seq_num)
{

    Tcl_CmdInfo info;
    tkSeqed *se;
    char *seq_name;
    int sequence_type;
    int seqed_id;

    Tcl_GetCommandInfo(interp, seqed_win, &info);
    se = (tkSeqed*)info.clientData;

    seq_name = GetSeqName(seq_num);
    sequence_type = GetSeqStructure(seq_num);

    seqed_add_sequence(se, strlen(sequence), sequence, seq_name, 
		       sequence_type, GetSeqId(seq_num), 0, 0); 
    seqed_id = seqed_reg(interp, seqed_win, seq_num, se);
    return seqed_id;
}

/*
 * update sequence position
 */
void update_seqed(Tcl_Interp *interp,
		  char *seqed_win,
		  int pos)
{

    Tcl_CmdInfo info;
    tkSeqed *se;

    Tcl_GetCommandInfo(interp, seqed_win, &info);
    se = (tkSeqed*)info.clientData;

    /* seqed_redisplay_seq(se, pos); */
    seqed_setCursorPos(se, pos);
}

void seqed_move_cursor(Tcl_Interp *interp,
		       char *seqed_win,
		       int pos)
{
    Tcl_CmdInfo info;
    tkSeqed *se;

    /* printf("seqed move cursor %s %d %d \n", seqed_win, seqed_id, pos); */

    Tcl_GetCommandInfo(interp, seqed_win, &info);
    se = (tkSeqed*)info.clientData;

    se->cursorPos = pos;
    seqed_showCursor(se, se->cursorSeq, se->cursorPos);
}


void seqed_set_cursor_pos(Tcl_Interp *interp,
			  int seqed_id, 
			  int pos) 
{
    tkSeqed *se;
      
    se = seqed_id_to_se(interp,seqed_id);
    seqed_showCursor(se, se->cursorSeq, pos);
    seqed_setCursorPos(se, pos);
}


void
seqed_callback(int seq_num, void *obj, seq_reg_data *jdata) 
{
    SeqedResult *result = (SeqedResult *) obj;
    char *seqed_win = result->seqed_win;
    tkSeqed *se;
    Tcl_CmdInfo info;

    Tcl_GetCommandInfo(result->interp, seqed_win, &info);
    se = (tkSeqed*)info.clientData;

    switch(jdata->job) {
    case SEQ_QUERY_NAME:
	{
	    sprintf(jdata->name.line, "sequence editor");
	    return;
	}
    case SEQ_QUIT:
    case SEQ_DELETE:
	{
	    seq_deregister(seq_num, seqed_callback, (SeqedResult *)result);

	    /* need to set prev_pos */

	    se->prev_pos = se->cursor->abspos;
	    delete_cursor(seq_num, se->cursor->id, 1);
	    seqed_shutdown(result->interp, result);
	    return;
	}
    case SEQ_GET_OPS:
	{
	    jdata->get_ops.ops = "Remove\0";
	    break;
	}

    case SEQ_INVOKE_OP:
	switch (jdata->invoke_op.op) {
	case 0:

	    /* need to set prev_pos before shutdown which frees se */
	    se->prev_pos = se->cursor->abspos;
	    delete_cursor(seq_num, se->cursor->id, 1);

	    seq_deregister(seq_num, seqed_callback, (SeqedResult *)result);
	    seqed_shutdown(result->interp, result); 

	    return;
	}
	break;
    case SEQ_CURSOR_NOTIFY: 
	{
	    cursor_t *cursor = (cursor_t *)jdata->cursor_notify.cursor;

#ifdef DEBUG
	    printf("SEQ_CURSOR_NOTIFY seqed pos %d id %d result id %d\n", 
		   cursor->abspos, cursor->id, se->cursor->id);
#endif	    
	    if (se->cursor->id == cursor->id) {
		seqed_move_cursor(result->interp, result->seqed_win, 
				  cursor->abspos);
	    }
	    break;
	}
    case SEQ_SETCURSOR: 
	{
	    seqed_move_cursor(result->interp, result->seqed_win, 
			      jdata->cursor_move.pos);
	    
	    break;
	}
    case SEQ_GENERIC:
	switch(jdata->generic.task) {
	case TASK_SEQED_SETCURSOR: 
	    {
		task_seqed_setcursor *tc =
		    (task_seqed_setcursor *)jdata->generic.data;
		
		seqed_move_cursor(result->interp, result->seqed_win, 
				      tc->pos);
		
		break;
	    }
	case TASK_SEQED_GETCURSOR:
	    {
		Tcl_CmdInfo info;
		tkSeqed *se;
		task_seqed_setcursor *tc;

		if (NULL == (tc = (task_seqed_setcursor *)xmalloc
			     (sizeof(task_seqed_setcursor))))
		    return;

		Tcl_GetCommandInfo(result->interp, result->seqed_win, &info);
		se = (tkSeqed*)info.clientData;

		tc->pos = se->cursorPos;
		tc->col = se->cursorCol;
		jdata->info.result = (void *)tc;
		break;
	    }
	}
	break;

    case SEQ_RESULT_INFO:
	switch (jdata->info.op) {
	case WINDOW:
	    jdata->info.result = (void *)seqed_win;
	    break;
	}
	break;
    case SEQ_SEQUENCE_TYPE:
	{
	    int *type = (int *)jdata->sequence_type.data;
	    
	    se->sequence_type = *type;
	    break;
	}
    }
}

int seqed_reg(Tcl_Interp *interp,
	      char *seqed_win,
	      int seq_num,
	      tkSeqed *se)
{
    int id;
    SeqedResult *seqed_result;
    char *colour;
    seq_cursor_notify cn;
    int line_width;

    if (NULL == (seqed_result = (SeqedResult *)xmalloc(sizeof(SeqedResult))))
	return -1;

    seqed_result->op_func = seqed_callback;
    seqed_result->seq_id = GetSeqId(seq_num);
    strcpy(seqed_result->seqed_win, seqed_win);
    seqed_result->interp = interp;

    id = get_reg_id();
    seqed_result->index = id;

    line_width = get_default_int(interp, spin_defs, 
				 w("SEQ.CURSOR.LINE_WIDTH"));

    colour = get_raster_colour();
    se->rid = id;
    se->seq_id = GetSeqId(seq_num);
    strcpy(se->cursorCol, colour);
    se->cursor = create_cursor(seq_num, 1, NULL, line_width, 1, HORIZONTAL);
    se->cursor_visible = 0;

    se->prev_pos = se->cursor->abspos;
    se->cursor->abspos = se->cursorPos;

    seq_register(seq_num, seqed_callback, (void *)seqed_result, SEQ_SEQED, 
		 id);

    cn.job = SEQ_CURSOR_NOTIFY;
    cn.cursor = se->cursor;
    cn.cursor->job = CURSOR_MOVE;
    seq_notify(seq_num, (seq_reg_data *)&cn); 
    
    return id;
}