48fa5f889b1e569f319332bbba32b391969030d9
cline
  Tue Sep 27 12:32:52 2011 -0700
Adding back some changes that were previously lost ina failed effort to neatly go back, review the commits, and write a better commit message.  With that said, (1) hdb.h, hdb.c, and utrFa.c were all revised to allow utrFa to take a user-specified path to the nib files rather than looking up the path in dbDb.  This allowed me to run utrFa on the transcripts in the temporary staging directory for the new UCSC Genes build, before those transcripts were in hg19 (the temporary directory was not in dbDb, and probably shouldn't be).  (2) Copied some code from hg19.txt (thanks, Fan) to generate the keggPathway table.  The previous code missed a lot of associations: since making this change, keggPathway has grown from about 9K to 60K lines
diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index e449473..d102a9e 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -941,30 +941,49 @@
     if (!fileExists(retNibName))
 	{
 	/* if 2bit file isn't there, try up one directory */
 	safef(retNibName, HDB_MAX_PATH_STRING, "%s/../%s.2bit",
 	    hDbDbNibPath(db), db);
 	if (!fileExists(retNibName))
 	    {
 	    /* still no 2bit, let's just try to find a nib */
 	    safef(retNibName, HDB_MAX_PATH_STRING, "%s/%s.nib",
 		hDbDbNibPath(db), chromName);
 	    }
 	}
     }
 }
 
+void hNibForChromFromPath(char *nibPath, char *db, char *chromName, 
+			  char retNibName[HDB_MAX_PATH_STRING])
+/* Get .nib file associated with chromosome, given a nib file path. */
+{
+safef(retNibName, HDB_MAX_PATH_STRING, "%s/%s.2bit", nibPath, db);
+if (!fileExists(retNibName))
+    {
+    /* if 2bit file isn't there, try up one directory */
+    safef(retNibName, HDB_MAX_PATH_STRING, "%s/../%s.2bit",
+	  nibPath, db);
+    if (!fileExists(retNibName))
+	{
+	/* still no 2bit, let's just try to find a nib */
+	safef(retNibName, HDB_MAX_PATH_STRING, "%s/%s.nib",
+	      nibPath, chromName);
+	}
+    }
+}
+
 static struct dnaSeq *fetchTwoBitSeq(char *fileName, char *seqName, int start, int end)
 /* fetch a sequence from a 2bit, caching open of the file */
 {
 static struct twoBitFile *tbf = NULL;  // cache of open file
 if ((tbf == NULL) || !sameString(fileName, tbf->fileName))
     {
     twoBitClose(&tbf);
     tbf = twoBitOpen(fileName);
     }
 struct dnaSeq *seq = twoBitReadSeqFrag(tbf, seqName, start, end);
 return seq;
 }
 
 struct dnaSeq *hFetchSeqMixed(char *fileName, char *seqName, int start, int end)
 /* Fetch mixed case sequence. */
@@ -984,38 +1003,57 @@
     struct dnaSeq *seq = fetchTwoBitSeq(fileName, seqName, start, end);
     tolowers(seq->dna);
     return seq;
     }
 return nibLoadPart(fileName, start, end-start);
 }
 
 struct dnaSeq *hChromSeqMixed(char *db, char *chrom, int start, int end)
 /* Return mixed case (repeats in lower case) DNA from chromosome. */
 {
 char fileName[HDB_MAX_PATH_STRING];
 hNibForChrom(db, chrom, fileName);
 return hFetchSeqMixed(fileName, chrom, start, end);
 }
 
+struct dnaSeq *hChromSeqMixedFromPath(char *nibPath, char *db, char *chrom, 
+				      int start, int end)
+/* Return mixed case (repeats in lower case) DNA from chromosome, given an
+ * input nib path. */
+{
+char fileName[HDB_MAX_PATH_STRING];
+hNibForChromFromPath(nibPath, db, chrom, fileName);
+return hFetchSeqMixed(fileName, chrom, start, end);
+}
+
 struct dnaSeq *hChromSeq(char *db, char *chrom, int start, int end)
 /* Return lower case DNA from chromosome. */
 {
 char fileName[HDB_MAX_PATH_STRING];
 hNibForChrom(db, chrom, fileName);
 return hFetchSeq(fileName, chrom, start, end);
 }
 
+struct dnaSeq *hChromSeqFromPath(char *nibPath, char *db, char *chrom, 
+				 int start, int end)
+/* Return lower case DNA from chromosome. */
+{
+char fileName[HDB_MAX_PATH_STRING];
+hNibForChromFromPath(nibPath, db, chrom, fileName);
+return hFetchSeq(fileName, chrom, start, end);
+}
+
 struct dnaSeq *hSeqForBed(char *db, struct bed *bed)
 /* Get the sequence associated with a particular bed concatenated together. */
 {
 char fileName[HDB_MAX_PATH_STRING];
 struct dnaSeq *block = NULL;
 struct dnaSeq *bedSeq = NULL;
 int i = 0 ;
 assert(bed);
 /* Handle very simple beds and beds with blocks. */
 if(bed->blockCount == 0)
     {
     bedSeq = hChromSeq(db, bed->chrom, bed->chromStart, bed->chromEnd);
     freez(&bedSeq->name);
     bedSeq->name = cloneString(bed->name);
     }