Skip to content
Snippets Groups Projects
Commit 9db60a9b authored by rnc's avatar rnc
Browse files

added code to draw features

parent 5cb0fc93
No related branches found
No related tags found
No related merge requests found
......@@ -27,9 +27,9 @@
* window displaying genome data.
*
* HISTORY:
* Last edited: Jul 13 15:49 2004 (edgrif)
* Last edited: Jul 15 10:26 2004 (rnc)
* Created: Thu Jul 24 15:21:56 2003 (edgrif)
* CVS info: $Id: zmapWindow.h,v 1.9 2004-07-14 09:02:38 edgrif Exp $
* CVS info: $Id: zmapWindow.h,v 1.10 2004-07-15 16:27:58 rnc Exp $
*-------------------------------------------------------------------
*/
#ifndef ZMAP_WINDOW_H
......@@ -133,7 +133,8 @@ void zMapRegionFreeDNA (ZMapRegion *region);
void zmapWindowDrawFeatures (ZMapFeatureContext feature_context);
void zmapWindowDrawFeatures (FooCanvas *canvas,
ZMapFeatureContext feature_context);
/* TEST SCAFFOLDING............... */
......
......@@ -26,9 +26,9 @@
*
* Exported functions: See zmapControl_P.h
* HISTORY:
* Last edited: Jul 15 15:51 2004 (edgrif)
* Last edited: Jul 15 17:12 2004 (rnc)
* Created: Thu Jul 8 12:54:27 2004 (edgrif)
* CVS info: $Id: zmapControlNavigator.c,v 1.2 2004-07-15 15:06:52 edgrif Exp $
* CVS info: $Id: zmapControlNavigator.c,v 1.3 2004-07-15 16:30:14 rnc Exp $
*-------------------------------------------------------------------
*/
......@@ -141,15 +141,15 @@ void navScale(FooCanvas *canvas, float offset, int start, int end)
for (x = start, count = 1 ; x < end ; x += 10, count++)
{
drawLine(FOO_CANVAS_GROUP(group), offset-5, x, offset, x, "black", 1.0);
zmapDrawLine(FOO_CANVAS_GROUP(group), offset-5, x, offset, x, "black", 1.0);
char text[25];
sprintf(text,"%dk", x);
if (count == 1)
displayText(FOO_CANVAS_GROUP(group), text, offset + 20, x);
zmapDisplayText(FOO_CANVAS_GROUP(group), text, offset + 20, x);
if (count > 9) count = 0;
}
drawLine(FOO_CANVAS_GROUP(group), offset+1, 0, offset+1, end, "black", 1.0);
zmapDrawLine(FOO_CANVAS_GROUP(group), offset+1, 0, offset+1, end, "black", 1.0);
return;
}
......
......@@ -27,9 +27,9 @@
*
* Exported functions: See zmapControl_P.h
* HISTORY:
* Last edited: Jul 15 15:51 2004 (edgrif)
* Last edited: Jul 15 17:15 2004 (rnc)
* Created: Thu Jul 24 14:36:27 2003 (edgrif)
* CVS info: $Id: zmapControlWindowButtons.c,v 1.9 2004-07-15 15:10:17 edgrif Exp $
* CVS info: $Id: zmapControlWindowButtons.c,v 1.10 2004-07-15 16:31:14 rnc Exp $
*-------------------------------------------------------------------
*/
......@@ -54,7 +54,8 @@ GtkWidget *zmapControlWindowMakeButtons(ZMap zmap)
{
GtkWidget *frame ;
GtkWidget *hbox, *new_button, *load_button, *stop_button, *quit_button,
*hsplit_button, *vsplit_button, *zoomin_button, *zoomout_button ;
*hsplit_button, *vsplit_button, *zoomin_button, *zoomout_button,
*close_button ;
frame = gtk_frame_new(NULL);
gtk_container_border_width(GTK_CONTAINER(frame), 5);
......@@ -97,7 +98,12 @@ GtkWidget *zmapControlWindowMakeButtons(ZMap zmap)
gtk_signal_connect(GTK_OBJECT(zoomout_button), "clicked",
GTK_SIGNAL_FUNC(zoomOutCB), (gpointer)zmap);
gtk_box_pack_start(GTK_BOX(hbox), zoomout_button, FALSE, FALSE, 0) ;
/*
close_button = gtk_button_new_with_label("Close\nPane") ;
gtk_signal_connect(GTK_OBJECT(close_button), "clicked",
GTK_SIGNAL_FUNC(closePane), (gpointer)zmap) ;
gtk_box_pack_start(GTK_BOX(hbox), close_button, FALSE, FALSE, 0) ;
*/
quit_button = gtk_button_new_with_label("Quit") ;
gtk_signal_connect(GTK_OBJECT(quit_button), "clicked",
GTK_SIGNAL_FUNC(quitCB), (gpointer)zmap) ;
......@@ -117,8 +123,9 @@ GtkWidget *zmapControlWindowMakeButtons(ZMap zmap)
/*
* ------------------- Internal functions -------------------
*/
static void testfunc(GQuark key_id, gpointer data, gpointer user_data);
/* These callbacks simple make calls to routines in zmapControl.c, this is because I want all
/* These callbacks simply make calls to routines in zmapControl.c, this is because I want all
* the state handling etc. to be in one file so that its easier to work on. */
static void loadCB(GtkWidget *widget, gpointer cb_data)
{
......
......@@ -25,9 +25,9 @@
* Description: Private header for interface that creates/manages/destroys
* instances of ZMaps.
* HISTORY:
* Last edited: Jul 15 15:52 2004 (edgrif)
* Last edited: Jul 15 17:16 2004 (rnc)
* Created: Thu Jul 24 14:39:06 2003 (edgrif)
* CVS info: $Id: zmapControl_P.h,v 1.6 2004-07-15 15:11:25 edgrif Exp $
* CVS info: $Id: zmapControl_P.h,v 1.7 2004-07-15 16:31:50 rnc Exp $
*-------------------------------------------------------------------
*/
#ifndef ZMAP_CONTROL_P_H
......@@ -58,14 +58,13 @@ typedef enum {
* this top level window there will be one or more zmap "Views". */
typedef struct _ZMapStruct
{
gchar *zmap_id ; /* unique for each zmap.... */
gchar *zmap_id ; /* unique for each zmap.... */
ZmapState state ; /* state of this zmap. */
ZmapState state ;
gboolean firstTime;
GdkAtom zmap_atom ; /* Used for communicating with zmap
windows. */
GdkAtom zmap_atom ; /* Used for communicating with zmap */
void *app_data ; /* Data passed back to all callbacks
registered for this ZMap. */
......@@ -80,9 +79,12 @@ typedef struct _ZMapStruct
/* The navigator. */
GtkWidget *navigator ;
FooCanvas *navcanvas ;
GtkWidget *navHBox, *navVBox;
/* The panes and views. */
// GtkWidget *displayvbox;
// GtkWidget *hbox;
/* I'm not completely sure this is necessary....revisit this later.... */
GtkWidget *pane_vbox ;
......@@ -90,6 +92,7 @@ typedef struct _ZMapStruct
ZMapPane focuspane ;
GNode *panesTree ;
// ZMapView curr_view ;
/* List of views in this zmap. */
GList *view_list ;
......@@ -118,7 +121,6 @@ typedef struct _ZMapPaneStruct
} ZMapPaneStruct ;
/* Functions internal to zmapControl. */
gboolean zmapControlWindowCreate (ZMap zmap) ;
GtkWidget *zmapControlWindowMakeMenuBar(ZMap zmap) ;
......
/* Last edited: Jun 25 12:13 2004 (edgrif) */
/* Last edited: Jul 8 12:21 2004 (rnc) */
/* This is a temporary file only to help with testing....it will go once GFF code is combined
* into the threads etc. code proper.... */
......@@ -9,6 +9,7 @@
static ZMapFeatureContext parseGFF(char *filename) ;
static void testfunc(GQuark key_id, gpointer data, gpointer user_data);
ZMapFeatureContext testGetGFF(void)
......@@ -107,11 +108,9 @@ static ZMapFeatureContext parseGFF(char *filename)
/* Try getting the features. */
feature_context = zmapGFFGetFeatures(parser) ;
zMapGFFSetFreeOnDestroy(parser, free_arrays) ;
zMapGFFDestroyParser(parser) ;
if (status == G_IO_STATUS_EOF)
{
if (g_io_channel_shutdown(gff_file, FALSE, &gff_file_err) != G_IO_STATUS_NORMAL)
......@@ -125,11 +124,28 @@ static ZMapFeatureContext parseGFF(char *filename)
printf("Error reading lines from gff file\n") ;
exit(-1) ;
}
}
return feature_context ;
}
static void testfunc(GQuark key_id, gpointer data, gpointer user_data)
{
ZMapFeatureSet zMapFeatureSet = (ZMapFeatureSet)data;
ZMapFeature zMapFeature;
int i;
printf("GFF_scaffold.c; call %s\n", (char*)user_data);
for (i=0; i<zMapFeatureSet->features->len; i++)
{
zMapFeature = &g_array_index(zMapFeatureSet->features, ZMapFeatureStruct, i);
printf("processing %s, x1 is %d, x2 is %d\n", zMapFeature->name, zMapFeature->x1, zMapFeature->x2);
}
return;
}
......@@ -27,41 +27,184 @@
*
* Exported functions:
* HISTORY:
* Last edited: Jul 2 18:09 2004 (edgrif)
* Last edited: Jul 15 16:02 2004 (rnc)
* Created: Thu Jul 29 10:45:00 2004 (rnc)
* CVS info: $Id: zmapWindowDrawFeatures.c,v 1.2 2004-07-02 18:24:54 edgrif Exp $
* CVS info: $Id: zmapWindowDrawFeatures.c,v 1.3 2004-07-15 16:34:51 rnc Exp $
*-------------------------------------------------------------------
*/
#include <zmapWindow_P.h>
#include <ZMap/zmapDraw.h>
typedef struct _ParamStruct {
FooCanvas *thisCanvas;
int height;
int length;
} ParamStruct;
static void zmapWindowProcessArray(GQuark key_id, gpointer data, gpointer user_data);
static void zmapWindowProcessFeatureSet(GQuark key_id, gpointer data, gpointer user_data);
void zmapWindowDrawFeatures(ZMapFeatureContext feature_context)
void zmapWindowDrawFeatures(FooCanvas *canvas, ZMapFeatureContext feature_context)
{
float column_spacing = 10.0;
float offset = 20.0;
float result;
double x1, x2, y1, y2;
GtkWidget *parent, *label, *vbox, *vscale, *frame;
GtkRequisition req;
ParamStruct params;
int ticks; // number of tickmarks on scale
int scaleUnit = 100; // spacing of tickmarks on scalebar
int seqUnit; // spacing, in bases of tickmarks
int type; // nomial, ie whether in K, M, etc.
int unitType;
int seqPos;
int scalePos;
int height, width;
char cp[20], unitName[] = { 0, 'k', 'M', 'G', 'T', 'P' }, buf[2] ;
GtkWidget *box;
// parent = gtk_widget_get_parent(GTK_WIDGET(canvas));
// gtk_widget_size_request(parent, &req);
foo_canvas_get_scroll_region(canvas, &x1, &y1, &x2, &y2); // for display panel
// gtk_widget_size_request(navHBox, &req); // for navigator
params.thisCanvas = canvas;
params.height = y2 - y1;
params.length = feature_context->sequence_to_parent.c2 - feature_context->sequence_to_parent.c1;
// Draw the navigator vscale
// how many tickmarks do we want?
// ticks = req.height/scaleUnit;
//what is their spacing in bases
// seqUnit = (feature_context->sequence_to_parent.c2 - feature_context->sequence_to_parent.c1)/ticks;
// are we working in K, M, or what?
// for (type = 1, unitType = 0 ;
// seqUnit > 0 && 1000 * type < seqUnit && unitType < 5;
// unitType++, type *= 1000) ;
// round seqUnit sensibly
// seqUnit = ((seqUnit + type/2)/type) * type;
// a vbox to hold all the scale numbers packed in
// vbox = gtk_vbox_new(TRUE, 0);
// gtk_box_pack_start(GTK_BOX(navHBox), vbox, FALSE, FALSE, 0);
// mark up the scale
/* for (scalePos = 0, seqPos = feature_context->sequence_to_parent.c1;
scalePos < req.height;
scalePos += scaleUnit, seqPos += seqUnit)
{
buf[0] = unitName[unitType] ; buf[1] = 0 ;
sprintf (cp, "%d%s", seqPos/type, buf) ;
if (width < strlen (cp))
width = strlen (cp) ;
box = gtk_hbox_new(TRUE, 0);
label = gtk_label_new(cp);
gtk_container_add(GTK_CONTAINER(box), label);
gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 0);
}
*/
// just trying out the vscale in case it's useful
// vscale = gtk_vscale_new_with_range(0, req.height, scaleUnit);
// gtk_box_pack_start(GTK_BOX(navHBox), vscale, FALSE, FALSE, 0);
result = zmapDrawScale(canvas , offset,
feature_context->sequence_to_parent.c1,
feature_context->sequence_to_parent.c2);
if (feature_context)
g_datalist_foreach(&(feature_context->features), zmapWindowProcessArray, &column_spacing);
g_datalist_foreach(&(feature_context->features), zmapWindowProcessFeatureSet, &params);
// gtk_widget_show_all(navHBox);
return;
}
static void zmapWindowProcessArray(GQuark key_id, gpointer data, gpointer user_data)
static void zmapWindowProcessFeatureSet(GQuark key_id, gpointer data, gpointer user_data)
{
ZMapFeatureSet zMapFeatureSet = (ZMapFeatureSet)data;
float *column_spacing = (float*)user_data;
int i;
ZMapFeature zMapFeature;
ZMapSpan zMapSpan, prevSpan;
ZMapAlignBlock *zMapAlign, *prevAlign;
ParamStruct *params = (ParamStruct*)user_data;
int i, j;
double offset = 40.0, column_spacing = 40.0, column_position;
double box_width = 10.0;
FooCanvasItem *group;
int x1, x2, y0, y1, y2;
float middle, line_width = 1.0;
// NB for each column we create a new canvas group, with the initial y coordinate set to
// 5.0 to just drop it a teeny bit from the top of the window. All items live in the group.
for (i = 0; i < zMapFeatureSet->features->len; i++)
{
// printf("processing %s\n", zMapFeatureSet->features->name);
}
column_position = offset + column_spacing;
zMapFeature = &g_array_index(zMapFeatureSet->features, ZMapFeatureStruct, i);
switch (zMapFeature->type)
{
case ZMAPFEATURE_HOMOL: /* type 1 is a homol */
group = foo_canvas_item_new(foo_canvas_root(params->thisCanvas),
foo_canvas_group_get_type(),
"x",(double)column_position,
"y",(double)5.0,
NULL);
zmapDrawBox(group, column_position, (zMapFeature->feature.homol.y1 * params->height / params->length),
column_position + box_width, (zMapFeature->feature.homol.y2 * params->height / params->length),
"black", "green");
break;
case ZMAPFEATURE_TRANSCRIPT: /* type 4 is a transcript */
column_position = offset;
group = foo_canvas_item_new(foo_canvas_root(params->thisCanvas),
foo_canvas_group_get_type(),
"x",(double)column_position,
"y",(double)5.0,
NULL);
for (j = 1; j < zMapFeature->feature.transcript.exons->len; j++)
{
zMapSpan = &g_array_index(zMapFeature->feature.transcript.exons, ZMapSpanStruct, j);
prevSpan = &g_array_index(zMapFeature->feature.transcript.exons, ZMapSpanStruct, j-1);
middle = ((prevSpan->x2 + zMapSpan->x1)/2) * params->height/params->length;
y0 = prevSpan->x1 * params->height/params->length; // y coord of preceding exon
y1 = prevSpan->x2 * params->height/params->length;
y2 = zMapSpan->x1 * params->height/params->length;
// skip this intron if its preceding exon is too small to draw. We use
// y0 and y1 since they are screen coordinates independent of magnification.
// Note this is a kludge which will meet its come-uppance during zooming
// because zooming doesn't revisit this block of code, so tiny exons will
// appear when zoomed, but the intervening introns will be lost forever.
if (y2 > y1 && y0 +2 <= y1)
{
zmapDrawLine(FOO_CANVAS_GROUP(group), column_position + box_width/2, y1,
column_position + box_width, middle, "blue", line_width);
zmapDrawLine(FOO_CANVAS_GROUP(group), column_position + box_width, middle,
column_position + box_width/2, y2, "blue", line_width);
}
}
for (j = 0; j < zMapFeature->feature.transcript.exons->len; j++)
{
zMapSpan = &g_array_index(zMapFeature->feature.transcript.exons, ZMapSpanStruct, j);
zmapDrawBox(group, column_position, (zMapSpan->x1 * params->height / params->length),
column_position + box_width, (zMapSpan->x2 * params->height / params->length),
"black", "blue");
}
break;
default:
break;
}
}
return;
}
/****************** end of file ************************************/
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment