Skip to content
Snippets Groups Projects
Commit 3ea535f0 authored by edgrif's avatar edgrif
Browse files

moved here from src/zmapWindow, they are redundant.

parent f6daa7f7
No related branches found
No related tags found
No related merge requests found
This directory contains code that was originally written by Simon Kelley to implement
a zmap running under xace.
Rob Clack then took this code and tried to change it to have genuinely acedb/non-acedb
parts, this was not a success and was abandonned.
The code is here just so that is does not get lost, that's all.
/* File: seqregion.c
* Author: Simon Kelley (srk@sanger.ac.uk)
* Copyright (c) Sanger Institute, 2004
*-------------------------------------------------------------------
* ZMap is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
*-------------------------------------------------------------------
* This file is part of the ZMap genome database package
* originated by
* Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk,
* Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk
*
* Description:
* Exported functions: See XXXXXXXXXXXXX.h
* HISTORY:
* Last edited: Jul 16 09:50 2004 (edgrif)
* Created: Wed Jun 30 13:38:10 2004 (edgrif)
* CVS info: $Id: seqregion.c,v 1.1 2005-01-10 10:21:50 edgrif Exp $
*-------------------------------------------------------------------
*/
#include <seqregion.h>
/* Returns a coordinate in the absolute direction. */
InvarCoord srInvarCoord(ZMapRegion *zMapRegion, Coord coord)
{
if (zMapRegion->rootIsReverse)
return coord - zMapRegion->length + 1;
else
return coord;
}
/* Returns a coordinate in the current direction. */
Coord srCoord(ZMapRegion *zMapRegion, InvarCoord coord)
{
if (zMapRegion->rootIsReverse)
return coord - zMapRegion->length + 1;
else
return coord;
}
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
/* this is not called from anywhere at the moment..... */
/* Creates a new, empty ZMapRegion structure. */
ZMapRegion *srCreate(void)
{
ZMapRegion *zMapRegion = (ZMapRegion*)g_malloc0(sizeof(ZMapRegion)) ;
zMapRegion->area1 = zMapRegion->area2 = 0 ;
zMapRegion->methods = NULL ;
zMapRegion->oldMethods = NULL ;
zMapRegion->dna = NULL ;
return zMapRegion ;
}
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
/* Retrieves a method structure from the methods array based on
* the ID it receives. Knows nothing of AceDB, which is why it's
* here, but could as well be in zmapcalls.c with it's sisters. */
srMeth *srMethodFromID(ZMapRegion *zMapRegion, methodID id)
{
srMeth *result = NULL ;
if (zMapRegion && zMapRegion->methods)
{
int i ;
for (i = 0 ; i < zMapRegionGetMethods(zMapRegion)->len ; i++)
{
srMeth *meth = g_ptr_array_index(zMapRegionGetMethods(zMapRegion), i) ;
if (meth->id == id)
{
result = meth ;
break ;
}
}
}
return result ;
}
/********************** end of file **********************************/
/* File: seqregion.h
* Author: Simon Kelley (srk@sanger.ac.uk)
* Copyright (c) Sanger Institute, 2004
*-------------------------------------------------------------------
* ZMap is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
*-------------------------------------------------------------------
* This file is part of the ZMap genome database package
* originated by
* Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk,
* Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk
*
* Description:
* Exported functions: See XXXXXXXXXXXXX.h
* HISTORY:
* Last edited: Jun 30 13:57 2004 (edgrif)
* Created: Wed Jun 30 13:50:48 2004 (edgrif)
* CVS info: $Id: seqregion.h,v 1.1 2005-01-10 10:21:50 edgrif Exp $
*-------------------------------------------------------------------
*/
#ifndef SEQREGION_H
#define SEQREGION_H
#include <ZMap/zmapWindow.h>
/*
THIS HAS NOT COME TO PASS...........THE WHOLE SEQREGION FILE MAY
DISAPPEAR........
This file defines the seqRegion interface.
The seqregion package populates a data structure with all the information
about a particular DNA area. This package is the interface between the drawing
code and the underlying database engine. Different version of the code access
acedb directly via the BS and sMap interfaces, or a remote server via Fex.
The public part of the seqRegion datastructure is exposed to the
drawing code. This may not depend on any back-end data structures or types:
No KEYS, classes or sMapInfos allowed.
*/
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
#define SEQUENCE 1
#define FEATURE 2
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
/* Create a new one - must call srActivate next */
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
/* totally unused currently........... */
ZMapRegion *srCreate() ;
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
/* Coordinate conversion. */
InvarCoord srInvarCoord(ZMapRegion *zMapRegion, Coord coord);
Coord srCoord(ZMapRegion *zMapRegion, InvarCoord coord);
/* Move from id to struct. */
srMeth *srMethodFromID(ZMapRegion *zmapRegion, methodID id);
#endif
/********************** end of file ************************/
/* Last edited: Jul 16 09:50 2004 (edgrif) */
/* file: stringbucket.c
* Author: Simon Kelley (srk@sanger.ac.uk)
* Copyright (c) Sanger Institute, 2003
*-------------------------------------------------------------------
* Zmap is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
*-------------------------------------------------------------------
* This file is part of the ZMap genome database package
* and was written by
* Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk,
* Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk and
* Simon Kelley (Sanger Institute, UK) srk@sanger.ac.uk
*/
#include <strings.h>
#include <glib.h>
#include <stringbucket.h>
struct sbucket {
struct sbucketchain *chain;
};
struct sbucketchain {
struct sbucketchain *next;
};
StringBucket *sbCreate(void)
{
StringBucket *b = g_malloc0(sizeof(struct sbucket)) ;
b->chain = NULL;
return b;
}
void sbDestroy(StringBucket *b)
{
struct sbucketchain *c = b->chain;
g_free(b);
while (c)
{
struct sbucketchain *tmp = c->next;
g_free(c);
c = tmp;
}
}
char *str2p(char *string, StringBucket *b)
{
struct sbucketchain *c = b->chain;
while (c && (strcmp((char *)(c+1), string) !=0))
c = c->next;
if (!c)
{
c = g_malloc0(sizeof(struct sbucketchain) + strlen(string) + 1) ;
c->next = b->chain;
b->chain = c;
strcpy((char *)(c+1), string);
}
return (char *)(c+1);
}
/*********************** end of file ***********************************/
/* Last edited: Jul 5 14:37 2004 (rnc) */
/* file: stringbucket.h
* Author: Simon Kelley (srk@sanger.ac.uk)
* Copyright (c) Sanger Institute, 2003
*-------------------------------------------------------------------
* Zmap is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
*-------------------------------------------------------------------
* This file is part of the ZMap genome database package
* and was written by
* Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk,
* Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk and
* Simon Kelley (Sanger Institute, UK) srk@sanger.ac.uk
*/
/* Stringbucket:
Given a string returns a copy which is persistant until the
bucket is destroyed.
Has the property that calling str2p twice on the same string yields
the same pointer.
*/
#ifndef STRINGBUCKET_H
#define STRINGBUCKET_H
struct sbucket;
typedef struct sbucket StringBucket;
StringBucket *sbCreate(void) ;
void sbDestroy(StringBucket *b);
char *str2p(char *string, StringBucket *b);
#endif
/* Last edited: Dec 3 13:46 2003 (rnc) */
/* file: zmap.h
* Author: Simon Kelley (srk@sanger.ac.uk)
* Copyright (c) Sanger Institute, 2003
*-------------------------------------------------------------------
* Zmap is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
*-------------------------------------------------------------------
* This file is part of the ZMap genome database package
* and was written by
* Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk,
* Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk and
* Simon Kelley (Sanger Institute, UK) srk@sanger.ac.uk
*/
#ifndef ZMAP_H
#define ZMAP_H
#include <wh/acedb.h>
BOOL zMapCall(KEY key, KEY from, BOOL isOldGraph, void *app_data);
#endif
/*********************** end of file ********************************/
/* Last edited: Jul 16 09:51 2004 (edgrif) */
/* file: zmapbccol.c
* Author: Simon Kelley (srk@sanger.ac.uk)
* Copyright (c) Sanger Institute, 2003
*-------------------------------------------------------------------
* Zmap is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
*-------------------------------------------------------------------
* This file is part of the ZMap genome database package
* and was written by
* Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk,
* Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk and
* Simon Kelley (Sanger Institute, UK) srk@sanger.ac.uk
*/
/* Generic box drawing column code */
/* This code was written on the day the US and UK
started the Second Oil War.
I think the module name "nbc" is somehow appropriate - srk */
#include <math.h>
#include <glib.h>
#include <ZMap/zmapFeature.h>
#include <ZMap/zmapDraw.h>
#include <seqregion.h>
/* A lot of this comes direct from acedb.......... */
enum Colour {WHITE, BLACK, LIGHTGRAY, DARKGRAY,
RED, GREEN, BLUE,
YELLOW, CYAN, MAGENTA,
LIGHTRED, LIGHTGREEN, LIGHTBLUE,
DARKRED, DARKGREEN, DARKBLUE,
PALERED, PALEGREEN, PALEBLUE,
PALEYELLOW, PALECYAN, PALEMAGENTA,
BROWN, ORANGE, PALEORANGE,
PURPLE, VIOLET, PALEVIOLET,
GRAY, PALEGRAY,
CERISE, MIDBLUE,
NUM_TRUECOLORS,
TRANSPARENT, /* pseudocolour only for background */
FORECOLOR, /* pseudocolor to force box->fcol after graphColor() */
BACKCOLOR /* pseudocolor to force box->bcol after graphColor() */
} ;
/* Defines the way columns are displayed when there are lots of features overlapping within
* a column. */
typedef enum {METHOD_OVERLAP_COMPLETE, METHOD_OVERLAP_BUMPED, METHOD_OVERLAP_CLUSTER} MethodOverlapModeType ;
/* AGH......THIS ALL NEEDS SORTING OUT......... */
/* forward declaration of opaque type */
typedef struct BumpStruct *BUMP;
#define METHOD_FRAME_SENSITIVE 0x00000004U /* if tag "Frame_sensitive" */
#define METHOD_STRAND_SENSITIVE 0x00000008U /* if tag "Stand_sensitive" */
#define METHOD_SHOW_UP_STRAND 0x00010000U /* if tag "Show_up_strand" */
#define METHOD_SCORE_BY_OFFSET 0x00000010U /* if tag "Score_by_offset" */
#define METHOD_SCORE_BY_WIDTH 0x00000020U /* if tag "score_by_width" */
#define METHOD_SCORE_BY_HIST 0x00002000U /* if tag "Score_by_histogram"*/
#define METHOD_PERCENT 0x00000400U /* if tag "Percent"
defaults Score_bounds
min/max to 25/100
(can be overridden) */
#define METHOD_BUMPABLE 0x00000200U /* if tag "Bumpable" */
#define METHOD_CLUSTER 0x00020000U /* if tag "Cluster" */
#define METHOD_BLASTN 0x00000001U /* if tag "BlastN" -
can calculate percent
from score */
#define METHOD_BELVU 0x00004000U /* if tag "Belvu"
esr, for PEPMAP */
#define METHOD_BLIXEM_X 0x00000040U /* if tag "Blixem_X" */
#define METHOD_BLIXEM_N 0x00000080U /* if tag "Blixem_N" */
#define METHOD_BLIXEM_P 0x00008000U /* if tag "Blixem_P" */
#define METHOD_EMBL_DUMP 0x00001000U /* if tag "EMBL_dump" */
#define METHOD_DONE 0x00000002U /* if method already cached */
#define METHOD_CALCULATED 0x00000800U /* used in addOldSegs */
#define METHOD_GAPS 0x00040000U /* Show gapped sequences and homols */
#define METHOD_JOIN_BLOCKS 0x00080000U /* Join all blocks of a single match with lines. */
/*#define METHOD_CACHED 0x00000100U * set if Method exists
* in cache and has a
* real obj in the DB */
/* convenience flag */
#define METHOD_SCORE (METHOD_SCORE_BY_OFFSET | \
METHOD_SCORE_BY_WIDTH | \
METHOD_SCORE_BY_HIST)
typedef enum { DEFAULT=0, WIDTH, OFFSET, HIST } BoxColModeType;
typedef struct {
MethodOverlapModeType overlap_mode ; /* See wh/method.h */
/* following not under user control */
float offset ;
gboolean isDown ;
BoxColModeType mode ;
float fmax ;
BUMP bump ;
GHashTable* cluster ;
int clusterCount ;
int width;
float histBase;
} nbcPrivate;
static void nbcFinalise(void *arg)
{
nbcPrivate *priv = (nbcPrivate *)arg;
// if (priv->bump)
// bumpDestroy(priv->bump);
return;
}
void nbcInit(ZMapPane pane, ZMapColumn *col)
{
/* this whole bit needs to be rewritten, so it's OK to comment it out, I think
srMeth *meth = srMethodFromID(zMapPaneGetZMapRegion(pane), col->meth);
nbcPrivate *bc = (nbcPrivate*)g_malloc0(sizeof(nbcPrivate));
// nbcPrivate *bc = handleAlloc(nbcFinalise, zMapWindowGetHandle(pane->window),
// sizeof(nbcPrivate));
col->private = bc;
if (meth->flags & METHOD_SCORE)
{
bc->mode = WIDTH;
if (meth->flags & METHOD_SCORE_BY_OFFSET
&& !col->isFrame)
bc->mode = OFFSET ;
else if (meth->flags & METHOD_SCORE_BY_HIST)
bc->mode = HIST ;
// checks to prevent arithmetic crash
if (bc->mode == OFFSET)
{
if (!meth->minScore)
meth->minScore = 1 ;
}
else
{
if (meth->maxScore == meth->minScore)
meth->maxScore = meth->minScore + 1 ;
}
}
else
// none of the SCORE_BY_xxx flags set
bc->mode = DEFAULT ;
if (meth->width)
{
if (bc->mode == WIDTH
&& meth->flags & METHOD_SCORE_BY_OFFSET
&& meth->width > 2)
bc->width = 2 ;
else
bc->width = meth->width ;
}
else
// the method doesn't set the width
{
if (bc->mode == OFFSET)
bc->width = 7 ;
else
bc->width = 2 ;
}
if (bc->mode == HIST)
{
// normalise the BoxCol's histBase
if (meth->minScore == meth->maxScore)
bc->histBase = meth->minScore ;
else
bc->histBase = (meth->histBase - meth->minScore) /
(meth->maxScore - meth->minScore) ;
if (bc->histBase < 0) bc->histBase = 0 ;
if (bc->histBase > 1) bc->histBase = 1 ;
bc->fmax = (bc->width * bc->histBase) + 0.2 ;
}
else
bc->fmax = 0 ;
*/
return;
}
static void nbcCalcBox (srMeth *methp, nbcPrivate *bc, float *x1p, float *x2p,
float *y1p, float *y2p, float score)
{
int xoff ;
float x1, x2, y1, y2;
float left, dx;
float numerator, denominator ;
double logdeux = log((double)2.0) ;
numerator = score - methp->minScore ;
denominator = methp->maxScore - methp->minScore ;
left = *x1p;
y1 = *y1p;
y2 = *y2p;
switch (bc->mode)
{
case OFFSET:
if (denominator == 0) /* catch div by zero */
{
if (numerator < 0)
dx = 0.8 ;
else if (numerator > 0)
dx = 3 ;
}
else
{
dx = 1 + (((float)numerator)/ ((float)(denominator))) ;
}
if (dx < .8) dx = .8 ; if (dx > 3) dx = 3 ; /* allow some leeway & catch dx == 0 */
dx = bc->width * log((double)dx)/logdeux ;
x1 = left + dx ;
x2 = left + dx + .9 ;
if (bc->fmax < dx + 1.5)
bc->fmax = dx + 1.5 ;
break ;
case HIST:
if (denominator == 0) /* catch div by zero */
{
if (numerator < 0)
dx = 0 ;
else if (numerator > 1)
dx = 1 ;
}
else
{
dx = numerator / denominator ;
if (dx < 0) dx = 0 ;
if (dx > 1) dx = 1 ;
}
x1 = left + (bc->width * bc->histBase) ;
x2 = left + (bc->width * dx) ;
if (bc->fmax < bc->width*dx)
bc->fmax = bc->width*dx ;
break ;
case WIDTH:
if (denominator == 0) /* catch div by zero */
{
if (numerator < 0)
dx = 0.25 ;
else if (numerator > 0)
dx = 1 ;
}
else
{
dx = 0.25 + ((0.75 * numerator) / denominator) ;
}
if (dx < 0.25) dx = 0.25 ;
if (dx > 1) dx = 1 ;
/* !WARNING! fall-through */
case DEFAULT:
if (bc->mode == DEFAULT)
dx = 0.75 ;
xoff = 1 ;
// if (bc->bump)
// bumpItem (bc->bump, 2, (y2-y1), &xoff, &y1) ;
#if 0
else if (bc->cluster) /* one subcolumn per key */
{
void *v ;
if (assFind (bc->cluster, assVoid(seg->parent), &v))
xoff = assInt(v) ;
else
{
xoff = ++bc->clusterCount ;
assInsert (bc->cluster, assVoid(seg->parent), assVoid(xoff)) ;
}
}
#endif
x1 = left + (0.5 * bc->width * (xoff - dx)) ;
x2 = left + (0.5 * bc->width * (xoff + dx)) ;
if (bc->fmax < 0.5*bc->width*(xoff+1))
bc->fmax = 0.5*bc->width*(xoff+1) ;
break ;
default:
//TODO: sort out error handling here
printf("Unknown bc->mode in fMapShowHomol(): %d", bc->mode) ;
exit;
}
*x1p = x1;
*x2p = x2;
*y1p = y1;
*y2p = y2;
return;
} /* nbcDrawBox */
struct geneSelectData{
ZMapFeature seg ;
gboolean isIntron ;
int exonNumber ;
};
void zMapGeneDraw(ZMapPane pane, ZMapColumn *col, float *offset, int frame)
{
ZMapRegion *zMapRegion; // = zMapPaneGetZMapRegion(pane);
srMeth *meth = srMethodFromID(zMapRegion, col->meth);
int i, j;
int box;
nbcPrivate *bc = (nbcPrivate *)col->private;
float maxwidth = *offset, width;
FooCanvasItem *group;
char colours[30][10] = { "red", "blue", "pink", "green", "orange", "yellow", "purple", "cyan", "magenta",
"red", "blue", "pink", "green", "orange", "yellow", "purple", "cyan", "magenta",
"red", "blue", "pink", "green", "orange", "yellow", "purple", "cyan", "magenta" };
/* I made these up. Need to find out what meth->colour
equates to */
/* temporary kludge */
if (!zMapRegion) return;
// if (meth && (meth->flags & METHOD_BUMPABLE))
// bc->bump = bumpCreate(30, 0);
// else
bc->bump = NULL;
for (i=0; i < zMapRegionGetSegs(zMapRegion)->len; i++)
{
ZMapFeature seg = &g_array_index(zMapRegionGetSegs(zMapRegion), ZMapFeatureStruct, i) ;
if (seg->method == col->meth &&
seg->type == col->type &&
zmIsOnScreen(pane, seg->x1, seg->x2))
{
GArray *exons = g_array_new(FALSE, FALSE, sizeof(ZMapExon));
float e1, e2, x, y = 0; /* y needs better default */
int xoff = 1;
struct geneSelectData *sd;
exons = g_array_append_vals(exons,
&seg->feature.transcript.exons,
seg->feature.transcript.exons->len);
// if (bc->bump)
// bumpItem(bc->bump, 1, seg->x2 - seg->x1, &xoff, &y);
x = *offset + xoff + 30;
if (x > maxwidth)
maxwidth = x;
/* NB the code below draws all the introns before drawing
any of the exons. This is deliberate as otherwise the
background on the adjoining intron obscures a little
bit of the next exon. */
/* make a group to contain the gene */
group = foo_canvas_item_new(FOO_CANVAS_GROUP(zMapPaneGetGroup(pane)),
foo_canvas_group_get_type(),
"x", (double)x,
"y", (double)y ,
NULL);
width = meth->width * 15; /* arbitrary multiplier - needs to be rationalised */
for (j = 1; j < exons->len; j++)
{ /* Intron */
float middle;
e1 = zmScreenCoord(col->pane, g_array_index(exons, ZMapExon, j-1)->x2);
e2 = zmScreenCoord(col->pane, g_array_index(exons, ZMapExon, j )->x1);
middle = (e1 + e2)/2.0;
/* TODO: if e1 < e2 then it's on the reverse strand so needs different handling */
if (e1 > e2);
zmapDrawLine(FOO_CANVAS_GROUP(group), x+(width/2), e1, x+width, middle, colours[meth->colour], 1.0);
zmapDrawLine(FOO_CANVAS_GROUP(group), x+width, middle, x+(width/2), e2, colours[meth->colour], 1.0);
}
for (j = 0; j <exons->len; j++)
{ /* exon */
e1 = zmScreenCoord(col->pane, g_array_index(exons, ZMapExon, j)->x1);
e2 = zmScreenCoord(col->pane, g_array_index(exons, ZMapExon, j)->x2);
/* if e1 < e2 then it's on the reverse strand so needs different handling */
if (e1 < e2)
zmapDrawBox(group, x, e1, x+width, e2, "black", colours[meth->colour]);
else
zmapDrawBox(group, x, e2, x+width, e1, "red", colours[meth->colour]);
}
}
}
// if (bc->bump)
// bumpDestroy (bc->bump);
*offset = maxwidth + 2.0 ;
return;
}
void geneSelect(ZMapPane pane, ZMapColumn *col,
void *arg, int box, double x, double y, gboolean isSelect)
{
struct geneSelectData *sd = (struct geneSelectData *)arg;
ZMapFeature seg = sd->seg;
GArray *exons = g_array_new(FALSE, FALSE, sizeof(ZMapExon));
Coord x1, x2;
char *string;
srMeth *meth; // = srMethodFromID(zMapPaneGetZMapRegion(pane), col->meth);
int colour = WHITE;
exons = g_array_append_vals(exons,
&seg->feature.transcript.exons,
seg->feature.transcript.exons->len);
if (isSelect)
{
colour = LIGHTRED;
if (sd->isIntron)
{
x1 = g_array_index(exons, ZMapExon, sd->exonNumber-1)->x2 + 1 ;
x2 = g_array_index(exons, ZMapExon, sd->exonNumber)->x1 - 1 ;
}
else
{
x1 = g_array_index(exons, ZMapExon, sd->exonNumber)->x1;
x2 = g_array_index(exons, ZMapExon, sd->exonNumber)->x2;
}
// string = g_strdup_printf("%s [%f] %d %d",
// seg->id, seg->score,
// zmVisibleCoord(zMapPaneGetZMapWindow(pane), x1),
// zmVisibleCoord(zMapPaneGetZMapWindow(pane), x2));
// gtk_entry_set_text(GTK_ENTRY(pane->window->infoSpace), string);
// g_free(string);
}
// graphBoxDraw(box, meth->colour, colour);
return;
}
void zMapFeatureColumn(ZMapPane pane, ZMapColumn *col, float *offset, int frame)
{
ZMapRegion *zMapRegion; // = zMapPaneGetZMapRegion(pane);
srMeth *meth; // = srMethodFromID(zMapRegion, col->meth);
int i;
nbcPrivate *bc = (nbcPrivate *)col->private;
float maxwidth = *offset;
// if (meth->flags & METHOD_BUMPABLE)
// bc->bump = bumpCreate(30, 0);
// else
bc->bump = NULL;
for (i=0; i < zMapRegionGetSegs(zMapRegion)->len; i++)
{
ZMapFeature seg = &g_array_index(zMapRegionGetSegs(zMapRegion), ZMapFeatureStruct, i);
if (seg->method == col->meth &&
seg->type == col->type &&
zmIsOnScreen(pane, seg->x1, seg->x2))
{
int box = 0; //graphBoxStart();
float y1, y2, x1, x2;
y1 = zmScreenCoord(col->pane, seg->x1);
y2 = zmScreenCoord(col->pane, seg->x2+1) ;
x1 = *offset;
nbcCalcBox(meth, bc, &x1, &x2, &y1, &y2, seg->score);
// graphRectangle(x1, y1, x2, y2);
// graphBoxEnd();
// graphBoxDraw (box, BLACK, meth->colour) ;
zmRegBox(pane, box, col, seg);
if (x2 > maxwidth)
maxwidth = x2;
}
}
// if (bc->bump)
// bumpDestroy (bc->bump);
*offset = maxwidth + 0.5 ;
return;
}
void nbcSelect(ZMapPane pane, ZMapColumn *col,
void *arg, int box, double x, double y, gboolean isSelect)
{
ZMapFeature seg = (ZMapFeature)arg ;
// char *string = g_strdup_printf("%s [%f] %d %d",
// seg->id, seg->score,
// zmVisibleCoord(zMapPaneGetZMapWindow(pane), seg->x1),
// zmVisibleCoord(zMapPaneGetZMapWindow(pane), seg->x2));
// gtk_entry_set_text(GTK_ENTRY(pane->window->infoSpace), string);
// g_free(string);
return;
}
/************************ end of file **********************************/
/* Last edited: Jun 29 15:40 2004 (edgrif) */
/* file: zmapcalls.c
* Author: Rob Clack (rnc@sanger.ac.uk)
* Copyright (c) Sanger Institute, 2003
*-------------------------------------------------------------------
* Zmap is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
*-------------------------------------------------------------------
* This file is part of the ZMap genome database package
* and was written by
* Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk,
* Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk and
* Simon Kelley (Sanger Institute, UK) srk@sanger.ac.uk
*/
#include <zmapcalls.h>
/* function prototypes ********************************************/
static methodID srMethCreate (SeqRegion *region, char *methodName);
static srMeth *srMethFromName(GPtrArray *methods, char *methodName);
static methodID srMethodMake (SeqRegion *region, char *methodName);
void srActivate(void *seqRegion,
char *seqspec,
ZMapRegion *zMapRegion,
Coord *r1,
Coord *r2,
STORE_HANDLE *handle);
static void calcSeqRegion(void *seqRegion,
Coord x1, Coord x2,
BOOL isReverse);
BOOL zMapDisplay(Activate_cb srActivate,
Calc_cb calcSeqRegion,
void *region,
char *seqspec,
char *fromspec,
BOOL isOldGraph);
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
/* functions ******************************************************/
/* zMapCall is called from w6/display.c where it is registered in
* display functions at line 1176. It calls zMapDisplay, passing
* pointers to 2 callback functions and a SeqRegion structure. The
* callback functions create a SEGs (zmap flavour segs, not fmap)
* array in the zMapRegion member of the region structure. */
BOOL zMapCall(KEY key, KEY from, BOOL isOldGraph, void *app_data)
{
BOOL ret;
// STORE_HANDLE handle = handleCreate();
STORE_HANDLE handle = NULL;
SeqRegion *region = halloc(sizeof(SeqRegion), handle);
char *keyspec = messalloc(strlen(className(key)) + strlen(name(key)) + 2);
char *fromspec = messalloc(strlen(className(from)) + strlen(name(from)) + 2);
sprintf(keyspec, "%s:%s", className(key), name(key));
sprintf(fromspec, "%s:%s", className(from), name(from));
ret = zMapDisplay(srActivate, calcSeqRegion, region, keyspec, fromspec, isOldGraph);
messfree(keyspec);
messfree(fromspec);
return ret;
}
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
/* srMethodMake ****************************************************/
/* If the required method already exists in either the methods or
* oldMethods array, uses that, else calls srMethCreate to make a
* new one. */
static methodID srMethodMake(SeqRegion *region, char *methodName)
{
srMeth *meth;
if ((meth = srMethFromName(zMapRegionGetMethods(region->zMapRegion), methodName)))
return meth->id;
else if ((meth = srMethFromName(zMapRegionGetOldMethods(region->zMapRegion), methodName)))
{
srMeth *new = g_ptr_array_index(zMapRegionGetMethods(region->zMapRegion),
zMapRegionGetMethods(region->zMapRegion)->len);
*new = *meth;
return new->id;
}
else
return srMethCreate(region, methodName);
}
/* srMethFromName *************************************************/
/* Retrieves the method structure from the methods array, based
* on the methodName which it recieves. */
static srMeth *srMethFromName(GPtrArray *methods, char *methodName)
{
int i;
if (methods)
for (i=0; i<methods->len; i++)
{
srMeth *meth = g_ptr_array_index(methods, i);
if (meth->name == methodName)
return meth;
}
return NULL;
}
/* srMethCreate ****************************************************/
/* Creates a method structure from AceDB. */
static methodID srMethCreate(SeqRegion *region, char *methodName)
{
srMeth *meth;
OBJ obj ;
int k;
char *text;
KEY methodKey;
if (!lexword2key(methodName, &methodKey, _VMethod))
messcrash ("srMethodCreate() - methodKey not found in lex.");
if (!(obj = bsCreate (methodKey)))
return 0;
meth = g_ptr_array_index(zMapRegionGetMethods(region->zMapRegion),
zMapRegionGetMethods(region->zMapRegion)->len);
meth->id = region->idc++;
meth->name = str2p(name(methodKey), region->bucket);
meth->flags &= ~METHOD_CALCULATED ;/* unset flag */
meth->flags |= METHOD_DONE ; /* set flag */
meth->no_display = FALSE ;
meth->colour = 0 ;
meth->CDS_colour = 0 ;
meth->upStrandColour = 0 ;
meth->width = 0.0 ;
meth->symbol = '\0' ;
meth->priority = 0.0 ;
meth->minScore = meth->maxScore = 0.0 ;
if (bsGetKeyTags (obj, str2tag("Colour"), &k))
meth->colour = k - str2tag("White") ; /* colour-tag to colour-enum */
if (bsGetKeyTags(obj, str2tag("CDS_colour"), &k))
meth->CDS_colour = k - str2tag("White") ; /* colour-tag to colour-enum */
bsGetData (obj, str2tag("Width"), _Float, &meth->width) ;
bsGetData (obj, str2tag("Right_priority"), _Float, &meth->priority) ;
if (bsGetData (obj, str2tag("Symbol"), _Text, &text))
meth->symbol = *text;
if (bsFindTag (obj, str2tag("Frame_sensitive")))
meth->flags |= METHOD_FRAME_SENSITIVE ;
if (bsFindTag (obj, str2tag("Strand_sensitive")))
meth->flags |= METHOD_STRAND_SENSITIVE ;
if (bsFindTag (obj, str2tag("Show_up_strand")))
{
meth->flags |= METHOD_SHOW_UP_STRAND ;
if (bsGetKeyTags(obj, str2tag("Show_up_strand"), &k))
meth->upStrandColour = k - str2tag("White") ;
}
if (bsFindTag (obj, str2tag("Blastn")))
meth->flags |= METHOD_BLASTN ;
if (bsFindTag (obj, str2tag("Blixem_X")))
meth->flags |= METHOD_BLIXEM_X ;
if (bsFindTag (obj, str2tag("Blixem_N")))
meth->flags |= METHOD_BLIXEM_N ;
if (bsFindTag (obj, str2tag("Blixem_P")))
meth->flags |= METHOD_BLIXEM_P ;
if (bsFindTag (obj, str2tag("Belvu")))
meth->flags |= METHOD_BELVU ;
if (bsFindTag (obj, str2tag("Bumpable")))
meth->flags |= METHOD_BUMPABLE ;
if (bsFindTag (obj, str2tag("Cluster")))
meth->flags |= METHOD_CLUSTER ;
if (bsFindTag (obj, str2tag("EMBL_dump")))
meth->flags |= METHOD_EMBL_DUMP ;
if (bsFindTag (obj, str2tag("Percent")))
{
meth->flags |= METHOD_PERCENT ;
meth->minScore = 25 ; /* so actual display is linear */
meth->maxScore = 100 ; /* can override explicitly */
}
if (bsGetData (obj, str2tag("Score_bounds"), _Float, &meth->minScore)
&& bsGetData (obj, _bsRight, _Float, &meth->maxScore))
{
if (bsFindTag (obj, str2tag("Score_by_offset")))
meth->flags |= METHOD_SCORE_BY_OFFSET ;
else if (bsFindTag (obj, str2tag("Score_by_width")))
meth->flags |= METHOD_SCORE_BY_WIDTH ;
else if (bsFindTag (obj, str2tag("Score_by_histogram")))
{
meth->flags |= METHOD_SCORE_BY_HIST ;
meth->histBase = meth->minScore ;
bsGetData (obj, _bsRight, _Float, &meth->histBase) ;
}
}
if (bsFindTag (obj, str2tag("Show_text")))
meth->showText = TRUE;
else
meth->showText = FALSE;
if (bsFindTag(obj, str2tag("No_display")))
meth->no_display = TRUE;
else
meth->no_display = FALSE;
meth->minMag = 0;
bsGetData (obj, str2tag("Min_mag"), _Float, &meth->minMag) ;
meth->maxMag = 0;
bsGetData (obj, str2tag("Max_mag"), _Float, &meth->maxMag) ;
bsDestroy (obj) ;
return meth->id;
}
/* seqRegionConvert ************************************************/
/* Converts the the SeqRegion smap into an array of zmap-flavour
* segs in zMapRegion structure. */
void seqRegionConvert(SeqRegion *region)
{
// STORE_HANDLE localHandle = handleCreate();
STORE_HANDLE localHandle = NULL;
KEYSET allKeys = sMapKeys(region->smap, localHandle);
int i;
GArray *units = g_array_new(FALSE, TRUE, 256);
zMapRegionFreeSegs(region->zMapRegion);
zMapRegionNewSegs(region->zMapRegion);
zMapRegionNewMethods(region->zMapRegion);
for (i = 0 ; i < keySetMax(allKeys) ; i++)
{
KEY methodKey, key = keySet(allKeys, i);
SMapKeyInfo *info = sMapKeyInfo(region->smap, key);
int x1, x2;
SEG *seg;
OBJ obj;
char *methodName;
if ((obj = bsCreate(key)) && bsGetKey(obj, str2tag("Method"), &methodKey))
{
Coord cdsStart, cdsEnd;
srType type = SR_SEQUENCE; /* default */
srPhase phase = 1;
BOOL isStartNotFound = FALSE;
BOOL isCDS = FALSE;
GArray *exons;
methodName = messalloc(strlen(name(methodKey))); /* need to remember to free this? */
methodName = str2p(name(methodKey), region->bucket);
if (bsFindTag(obj, str2tag("Start_not_Found")))
{
isStartNotFound = TRUE;
bsGetData(obj, _bsRight, _Int, &phase);
}
/* Commenting this block out so I don't have to retrofit
** a bsFlatten-equivalent. Don't think this code will make
** it into the end result anyway.
if (bsFindTag(obj, str2tag("Source_Exons")) &&
(bsFlatten (obj, 2, units)))
{
int j; type = SR_TRANSCRIPT;
sMapUnsplicedMap(info, 1, 0, &x1, &x2, NULL, NULL);
dnaExonsSort (units) ;
exons = g_array_new(FALSE, TRUE, sizeof(srExon), 20);
for(j = 0; j < units->len; j += 2)
{
srExon *e = g_array_index(exons, srExon, exons->len);
sMapUnsplicedMap(info,
g_ptr_array_index(units, BSunit, j).i,
g_ptr_array_index(units, BSunit, j+1).i,
&e->x1, &e->x2, NULL, NULL);
}
} */
else
sMapMap(info, 1, 0, &x1, &x2, NULL, NULL);
if (bsFindTag(obj, str2tag("CDS")))
{
int c1, c2;
type = SR_TRANSCRIPT;
if (bsGetData(obj, _bsRight, _Int, &c1) &&
bsGetData(obj, _bsRight, _Int, &c2))
{
isCDS = TRUE;
sMapMap(info, c1, c2, &cdsStart, &cdsEnd, NULL, NULL);
if (isStartNotFound && c1 != 1)
messerror("StartNotFound but CDS doesn't start at 1 in object %s",
name(key));
}
/* If no source exons, fake one up which covers the whole of the CDS. */
if (!exons)
{
exons = g_array_new(FALSE, TRUE, 1);
g_array_insert_val(exons, 0, cdsStart);
g_array_insert_val(exons, 0, cdsEnd);
}
}
seg = &g_array_index(zMapRegionGetSegs(region->zMapRegion), SEG,
zMapRegionGetSegs(region->zMapRegion)->len);
seg->id = str2p(name(key), region->bucket);
seg->type = type;
seg->x1 = x1;
seg->x2 = x2;
seg->phase = phase;
seg->method = srMethodMake(region, methodName);
if (type == SR_TRANSCRIPT)
{
if (!isCDS)
sMapMap(info, 1, 0, &cdsStart, &cdsEnd, NULL, NULL);
if (bsFindTag(obj, str2tag("End_not_found")))
seg->u.transcript.endNotFound = TRUE;
else
seg->u.transcript.endNotFound = FALSE;
seg->u.transcript.cdsStart = cdsStart;
seg->u.transcript.cdsEnd = cdsEnd;
// seg->u.transcript.exons = exons;
}
/* commentint this block out so I don't have to write a
** bsFlatten-equivalent. Don't think this code will make
** it to the final version.
if (bsFindTag(obj, str2tag("Feature")) &&
bsFlatten (obj, 5, units))
{
int j ;
for (j = 0 ; j < units->len ; j += 5)
{
BSunit *u = g_ptr_array_index(units, BSunit, j);
SEG *seg;
SMapStatus status ;
status = sMapMap(info, u[1].i, u[2].i, &x1, &x2, NULL, NULL) ;
if (status & SMAP_STATUS_NO_OVERLAP)
continue;
seg = g_ptr_array_index(region->zMapRegion->segs, SEG, region->zMapRegion->segs->len);
seg->id = str2p(name(u[0].k), region->bucket);
seg->type = SR_FEATURE;
seg->x1 = x1;
seg->x2 = x2;
seg->score = u[3].f;
seg->method = srMethodMake(region, str2p(name(u[0].k), region->bucket));
}
}
*/
if (bsFindTag(obj, str2tag("Homol")))
{
}
}
bsDestroy(obj);
}
// handleDestroy(localHandle);
}
/* srActivate ************************************************/
/* Starts initial construction of the SeqRegion, then calls
* srCalculate and srGetDNA to complete the job. */
void srActivate(void *seqRegion,
char *seqspec,
ZMapRegion *zMapRegion,
Coord *r1,
Coord *r2,
STORE_HANDLE *handle)
{
int x1, x2, seqLen;
KEY key;
SeqRegion *region = (SeqRegion *)seqRegion;
/* Get out own handle */
// STORE_HANDLE newHandle = handleHandleCreate(*handle);
STORE_HANDLE newHandle = NULL;
region->handle = newHandle;
region->smap = NULL;
region->bucket = NULL;
region->zMapRegion = zMapRegion;
region->idc = 1;
if (!lexClassKey(seqspec, &key) ||
!sMapTreeRoot(key, 1, 0, &region->rootKey, &x1, &x2))
return;
region->zMapRegion->length = sMapLength(region->rootKey);
/* If the key is reversed wrt to the root, record that we need to
make the sMap reversed, and calculate the coords that the key
has on the reversed sMap. */
if (x1 > x2)
{
*r1 = region->zMapRegion->length - x1 + 1;
*r2 = region->zMapRegion->length - x2 + 1;
region->zMapRegion->rootIsReverse = 1;
}
else
{
region->zMapRegion->rootIsReverse = 0;
*r1 = x1;
*r2 = x2;
}
/* policy: we start by calculating three times the length of
the initial object. This policy will have to change! */
seqLen = x2 - x1;
srCalculate(region, x1 - seqLen, x2 + seqLen);
srGetDNA(region);
return;
}
/* calcSeqRegion *************************************************/
/* (Re)Initialises the dna, methods, oldMethods arrays and sets up
* a new smap, then calls seqRegionConvert to convert the smap to
* zmap-flavour segs. Called from several places when recalculating
* or reverse-complementing, frinstance. */
static void calcSeqRegion(void *seqRegion,
Coord x1, Coord x2,
BOOL isReverse)
{
SeqRegion *region = (SeqRegion *)seqRegion;
if (x1 < 1) x1 = 1;
if (x2 > region->zMapRegion->length) x2 = region->zMapRegion->length;
/* Note: this currently throws everything away and starts again.
* It's designed to be capable of incrementally adding to existing structures.
*/
if (region->smap)
sMapDestroy(region->smap);
if (zMapRegionGetDNA(region->zMapRegion))
zMapRegionFreeDNA(region->zMapRegion);
if (region->bucket)
sbDestroy(region->bucket);
zMapRegionSetOldMethods(region->zMapRegion, zMapRegionGetMethods(region->zMapRegion));
zMapRegionSetMethods(region->zMapRegion, NULL);
/* currently just put in new area - might need these to see what we have
already got. */
region->zMapRegion->area1 = x1;
region->zMapRegion->area2 = x2;
region->zMapRegion->rootIsReverse = isReverse;
region->bucket = sbCreate(region->handle);
/* Build an smap which seqRegionConvert will then convert
* into zmap-flavour segs and put in zMapRegion->segs. */
if (region->zMapRegion->rootIsReverse)
region->smap = sMapCreateEx(region->handle, region->rootKey,
0, region->zMapRegion->length,
region->zMapRegion->area1,
region->zMapRegion->area2, NULL);
else
region->smap = sMapCreateEx(region->handle, region->rootKey,
region->zMapRegion->length, 1,
region->zMapRegion->area1,
region->zMapRegion->area2, NULL);
seqRegionConvert(region);
/* When recalculating, for whatever reason, we need to repopulate
* the dna array. On initial display, srGetDNA is called by
* srActivate, but recalculation doesn't tread that path. */
if (!zMapRegionGetDNA(region->zMapRegion))
srGetDNA(region);
zMapRegionFreeOldMethods(region->zMapRegion);
}
/* srGetDNA ***********************************************************/
/* Populates the dna array. */
void srGetDNA(SeqRegion *region)
{
/* TODO handle callback stuff */
/* Commenting out until I know what is required here. */
// if (!zMapRegionGetDNA(region->zMapRegion))
// zMapRegionSetDNA(region->zMapRegion, sMapDNA(region->smap, region->handle, 0));
return;
}
/* srCalculate ********************************************************/
/* Just a wrapper, since calcSeqRegion is called variously to reverse-
* complement and recalculate, so needs slightly different params. */
void srCalculate(SeqRegion *region, Coord x1, Coord x2)
{
calcSeqRegion(region, x1, x2, region->zMapRegion->rootIsReverse);
}
/* srRevComp **********************************************************/
/* Calls calcSeqRegion with reversed coordinates to reverse-complement.
* Actually it's not used yet. */
void srRevComp(SeqRegion *region)
{
calcSeqRegion(region,
region->zMapRegion->length - region->zMapRegion->area2 + 1,
region->zMapRegion->length - region->zMapRegion->area1 + 1,
!region->zMapRegion->rootIsReverse);
}
void seqRegionDestroy(SeqRegion *region)
{
// handleDestroy(region->handle); yes, I know I have to deal with this.
}
/***************************** end of file ******************************/
/* Last edited: Jun 29 12:09 2004 (edgrif) */
/* file: zmapcalls.h
* Author: Rob Clack (rnc@sanger.ac.uk)
* Copyright (c) Sanger Institute, 2003
*-------------------------------------------------------------------
* Zmap is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
*-------------------------------------------------------------------
* This file is part of the ZMap genome database package
* and was written by
* Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk,
* Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk and
* Simon Kelley (Sanger Institute, UK) srk@sanger.ac.uk
*/
#ifndef ZMAPCALLS_H
#define ZMAPCALLS_H
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
#include <../acedb/acedb.h>
#include <../acedb/regular.h>
#include <../acedb/lex.h>
#include <../acedb/smap.h>
#include <../acedb/method.h>
#include <../acedb/smap.h>
#include <../acedb/systags.h> /* _Float, _Text, _bsRight, etc */
#include <../acedb/classes.h> /* _VMethod */
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
#include <ZMap/zmapcommon.h>
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
#include <ZMap/zmapFeature.h>
#include <ZMap/zmapWindow.h>
#include <../zmapWindow/stringbucket.h>
/*
This file defines the seqRegion interface.
The seqregion package populates a data structure with all the information
about a particular DNA area. This package is the interface between the drawing
code and the underlying database engine. Different version of the code access
acedb directly via the BS and sMap interfaces, or a remote server via Fex.
The public part of the seqRegion datastructure is exposed to the
drawing code. This may not depend on any back-end data structures or types:
No KEYS, classes or sMapInfos allowed.
*/
struct seqRegionStruct {
ZMapRegion *zMapRegion;
/* Private elements - acedb version. */
StringBucket *bucket;
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
KEY rootKey;
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
STORE_HANDLE handle;
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
SMap *smap;
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
methodID idc; /* increment to make unique ids. */
};
typedef struct seqRegionStruct SeqRegion;
/* Routines */
/* Finds root and orientation: returns coords of seq in r1 and r2 */
void srActivate(void *seqRegion,
char* seqspec,
ZMapRegion *zMapRegion,
Coord *r1,
Coord *r2) ;
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
STORE_HANDLE *handle);
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
/* Populate region between x1 and x2 */
/* This may be called repeatedly as required with changing x1, x2 */
void srCalculate(SeqRegion *region, Coord x1, Coord x2);
/* Determine DNA for region. Call this again if you call srCalculate again. */
void srGetDNA(SeqRegion *region);
void seqRegionConvert(SeqRegion *region);
/* Flip orientation of region. */
void srRevComp(SeqRegion *region);
#endif
/*********************** end of file ********************************/
/* Last edited: Jul 14 16:22 2004 (rnc) */
/* file: zmapcols.c
* Author: Simon Kelley (srk@sanger.ac.uk)
* Copyright (c) Sanger Institute, 2003
*-------------------------------------------------------------------
* Zmap is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
*-------------------------------------------------------------------
* This file is part of the ZMap genome database package
* and was written by
* Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk,
* Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk and
* Simon Kelley (Sanger Institute, UK) srk@sanger.ac.uk
*/
#include <seqregion.h>
#include <ZMap/zmapDraw.h>
#include <ZMap/zmapFeature.h>
#include <ZMap/zmapWindow.h>
/*************** function prototypes *****************************************/
static void zMapDNAColumn(ZMapPane pane, ZMapColumn *col,
float *offsetp, int frame);
/*************** start function definitions **********************************/
static void zMapScaleColumn(ZMapPane pane, ZMapColumn *col, float *offset, int frame)
{
// *offset = zmMainScale(zMapPaneGetCanvas(pane), *offset,
// zmVisibleCoord(zMapPaneGetZMapWindow(pane), zmCoordFromScreen(pane, 0)),
// zmVisibleCoord(zMapPaneGetZMapWindow(pane),
// zmCoordFromScreen(pane, zMapPaneGetHeight(pane))));
return;
}
/* cut this from zmapsequence.c and pasted here for now */
void zMapDNAColumn(ZMapPane pane, ZMapColumn *col,
float *offsetp, int frame)
{
float offset = *offsetp;
float max = offset;
float BPL = zMapPaneGetBPL(pane);
ZMapRegion *zMapRegion; // = zMapPaneGetZMapRegion(pane);
Coord seqstart = srCoord(zMapRegion, zMapPaneGetCentre(pane)) -
(zMapPaneGetHeight(pane) * BPL) / 2;
Coord seqend = srCoord(zMapRegion, zMapPaneGetCentre(pane)) +
(zMapPaneGetHeight(pane) * BPL) / 2;
Coord i;
if (seqstart < zMapRegion->area1)
seqstart = zMapRegion->area1;
if (seqend > zMapRegion->area2)
seqend = zMapRegion->area2;
if (zMapRegion->dna->len == 0)
return;
for (i = seqstart; i < seqend; i += BPL)
{
char *dnap, buff[10];
int j;
ScreenCoord y = zmScreenCoord(pane, i);
// sprintf(buff, "%7d", zmVisibleCoord(zMapPaneGetZMapWindow(pane), i));
// graphText(buff, offset, y);
dnap = &g_array_index(zMapRegion->dna,
char,
i - (zMapRegion->area1-1));
for (j = 0; j < BPL; j++)
{
float x = offset+8+j;
// buff[0] = dnaDecodeChar[(int)*(dnap+j)];
// buff[1] = 0;
// graphText(buff, x, y);
if (j+i > zMapRegion->area2)
break;
if (j+1 == zMapPaneGetDNAwidth(pane))
{
// graphText("...", x+1, y);
j = BPL;
x += 4;
}
if (x > max)
max = x;
}
}
*offsetp = max+1;
}
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
static void pruneCols(ZMapPane pane)
/* Remove Columns which have invalid methods */
{
int i, j;
for (i = 0; i < zMapPaneGetCols(pane)->len; i++)
{
ZMapColumn *c = g_ptr_array_index(zMapPaneGetCols(pane), i);
if (c->type != ZMAPFEATURE_INVALID && c->meth)
// && !srMethodFromID(zMapPaneGetZMapRegion(pane), c->meth))
{
for (j = i+1; j < (zMapPaneGetCols(pane))->len; j++)
g_ptr_array_remove_index(zMapPaneGetCols(pane), j-1); // = arr(pane->cols, j, ZMapColumn);
}
}
}
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
static void insertCol(ZMapPane pane, methodID meth, ZMapFeatureType type)
{
/* NB call this one with type == SR_INVALID to put in default columns. */
/* Where column code links in.
Fields are :
1) Creation Routine.
2) Draw routine.
3) Config routine.
4) Flag set for phase sensistive column - gets repeated three times.
5) Name - only valid for SR_INVALID columns.
6) Right priority - only valid for SR_INVALID columns.
7) Type - SR_INVALID for default columns which are always present
otherwise matches values in segs from convert routines.
*/
static struct ZMapColDefs defs[] = {
{ NULL, zMapScaleColumn , NULL, NULL , FALSE, 1.0, "Scale" , ZMAPFEATURE_INVALID},
{ nbcInit, zMapFeatureColumn, NULL, nbcSelect , FALSE, 2.0, "Features", ZMAPFEATURE_SEQUENCE },
{ nbcInit, zMapFeatureColumn, NULL, nbcSelect , FALSE, 2.0, "Features", ZMAPFEATURE_BASIC },
{ nbcInit, zMapGeneDraw , NULL, geneSelect, FALSE, 2.0, "Features", ZMAPFEATURE_TRANSCRIPT },
{ NULL, zMapDNAColumn , NULL, NULL , FALSE, 11.0, "DNA" , ZMAPFEATURE_INVALID },
};/* init, draw, config, select, isframe, prio, name, type */
int i, j, k;
ZMapColumn *c;
srMeth *methp;
char *name;
float priority;
for( i=0; i < sizeof(defs)/sizeof(struct ZMapColDefs); i++)
{
if (defs[i].type == ZMAPFEATURE_INVALID && type == ZMAPFEATURE_INVALID)
{ /* insert default column */
name = defs[i].name;
priority = defs[i].priority;
meth = 0;
}
else if ((type == defs[i].type))
{
// if (!(methp = srMethodFromID(zMapPaneGetZMapRegion(pane), meth)))
// {
// TODO: sort out error handling here
// printf("Failed to find method in insertCol\n");
// exit;
// }
name = (char*)g_string_new(methp->name); //previously hung on pane->window->handle);
priority = methp->priority;
}
else
continue;
/* TODO: This bit is completely wrong. I think the pane->cols array needs to be in
** priority order, but GPtrArray doesn't have an insert function, just adds at the
** end. Might have to write an insert function or use GArray instead, but for now
** I'm not actually doing anything, as I've been in the pub at lunchtime and a couple
** of beers is a sure way to break it. */
/* for (j = 0;
j < (&pane->cols)->len &&
g_ptr_array_index(pane->cols, j).priority < priority;
j++);
*/
// if (j < (&pane->cols)->len)
// {
// /* default columns */
// if (!meth &&
// g_ptr_array_index(pane->cols, j).name == name)
// continue; /* already there */
//
// /* method columns */
// if (meth &&
// g_ptr_array_index(pane->cols, j).meth == meth &&
// g_ptr_array_index(pane->cols, j).type == type)
// continue; /* already there */
// }
// if ( j < pane->cols->len)
/* make space */
// for (k = arrayMax(pane->cols); k >= j+1; k--)
// {
// ZMapColumn tmp = array(pane->cols, k-1, ZMapColumn);
// *arrayp(pane->cols, k, ZMapColumn) = tmp;
// }
// c = g_ptr_array_index(pane->cols, j);
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
/* Needs sorting out............... */
c->drawFunc = defs[i].drawFunc;
c->configFunc = defs[i].configFunc;
c->selectFunc = defs[i].selectFunc;
c->isFrame = defs[i].isFrame;
c->name = name;
c->pane = pane;
c->priority = priority;
c->type = type;
c->meth = meth; /* zero for default columns */
if (defs[i].initFunc)
(*defs[i].initFunc)(pane, c);
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
}
}
void buildCols(ZMapPane pane)
/* Add a column for each method */
{
ZMapRegion *zMapRegion; // = zMapPaneGetZMapRegion(pane);
int i;
for (i=0; i < zMapRegionGetSegs(zMapRegion)->len; i++)
{
ZMapFeature seg = &g_array_index(zMapRegionGetSegs(zMapRegion), ZMapFeatureStruct, i);
methodID id = seg->method;
if (id)
insertCol(pane, id, seg->type);
}
}
void makezMapDefaultColumns(ZMapPane pane)
{
insertCol(pane, 0, ZMAPFEATURE_INVALID);
}
/********************** 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