From 7ea332842b711204ff6b7ba38c61c60536adbc74 Mon Sep 17 00:00:00 2001 From: edgrif <edgrif> Date: Mon, 12 Mar 2007 12:26:37 +0000 Subject: [PATCH] add function from zmapView.c and generalise to one that takes strings of words and makes context ids from them. --- src/include/ZMap/zmapFeature.h | 7 ++- src/zmapFeature/zmapFeatureContext.c | 75 +++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 4 deletions(-) diff --git a/src/include/ZMap/zmapFeature.h b/src/include/ZMap/zmapFeature.h index 85971d8f1..7e4f11a22 100755 --- a/src/include/ZMap/zmapFeature.h +++ b/src/include/ZMap/zmapFeature.h @@ -25,9 +25,9 @@ * Description: Data structures describing a sequence feature. * * HISTORY: - * Last edited: Mar 2 11:50 2007 (rds) + * Last edited: Mar 12 09:11 2007 (edgrif) * Created: Fri Jun 11 08:37:19 2004 (edgrif) - * CVS info: $Id: zmapFeature.h,v 1.116 2007-03-02 14:27:31 rds Exp $ + * CVS info: $Id: zmapFeature.h,v 1.117 2007-03-12 12:26:37 edgrif Exp $ *------------------------------------------------------------------- */ #ifndef ZMAP_FEATURE_H @@ -622,6 +622,9 @@ void zMapFeatureContextDestroy(ZMapFeatureContext context, gboolean free_data) ; /* THOSE IN FEATURECONTEXT.C */ +GList *zMapFeatureString2QuarkList(char *string_list) ; + + void zMapFeatureContextExecute(ZMapFeatureAny feature_any, ZMapFeatureStructType stop, ZMapGDataRecurseFunc callback, diff --git a/src/zmapFeature/zmapFeatureContext.c b/src/zmapFeature/zmapFeatureContext.c index 7313fc09e..1a26f6284 100755 --- a/src/zmapFeature/zmapFeatureContext.c +++ b/src/zmapFeature/zmapFeatureContext.c @@ -27,9 +27,9 @@ * * Exported functions: See ZMap/zmapFeature.h * HISTORY: - * Last edited: Feb 27 16:00 2007 (rds) + * Last edited: Mar 12 09:11 2007 (edgrif) * Created: Tue Jan 17 16:13:12 2006 (edgrif) - * CVS info: $Id: zmapFeatureContext.c,v 1.19 2007-03-02 14:29:54 rds Exp $ + * CVS info: $Id: zmapFeatureContext.c,v 1.20 2007-03-12 12:26:37 edgrif Exp $ *------------------------------------------------------------------- */ @@ -223,6 +223,46 @@ char *zMapFeatureGetTranscriptDNA(ZMapFeatureContext context, ZMapFeature transc } + + +/* Take a string containing space separated context names (e.g. perhaps a list + * of featuresets: "coding fgenes codon") and convert it to a list of + * proper context id quarks. */ +GList *zMapFeatureString2QuarkList(char *string_list) +{ + GList *context_quark_list = NULL ; + char *list_pos = NULL ; + char *next_context = NULL ; + char *target ; + + target = string_list ; + do + { + GQuark context_id ; + + if (next_context) + { + target = NULL ; + context_id = zMapStyleCreateID(next_context) ; + context_quark_list = g_list_append(context_quark_list, GUINT_TO_POINTER(context_id)) ; + } + else + list_pos = target ; + } + while (((list_pos && nextIsQuoted(&list_pos)) + && (next_context = strtok_r(target, "\"", &list_pos))) + || (next_context = strtok_r(target, " \t", &list_pos))) ; + +#ifdef ED_G_NEVER_INCLUDE_THIS_CODE + zMap_g_quark_list_print(context_quark_list) ; /* debug.... */ +#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ + + return context_quark_list ; +} + + + + /*! * \brief A similar call to g_datalist_foreach. However there are a number of differences. * @@ -883,3 +923,34 @@ static void doFeatureAnyCB(ZMapFeatureAny any_feature, gpointer user_data) } #endif + + + +/* Look through string to see if next non-space char is a quote mark, if it is return TRUE + * and set *text to point to the quote mark, otherwise return FALSE and leave *text unchanged. */ +static gboolean nextIsQuoted(char **text) +{ + gboolean quoted = FALSE ; + char *text_ptr = *text ; + + while (*text_ptr) + { + if (!(g_ascii_isspace(*text_ptr))) + { + if (*text_ptr == '"') + { + quoted = TRUE ; + *text = text_ptr ; + } + break ; + } + + text_ptr++ ; + } + + return quoted ; +} + + + + -- GitLab