From fc542718391478c788ab5a994d5a4aaddcae9adc Mon Sep 17 00:00:00 2001 From: rds <rds> Date: Fri, 8 May 2009 14:19:54 +0000 Subject: [PATCH] DNA and 3 Frame Translation feature code --- src/zmapFeature/Makefile.am | 27 +- src/zmapFeature/zmapFeature.c | 35 +-- .../zmapFeature3FrameTranslation.c | 293 ++++++++++++++++++ src/zmapFeature/zmapFeatureContext.c | 33 +- src/zmapFeature/zmapFeatureDNA.c | 195 ++++++++++++ src/zmapFeature/zmapFeatureUtils.c | 203 +----------- src/zmapServer/acedb/acedbServer.c | 62 ++-- 7 files changed, 542 insertions(+), 306 deletions(-) create mode 100755 src/zmapFeature/zmapFeature3FrameTranslation.c create mode 100755 src/zmapFeature/zmapFeatureDNA.c diff --git a/src/zmapFeature/Makefile.am b/src/zmapFeature/Makefile.am index cb077f21a..b8277b379 100755 --- a/src/zmapFeature/Makefile.am +++ b/src/zmapFeature/Makefile.am @@ -5,19 +5,22 @@ SUBDIRS = . tests noinst_LTLIBRARIES = libZMapFeature.la -libZMapFeature_la_SOURCES = zmapFeatureTypes.c \ -zmapStyle_P.h \ +libZMapFeature_la_SOURCES = \ +zmapFeature.c \ +zmapFeature_P.h \ +zmapFeature3FrameTranslation.c \ +zmapFeatureContext.c \ +zmapFeatureContextUtils.c \ +zmapFeatureDNA.c \ +zmapFeatureFormatInput.c \ zmapFeatureOutput.c \ -zmapFeatureFormatInput.c \ -zmapFeature.c \ -zmapFeatureXML.c \ -zmapFeatureUtils.c \ -zmapStyle.c \ -zmapFeature_P.h \ -zmapStyle_I.h \ -zmapFeatureContextUtils.c \ -zmapFeatureContext.c \ -zmapStyleUtils.c \ +zmapFeatureTypes.c \ +zmapFeatureUtils.c \ +zmapFeatureXML.c \ +zmapStyle.c \ +zmapStyle_I.h \ +zmapStyle_P.h \ +zmapStyleUtils.c \ $(NULL) libZMapFeature_la_CFLAGS = $(INCLUDE_COMMON) -I$(top_srcdir)/zmapUtils diff --git a/src/zmapFeature/zmapFeature.c b/src/zmapFeature/zmapFeature.c index db6152ba3..6f9f5a944 100755 --- a/src/zmapFeature/zmapFeature.c +++ b/src/zmapFeature/zmapFeature.c @@ -27,9 +27,9 @@ * * Exported functions: See zmapView_P.h * HISTORY: - * Last edited: Apr 28 12:44 2009 (edgrif) + * Last edited: Apr 29 15:55 2009 (rds) * Created: Fri Jul 16 13:05:58 2004 (edgrif) - * CVS info: $Id: zmapFeature.c,v 1.110 2009-04-28 14:29:49 edgrif Exp $ + * CVS info: $Id: zmapFeature.c,v 1.111 2009-05-08 14:19:54 rds Exp $ *------------------------------------------------------------------- */ @@ -499,37 +499,6 @@ void zMapFeatureAnyDestroy(ZMapFeatureAny feature_any) - -/*! - * A Blocks DNA - */ -gboolean zMapFeatureBlockDNA(ZMapFeatureBlock block, - char **seq_name_out, int *seq_len_out, char **sequence_out) -{ - gboolean result = FALSE; - ZMapFeatureContext context = NULL; - - zMapAssert( block ) ; - - if(block->sequence.sequence && - block->sequence.type != ZMAPSEQUENCE_NONE && - block->sequence.type == ZMAPSEQUENCE_DNA && - (context = (ZMapFeatureContext)zMapFeatureGetParentGroup((ZMapFeatureAny)block, - ZMAPFEATURE_STRUCT_CONTEXT))) - { - if(seq_name_out) - *seq_name_out = (char *)g_quark_to_string(context->sequence_name) ; - if(seq_len_out) - *seq_len_out = block->sequence.length ; - if(sequence_out) - *sequence_out = block->sequence.sequence ; - result = TRUE ; - } - - return result; -} - - /*! * Returns a single feature correctly intialised to be a "NULL" feature. * diff --git a/src/zmapFeature/zmapFeature3FrameTranslation.c b/src/zmapFeature/zmapFeature3FrameTranslation.c new file mode 100755 index 000000000..78d34d67d --- /dev/null +++ b/src/zmapFeature/zmapFeature3FrameTranslation.c @@ -0,0 +1,293 @@ +/* File: zmapFeature3FrameTranslation.c + * Author: Roy Storey (rds@sanger.ac.uk) + * Copyright (c) 2009: Genome Research Ltd. + *------------------------------------------------------------------- + * 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 + * originally written by: + * + * Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk, + * Roy Storey (Sanger Institute, UK) rds@sanger.ac.uk + * + * Description: + * + * Exported functions: See XXXXXXXXXXXXX.h + * HISTORY: + * Last edited: May 1 19:01 2009 (rds) + * Created: Wed Apr 8 16:18:11 2009 (rds) + * CVS info: $Id: zmapFeature3FrameTranslation.c,v 1.1 2009-05-08 14:19:54 rds Exp $ + *------------------------------------------------------------------- + */ + +#include <ZMap/zmapUtils.h> +#include <ZMap/zmapPeptide.h> +#include <zmapFeature_P.h> + + +void zmapFeature3FrameTranslationDestroySequenceData(ZMapFeature feature); + + +static void zmapFeature3FrameTranslationPopulate(ZMapFeatureSet feature_set, + ZMapFeatureTypeStyle style); +static void fudge_rev_comp_translation(gpointer key, gpointer value, gpointer user_data); +static void translation_set_populate(ZMapFeatureBlock feature_block, + ZMapFeatureSet feature_set, + ZMapFeatureTypeStyle style, + char *seq_name, + char *seq); + +gboolean zMapFeature3FrameTranslationCreateSet(ZMapFeatureBlock block, ZMapFeatureSet *set_out) +{ + ZMapFeatureSet feature_set = NULL; + GQuark frame_id = 0; + gboolean created = FALSE; + + /* No sequence. No Translation _return_ EARLY */ + if(!(block->sequence.length)) + return created; + + frame_id = zMapStyleCreateID(ZMAP_FIXED_STYLE_3FT_NAME); + + if(!(feature_set = zMapFeatureBlockGetSetByID(block, frame_id))) + { + GQuark original_id = 0; + GQuark unique_id = frame_id; + + original_id = g_quark_from_string(ZMAP_FIXED_STYLE_3FT_NAME); + + feature_set = zMapFeatureSetIDCreate(original_id, unique_id, NULL, NULL) ; + + zMapFeatureBlockAddFeatureSet(block, feature_set); + + created = TRUE; + } + + if(set_out) + *set_out = feature_set; + + return created; +} + +void zMapFeature3FrameTranslationSetCreateFeatures(ZMapFeatureSet feature_set, + ZMapFeatureTypeStyle style) +{ + /* public version of... */ + zmapFeature3FrameTranslationPopulate(feature_set, style); + + return ; +} + +void zMapFeature3FrameTranslationSetRevComp(ZMapFeatureSet feature_set, int origin) +{ + zmapFeature3FrameTranslationPopulate(feature_set, NULL); + + /* We have to do this as the features get rev comped later, but + * we're actually recreating the translation in the new orientation + * so the numbers don't need rev comping then, so we do it here. + * I figured doing it twice was less hassle than special case + * elsewhere... RDS */ + g_hash_table_foreach(feature_set->features, fudge_rev_comp_translation, GINT_TO_POINTER(origin)); + + return ; +} + +char *zMapFeature3FrameTranslationFeatureName(ZMapFeatureSet feature_set, ZMapFrame frame) +{ + char *feature_name = NULL, *frame_str; + + switch (frame) + { + case ZMAPFRAME_0: + frame_str = "0" ; + break ; + case ZMAPFRAME_1: + frame_str = "1" ; + break ; + case ZMAPFRAME_2: + frame_str = "2" ; + break ; + default: + frame_str = "." ; + } + + feature_name = g_strdup_printf("%s_frame-%s", g_quark_to_string(feature_set->unique_id), frame_str); + + return feature_name; +} + +void zMapFeature3FrameTranslationAddSequenceData(ZMapFeature feature, char *peptide_str, int sequence_length) +{ + + if(!feature->feature.sequence.sequence && + feature->type == ZMAPSTYLE_MODE_PEP_SEQUENCE) + { + feature->feature.sequence.sequence = peptide_str; + feature->feature.sequence.length = sequence_length; + feature->feature.sequence.type = ZMAPSEQUENCE_PEPTIDE; + } + + return ; +} + + + +void zmapFeature3FrameTranslationDestroySequenceData(ZMapFeature feature) +{ + if(feature->feature.sequence.sequence != NULL && + feature->type == ZMAPSTYLE_MODE_PEP_SEQUENCE) + { + g_free(feature->feature.sequence.sequence); + feature->feature.sequence.sequence = NULL; + feature->feature.sequence.length = 0; + feature->feature.sequence.type = ZMAPSEQUENCE_NONE; + } + + return ; +} + +/* INTERNALS */ + +/* Accepts NULL as style. */ +static void zmapFeature3FrameTranslationPopulate(ZMapFeatureSet feature_set, + ZMapFeatureTypeStyle style) +{ + ZMapFeatureTypeStyle temp_style = NULL; + ZMapFeatureBlock feature_block; + char *sequence_name; + char *dna_sequence; + + feature_block = + (ZMapFeatureBlock)zMapFeatureGetParentGroup((ZMapFeatureAny)feature_set, + ZMAPFEATURE_STRUCT_BLOCK); + + zMapAssert(feature_block); + + sequence_name = (char *)g_quark_to_string(feature_block->original_id); + + dna_sequence = feature_block->sequence.sequence; + + if(style == NULL) + { + temp_style = style = zMapStyleCreate(ZMAP_FIXED_STYLE_3FT_NAME, + ZMAP_FIXED_STYLE_3FT_NAME_TEXT); + } + + if(dna_sequence) + translation_set_populate(feature_block, + feature_set, + style, + sequence_name, + dna_sequence); + + if(temp_style) + zMapStyleDestroy(temp_style); + + return ; +} + +static void fudge_rev_comp_translation(gpointer key, gpointer value, gpointer user_data) +{ + ZMapFeature feature = (ZMapFeature)value; + zmapFeatureRevComp(Coord, GPOINTER_TO_INT(user_data), feature->x1, feature->x2); + return ; +} + +static void translation_set_populate(ZMapFeatureBlock feature_block, + ZMapFeatureSet feature_set, + ZMapFeatureTypeStyle style, + char *seq_name, + char *dna) +{ + int i, block_position; + ZMapFeature frame_feature; + char *feature_name_id = "__delete_me__"; + char *feature_name = "__delete_me__"; + char *sequence = "__delete_me__"; + char *ontology = "sequence"; + + frame_feature = zMapFeatureCreateEmpty(); + + zMapFeatureAddStandardData(frame_feature, feature_name_id, + feature_name, sequence, + ontology, ZMAPSTYLE_MODE_PEP_SEQUENCE, + style, 1, 10, FALSE, 0.0, + ZMAPSTRAND_NONE, ZMAPPHASE_NONE); + + zMapFeatureSetAddFeature(feature_set, frame_feature); + + block_position = feature_block->block_to_sequence.q1; + + for (i = ZMAPFRAME_0; dna && *dna && i <= ZMAPFRAME_2; i++, dna++, block_position++) + { + ZMapPeptide pep; + ZMapFeature translation; + char *feature_name = NULL; /* Remember to free this */ + GQuark feature_id; + ZMapFrame curr_frame; + char *peptide_str; + int peptide_length; + + frame_feature->x1 = block_position; + + curr_frame = zMapFeatureFrame(frame_feature); + feature_name = zMapFeature3FrameTranslationFeatureName(feature_set, curr_frame); + feature_id = g_quark_from_string(feature_name); + + pep = zMapPeptideCreateSafely(NULL, NULL, dna, NULL, FALSE); + + if((translation = zMapFeatureSetGetFeatureByID(feature_set, feature_id))) + { + /* clear sequence? */ + zmapFeature3FrameTranslationDestroySequenceData(translation); + } + else + { + int x1, x2; + + x1 = frame_feature->x1; + x2 = x1 + zMapPeptideFullSourceCodonLength(pep) - 1; + + translation = zMapFeatureCreateEmpty(); + + zMapFeatureAddStandardData(translation, feature_name, feature_name, + seq_name, "sequence", + ZMAPSTYLE_MODE_PEP_SEQUENCE, style, + x1, x2, FALSE, 0.0, + ZMAPSTRAND_NONE, ZMAPPHASE_NONE); + + zMapFeatureSetAddFeature(feature_set, translation); + } + + peptide_str = zMapPeptideSequence(pep); + + peptide_str = g_strdup(peptide_str); + + peptide_length = zMapPeptideLength(pep); + + zMapFeature3FrameTranslationAddSequenceData(translation, peptide_str, peptide_length); + + zMapPeptideDestroy(pep) ; + + if(feature_name) + g_free(feature_name); + } + + zMapFeatureSetRemoveFeature(feature_set, frame_feature); + zMapFeatureDestroy(frame_feature); + + return ; +} diff --git a/src/zmapFeature/zmapFeatureContext.c b/src/zmapFeature/zmapFeatureContext.c index b2e4eba6b..1f8f08686 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 4 14:08 2009 (edgrif) + * Last edited: May 1 18:45 2009 (rds) * Created: Tue Jan 17 16:13:12 2006 (edgrif) - * CVS info: $Id: zmapFeatureContext.c,v 1.42 2009-02-04 16:07:06 edgrif Exp $ + * CVS info: $Id: zmapFeatureContext.c,v 1.43 2009-05-08 14:19:54 rds Exp $ *------------------------------------------------------------------- */ @@ -895,26 +895,13 @@ static ZMapFeatureContextExecuteStatus revCompFeaturesCB(GQuark key, case ZMAPFEATURE_STRUCT_BLOCK: { ZMapFeatureBlock feature_block = NULL; - ZMapFeatureSet translations ; - GQuark translation_id; feature_block = (ZMapFeatureBlock)feature_any; - translation_id = zMapStyleCreateID(ZMAP_FIXED_STYLE_3FT_NAME); /* Complement the dna. */ if (feature_block->sequence.sequence) { revcompDNA(feature_block->sequence.sequence, feature_block->sequence.length) ; - - /* Now redo the 3 frame translations from the dna (if they exist). */ - if ((translations = zMapFeatureBlockGetSetByID(feature_block, translation_id))) - zMapFeature3FrameTranslationRevComp(translations, cb_data->end); - } - else - { - /* paranoia makes me want to check we haven't got a three frame translation... */ - if ((translations = zMapFeatureBlockGetSetByID(feature_block, translation_id))) - zMapFeatureSetDestroy(translations, TRUE); } zmapFeatureRevComp(Coord, cb_data->end, @@ -925,8 +912,12 @@ static ZMapFeatureContextExecuteStatus revCompFeaturesCB(GQuark key, case ZMAPFEATURE_STRUCT_FEATURESET: { ZMapFeatureSet feature_set = NULL; + feature_set = (ZMapFeatureSet)feature_any; - /* Nothing to swop here, I think..... */ + + /* Now redo the 3 frame translations from the dna (if they exist). */ + if(feature_set->original_id == g_quark_from_string(ZMAP_FIXED_STYLE_3FT_NAME)) + zMapFeature3FrameTranslationSetRevComp(feature_set, cb_data->end); } break; case ZMAPFEATURE_STRUCT_FEATURE: @@ -937,16 +928,6 @@ static ZMapFeatureContextExecuteStatus revCompFeaturesCB(GQuark key, revCompFeature(feature_ft, cb_data->end); - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - /* Shouldn't need to do this, just leave style_id alone..... */ - - /* If list of styles provided then reset feature style from there. */ - if (cb_data->styles) - feature_ft->style = zMapFindStyle(cb_data->styles, zMapStyleGetUniqueID(feature_ft->style)) ; -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - break; } case ZMAPFEATURE_STRUCT_INVALID: diff --git a/src/zmapFeature/zmapFeatureDNA.c b/src/zmapFeature/zmapFeatureDNA.c new file mode 100755 index 000000000..4ce01ce6b --- /dev/null +++ b/src/zmapFeature/zmapFeatureDNA.c @@ -0,0 +1,195 @@ +/* File: zmapFeatureDNA.c + * Author: Roy Storey (rds@sanger.ac.uk) + * Copyright (c) 2009: Genome Research Ltd. + *------------------------------------------------------------------- + * 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 + * originally written by: + * + * Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk, + * Roy Storey (Sanger Institute, UK) rds@sanger.ac.uk + * + * Description: + * + * Exported functions: See XXXXXXXXXXXXX.h + * HISTORY: + * Last edited: May 1 18:34 2009 (rds) + * Created: Tue Apr 7 10:32:21 2009 (rds) + * CVS info: $Id: zmapFeatureDNA.c,v 1.1 2009-05-08 14:19:54 rds Exp $ + *------------------------------------------------------------------- + */ + +#include <ZMap/zmapUtils.h> +#include <zmapFeature_P.h> + + +/*! + * A Blocks DNA + */ +gboolean zMapFeatureBlockDNA(ZMapFeatureBlock block, + char **seq_name_out, int *seq_len_out, char **sequence_out) +{ + gboolean result = FALSE; + ZMapFeatureContext context = NULL; + + zMapAssert( block ) ; + + if(block->sequence.sequence && + block->sequence.type != ZMAPSEQUENCE_NONE && + block->sequence.type == ZMAPSEQUENCE_DNA && + (context = (ZMapFeatureContext)zMapFeatureGetParentGroup((ZMapFeatureAny)block, + ZMAPFEATURE_STRUCT_CONTEXT))) + { + if(seq_name_out) + *seq_name_out = (char *)g_quark_to_string(context->sequence_name) ; + if(seq_len_out) + *seq_len_out = block->sequence.length ; + if(sequence_out) + *sequence_out = block->sequence.sequence ; + result = TRUE ; + } + + return result; +} + +/* Free return when finished! */ +char *zMapFeatureDNAFeatureName(ZMapFeatureBlock block) +{ + char *dna_name = NULL; + + dna_name = g_strdup_printf("%s (%s)", "DNA", g_quark_to_string(block->original_id)); + + return dna_name; +} + + +gboolean zMapFeatureDNACreateFeatureSet(ZMapFeatureBlock block, ZMapFeatureSet *feature_set_out) +{ + ZMapFeatureSet dna_feature_set = NULL; + gboolean created = FALSE; + GQuark dna_set_id = 0; + + dna_set_id = zMapFeatureSetCreateID(ZMAP_FIXED_STYLE_DNA_NAME); + + if(!(dna_feature_set = zMapFeatureBlockGetSetByID(block, dna_set_id))) + { + GQuark original_id = 0; + GQuark unique_id = dna_set_id; + + original_id = g_quark_from_string(ZMAP_FIXED_STYLE_DNA_NAME); + + dna_feature_set = zMapFeatureSetIDCreate(original_id, unique_id, NULL, NULL) ; + + zMapFeatureBlockAddFeatureSet(block, dna_feature_set); + + created = TRUE; + } + + if(feature_set_out) + *feature_set_out = dna_feature_set; + + return created; +} + +void zMapFeatureDNAAddSequenceData(ZMapFeature dna_feature, char *dna_str, int sequence_length) +{ + + if(!dna_feature->feature.sequence.sequence && + dna_feature->type == ZMAPSTYLE_MODE_RAW_SEQUENCE) + { + dna_feature->feature.sequence.sequence = dna_str; + dna_feature->feature.sequence.length = sequence_length; + dna_feature->feature.sequence.type = ZMAPSEQUENCE_DNA; + } + + return ; +} + +ZMapFeature zMapFeatureDNACreateFeature(ZMapFeatureBlock block, + ZMapFeatureTypeStyle style, + char *dna_str, + int sequence_length) +{ + ZMapFeatureSet dna_feature_set = NULL; + ZMapFeature dna_feature = NULL; + GQuark dna_set_id = 0; + + zMapAssert(block); + zMapAssert(dna_str); + zMapAssert(sequence_length != 0); + + dna_set_id = zMapFeatureSetCreateID(ZMAP_FIXED_STYLE_DNA_NAME); + + dna_feature_set = zMapFeatureBlockGetSetByID(block, dna_set_id); + + if(dna_feature_set) + { + char *feature_name, *sequence, *ontology; + GQuark dna_id; + int block_start, block_end; + + block_start = block->block_to_sequence.q1 ; + block_end = block->block_to_sequence.q2 ; + + feature_name = zMapFeatureDNAFeatureName(block); + + dna_id = g_quark_from_string(feature_name); + + if(block->sequence.sequence) + { + /* hmm, we've already got dna */ + + /* We should be able to get the feature from the feature set, */ + /* but not before issuing a warning */ + zMapLogWarning("%s", "Block already has DNA"); + + dna_feature = zMapFeatureSetGetFeatureByID(dna_feature_set, dna_id); + } + else + { + ZMapStrand strand = ZMAPSTRAND_FORWARD; /* DNA is forward */ + + /* check dna length == block length? */ + + dna_feature = zMapFeatureCreateFromStandardData(feature_name, + sequence, + ontology, + ZMAPSTYLE_MODE_RAW_SEQUENCE, + style, + block_start, + block_end, + FALSE, 0.0, + strand, + ZMAPPHASE_NONE); + + zMapFeatureDNAAddSequenceData(dna_feature, dna_str, sequence_length); + + zMapFeatureSetAddFeature(dna_feature_set, dna_feature); + + block->sequence.sequence = dna_feature->feature.sequence.sequence; + block->sequence.type = dna_feature->feature.sequence.type; + block->sequence.length = dna_feature->feature.sequence.length; + + } + + if(feature_name) + g_free(feature_name); + } + + + return dna_feature; +} diff --git a/src/zmapFeature/zmapFeatureUtils.c b/src/zmapFeature/zmapFeatureUtils.c index 95925546b..29d44f9cb 100755 --- a/src/zmapFeature/zmapFeatureUtils.c +++ b/src/zmapFeature/zmapFeatureUtils.c @@ -26,9 +26,9 @@ * * Exported functions: See ZMap/zmapFeature.h * HISTORY: - * Last edited: Feb 9 15:47 2009 (rds) + * Last edited: May 1 19:02 2009 (rds) * Created: Tue Nov 2 2004 (rnc) - * CVS info: $Id: zmapFeatureUtils.c,v 1.65 2009-02-09 15:48:13 rds Exp $ + * CVS info: $Id: zmapFeatureUtils.c,v 1.66 2009-05-08 14:19:54 rds Exp $ *------------------------------------------------------------------- */ @@ -54,13 +54,6 @@ static ZMapFrame feature_frame(ZMapFeature feature, int start_coord); static int feature_block_frame_offset(ZMapFeature feature); static void get_feature_list_extent(gpointer list_data, gpointer span_data); - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE -static void translation_set_populate(ZMapFeatureSet feature_set, ZMapFeatureTypeStyle style, char *seq_name, char *seq); -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - - static gint findStyleName(gconstpointer list_data, gconstpointer user_data) ; static void addTypeQuark(GQuark style_id, gpointer data, gpointer user_data) ; @@ -570,16 +563,6 @@ GQuark zMapFeatureSetCreateID(char *set_name) return zMapStyleCreateID(set_name); } -/* Free return when finished! */ -char *zMapFeatureMakeDNAFeatureName(ZMapFeatureBlock block) -{ - char *dna_name = NULL; - - dna_name = g_strdup_printf("%s (%s)", "DNA", g_quark_to_string(block->original_id)); - - return dna_name; -} - void zMapFeatureSortGaps(GArray *gaps) { @@ -724,119 +707,6 @@ void zMapFeature2MasterCoords(ZMapFeature feature, double *feature_x1, double *f return ; } -gboolean zMapFeature3FrameTranslationCreateSet(ZMapFeatureBlock block, ZMapFeatureSet *set_out) -{ - ZMapFeatureContext context = NULL; - ZMapFeatureSet feature_set = NULL; - gboolean created = FALSE; - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - style_id = zMapStyleCreateID(ZMAP_FIXED_STYLE_3FT_NAME); -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - - /* No sequence. No Translation _return_ EARLY */ - if(!(block->sequence.length)) - return created; - - if ((context = (ZMapFeatureContext)(zMapFeatureGetParentGroup((ZMapFeatureAny)block, ZMAPFEATURE_STRUCT_CONTEXT)))) - { - /* DON'T CHECK FOR STYLE, JUST DO IT, IF STYLE IS NOT THERE LATER THEN TOUGH.... */ -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - if ((style = zMapFindStyle(context->styles, style_id)) != NULL) - { -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - feature_set = zMapFeatureSetCreate(ZMAP_FIXED_STYLE_3FT_NAME, NULL); - //feature_set->style = style; - created = TRUE; - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - } -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - } - - if(set_out && created) - *set_out = feature_set; - else - created = FALSE; - - return created; -} - -static void fudge_rev_comp_translation(gpointer key, gpointer value, gpointer user_data) -{ - ZMapFeature feature = (ZMapFeature)value; - zmapFeatureRevComp(Coord, GPOINTER_TO_INT(user_data), feature->x1, feature->x2); - return ; -} - -void zMapFeature3FrameTranslationRevComp(ZMapFeatureSet feature_set, int origin) -{ - zMapFeature3FrameTranslationPopulate(feature_set); - - /* We have to do this as the features get rev comped later, but - * we're actually recreating the translation in the new orientation - * so the numbers don't need rev comping then, so we do it here. - * I figured doing it twice was less hassle than special case - * elsewhere... RDS */ - g_hash_table_foreach(feature_set->features, fudge_rev_comp_translation, GINT_TO_POINTER(origin)); - - return ; -} - -char *zMapFeature3FrameTranslationFeatureName(ZMapFeatureSet feature_set, ZMapFrame frame) -{ - char *feature_name = NULL, *frame_str; - - switch (frame) - { - case ZMAPFRAME_0: - frame_str = "0" ; - break ; - case ZMAPFRAME_1: - frame_str = "1" ; - break ; - case ZMAPFRAME_2: - frame_str = "2" ; - break ; - default: - frame_str = "." ; - } - - feature_name = g_strdup_printf("%s_frame-%s", g_quark_to_string(feature_set->unique_id), frame_str); - - return feature_name; -} - -void zMapFeature3FrameTranslationPopulate(ZMapFeatureSet feature_set) -{ - ZMapFeatureBlock block; - char *seq = NULL, *seq_name; - - block = (ZMapFeatureBlock)(zMapFeatureGetParentGroup((ZMapFeatureAny)feature_set, ZMAPFEATURE_STRUCT_BLOCK)); - - zMapAssert(block); /* No block! BIG error! */ - zMapAssert(block->sequence.length); /* No sequence. Why we got a 3ft anyway? Error! */ - - //style = feature_set->style; - //zMapAssert(style); - - seq_name = (char *)g_quark_to_string(block->original_id); - - seq = block->sequence.sequence ; - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - translation_set_populate(feature_set, style, seq_name, seq); -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - - return ; -} - gboolean zMapFeatureGetFeatureListExtent(GList *feature_list, int *start_out, int *end_out) { gboolean done = FALSE; @@ -1156,75 +1026,6 @@ static int feature_block_frame_offset(ZMapFeature feature) return offset; } - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE -static void translation_set_populate(ZMapFeatureSet feature_set, ZMapFeatureTypeStyle style, char *seq_name, char *seq) -{ - ZMapFeatureBlock block; - int i, block_position; - ZMapFeature frame_feature; - - frame_feature = zMapFeatureCreateEmpty(); - zMapFeatureAddStandardData(frame_feature, "_delete_me_", "_delete_me_", - "_delete_me_", "sequence", ZMAPSTYLE_MODE_PEP_SEQUENCE, - style, 1, 10, FALSE, 0.0, ZMAPSTRAND_NONE, ZMAPPHASE_NONE); - zMapFeatureSetAddFeature(feature_set, frame_feature); - - zMapAssert(feature_set->parent); - block = (ZMapFeatureBlock)(feature_set->parent); - block_position = block->block_to_sequence.q1; - - for (i = ZMAPFRAME_0; seq && *seq && i <= ZMAPFRAME_2; i++, seq++, block_position++) - { - ZMapPeptide pep; - ZMapFeature translation; - char *feature_name; /* Remember to free this */ - GQuark feature_id; - ZMapFrame curr_frame; - - frame_feature->x1 = block_position; - - curr_frame = zMapFeatureFrame(frame_feature); - feature_name = zMapFeature3FrameTranslationFeatureName(feature_set, curr_frame); - feature_id = g_quark_from_string(feature_name); - - pep = zMapPeptideCreateSafely(NULL, NULL, seq, NULL, FALSE); - - if((translation = zMapFeatureSetGetFeatureByID(feature_set, feature_id))) - g_free(translation->text); - else - { - int x1, x2; - - x1 = frame_feature->x1; - x2 = x1 + zMapPeptideFullSourceCodonLength(pep) - 1; - - translation = zMapFeatureCreateEmpty(); - - zMapFeatureAddStandardData(translation, feature_name, feature_name, - seq_name, "sequence", - ZMAPSTYLE_MODE_PEP_SEQUENCE, style, - x1, x2, FALSE, 0.0, - ZMAPSTRAND_NONE, ZMAPPHASE_NONE); - - zMapFeatureSetAddFeature(feature_set, translation); - } - - translation->text = g_strdup(zMapPeptideSequence(pep)); - - zMapPeptideDestroy(pep) ; - - g_free(feature_name); - } - - zMapFeatureSetRemoveFeature(feature_set, frame_feature); - zMapFeatureDestroy(frame_feature); - - return ; -} -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - static void get_feature_list_extent(gpointer list_data, gpointer span_data) { ZMapFeature feature = (ZMapFeature)list_data; diff --git a/src/zmapServer/acedb/acedbServer.c b/src/zmapServer/acedb/acedbServer.c index 5509fec35..573811e0c 100755 --- a/src/zmapServer/acedb/acedbServer.c +++ b/src/zmapServer/acedb/acedbServer.c @@ -27,9 +27,9 @@ * * Exported functions: See zmapServer.h * HISTORY: - * Last edited: May 8 09:10 2009 (edgrif) + * Last edited: May 8 15:07 2009 (rds) * Created: Wed Aug 6 15:46:38 2003 (edgrif) - * CVS info: $Id: acedbServer.c,v 1.132 2009-05-08 08:12:52 edgrif Exp $ + * CVS info: $Id: acedbServer.c,v 1.133 2009-05-08 14:20:09 rds Exp $ *------------------------------------------------------------------- */ @@ -1481,39 +1481,25 @@ static gboolean blockDNARequest(AcedbServer server, GData *styles, ZMapFeatureBl { ZMapFeature feature = NULL; ZMapFeatureSet feature_set = NULL; - ZMapFeatureTypeStyle style = NULL; + ZMapFeatureTypeStyle dna_style = NULL; - feature_block->sequence.type = ZMAPSEQUENCE_DNA ; - feature_block->sequence.length = dna_length ; - feature_block->sequence.sequence = dna_sequence ; - - if ((style = zMapFindStyle(styles, zMapStyleCreateID(ZMAP_FIXED_STYLE_DNA_NAME)))) + if (zMapFeatureDNACreateFeatureSet(feature_block, &feature_set)) { - feature_set = zMapFeatureSetCreate(ZMAP_FIXED_STYLE_DNA_NAME, NULL); - - //feature_set->style = style; - } - + ZMapFeatureTypeStyle temp_style = NULL; + + /* This temp style creation feels wrong, and probably is, + * but we don't have the merged in default styles in here, + * or so it seems... */ - if (feature_set) - { - const char *sequence = g_quark_to_string(feature_block->original_id); - char *feature_name = NULL; - feature_name = g_strdup_printf("DNA (%s)", sequence); - feature = - zMapFeatureCreateFromStandardData(feature_name, - (char *)sequence, - "sequence", - ZMAPSTYLE_MODE_RAW_SEQUENCE, - style, - block_start, - block_end, - FALSE, 0.0, - ZMAPSTRAND_NONE, - ZMAPPHASE_NONE) ; - zMapFeatureSetAddFeature(feature_set, feature); - zMapFeatureBlockAddFeatureSet(feature_block, feature_set); - g_free(feature_name); + if (!(dna_style = zMapFindStyle(styles, zMapStyleCreateID(ZMAP_FIXED_STYLE_DNA_NAME)))) + temp_style = dna_style = zMapStyleCreate(ZMAP_FIXED_STYLE_DNA_NAME, + ZMAP_FIXED_STYLE_DNA_NAME_TEXT); + + feature = zMapFeatureDNACreateFeature(feature_block, dna_style, + dna_sequence, dna_length); + + if(temp_style) + zMapStyleDestroy(temp_style); } /* I'm going to create the three frame translation up front! */ @@ -1521,8 +1507,16 @@ static gboolean blockDNARequest(AcedbServer server, GData *styles, ZMapFeatureBl { if ((zMapFeature3FrameTranslationCreateSet(feature_block, &feature_set))) { - zMapFeatureBlockAddFeatureSet(feature_block, feature_set); - zMapFeature3FrameTranslationPopulate(feature_set); + ZMapFeatureTypeStyle frame_style = NULL; + gboolean style_absolutely_required = FALSE; + + frame_style = zMapFindStyle(styles, zMapStyleCreateID(ZMAP_FIXED_STYLE_3FT_NAME)); + + if(style_absolutely_required && !frame_style) + zMapLogWarning("Cowardly refusing to create features '%s' without style", + ZMAP_FIXED_STYLE_3FT_NAME); + else + zMapFeature3FrameTranslationSetCreateFeatures(feature_set, frame_style); } } -- GitLab