/* * Removes the template and reading display (and unplots etc). */ static void cs_shutdown(GapIO *io, obj_cs *cs) { int i; reg_quit rq; /* for (i = 1; i <= NumContigs(io); i++) { contig_deregister(io, i, cs_callback, (void *)cs); } */ rq.job = REG_QUIT; rq.lock = REG_LOCK_WRITE; type_notify(io, REG_TYPE_FIJ, (reg_data *)&rq, 1); type_notify(io, REG_TYPE_READPAIR, (reg_data *)&rq, 1); type_notify(io, REG_TYPE_REPEAT, (reg_data *)&rq, 1); type_notify(io, REG_TYPE_CHECKASS, (reg_data *)&rq, 1); type_notify(io, REG_TYPE_OLIGO, (reg_data *)&rq, 1); /* * need to deregister AFTER done type_notify requests because they need * the cs data structure which is deleted during deregistration */ for (i = 1; i <= NumContigs(io); i++) { contig_deregister(io, i, cs_callback, (void *)cs); } if (TCL_ERROR == Tcl_VarEval(GetInterp(), "DeleteContigSelector ", cs->frame, NULL)) { printf("cs_shutdown %s\n", GetInterpResult()); } free_win_list(cs->win_list, cs->num_wins); xfree(cs->line_colour); xfree(cs->canvas); xfree(cs->world->visible); xfree(cs->world->total); xfree(cs->world); if (cs->cursor.colour) free(cs->cursor.colour); if (cs->tick->colour) free(cs->tick->colour); freeZoom(&cs->zoom); xfree(cs); }
/* * Handle a REG_NUMBER_CHANGE request for match objects */ void csmatch_renumber(GapIO *io, int old_contig, int new_contig, mobj_repeat *r, HTablePtr T[], char *cs_plot) { int n, i; n = r->num_match; for (i = 0; i < n; i++) { if (abs(r->match[i].c1) == old_contig) r->match[i].c1 = r->match[i].c1 > 0 ? new_contig : -new_contig; if (abs(r->match[i].c2) == old_contig) r->match[i].c2 = r->match[i].c2 > 0 ? new_contig : -new_contig; } /* FIXME */ DeleteRepeats(GetInterp(), r, cs_plot, T); PlotRepeats(io, r); return; }
/* * Handle a REG_JOIN_TO request for match objects * 'r' isn't always a mobj_repeat, but sometimes a mobj_template or * mobj_fij. For the time being though these are all equivalent. */ void csmatch_join_to(GapIO *io, int contig, reg_join *j, mobj_repeat *r, HTablePtr T[], char *cs_plot) { int i; /* printf("Joining %d to %d at offset %d\n", contig, j->contig, j->offset); */ for (i = 0; i < r->num_match; i++) { if (abs(r->match[i].c1) == contig) { r->match[i].pos1 += j->offset; r->match[i].c1 = r->match[i].c1 > 0 ? j->contig : -j->contig; } if (abs(r->match[i].c2) == contig) { r->match[i].pos2 += j->offset; r->match[i].c2 = r->match[i].c2 > 0 ? j->contig : -j->contig; } /* For FIJ: remove match if moved onto diagonal */ if (r->match_type == REG_TYPE_FIJ && r->match[i].c1 == r->match[i].c2) { obj_match *o = &r->match[i]; if (i <= r->current) r->current--; i--; memmove(o, o+1, (--r->num_match - (o - r->match)) * sizeof(*o)); } } if (r->num_match > 0) { DeleteRepeats(GetInterp(), r, cs_plot, T); PlotRepeats(io, r); } else { csmatch_remove(io, cs_plot, r, T); } return; }
static AP_Result tcl_coerce_list(AP_World *w, AP_Obj interp_name, AP_Obj item, AP_Obj list) { Tcl_Interp *interp; AP_Obj result; interp = GetInterp(w, interp_name); if (!interp) return AP_EXCEPTION; if (AP_ObjType(w, item) == AP_LIST || AP_IsNullList(w, item)) result = item; else { Tcl_Obj *tcl_obj = PrologToTclObj(w, item, interp); int r = Tcl_ConvertToType(interp, tcl_obj, tcl_list_type); if (r != TCL_OK) return AP_SetException(w, AP_NewInitStructure(w, AP_NewSymbolFromStr(w, "error"), 2, AP_NewInitStructure(w, AP_NewSymbolFromStr(w, "tcl_error"), 1, TclToPrologObj(interp, Tcl_GetObjResult(interp), w, NULL)), AP_UNBOUND_OBJ)); result = TclToPrologObj(interp, tcl_obj, w, NULL); Tcl_DecrRefCount(tcl_obj); } return AP_Unify(w, result, list); }
void cs_callback(GapIO *io, int contig, void *fdata, reg_data *jdata) { char cmd[1024]; obj_cs *cs = (obj_cs *)fdata; switch(jdata->job) { case REG_BUFFER_START: { #ifdef DEBUG printf("REG_BUFFER_START count %d \n", cs->buffer_count); #endif cs->buffer_count++; cs->do_update = REG_BUFFER_START; return; } case REG_BUFFER_END: { #ifdef DEBUG printf("REG_BUFFER_END count %d \n", cs->buffer_count); #endif cs->buffer_count--; if (cs->buffer_count <= 0) { cs->buffer_count = 0; if (cs->do_update & REG_LENGTH) { } else if (cs->do_update & REG_ANNO) { Tcl_VarEval(GetInterp(), cs->hori, " delete tag", NULL); display_cs_tags(GetInterp(), io, cs); scaleSingleCanvas(GetInterp(), cs->world, cs->canvas, cs->hori, 'x', "tag"); } else if (cs->do_update & REG_ORDER) { update_contig_selector(GetInterp(), io, cs); if (cs->vert[0] != '\0') { update_contig_comparator(GetInterp(), io, cs); } } cs->do_update = 0; } return; } case REG_QUERY_NAME: { sprintf(jdata->name.line, "Contig selector"); return; } case REG_GET_OPS: { /* jdata->get_ops.ops = "Information\0Configure\0"; */ return; } case REG_ANNO: { #ifdef DEBUG printf("contig selector REG_ANNO\n"); #endif if (!cs->do_update) { Tcl_VarEval(GetInterp(), cs->hori, " delete tag", NULL); display_cs_tags(GetInterp(), io, cs); scaleSingleCanvas(GetInterp(), cs->world, cs->canvas, cs->hori, 'x', "tag"); } else { cs->do_update |= REG_ANNO; } return; } case REG_ORDER: { #ifdef DEBUG printf("contig selector REG_ORDER %d\n", cs->buffer_count); #endif if (!cs->do_update) { update_contig_selector(GetInterp(), io, cs); if (cs->vert[0] != '\0') { update_contig_comparator(GetInterp(), io, cs); } } else { cs->do_update |= REG_ORDER; } break; } case REG_QUIT: { cs_shutdown(io, cs); return; } case REG_GENERIC: switch(jdata->generic.task) { case TASK_WINDOW_ADD: { win *winfo = (win *)jdata->generic.data; addWindow(cs->win_list, &cs->num_wins, winfo->window, winfo->scroll, winfo->id); break; } case TASK_WINDOW_DELETE: { char *window = (char *)jdata->generic.data; deleteWindow(cs->win_list, &cs->num_wins, window); break; } case TASK_CANVAS_SCROLLX: { char *scroll = (char *)jdata->generic.data; canvasScrollX(GetInterp(), cs->window, cs->win_list, cs->num_wins, cs->world->visible, cs->canvas, scroll); break; } case TASK_CANVAS_SCROLLY: { char *scroll = (char *)jdata->generic.data; canvasScrollY(GetInterp(), cs->window, cs->win_list, cs->num_wins, cs->world->visible, cs->canvas, scroll); break; } case TASK_CANVAS_RESIZE: { char scroll_args[20]; /* resize template display window */ resizeCanvas(GetInterp(), cs->window, cs->win_list, cs->num_wins, cs->world->visible, cs->world->total, cs->canvas); sprintf(scroll_args, "scroll 0 units"); canvasScrollX(GetInterp(), cs->window, cs->win_list, cs->num_wins, cs->world->visible, cs->canvas, scroll_args); break; } case TASK_CANVAS_ZOOMBACK: { if (lengthZoom(cs->zoom) <= 2) { freeZoom(&cs->zoom); pushZoom(&cs->zoom, cs->world->total); } canvasZoomback(GetInterp(), cs->canvas, cs->window, cs->world, cs->win_list, cs->num_wins, &cs->zoom); break; } case TASK_CANVAS_ZOOM: { s_zoom *szoom = (s_zoom *)jdata->generic.data; canvasZoom(GetInterp(), cs->canvas, cs->window, cs->world, cs->win_list, cs->num_wins, &cs->zoom, szoom->zoom, szoom->scroll); break; } case TASK_CANVAS_CURSOR_X: { char *label; int *cx = (int *)jdata->generic.data; double local_pos; double wx, wy; CanvasToWorld(cs->canvas, *cx, 0, &wx, &wy); label = get_default_string(GetInterp(), gap_defs, "CONTIG_SEL.CURSOR1_X"); canvasCursorX(GetInterp(), cs->canvas, cs->frame, label, cs->cursor.colour, cs->cursor.width, *cx, wx, cs->win_list, cs->num_wins); /* fill in local position of cursor in label box */ local_pos = CSLocalCursor(io, wx); label = get_default_string(GetInterp(), gap_defs, "CONTIG_SEL.CURSOR2_X"); sprintf(cmd, "%s%s configure -text %d\n", cs->frame, label, (int)local_pos); Tcl_Eval(GetInterp(), cmd); break; } case TASK_CANVAS_CURSOR_Y: { char *label; int *cy = (int *)jdata->generic.data; double local_pos; double wx, wy; char cmd[1024]; double cx1, cy1; CanvasToWorld(cs->canvas, 0, *cy, &wx, &wy); WorldToCanvas(cs->canvas, wy, 0, &cx1, &cy1); label = get_default_string(GetInterp(), gap_defs, "CONTIG_SEL.CURSOR1_Y"); canvasCursorY(GetInterp(), cs->canvas, cs->frame, label, cs->cursor.colour, cs->cursor.width, *cy, wy, cs->win_list, cs->num_wins); sprintf(cmd, "DrawCanvasCursorX1 %s %s %.20f %s %d\n", cs->frame, cs->hori, cx1, cs->cursor.colour, cs->cursor.width); if (TCL_ERROR == Tcl_Eval(GetInterp(), cmd)) printf("%s\n", GetInterpResult()); /* fill in local position of cursor in label box */ local_pos = CSLocalCursor(io, wy); label = get_default_string(GetInterp(), gap_defs, "CONTIG_SEL.CURSOR2_Y"); sprintf(cmd, "%s%s configure -text %d\n", cs->frame, label, (int)local_pos); Tcl_Eval(GetInterp(), cmd); break; } case TASK_CANVAS_CURSOR_DELETE: { int i; for (i = 0; i < cs->num_wins; i++) { Tcl_VarEval(GetInterp(), cs->win_list[i]->window, " delete cursor_x cursor_x1 cursor_y", NULL); } break; } case TASK_CS_REDRAW: { /* HACK - never used */ int i, id = register_id(); for (i = 1; i <= NumContigs(io); i++) { contig_deregister(io, i, cs_callback, fdata); contig_register(io, i, cs_callback, fdata, id, REG_REQUIRED | REG_DATA_CHANGE | REG_OPS | REG_NUMBER_CHANGE | REG_ANNO | REG_GENERIC | REG_FLAG_INVIS | REG_BUFFER, REG_TYPE_CONTIGSEL); } break; } break; } break; case REG_JOIN_TO: case REG_LENGTH: case REG_DELETE: case REG_COMPLEMENT: case REG_NUMBER_CHANGE: #ifdef DEBUG printf("contig selector REG_REDRAW %d\n", cs->buffer_count); #endif update_contig_selector(GetInterp(), io, cs); if (cs->vert[0] != '\0') { update_contig_comparator(GetInterp(), io, cs); } /* update tcl globals, CurContig, LREG and RREG */ sprintf(cmd, "ContigParams %d", *handle_io(io)); Tcl_Eval(GetInterp(), cmd); #ifdef HACK printf("COM %s \n", cs->com); if (cs->buffer_count) { cs->do_update = 1; } else { Tcl_Eval(cs->interp, cs->com); } #endif break; } }
/* * plots the results of a search on the plot window of the contig selector */ void PlotRepeats(GapIO *io, mobj_repeat *repeat) { int i; char cmd[1024]; int pos1, pos2; int x1, y1, x2, y2; /* int max_x = 0; */ int sense1 = 1; int sense2 = 1; int inum; char *colour = repeat->colour; int width = repeat->linewidth; char *tag_id = repeat->tagname; obj_match new_match; int cs_id; obj_cs *cs; cs_id = type_to_result(io, REG_TYPE_CONTIGSEL, 0); cs = result_data(io, cs_id, 0); for (i = 0; i < repeat->num_match; i++){ obj_match *match = (obj_match *)&repeat->match[i]; /* Check if shown */ if (match->flags & OBJ_FLAG_HIDDEN) continue; /* clip length of match if necessary */ new_match = *match; DoClipping(io, &new_match); /* * printf("new pos1 %d pos2 %d length %d\n", * new_match.pos1, new_match.pos2, new_match.length); * printf("match pos1 %d pos2 %d length %d \n", * match->pos1, match->pos2, match->length); */ pos1 = find_position_in_DB(io, abs(new_match.c1), new_match.pos1); pos2 = find_position_in_DB(io, abs(new_match.c2), new_match.pos2); /* convert contig code back to sense ie -ve contig number means * match on opposite strand */ if (new_match.c1 < 0) { sense1 = -1; } else { sense1 = 1; } if (new_match.c2 < 0) { sense2 = -1; } else { sense2 = 1; } /* * draw matches of same sense (+:+ or -:-) as p1,p2 * \ * p1+len, p2+len * draw matches of different sense (+:- or -:+) as p1+len, p2 * / * p1, p2+len */ x1 = pos1; x2 = pos1 + new_match.length; if (sense1 == sense2) { y1 = pos2; y2 = pos2 + new_match.length; } else { y1 = pos2 + new_match.length; y2 = pos2; } /* need to plot in top half of screen therefore 'x' contig should be * larger than the corresponding 'y' contig */ /* printf("R:%d@%d,%d@%d(%d) C:%d@%d,%d@%d(%d)\n", match->pos1, match->c1, match->pos2, match->c2, match->length, new_match.pos1, new_match.c1, new_match.pos2, new_match.c2, new_match.length); printf("tag_id %s \n", tag_id); */ if (pos1 > pos2){ sprintf(cmd,"%s create line %d %d %d %d -width %d -capstyle round " "-tags {num_%d num_%d %s S} -fill %s", cs->window, x1, y1, x2, y2, width, abs(new_match.c1), abs(new_match.c2), tag_id, colour); } else { sprintf(cmd,"%s create line %d %d %d %d -width %d -capstyle round " "-tags \"num_%d num_%d %s S\" -fill %s", cs->window, y1, x1, y2, x2, width, abs(new_match.c1), abs(new_match.c2), tag_id, colour); } /* printf("cmd %s \n", cmd); */ if (TCL_ERROR == Tcl_Eval(GetInterp(), cmd)) printf("%s \n", GetInterpResult()); inum = atoi(GetInterpResult()); match->inum = inum; HashInsert(csplot_hash, inum, match); } /* scale new matches */ scaleSingleCanvas(GetInterp(), cs->world, cs->canvas, cs->window, 'b', tag_id); }
char* GetInterpResult( void ) { assert(our_interp); return Tcl_GetStringResult(GetInterp()); }
int check_assembly_plot(GapIO *io, tg_rec *reads, tg_rec *conts, int *score, int *pos, int *length, int count) { int i, id; mobj_checkass *ca; obj_checkass *matches; char *val; if (count == 0) return 0; if (NULL == (ca = (mobj_checkass *)xmalloc(sizeof(mobj_checkass)))) { return -1; } if (NULL == (matches = (obj_checkass *)xmalloc(count * sizeof(obj_checkass)))) { xfree(ca); return -1; } /* Setup the meta-object */ ca->num_match = count; ca->match = (obj_match *)matches; ca->io = io; ca->cutoffs = 0; strcpy(ca->tagname, CPtr2Tcl(ca)); val = get_default_string(GetInterp(), gap5_defs, "CHECK_ASSEMBLY.COLOUR"); strcpy(ca->colour, val); ca->linewidth = get_default_int(GetInterp(), gap5_defs, "CHECK_ASSEMBLY.LINEWIDTH"); ca->params = (char *)xmalloc(100); if (ca->params) sprintf(ca->params, "Unknown at present"); ca->all_hidden = 0; ca->current = -1; ca->current = -1; ca->reg_func = check_assembly_callback; ca->match_type = REG_TYPE_CHECKASS; /* Set up each object */ for (i=0; i<count; i++) { matches[i].func = (void *(*)(int, void *, struct obj_match_t *, struct mobj_repeat_t *))checkass_obj_func; matches[i].data = (mobj_repeat *)ca; matches[i].c1 = matches[i].c2 = conts[i]; matches[i].pos1 = matches[i].pos2 = pos[i]; matches[i].end1 = matches[i].end2 = pos[i] + length[i]; matches[i].length = length[i]; matches[i].score = score[i]; matches[i].flags = 0; matches[i].read = reads[i]; } /* Sort matches */ qsort(ca->match, ca->num_match, sizeof(obj_match), sort_func); PlotRepeats(io, (mobj_repeat *)ca); Tcl_VarEval(GetInterp(), "CSLastUsed ", CPtr2Tcl(ca), NULL); /* * Register the repeat search with each of the contigs used. * Currently we assume that this is all. */ id = register_id(); contig_register(io, 0, check_assembly_callback, (void *)ca, id, REG_REQUIRED | REG_DATA_CHANGE | REG_OPS | REG_NUMBER_CHANGE | REG_ORDER, REG_TYPE_CHECKASS); update_results(io); return 0; }
void check_assembly_callback(GapIO *io, tg_rec contig, void *fdata, reg_data *jdata) { mobj_checkass *r = (mobj_checkass *)fdata; obj_cs *cs; int cs_id; cs_id = type_to_result(io, REG_TYPE_CONTIGSEL, 0); cs = result_data(io, cs_id); switch (jdata->job) { case REG_QUERY_NAME: sprintf(jdata->name.line, "Check Assembly"); break; case REG_JOIN_TO: csmatch_join_to(io, contig, &jdata->join, (mobj_repeat *)r, csplot_hash, cs->window); break; case REG_COMPLEMENT: csmatch_complement(io, contig, (mobj_repeat *)r, csplot_hash, cs->window); break; case REG_GET_OPS: if (r->all_hidden) jdata->get_ops.ops = "PLACEHOLDER\0PLACEHOLDER\0Information\0" "PLACEHOLDER\0Hide all\0Reveal all\0Sort Matches\0" "SEPARATOR\0Remove\0"; else jdata->get_ops.ops = "Use for 'Next'\0Reset 'Next'\0Information\0" "Configure\0Hide all\0Reveal all\0Sort Matches\0" "SEPARATOR\0Remove\0"; break; case REG_INVOKE_OP: switch (jdata->invoke_op.op) { case 0: /* Next */ Tcl_VarEval(GetInterp(), "CSLastUsed ", CPtr2Tcl(r), NULL); break; case 1: /* Reset Next */ csmatch_reset_next((mobj_repeat *)r); break; case 2: /* Information */ csmatch_info((mobj_repeat *)r, "Check Assembly"); break; case 3: /* Configure */ csmatch_configure(io, cs->window, (mobj_repeat *)r); break; case 4: /* Hide all */ csmatch_hide(GetInterp(), cs->window, (mobj_repeat *)r, csplot_hash); break; case 5: /* Reveal all */ csmatch_reveal(GetInterp(), cs->window, (mobj_repeat *)r, csplot_hash); break; case 6: /* Sort */ qsort(r->match, r->num_match, sizeof(obj_checkass), sort_func); csmatch_reset_hash(csplot_hash, (mobj_repeat *)r); r->current = -1; break; case 7: /* Remove */ csmatch_remove(io, cs->window, (mobj_repeat *)r, csplot_hash); break; } break; case REG_PARAMS: jdata->params.string = r->params; break; case REG_NUMBER_CHANGE: csmatch_renumber(io, contig, jdata->number.number, (mobj_repeat *)r, csplot_hash, cs->window); break; case REG_ORDER: csmatch_replot(io, (mobj_repeat *)r, csplot_hash, cs->window); break; case REG_QUIT: csmatch_remove(io, cs->window, (mobj_repeat *)r, csplot_hash); break; case REG_DELETE: csmatch_contig_delete(io, (mobj_repeat *)r, contig, cs->window, csplot_hash); break; case REG_LENGTH: csmatch_replot(io, (mobj_repeat *)r, csplot_hash, cs->window); break; } }
/* * Match callback. * 'obj' is a match contained within the check assembly list. */ void *checkass_obj_func(int job, void *jdata, obj_checkass *obj, mobj_checkass *ca) { static char buf[80]; obj_cs *cs; int cs_id; cs_id = type_to_result(ca->io, REG_TYPE_CONTIGSEL, 0); cs = result_data(ca->io, cs_id); switch(job) { case OBJ_LIST_OPERATIONS: return "Information\0Hide\0Invoke contig editor *\0" "SEPARATOR\0Remove\0"; case OBJ_INVOKE_OPERATION: switch(*((int *)jdata)) { case 0: /* Information */ vfuncgroup(1, "2D plot matches"); case -1: /* Information from results manager */ start_message(); vmessage("check_assembly match:\n"); vmessage(" From contig %s(#%"PRIrec") at %d\n", get_contig_name(ca->io, ABS(obj->c1)), io_clnbr(ca->io, ABS(obj->c1)), obj->pos1); vmessage(" With contig %s(#%"PRIrec") at %d\n", get_contig_name(ca->io, ABS(obj->c2)), io_clnbr(ca->io, ABS(obj->c2)), obj->pos2); vmessage(" Length %d, mismatch %2.2f%%\n\n", obj->length, ((float)obj->score)/10000); end_message(cs->window); break; case 1: /* Hide */ obj_hide(GetInterp(), cs->window, obj, (mobj_repeat *)ca, csplot_hash); break; case -2: /* default */ case 2: /* Invoke contig editor */ { tg_rec cnum, llino; int pos; obj->flags |= OBJ_FLAG_VISITED; ca->current = obj - ca->match; Tcl_VarEval(GetInterp(), "CSLastUsed ", CPtr2Tcl(ca), NULL); cnum = abs(obj->c1); llino = obj->read; pos = obj->pos1 - io_relpos(ca->io, llino); if (pos < 1) pos = 1; if (pos > ABS(io_length(ca->io, llino))) pos = ABS(io_length(ca->io, llino)); // if ((id = editor_available(cnum, 1)) != -1) { // move_editor(id, llino, pos); // } else { edit_contig(ca->io, cnum, llino, pos); // } break; } case 3: /* Remove */ obj_remove(GetInterp(), cs->window, obj, (mobj_repeat *)ca, csplot_hash); break; } break; case OBJ_GET_BRIEF: sprintf(buf, "check_assembly: #%"PRIrec"@%d len %d, mis %2.2f%%", obj->read, obj->pos1, obj->length, ((float)obj->score)/10000); return buf; } return NULL; }
void plot_rpt(GapIO *io, int nres, int c1[], int pos1[], int c2[], int pos2[], int len[]) { int i, id; mobj_repeat *repeat; obj_match *matches = NULL; char *val; /* If nres is zero - do nothing */ if (0 == nres) return; if (NULL == (repeat = (mobj_repeat *)xmalloc(sizeof(mobj_repeat)))) { f_proc_return(); } if (NULL == (matches = (obj_match *)xmalloc(nres * sizeof(obj_match)))) { xfree(repeat); f_proc_return(); } repeat->num_match = nres; repeat->match = matches; repeat->io = io; strcpy(repeat->tagname, CPtr2Tcl(repeat)); val = get_default_string(GetInterp(), gap_defs,"FINDREP.COLOUR"); strcpy(repeat->colour, val); repeat->linewidth = get_default_int(GetInterp(), gap_defs, "FINDREP.LINEWIDTH"); repeat->params = (char *)xmalloc(100); if (repeat->params) sprintf(repeat->params, "Unknown at present"); repeat->all_hidden = 0; repeat->current = -1; repeat->reg_func = repeat_callback; repeat->match_type = REG_TYPE_REPEAT; /* Create and plot our match array */ for (i= 0; i < nres; i++){ matches[i].func = repeat_obj_func; matches[i].data = repeat; matches[i].c1 = rnumtocnum(io, ABS(c1[i])) * (c1[i] < 1 ? -1 : 1); matches[i].pos1 = pos1[i]; matches[i].c2 = rnumtocnum(io, ABS(c2[i])) * (c2[i] < 1 ? -1 : 1); matches[i].pos2 = pos2[i]; matches[i].length = len[i]; matches[i].score = 0; matches[i].flags = 0; } /* Sort matches */ qsort(repeat->match, repeat->num_match, sizeof(obj_match), sort_func); PlotRepeats(io, repeat); Tcl_VarEval(GetInterp(), "CSLastUsed ", CPtr2Tcl(repeat), NULL); /* * Register the repeat search with each of the contigs used. * Currently we assume that this is all. */ id = register_id(); for (i = 1; i <= NumContigs(io); i++) { contig_register(io, i, repeat_callback, (void *)repeat, id, REG_REQUIRED | REG_DATA_CHANGE | REG_OPS | REG_NUMBER_CHANGE | REG_ORDER, REG_TYPE_REPEAT); } }
/* * Match callback. * 'obj' is a match contained within the 'repeat' list. */ void *repeat_obj_func(int job, void *jdata, obj_match *obj, mobj_repeat *repeat) { static char buf[80]; obj_cs *cs; int cs_id; cs_id = type_to_result(repeat->io, REG_TYPE_CONTIGSEL, 0); cs = result_data(repeat->io, cs_id, 0); switch(job) { case OBJ_LIST_OPERATIONS: if (io_rdonly(repeat->io) && ((obj->c1 > 0 && obj->c2 < 0) || (obj->c1 < 0 && obj->c2 > 0))) { return "Information\0Hide\0IGNORE\0" "IGNORE\0SEPARATOR\0Remove\0"; } else { return "Information\0Hide\0Invoke join editor *\0" "Invoke contig editors\0SEPARATOR\0Remove\0"; } case OBJ_INVOKE_OPERATION: switch(*((int *)jdata)) { case 0: /* Information */ vfuncgroup(1, "2D plot matches"); case -1: /* Information from results manager */ start_message(); vmessage("Repeat match (%s)\n", ((obj->c1 > 0) == (obj->c2 > 0)) ? "direct" : "inverted"); vmessage(" From contig %s(#%d) at %d\n", get_contig_name(repeat->io, ABS(obj->c1)), io_clnbr(repeat->io, ABS(obj->c1)), obj->pos1); vmessage(" With contig %s(#%d) at %d\n", get_contig_name(repeat->io, ABS(obj->c2)), io_clnbr(repeat->io, ABS(obj->c2)), obj->pos2); vmessage(" Length %d\n\n", obj->length); end_message(cs->window); break; case 1: /* Hide */ obj_hide(GetInterp(), cs->window, obj, (mobj_repeat *)repeat, csplot_hash); break; case -2: /* default */ case 2: /* Invoke join editor */ { int cnum[2], llino[2], pos[2]; obj->flags |= OBJ_FLAG_VISITED; repeat->current = obj - repeat->match; Tcl_VarEval(GetInterp(), "CSLastUsed ", CPtr2Tcl(repeat), NULL); cnum[0] = ABS(obj->c1); cnum[1] = ABS(obj->c2); /* Complement a contig if needed */ if ((obj->c1 > 0) != (obj->c2 > 0)) { if (cnum[0] == cnum[1]) { verror(ERR_WARN, "join_editor", "cannot display the same contig in two " "different orientations"); break; } if (io_rdonly(repeat->io)) { bell(); break; } if (io_clength(repeat->io, ABS(obj->c1)) < io_clength(repeat->io, ABS(obj->c2))) { if (-1 == complement_contig(repeat->io, ABS(obj->c1))) if (-1 == complement_contig(repeat->io, ABS(obj->c2))) return NULL; } else { if (-1 == complement_contig(repeat->io, ABS(obj->c2))) if (-1 == complement_contig(repeat->io, ABS(obj->c1))) return NULL; } } /* * NB: obj->pos1 now may not be the same value as when this * function was entered, due to the complementing! */ pos[0] = obj->pos1; pos[1] = obj->pos2; llino[0] = io_clnbr(repeat->io, cnum[0]); llino[1] = io_clnbr(repeat->io, cnum[1]); join_contig(GetInterp(), repeat->io, cnum, llino, pos, consensus_cutoff, quality_cutoff); break; } case 3: /* Invoke contig editors */ { int cnum, llino, pos; cnum = ABS(obj->c1); llino = io_clnbr(repeat->io, cnum); pos = obj->pos1; edit_contig(GetInterp(), repeat->io, cnum, llino, pos, consensus_cutoff, quality_cutoff, 0, NULL); cnum = ABS(obj->c2); llino = io_clnbr(repeat->io, cnum); pos = obj->pos2; edit_contig(GetInterp(), repeat->io, cnum, llino, pos, consensus_cutoff, quality_cutoff, 0, NULL); break; } case 4: /* Remove */ obj_remove(GetInterp(), cs->window, obj, (mobj_repeat *)repeat, csplot_hash); break; } break; case OBJ_GET_BRIEF: sprintf(buf, "Repeat: %c#%d@%d with %c#%d@%d, len %d", obj->c1 > 0 ? '+' : '-', io_clnbr(repeat->io, ABS(obj->c1)), obj->pos1, obj->c2 > 0 ? '+' : '-', io_clnbr(repeat->io, ABS(obj->c2)), obj->pos2, obj->length); return buf; } return NULL; }
int find_oligos(GapIO *io, int num_contigs, contig_list_t *contig_array, float mis_match, char *string, int consensus_only, int in_cutoff) { int i; int *pos1 = NULL; int *pos2 = NULL; int *score = NULL; int *length = NULL; tg_rec *c1 = NULL; tg_rec *c2 = NULL; int max_matches, abs_max; int seq_len; int n_matches; int max_clen; char **cons_array = NULL; /* Calculate maximum contig length and total contig length */ for (max_matches = 0, max_clen = 0, i=0; i<num_contigs; i++) { if (io_clength(io, contig_array[i].contig) > max_clen) max_clen = io_clength(io, contig_array[i].contig); max_matches += io_clength(io, contig_array[i].contig); } max_matches *= 2; /* both strands */ abs_max = get_default_int(GetInterp(), gap5_defs, "FINDOLIGO.MAX_MATCHES"); if (max_matches > abs_max) max_matches = abs_max; if (NULL == (pos1 = (int *)xmalloc((max_matches + 1) * sizeof(int)))) goto error; if (NULL == (pos2 = (int *)xmalloc((max_matches + 1) * sizeof(int)))) goto error; if (NULL == (score = (int *)xmalloc((max_matches + 1) * sizeof(int)))) goto error; if (NULL == (length = (int *)xmalloc((max_matches + 1) * sizeof(int)))) goto error; if (NULL == (c1 = (tg_rec *)xmalloc((max_matches + 1) * sizeof(tg_rec)))) goto error; if (NULL == (c2 = (tg_rec *)xmalloc((max_matches + 1) * sizeof(tg_rec)))) goto error; /* save consensus for each contig */ if (NULL == (cons_array = (char **)xmalloc(num_contigs * sizeof(char *)))) goto error; for (i = 0; i < num_contigs; i++) { seq_len = contig_array[i].end - contig_array[i].start + 1; if (NULL == (cons_array[i] = (char *)xmalloc(seq_len + 1))) goto error; calculate_consensus_simple(io, contig_array[i].contig, contig_array[i].start, contig_array[i].end, cons_array[i], NULL); cons_array[i][seq_len] = '\0'; } /* do match on either tag(s) or string */ if (string && *string) { n_matches = StringMatch(io, num_contigs, contig_array, cons_array, string, mis_match, pos1, pos2, score, length, c1, c2, max_matches, consensus_only, in_cutoff); if (-1 == RegFindOligo(io, SEQUENCE, pos1, pos2, score, length, c1, c2, n_matches)) goto error; } else { /* if (-1 == (n_matches = TagMatch(io, max_clen, num_contigs, contig_array, cons_array, mis_match, pos1, pos2, score, length, c1, c2, max_matches))) goto error; if (-1 == RegFindOligo(io, TAG, pos1, pos2, score, length, c1, c2, n_matches)) */ goto error; } for (i = 0; i < num_contigs; i++) { if (cons_array[i]) xfree(cons_array[i]); } xfree(cons_array); xfree(c1); xfree(c2); xfree(pos1); xfree(pos2); xfree(score); xfree(length); return 0; error: if (c1) xfree(c1); if (c2) xfree(c2); if (cons_array) xfree(cons_array); if (pos1) xfree(pos1); if (pos2) xfree(pos2); if (score) xfree(score); if (length) xfree(length); return -1; }
int RegFindOligo(GapIO *io, int type, int *pos1, int *pos2, int *score, int *length, tg_rec *c1, tg_rec *c2, int n_matches) { mobj_find_oligo *find_oligo; obj_match *matches = NULL; char *val; int i, id; if (0 == n_matches) return 0; if (NULL == (find_oligo = (mobj_find_oligo *)xmalloc(sizeof(mobj_find_oligo)))) return -1; if (NULL == (matches = (obj_match *)xmalloc(n_matches * sizeof(obj_match)))) return -1; find_oligo->num_match = n_matches; find_oligo->match = matches; find_oligo->io = io; strcpy(find_oligo->tagname, CPtr2Tcl(find_oligo)); val = get_default_string(GetInterp(), gap5_defs, "FINDOLIGO.COLOUR"); strcpy(find_oligo->colour, val); find_oligo->linewidth = get_default_int(GetInterp(), gap5_defs, "FINDOLIGO.LINEWIDTH"); find_oligo->params = (char *)xmalloc(100); if (find_oligo->params) sprintf(find_oligo->params, "Unknown at present"); find_oligo->all_hidden = 0; find_oligo->current = -1; find_oligo->reg_func = find_oligo_callback; find_oligo->match_type = REG_TYPE_OLIGO; for (i = 0; i < n_matches; i++) { if (type == TAG) { matches[i].func = (void *(*)(int, void *, struct obj_match_t *, struct mobj_repeat_t *))find_oligo_obj_func1; } else if (type == SEQUENCE) { matches[i].func = (void *(*)(int, void *, struct obj_match_t *, struct mobj_repeat_t *))find_oligo_obj_func2; } else { return -1; } matches[i].data = find_oligo; matches[i].c1 = c1[i]; matches[i].c2 = c2[i]; matches[i].pos1 = pos1[i]; matches[i].pos2 = pos2[i]; matches[i].length = length[i]; matches[i].score = score[i]; matches[i].flags = 0; } /* Sort matches */ qsort(find_oligo->match, find_oligo->num_match, sizeof(obj_match), sort_func); PlotRepeats(io, find_oligo); Tcl_VarEval(GetInterp(), "CSLastUsed ", CPtr2Tcl(find_oligo), NULL); /* * Register the find oligo search with each of the contigs used. * Currently we assume that this is all. */ id = register_id(); contig_register(io, 0, find_oligo_callback, (void *)find_oligo, id, REG_REQUIRED | REG_DATA_CHANGE | REG_OPS | REG_NUMBER_CHANGE | REG_ORDER, REG_TYPE_OLIGO); update_results(io); return 0; }
/* * functions to act upon matches generated using TAGs */ void *find_oligo_obj_func1(int job, void *jdata, obj_match *obj, mobj_find_oligo *find_oligo) { static char buf[80]; obj_cs *cs; int cs_id; cs_id = type_to_result(find_oligo->io, REG_TYPE_CONTIGSEL, 0); cs = result_data(find_oligo->io, cs_id); switch(job) { case OBJ_LIST_OPERATIONS: return "Information\0Hide\0Invoke join editor *\0" "Invoke contig editors\0SEPARATOR\0Remove\0"; case OBJ_INVOKE_OPERATION: switch(*((int *)jdata)) { case 0: /* Information */ vfuncgroup(1, "2D plot matches"); case -1: /* Information from results manager */ start_message(); vmessage("Sequence search:\n"); vmessage(" From contig %s(#%"PRIrec") at %d\n", get_contig_name(find_oligo->io, ABS(obj->c1)), io_clnbr(find_oligo->io, ABS(obj->c1)), obj->pos1); vmessage(" With contig %s(#%"PRIrec") at %d\n", get_contig_name(find_oligo->io, ABS(obj->c2)), io_clnbr(find_oligo->io, ABS(obj->c2)), obj->pos2); vmessage(" Length %d, match %2.2f%%\n\n", obj->length, (float)obj->score / obj->length * 100.0 ); end_message(cs->window); break; case 1: /* Hide */ obj_hide(GetInterp(), cs->window, obj, (mobj_find_oligo *)find_oligo, csplot_hash); break; case -2: /* default */ case 2: /* Invoke join editor */ { tg_rec cnum[2], llino[2]; int pos[2]; obj->flags |= OBJ_FLAG_VISITED; find_oligo->current = obj - find_oligo->match; Tcl_VarEval(GetInterp(), "CSLastUsed ", CPtr2Tcl(find_oligo), NULL); cnum[0] = ABS(obj->c1); cnum[1] = ABS(obj->c2); /* Complement a contig if needed */ if ((obj->c1 > 0) != (obj->c2 > 0)) { if (cnum[0] == cnum[1]) { verror(ERR_WARN, "join_editor", "cannot display the same contig in two " "different orientations"); break; } if (find_oligo->io->read_only) { bell(); break; } if (io_clength(find_oligo->io, ABS(obj->c1)) < io_clength(find_oligo->io, ABS(obj->c2))) { if (-1 == complement_contig(find_oligo->io, ABS(obj->c1))) if (-1 == complement_contig(find_oligo->io, ABS(obj->c2))) return NULL; } else { if (-1 == complement_contig(find_oligo->io, ABS(obj->c2))) if (-1 == complement_contig(find_oligo->io, ABS(obj->c1))) return NULL; } } /* * NB: obj->pos1 now may not be the same value as when this * function was entered, due to the complementing! */ pos[0] = obj->pos1; pos[1] = obj->pos2; llino[0] = io_clnbr(find_oligo->io, cnum[0]); llino[1] = io_clnbr(find_oligo->io, cnum[1]); join_contig(find_oligo->io, cnum, llino, pos); break; } case 3: /* Invoke contig editors */ { tg_rec cnum, llino; int pos; cnum = ABS(obj->c1); llino = io_clnbr(find_oligo->io, cnum); pos = obj->pos1; edit_contig(find_oligo->io, cnum, llino, pos); cnum = ABS(obj->c2); llino = io_clnbr(find_oligo->io, cnum); pos = obj->pos2; edit_contig(find_oligo->io, cnum, llino, pos); break; } case 4: /* Remove */ obj_remove(GetInterp(), cs->window, obj, (mobj_find_oligo *)find_oligo, csplot_hash); break; } break; case OBJ_GET_BRIEF: sprintf(buf, "Oligo: %c#%"PRIrec"@%d with %c#%"PRIrec"@%d, " "len %d, match %2.2f%%", obj->c1 > 0 ? '+' : '-', io_clnbr(find_oligo->io, ABS(obj->c1)), obj->pos1, obj->c2 > 0 ? '+' : '-', io_clnbr(find_oligo->io, ABS(obj->c2)), obj->pos2, obj->length, (float)obj->score / obj->length * 100.0); return buf; } return NULL; }
/* * functions to act upon matches generated using SEQUENCE */ void *find_oligo_obj_func2(int job, void *jdata, obj_match *obj, mobj_find_oligo *find_oligo) { static char buf[80]; obj_cs *cs; int cs_id; cs_id = type_to_result(find_oligo->io, REG_TYPE_CONTIGSEL, 0); cs = result_data(find_oligo->io, cs_id); switch(job) { case OBJ_LIST_OPERATIONS: return "Information\0Hide\0Invoke contig editor *\0" "SEPARATOR\0Remove\0"; case OBJ_INVOKE_OPERATION: switch(*((int *)jdata)) { case 0: /* Information */ vfuncgroup(1, "2D plot matches"); case -1: /* Information from results manager */ start_message(); vmessage("Sequence search\n"); vmessage(" Contig %s(#%"PRIrec") at %d\n", get_contig_name(find_oligo->io, ABS(obj->c1)), io_clnbr(find_oligo->io, ABS(obj->c1)), obj->pos1); vmessage(" Length %d, match %2.2f%%\n\n", obj->length, (float)obj->score / obj->length * 100.0 ); end_message(cs->window); break; case 1: /* Hide */ obj_hide(GetInterp(), cs->window, obj, (mobj_find_oligo *)find_oligo, csplot_hash); break; case -2: /* default */ case 2: /* Invoke contig editor */ { tg_rec cnum, llino; int pos; obj->flags |= OBJ_FLAG_VISITED; find_oligo->current = (int)(obj - find_oligo->match); cnum = ABS(obj->c1); llino = 0; pos = obj->pos1; /* FIXME if ((id = editor_available(cnum, 1)) == -1) { edit_contig(GetInterp(), find_oligo->io, cnum, llino, pos, consensus_cutoff, quality_cutoff, 0, NULL); } if ((id = editor_available(cnum, 1)) != -1) { move_editor(id, llino, pos); editor_select_region(id, llino, pos, obj->length); } */ edit_contig(find_oligo->io, cnum, llino, pos); break; } case 3: /* Remove */ obj_remove(GetInterp(), cs->window, obj, (mobj_find_oligo *)find_oligo, csplot_hash); break; } break; case OBJ_GET_BRIEF: sprintf(buf, "Oligo: %c#%"PRIrec"@%d with %c#%"PRIrec"@%d, " "len %d, match %2.2f%%", obj->c1 > 0 ? '+' : '-', io_clnbr(find_oligo->io, ABS(obj->c1)), obj->pos1, obj->c2 > 0 ? '+' : '-', io_clnbr(find_oligo->io, ABS(obj->c2)), obj->pos2, obj->length, (float)obj->score / obj->length * 100.0); return buf; } return NULL; }