efd363d44327be79c6b602c165cae2bf19242461
kent
  Wed Feb 27 22:08:39 2013 -0800
Adding routine to do relatively efficient finding of multiple names in a bigBed name index,  and giving bigBedNamedItems a command line option to do this.
diff --git src/utils/bigBedNamedItems/bigBedNamedItems.c src/utils/bigBedNamedItems/bigBedNamedItems.c
index 9f354d7..33e7818 100644
--- src/utils/bigBedNamedItems/bigBedNamedItems.c
+++ src/utils/bigBedNamedItems/bigBedNamedItems.c
@@ -1,47 +1,62 @@
 /* bigBedNamedItems - Extract item(s) of given name(s) from bigBed. */
 #include "common.h"
 #include "linefile.h"
 #include "hash.h"
 #include "options.h"
 #include "localmem.h"
 #include "udc.h"
 #include "bPlusTree.h"
 #include "bigBed.h"
 #include "obscure.h"
 #include "zlibFace.h"
 
 void usage()
 /* Explain usage and exit. */
 {
 errAbort(
   "bigBedNamedItems - Extract item of given name from bigBed\n"
   "usage:\n"
   "   bigBedNamedItems file.bb name output.bed\n"
+  "options:\n"
+  "   -nameFile - if set, treat name parameter as file full of space delimited names\n"
   );
 }
 
 /* Command line validation table. */
 static struct optionSpec options[] = {
+   {"nameFile", OPTION_BOOLEAN},
    {NULL, 0},
 };
 
 void bigBedNamedItems(char *bigBedFile, char *name, char *outFile)
 /* bigBedNamedItems - Extract item(s) of given name(s) from bigBed. */
 {
 struct bbiFile *bbi = bigBedFileOpen(bigBedFile);
 FILE *f = mustOpen(outFile, "w");
 struct lm *lm = lmInit(0);
-struct bigBedInterval *intervalList = bigBedNameQuery(bbi, name, lm);
+struct bigBedInterval *intervalList;
+if (optionExists("nameFile"))
+    {
+    int wordCount = 0;
+    char **words;
+    char *buf;
+    readAllWords(name, &words, &wordCount, &buf);
+    intervalList = bigBedMultiNameQuery(bbi, words, wordCount, lm);
+    }
+else
+    {
+    intervalList = bigBedNameQuery(bbi, name, lm);
+    }
 bigBedIntervalListToBedFile(bbi, intervalList, f);
 carefulClose(&f);
 }
 
 int main(int argc, char *argv[])
 /* Process command line. */
 {
 optionInit(&argc, argv, options);
 if (argc != 4)
     usage();
 bigBedNamedItems(argv[1], argv[2], argv[3]);
 return 0;
 }