From 3d19c9e11f226a89451ad1e2f81dec29ea833af4 Mon Sep 17 00:00:00 2001
From: edgrif <edgrif>
Date: Wed, 18 Nov 2009 16:29:39 +0000
Subject: [PATCH] handle NULL return from dna routines.

---
 src/zmapWindow/zmapWindowFeature.c | 47 ++++++++++--------
 src/zmapWindow/zmapWindowMenus.c   | 79 ++++++++++++++++--------------
 2 files changed, 68 insertions(+), 58 deletions(-)

diff --git a/src/zmapWindow/zmapWindowFeature.c b/src/zmapWindow/zmapWindowFeature.c
index 947d674ab..41ad8b86c 100755
--- a/src/zmapWindow/zmapWindowFeature.c
+++ b/src/zmapWindow/zmapWindowFeature.c
@@ -28,9 +28,9 @@
  *
  * Exported functions: See zmapWindow_P.h
  * HISTORY:
- * Last edited: Oct 16 14:17 2009 (edgrif)
+ * Last edited: Nov 18 16:17 2009 (edgrif)
  * Created: Mon Jan  9 10:25:40 2006 (edgrif)
- * CVS info:   $Id: zmapWindowFeature.c,v 1.165 2009-10-16 13:26:13 edgrif Exp $
+ * CVS info:   $Id: zmapWindowFeature.c,v 1.166 2009-11-18 16:29:39 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
@@ -666,12 +666,13 @@ FooCanvasGroup *zmapWindowFeatureItemsMakeGroup(ZMapWindow window, GList *featur
  * there's no falling over phase values and stop codons... */
 char *zmapWindowFeatureTranscriptFASTA(ZMapFeature feature, gboolean spliced, gboolean cds_only)
 {
-  ZMapFeatureContext context;
-  char *peptide_fasta = NULL;
+  char *peptide_fasta = NULL ;
+  ZMapFeatureContext context ;
+
 
-  if((feature->type == ZMAPSTYLE_MODE_TRANSCRIPT) &&
-     ((context       = (ZMapFeatureContext)zMapFeatureGetParentGroup((ZMapFeatureAny)feature, 
-								     ZMAPFEATURE_STRUCT_CONTEXT))))
+  if((feature->type == ZMAPSTYLE_MODE_TRANSCRIPT)
+     && ((context = (ZMapFeatureContext)zMapFeatureGetParentGroup((ZMapFeatureAny)feature, 
+								  ZMAPFEATURE_STRUCT_CONTEXT))))
     {
       ZMapPeptide peptide;
       char *dna, *seq_name = NULL, *gene_name = NULL;
@@ -679,23 +680,27 @@ char *zmapWindowFeatureTranscriptFASTA(ZMapFeature feature, gboolean spliced, gb
       
       seq_name  = (char *)g_quark_to_string(context->original_id);
       gene_name = (char *)g_quark_to_string(feature->original_id);
-      dna       = zMapFeatureGetTranscriptDNA(context, feature, spliced, cds_only) ;
-      
-      /* Adjust for when its known that the start exon is incomplete.... */
-      if (feature->feature.transcript.flags.start_not_found)
-	start_incr = feature->feature.transcript.start_phase - 1 ; /* Phase values are 1 <= phase <= 3 */
+
+      if ((dna = zMapFeatureGetTranscriptDNA(feature, spliced, cds_only)))
+	{
+	  /* Adjust for when its known that the start exon is incomplete.... */
+	  if (feature->feature.transcript.flags.start_not_found)
+	    start_incr = feature->feature.transcript.start_phase - 1 ; /* Phase values are 1 <= phase <= 3 */
       
-      peptide = zMapPeptideCreate(seq_name, gene_name, (dna + start_incr), NULL, TRUE) ;
+	  peptide = zMapPeptideCreate(seq_name, gene_name, (dna + start_incr), NULL, TRUE) ;
       
-      /* Note that we do not include the "Stop" in the peptide length, is this the norm ? */
-      pep_length = zMapPeptideLength(peptide) ;
-      if (zMapPeptideHasStopCodon(peptide))
-	pep_length-- ;
+	  /* Note that we do not include the "Stop" in the peptide length, is this the norm ? */
+	  pep_length = zMapPeptideLength(peptide) ;
+	  if (zMapPeptideHasStopCodon(peptide))
+	    pep_length-- ;
       
-      peptide_fasta = zMapFASTAString(ZMAPFASTA_SEQTYPE_AA, 
-				      seq_name, "Protein",
-				      gene_name, pep_length,
-				      zMapPeptideSequence(peptide));
+	  peptide_fasta = zMapFASTAString(ZMAPFASTA_SEQTYPE_AA, 
+					  seq_name, "Protein",
+					  gene_name, pep_length,
+					  zMapPeptideSequence(peptide));
+
+	  g_free(dna) ;
+	}
     }
 
   return peptide_fasta;
diff --git a/src/zmapWindow/zmapWindowMenus.c b/src/zmapWindow/zmapWindowMenus.c
index ffe176176..d03b8d202 100755
--- a/src/zmapWindow/zmapWindowMenus.c
+++ b/src/zmapWindow/zmapWindowMenus.c
@@ -27,9 +27,9 @@
  * Exported functions: ZMap/zmapWindows.h
  *              
  * HISTORY:
- * Last edited: Jul  3 16:54 2009 (rds)
+ * Last edited: Nov 18 16:17 2009 (edgrif)
  * Created: Thu Mar 10 07:56:27 2005 (edgrif)
- * CVS info:   $Id: zmapWindowMenus.c,v 1.62 2009-07-27 03:15:13 rds Exp $
+ * CVS info:   $Id: zmapWindowMenus.c,v 1.63 2009-11-18 16:30:02 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
@@ -410,14 +410,18 @@ static void dnaMenuCB(int menu_item_id, gpointer callback_data)
     }
   else if (feature->type == ZMAPSTYLE_MODE_TRANSCRIPT)
     {
-      dna = zMapFeatureGetTranscriptDNA(context, feature, spliced, cds) ;
+      dna = zMapFeatureGetTranscriptDNA(feature, spliced, cds) ;
     }
   else
     {
-      dna = zMapFeatureGetFeatureDNA(context, feature) ;
+      dna = zMapFeatureGetFeatureDNA(feature) ;
     }
 
-  if (dna)
+  if (!dna)
+    {
+      zMapWarning("%s", "No DNA available") ;
+    }
+  else
     {
       /* Would be better to have the dna functions calculate and return this.... */
       seq_len = strlen(dna) ;
@@ -644,46 +648,47 @@ static void peptideMenuCB(int menu_item_id, gpointer callback_data)
   molecule_type = "Protein" ;
   gene_name = (char *)g_quark_to_string(feature->original_id) ;
 
-  dna = zMapFeatureGetTranscriptDNA(menu_data->window->feature_context, feature, spliced, cds) ;
-
-  /* Adjust for when its known that the start exon is incomplete.... */
-  if (feature->feature.transcript.flags.start_not_found)
-    start_incr = feature->feature.transcript.start_phase - 1 ; /* Phase values are 1 <= phase <= 3 */
+  if ((dna = zMapFeatureGetTranscriptDNA(feature, spliced, cds)))
+    {
+      /* Adjust for when its known that the start exon is incomplete.... */
+      if (feature->feature.transcript.flags.start_not_found)
+	start_incr = feature->feature.transcript.start_phase - 1 ; /* Phase values are 1 <= phase <= 3 */
 
-  peptide = zMapPeptideCreate(seq_name, gene_name, (dna + start_incr), NULL, TRUE) ;
+      peptide = zMapPeptideCreate(seq_name, gene_name, (dna + start_incr), NULL, TRUE) ;
 
-  /* Note that we do not include the "Stop" in the peptide length, is this the norm ? */
-  pep_length = zMapPeptideLength(peptide) ;
-  if (zMapPeptideHasStopCodon(peptide))
-    pep_length-- ;
+      /* Note that we do not include the "Stop" in the peptide length, is this the norm ? */
+      pep_length = zMapPeptideLength(peptide) ;
+      if (zMapPeptideHasStopCodon(peptide))
+	pep_length-- ;
 
-  if (menu_item_id == ZMAPCDS || menu_item_id == ZMAPTRANSCRIPT || menu_item_id == ZMAPUNSPLICED)
-    {
-      char *title ;
-      char *peptide_fasta ;
+      if (menu_item_id == ZMAPCDS || menu_item_id == ZMAPTRANSCRIPT || menu_item_id == ZMAPUNSPLICED)
+	{
+	  char *title ;
+	  char *peptide_fasta ;
 
-      peptide_fasta = zMapFASTAString(ZMAPFASTA_SEQTYPE_AA, seq_name, molecule_type, gene_name,
-				      pep_length, zMapPeptideSequence(peptide)) ;
+	  peptide_fasta = zMapFASTAString(ZMAPFASTA_SEQTYPE_AA, seq_name, molecule_type, gene_name,
+					  pep_length, zMapPeptideSequence(peptide)) ;
 
-      title = g_strdup_printf("%s%s%s",
-			      seq_name,
-			      gene_name ? ":" : "",
-			      gene_name ? gene_name : "") ;
-      zMapGUIShowText(title, peptide_fasta, FALSE) ;
-      g_free(title) ;
+	  title = g_strdup_printf("%s%s%s",
+				  seq_name,
+				  gene_name ? ":" : "",
+				  gene_name ? gene_name : "") ;
+	  zMapGUIShowText(title, peptide_fasta, FALSE) ;
+	  g_free(title) ;
 
-      g_free(peptide_fasta) ;
-    }
-  else
-    {
-      dumpFASTA(menu_data->window, ZMAPFASTA_SEQTYPE_AA,
-		zMapPeptideSequence(peptide), seq_name,
-		pep_length, molecule_type, gene_name) ;
-    }
+	  g_free(peptide_fasta) ;
+	}
+      else
+	{
+	  dumpFASTA(menu_data->window, ZMAPFASTA_SEQTYPE_AA,
+		    zMapPeptideSequence(peptide), seq_name,
+		    pep_length, molecule_type, gene_name) ;
+	}
 
-  zMapPeptideDestroy(peptide) ;
+      zMapPeptideDestroy(peptide) ;
 
-  g_free(dna) ;
+      g_free(dna) ;
+    }
 
   g_free(menu_data) ;
 
-- 
GitLab