src/hg/lib/hgSeq.c 1.39

1.39 2009/02/28 00:36:42 angie
Made hgSeqChromSize more concise, and took out a redundant call to it (chromSize is passed down instead).
Index: src/hg/lib/hgSeq.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/hgSeq.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -b -B -U 4 -r1.38 -r1.39
--- src/hg/lib/hgSeq.c	20 Oct 2008 17:27:29 -0000	1.38
+++ src/hg/lib/hgSeq.c	28 Feb 2009 00:36:42 -0000	1.39
@@ -18,20 +18,10 @@
 /* get chrom size if there's a database out there,
  * otherwise just return 0 */
 {
 int thisSize = 0;
-
-/* first check to see if we can connect to the database */
-struct sqlConnection *conn = sqlMayConnect(db);
-
-if (conn != NULL)
-    {
-    sqlDisconnect(&conn);
-
-    /* we know there is a db out there */
+if (sqlDatabaseExists(db))
     thisSize = hChromSize(db, chromName);
-    }
-
 return thisSize;
 }
 
 static void hgSeqFeatureRegionOptions(struct cart *cart, boolean canDoUTR,
@@ -251,9 +241,9 @@
     }
 hgSeqOptionsHtiCart(hti, cart);
 }
 
-static void hgSeqConcatRegionsDb(char *db, char *chrom, char strand, char *name,
+static void hgSeqConcatRegionsDb(char *db, char *chrom, int chromSize, char strand, char *name,
 			  int rCount, unsigned *rStarts, unsigned *rSizes,
 			  boolean *exonFlags, boolean *cdsFlags)
 /* Concatenate and print out dna for a series of regions. */
 {
@@ -267,9 +257,8 @@
 char recName[256];
 int seqStart, seqEnd;
 int offset, cSize;
 int i;
-int chromSize = hgSeqChromSize(db, chrom);
 boolean isRc     = (strand == '-') || cgiBoolean("hgSeq.revComp");
 boolean maskRep  = cgiBoolean("hgSeq.maskRepeats");
 int padding5     = cgiOptionalInt("hgSeq.padding5", 0);
 int padding3     = cgiOptionalInt("hgSeq.padding3", 0);
@@ -386,18 +375,18 @@
 freeDnaSeq(&cSeq);
 }
 
 
-static void hgSeqRegionsAdjDb(char *db, char *chrom, char strand, char *name,
+static void hgSeqRegionsAdjDb(char *db, char *chrom, int chromSize, char strand, char *name,
 		       boolean concatRegions, boolean concatAdjacent,
 		       int rCount, unsigned *rStarts, unsigned *rSizes,
 		       boolean *exonFlags, boolean *cdsFlags)
 /* Concatenate and print out dna for a series of regions, 
  * optionally concatenating adjacent exons. */
 {
 if (concatRegions || (rCount == 1))
     {
-    hgSeqConcatRegionsDb(db, chrom, strand, name,
+    hgSeqConcatRegionsDb(db, chrom, chromSize, strand, name,
 			 rCount, rStarts, rSizes, exonFlags, cdsFlags);
     }
 else
     {
@@ -425,22 +414,22 @@
 		}
 	    }
 	len = (isRc ? (j - jEnd) : (jEnd - j));
 	lo  = (isRc ? (jEnd + 1) : j);
-	hgSeqConcatRegionsDb(db, chrom, strand, rName,
+	hgSeqConcatRegionsDb(db, chrom, chromSize, strand, rName,
 			     len, &rStarts[lo], &rSizes[lo], &exonFlags[lo],
 			     &cdsFlags[lo]);
 	}
     }
 }
 
-static void hgSeqRegionsDb(char *db, char *chrom, char strand, char *name,
+static void hgSeqRegionsDb(char *db, char *chrom, int chromSize, char strand, char *name,
 		    boolean concatRegions,
 		    int rCount, unsigned *rStarts, unsigned *rSizes,
 		    boolean *exonFlags, boolean *cdsFlags)
 /* Concatenate and print out dna for a series of regions. */
 {
-hgSeqRegionsAdjDb(db, chrom, strand, name, concatRegions, FALSE,
+hgSeqRegionsAdjDb(db, chrom, chromSize, strand, name, concatRegions, FALSE,
 		  rCount, rStarts, rSizes, exonFlags, cdsFlags);
 }
 
 static int maxStartsOffset = 0;
@@ -481,9 +470,9 @@
 maxStartsOffset = 0;
 addFeature(&count, starts, sizes, exonFlags, cdsFlags,
 	   chromStart, chromEnd - chromStart, FALSE, FALSE, chromSize);
 
-hgSeqRegionsDb(db, chrom, strand, name, FALSE, count, starts, sizes, exonFlags,
+hgSeqRegionsDb(db, chrom, chromSize, strand, name, FALSE, count, starts, sizes, exonFlags,
                cdsFlags);
 }
 
 
@@ -770,9 +759,9 @@
 	addFeature(&count, starts, sizes, exonFlags, cdsFlags,
 		   bedItem->chromEnd, promoterSize, FALSE, FALSE, chromSize);
 	}
     snprintf(itemName, sizeof(itemName), "%s_%s", hti->rootName, bedItem->name);
-    hgSeqRegionsAdjDb(db, bedItem->chrom, bedItem->strand[0], itemName,
+    hgSeqRegionsAdjDb(db, bedItem->chrom, chromSize, bedItem->strand[0], itemName,
 		      concatRegions, concatAdjacent,
 		      count, starts, sizes, exonFlags, cdsFlags);
     totalCount += count;
     freeMem(starts);