fa9b1baf11ef0bda5abd10904cb385867db9a26b
aamp
  Mon Apr 4 06:15:53 2011 -0700
Updated CGI to use new library function and deleted bits associated with having a variable data format.
diff --git src/hg/hgLiftOver/hgLiftOver.c src/hg/hgLiftOver/hgLiftOver.c
index 733571e..464e008 100644
--- src/hg/hgLiftOver/hgLiftOver.c
+++ src/hg/hgLiftOver/hgLiftOver.c
@@ -10,73 +10,62 @@
 #include "cheapcgi.h"
 #include "htmshell.h"
 #include "hdb.h"
 #include "hui.h"
 #include "cart.h"
 #include "web.h"
 #include "hash.h"
 #include "liftOver.h"
 #include "liftOverChain.h"
 
 static char const rcsid[] = "$Id: hgLiftOver.c,v 1.62 2009/07/14 20:17:30 markd Exp $";
 
 /* CGI Variables */
 #define HGLFT_USERDATA_VAR "hglft_userData"     /* typed/pasted in data */
 #define HGLFT_DATAFILE_VAR "hglft_dataFile"     /* file of data to convert */
-#define HGLFT_DATAFORMAT_VAR "hglft_dataFormat" /* format of data to convert */
 #define HGLFT_FROMORG_VAR "hglft_fromOrg"         /* FROM organism */
 #define HGLFT_FROMDB_VAR "hglft_fromDb"         /* FROM assembly */
 #define HGLFT_TOORG_VAR   "hglft_toOrg"           /* TO organism */
 #define HGLFT_TODB_VAR   "hglft_toDb"           /* TO assembly */
 #define HGLFT_ERRORHELP_VAR "hglft_errorHelp"      /* Print explanatory text */
 #define HGLFT_REFRESHONLY_VAR "hglft_doRefreshOnly"      /* Just refresh drop-down lists */
 
 /* liftOver options: */
 #define HGLFT_MINMATCH "hglft_minMatch"          
 #define HGLFT_MINSIZEQ "hglft_minSizeQ"
 #define HGLFT_MINCHAINT "hglft_minChainT"
 #define HGLFT_MULTIPLE "hglft_multiple"
 #define HGLFT_MINBLOCKS "hglft_minBlocks"
 #define HGLFT_FUDGETHICK "hglft_fudgeThick"
 
 /* Global Variables */
 struct cart *cart;	        /* CGI and other variables */
 struct hash *oldVars = NULL;
 
-/* Data Formats */
-#define POSITION_FORMAT "Position"
-#define BED_FORMAT      "BED"
-#define WIGGLE_FORMAT   "Wiggle"
-
-char *formatList[] = 
-        {BED_FORMAT, POSITION_FORMAT, 0};
-
-#define DEFAULT_FORMAT  "BED"
-
 /* Filename prefix */
 #define HGLFT   "hglft"
 
 /* Javascript to support New Assembly pulldown when Orig Assembly changes */
 /* Copies selected value from the Original Assembly pulldown to a hidden form
 */
 char *onChange = 
 "onchange=\"document.mainForm."
 HGLFT_REFRESHONLY_VAR
 ".value = 1;"
 "document.mainForm.submit();\"";
 
-void webMain(struct liftOverChain *chain, char *dataFormat, boolean multiple)
+void webMain(struct liftOverChain *chain, boolean multiple)
 /* set up page for entering data */
 {
 struct dbDb *dbList;
 char *fromOrg = hArchiveOrganism(chain->fromDb), *toOrg = hArchiveOrganism(chain->toDb);
 cgiParagraph(
     "This tool converts genome coordinates and genome annotation files "
     "between assemblies.  "
     "The input data can be pasted into the text box, or uploaded from a file.  "
     "If a pair of assemblies cannot be selected from the pull-down menus,"
     " a direct lift between them is unavailable.  "
     "However, a sequential lift may be possible.  "
     "Example: lift from Mouse, May 2004, to Mouse, Feb. 2006, and then from Mouse, "
     "Feb. 2006 to Mouse, July 2007 to achieve a lift from mm5 to mm9.  "
     "");
 
@@ -176,43 +165,30 @@
 cgiTableField("Min ratio of alignment blocks or exons that must map:");
 cgiSimpleTableFieldStart();
 cgiMakeDoubleVar(HGLFT_MINBLOCKS,chain->minBlocks,6);
 cgiTableFieldEnd();
 cgiTableRowEnd();
 
 cgiSimpleTableRowStart();
 cgiTableField("If thickStart/thickEnd is not mapped, use the closest mapped base:");
 cgiSimpleTableFieldStart();
 cgiMakeCheckBox(HGLFT_FUDGETHICK,(chain->fudgeThick[0]=='Y') ? TRUE : FALSE);
 cgiTableFieldEnd();
 cgiTableRowEnd();
 
 cgiTableEnd();
 
-/* next row -- file format menu */
-cgiParagraph(
-         " For descriptions of the supported data formats, see the bottom of this page.");
-cgiSimpleTableStart();
-cgiSimpleTableRowStart();
-cgiTableField("Data Format: ");
-cgiSimpleTableFieldStart();
-cgiMakeDropList(HGLFT_DATAFORMAT_VAR, 
-                formatList, sizeof(formatList)/sizeof (char*) - 1, dataFormat);
-cgiTableFieldEnd();
-cgiTableRowEnd();
-cgiTableEnd();
-
 /* text box and two buttons (submit, reset) */
 cgiParagraph(" Paste in data:\n");
 cgiSimpleTableStart();
 cgiSimpleTableRowStart();
 
 cgiSimpleTableFieldStart();
 cgiMakeTextArea(HGLFT_USERDATA_VAR, cartCgiUsualString(cart, HGLFT_USERDATA_VAR, NULL), 10, 80);
 cgiTableFieldEnd();
 
 /* right element of table is a nested table
  * with two buttons stacked on top of each other */
 cgiSimpleTableFieldStart();
 cgiSimpleTableStart();
 
 cgiSimpleTableRowStart();
@@ -430,79 +406,77 @@
 	{
 	choice = this;
 	bestScore = score;
 	}
     }
 
 return choice;
 }
 
 void doMiddle(struct cart *theCart)
 /* Set up globals and make web page */
 {
 /* struct liftOverChain *chainList = NULL, *chain; */
 char *userData;
 /* char *dataFile; */
-char *dataFormat;
 char *organism;
 char *db;
 float minBlocks, minMatch;
 boolean multiple, fudgeThick;
 int minSizeQ, minChainT;
 boolean refreshOnly = FALSE;
 
 /* char *err = NULL; */
 struct liftOverChain *chainList = NULL, *choice;
 
 cart = theCart;
 
 if (cgiOptionalString(HGLFT_ERRORHELP_VAR))
     {
     puts("<PRE>");
     puts(liftOverErrHelp());
     //system("/usr/bin/cal");
     puts("</PRE>");
     return;
     }
 
 /* Get data to convert - from userData variable, or if 
  * that is empty from a file. */
 
 if (cartOptionalString(cart, "SubmitFile"))
     userData = cartOptionalString(cart, HGLFT_DATAFILE_VAR);
 else
     userData = cartOptionalString(cart, HGLFT_USERDATA_VAR);
-dataFormat = cartCgiUsualString(cart, HGLFT_DATAFORMAT_VAR, DEFAULT_FORMAT);
 cartWebStart(cart, NULL, "Lift Genome Annotations");
 
 getDbAndGenome(cart, &db, &organism, oldVars);
 
 chainList = liftOverChainList();
 
 choice = defaultChoices(chainList, db);
 if (choice == NULL)
     errAbort("Sorry, no conversions available from this assembly\n");
 
 minSizeQ = cartCgiUsualInt(cart, HGLFT_MINSIZEQ, choice->minSizeQ);
 minChainT = cartCgiUsualInt(cart, HGLFT_MINCHAINT, choice->minChainT);
 minBlocks = cartCgiUsualDouble(cart, HGLFT_MINBLOCKS, choice->minBlocks);
 minMatch = cartCgiUsualDouble(cart, HGLFT_MINMATCH, choice->minMatch);
 fudgeThick = cartCgiUsualBoolean(cart, HGLFT_FUDGETHICK, (choice->fudgeThick[0]=='Y') ? TRUE : FALSE);
 multiple = cartCgiUsualBoolean(cart, HGLFT_MULTIPLE, (choice->multiple[0]=='Y') ? TRUE : FALSE);
 refreshOnly = cartCgiUsualInt(cart, HGLFT_REFRESHONLY_VAR, 0);
 
-webMain(choice, dataFormat, multiple);
+webMain(choice, multiple);
 liftOverChainFreeList(&chainList);
 
 if (!refreshOnly && userData != NULL && userData[0] != '\0')
     {
     struct hash *chainHash = newHash(0);
     char *chainFile;
     struct tempName oldTn, mappedTn, unmappedTn;
     FILE *old, *mapped, *unmapped;
     char *line;
     int lineSize;
     char *fromDb, *toDb;
     int ct = 0, errCt = 0;
 
     /* read in user data and save to file */
     makeTempName(&oldTn, HGLFT, ".user");
@@ -516,85 +490,67 @@
      * for lines that could not be mapped */
     makeTempName(&mappedTn, HGLFT, ".bed");
     makeTempName(&unmappedTn, HGLFT, ".err");
     mapped = mustOpen(mappedTn.forCgi, "w");
     chmod(mappedTn.forCgi, 0666);
     unmapped = mustOpen(unmappedTn.forCgi, "w");
     chmod(unmappedTn.forCgi, 0666);
 
     fromDb = cgiString(HGLFT_FROMDB_VAR);
     toDb = cgiString(HGLFT_TODB_VAR);
     chainFile = liftOverChainFile(fromDb, toDb);
     if (chainFile == NULL)
         errAbort("ERROR: Can't convert from %s to %s: no chain file loaded",
                                 fromDb, toDb);
     readLiftOverMap(chainFile, chainHash);
-    if (sameString(dataFormat, WIGGLE_FORMAT))
-        /* TODO: implement Wiggle */
-	{}
-    else if (sameString(dataFormat, POSITION_FORMAT))
-	{
-	ct = liftOverPositions(oldTn.forCgi, chainHash, 
-			minMatch, minBlocks, 0, minSizeQ,
-			minChainT, 0, 
-			fudgeThick, mapped, unmapped, FALSE, NULL, &errCt);
-
-	
-        }
-    else if (sameString(dataFormat, BED_FORMAT))
-        {
-        ct = liftOverBed(oldTn.forCgi, chainHash, 
+    ct = liftOverBedOrPositions(oldTn.forCgi, chainHash, 
 			minMatch, minBlocks, 0, minSizeQ,
 			minChainT, 0,
 			fudgeThick, mapped, unmapped, multiple, NULL, &errCt);
-        }
-    else
+    if (ct == -1)
         /* programming error */
-        errAbort("ERROR: Unsupported data format: %s\n", dataFormat);
+        errAbort("ERROR: Unsupported data format.\n");
 
     webNewSection("Results");
-    if (ct)
+    if (ct > 0)
         {
         /* some records succesfully converted */
         cgiParagraph("");
         printf("Successfully converted %d record", ct);
         printf("%s: ", ct > 1 ? "s" : "");
         printf("<A HREF=%s TARGET=_blank>View Conversions</A>\n", mappedTn.forCgi);
         }
     if (errCt)
         {
         /* some records not converted */
         cgiParagraph("");
         printf("Conversion failed on %d record", errCt);
         printf("%s. &nbsp;&nbsp;&nbsp;", errCt > 1 ? "s" : "");
         printf("<A HREF=%s TARGET=_blank>Display failure file</A>&nbsp; &nbsp;\n",
                          unmappedTn.forCgi);
         printf("<A HREF=\"../cgi-bin/hgLiftOver?%s=1\" TARGET=_blank>Explain failure messages</A>\n", HGLFT_ERRORHELP_VAR);
         puts("<P>Failed input regions:\n");
         struct lineFile *errFile = lineFileOpen(unmappedTn.forCgi, TRUE);
         puts("<BLOCKQUOTE><PRE>\n");
         while (lineFileNext(errFile, &line, &lineSize))
             puts(line);
         lineFileClose(&errFile);
         puts("</PRE></BLOCKQUOTE>\n");
         }
-    if (sameString(dataFormat, POSITION_FORMAT) && multiple)
-	{
         puts("<BLOCKQUOTE><PRE>\n");
-        puts("Note: multiple checkbox ignored since it is not supported for position format.");
+    puts("Note: &quot;multiple&quot; option is not supported for position format.");
         puts("</PRE></BLOCKQUOTE>\n");
-	}
 
     webParamsUsed(minMatch, multiple, minSizeQ, minChainT, minBlocks, fudgeThick);
 
     carefulClose(&unmapped);
     }
 webDataFormats();
 webDownloads();
 cartWebEnd();
 }
 
 /* Null terminated list of CGI Variables we don't want to save
  * permanently. */
 char *excludeVars[] = {"Submit", "submit", "SubmitFile",
                         HGLFT_USERDATA_VAR,
                         HGLFT_DATAFILE_VAR,