void hapmapPrimateAllelesSaveToDb(struct sqlConnection *conn, struct hapmapPrimateAlleles *el, char *tableName, int updateSize)
/* Save hapmapPrimateAlleles as a row to the table specified by tableName. 
 * As blob fields may be arbitrary size updateSize specifies the approx size
 * of a string that would contain the entire query. Arrays of native types are
 * converted to comma separated strings and loaded as such, User defined types are
 * inserted as NULL. Note that strings must be escaped to allow insertion into the database.
 * For example "autosql's features include" --> "autosql\'s features include" 
 * If worried about this use hapmapPrimateAllelesSaveToDbEscaped() */
{
struct dyString *update = newDyString(updateSize);
dyStringPrintf(update, "insert into %s values ( '%s',%u,%u,'%s',%u,'%c','%c','%c','%s',%u,'%c','%s',%u,'%s',%u,'%c','%s',%u)", 
	tableName,  el->chrom,  el->chromStart,  el->chromEnd,  el->name,  el->score,  el->strand,  el->refAllele,  el->otherAllele,  el->chimpChrom,  el->chimpPos,  el->chimpStrand,  el->chimpAllele,  el->chimpQual,  el->rhesusChrom,  el->rhesusPos,  el->rhesusStrand,  el->rhesusAllele,  el->rhesusQual);
sqlUpdate(conn, update->string);
freeDyString(&update);
}
void protVarSaveToDb(struct sqlConnection *conn, struct protVar *el, char *tableName, int updateSize)
/* Save protVar as a row to the table specified by tableName.
 * As blob fields may be arbitrary size updateSize specifies the approx size
 * of a string that would contain the entire query. Arrays of native types are
 * converted to comma separated strings and loaded as such, User defined types are
 * inserted as NULL. Note that strings must be escaped to allow insertion into the database.
 * For example "autosql's features include" --> "autosql\'s features include"
 * If worried about this use protVarSaveToDbEscaped() */
{
    struct dyString *update = newDyString(updateSize);
    dyStringPrintf(update, "insert into %s values ( '%s','%s','%s','%s','%s',%u)",
                   tableName,  el->id,  el->name,  el->srcId,  el->baseChangeType,  el->location,  el->coordinateAccuracy);
    sqlUpdate(conn, update->string);
    freeDyString(&update);
}
void dbRIPSaveToDb(struct sqlConnection *conn, struct dbRIP *el, char *tableName, int updateSize)
/* Save dbRIP as a row to the table specified by tableName.
 * As blob fields may be arbitrary size updateSize specifies the approx size
 * of a string that would contain the entire query. Arrays of native types are
 * converted to comma separated strings and loaded as such, User defined types are
 * inserted as NULL. Note that strings must be escaped to allow insertion into the database.
 * For example "autosql's features include" --> "autosql\'s features include"
 * If worried about this use dbRIPSaveToDbEscaped() */
{
    struct dyString *update = newDyString(updateSize);
    dyStringPrintf(update, "insert into %s values ( '%s',%u,%u,'%s',%u,'%s','%s','%s','%s','%s','%s','%s',%s,'%s',%s,'%s','%s',%g,%d,%d,'%s','%s')",
                   tableName,  el->chrom,  el->chromStart,  el->chromEnd,  el->name,  el->score,  el->strand,  el->originalId,  el->forwardPrimer,  el->reversePrimer,  el->polyClass,  el->polyFamily,  el->polySubfamily,  el->polySeq,  el->polySource,  el->reference,  el->ascertainingMethod,  el->remarks,  el->tm,  el->filledSize,  el->emptySize,  el->disease,  el->genoRegion);
    sqlUpdate(conn, update->string);
    freeDyString(&update);
}
void chainStats(char *chains)
{
int lastChainId = -1;
struct lineFile *chainsLf = lineFileOpen(chains, TRUE);
struct cseqPair *cspList = NULL, *csp;
struct dyString *dy = newDyString(512);
struct hash *chainHash = newHash(0);  /* Hash keyed by qSeq<strand>tSeq */
struct chain *chain;
struct cBlock *block;
int count;

count = 0;
while ((chain = chainRead(chainsLf)) != NULL)
    {
    if (chain->id > lastChainId)
	lastChainId = chain->id;
    dyStringClear(dy);
    dyStringPrintf(dy, "%s%c%s", chain->qName, chain->qStrand, chain->tName);
    csp = hashFindVal(chainHash, dy->string);
    if (csp == NULL)
        {
	AllocVar(csp);
	slAddHead(&cspList, csp);
	hashAddSaveName(chainHash, dy->string, csp, &csp->name);
	csp->qName = cloneString(chain->qName);
	csp->tName = cloneString(chain->tName);
	csp->qStrand = chain->qStrand;
	}
    slAddHead(&csp->chain, chain);
    count++;
    }
lineFileClose(&chainsLf);
printf("read in %d chains\n",count);

for(csp = cspList; csp; csp = csp->next)
    {
    slSort(&csp->chain, chainCmpTarget);
    gapChains(csp->chain);
    for(chain = csp->chain ; chain ; chain = chain->next)
	{
	for(block = chain->blockList; block; block = block->next)
	    {
	    }
	}
    }

dyStringFree(&dy);
}
示例#5
0
static void testOneSql(int start, int end, char *expected)
{
struct dyString *sqlQuery;
sqlQuery = newDyString(1024);
hAddBinToQuery(start, end, sqlQuery);
if (NULL != expected)
    if (differentString(sqlQuery->string,expected))
	{
	verbose(2,"#\tERROR: SQL incorrect at (%d, %d)\n",
	    start, end);
	++failureCount;
	}

verbose(3,"# (%d, %d):\nsql:\"%s\",\n", start, end, sqlQuery->string);
freeDyString(&sqlQuery);
}
示例#6
0
文件: docIdSub.c 项目: bowhan/kent
char *docIdGetPath(char *docId, char *docIdDir, char *type, char *submitPath)
{
char *ptr = docId + strlen(docId) - 1;
struct dyString *dy = newDyString(20);
char *suffix = docDecorateType(type);

dyStringPrintf(dy, "%s/", docIdDir);
for (; ptr != docId; ptr--)
    {
    dyStringPrintf(dy, "%c/", *ptr);   
    }

dyStringPrintf(dy, "%s.%s", docId, suffix);

return dyStringCannibalize(&dy);
}
示例#7
0
static char *getDbList(struct trackHub *tHub, int *pCount)
/* calculate dbList for hubStatus table from trackHub */
{
struct hashEl *hel;
struct dyString *dy = newDyString(1024);
struct hashCookie cookie = hashFirst(tHub->genomeHash);
int dbCount = 0;
while ((hel = hashNext(&cookie)) != NULL)
    {
    dbCount++;
    dyStringPrintf(dy,"%s,", hel->name);
    }
*pCount = dbCount;

return dy->string;
}
示例#8
0
void gtexGeneBedSaveToDb(struct sqlConnection *conn, struct gtexGeneBed *el, char *tableName, int updateSize)
/* Save gtexGeneBed as a row to the table specified by tableName. 
 * As blob fields may be arbitrary size updateSize specifies the approx size
 * of a string that would contain the entire query. Arrays of native types are
 * converted to comma separated strings and loaded as such, User defined types are
 * inserted as NULL. This function automatically escapes quoted strings for mysql. */
{
struct dyString *update = newDyString(updateSize);
char  *expScoresArray;
expScoresArray = sqlFloatArrayToString(el->expScores, el->expCount);
sqlDyStringPrintf(update, "insert into %s values ( '%s',%u,%u,'%s',%u,'%s','%s','%s',%u,'%s')", 
	tableName,  el->chrom,  el->chromStart,  el->chromEnd,  el->name,  el->score,  el->strand,  el->geneId,  el->geneType,  el->expCount,  expScoresArray );
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&expScoresArray);
}
示例#9
0
char *gsUploadUrl(char *gsToken, char *user, char *uploadFileName, off_t contentLength, char *base64Md5, char *contentType)
/* call uploadurl */
{
// UPLOADURLS 

// TODO deal with creating parent dirs if uploadFileName contains a path? maybe not.

// old:  "https://identity.genomespace.org/datamanager/uploadurls/users/"
// old     "https://dm.genomespace.org/datamanager/v1.0/uploadurl/users/"  // if this works, use default dir fetched earlier instead

char *dmSvr = getGenomeSpaceConfig("dmServer");
char uploadUrl[1024];
safef(uploadUrl, sizeof(uploadUrl),
    "%s/v1.0/uploadurl/users/"
    "%s/"
    "%s"
    "?Content-Length=%lld"
    "&Content-MD5=%s"
    "&Content-Type=%s"
    , dmSvr
    , user
    , uploadFileName
    , (long long) contentLength
    , cgiEncode(base64Md5)
    , contentType
    );


struct dyString *reqExtra = newDyString(256);
dyStringPrintf(reqExtra, "Cookie: gs-token=%s\r\n", gsToken);

int sd = netOpenHttpExt(uploadUrl, "GET", reqExtra->string);
if (sd < 0)
    errAbort("failed to open socket for [%s]", uploadUrl);

char *responseCode = NULL;
char *s3UploadUrl = parseResponse(sd, &responseCode);
if (sameString(responseCode, "404 Not Found"))
    errAbort("GenomeSpace: %s, if a path was used in the output name, it may indicate the path does not exist in GenomeSpace.", responseCode);
if (!sameString(responseCode, "200 OK"))
    errAbort("GenomeSpace: %s", responseCode);

dyStringFree(&reqExtra);

return s3UploadUrl;

}
示例#10
0
static char *getGsPersonalDirectory(char *gsToken)
/* Get User's default directory from GenomeSpace DM 
 * Returns a url like [https://identity.genomespace.org/datamanager/files/users/<user>]    
 */
{
// DEFAULT DIRECTORY

// old1 char *defaultDirectoryUrl = "https://identity.genomespace.org/datamanager/defaultdirectory";
// old2 char *defaultDirectoryUrl = "https://dmtest.genomespace.org:8444/datamanager/defaultdirectory";
// old3 char *defaultDirectoryUrl = "https://dm.genomespace.org/datamanager/v1.0/defaultdirectory";
// NOTE the defaultdirectory method got renamed to personaldirectory
// old4 char *personalDirectoryUrl = "https://dm.genomespace.org/datamanager/v1.0/personaldirectory";

char *dmSvr = getGenomeSpaceConfig("dmServer");
char personalDirectoryUrl[1024];
safef(personalDirectoryUrl, sizeof personalDirectoryUrl, "%s/v1.0/personaldirectory", dmSvr);
    
struct dyString *reqExtra = newDyString(256);
dyStringPrintf(reqExtra, "Cookie: gs-token=%s\r\n", gsToken);
    
int sd = netOpenHttpExt(personalDirectoryUrl, "GET", reqExtra->string);
if (sd < 0)
    errAbort("failed to open socket for [%s]", personalDirectoryUrl);

struct dyString *dy = netSlurpFile(sd);
close(sd);

char *personalDirectory = NULL;

if (strstr(dy->string, "HTTP/1.1 303 See Other"))
    {
    char *valStart = strstr(dy->string, "Location: ");
    if (valStart)
	{
	valStart += strlen("Location: ");
	char *valEnd = strstr(valStart, "\r\n");
	if (!valEnd)
	    errAbort("location not found in response headers");
	personalDirectory = cloneStringZ(valStart, valEnd - valStart);
	}
    }    
dyStringFree(&dy);
dyStringFree(&reqExtra);

return personalDirectory;

}
示例#11
0
void omimParseRec(char *omimTextFile, FILE *recFh, FILE *fieldFh)
/* omimParseRec - parse OMIM flat text file. */
{
struct lineFile *lf = lineFileOpen(omimTextFile, TRUE);
struct omimRecord *omimr;
struct dyString *dy = newDyString(4096);

for (;;)
    {
    struct lm *lm = lmInit(8*1024);
    omimr = omimRecordNext(lf, lm, dy, recFh, fieldFh);
    if (omimr == NULL)
        break;
    lmCleanup(&lm);
    }
dyStringFree(&dy);
}
int main(int argc, char** argv)
{
FILE *infile;
struct dyString *path = newDyString(128);
usage(argv);
    if(argv[2] != NULL)
        {
        dyStringAppend(path, argv[2]);
        if(!endsWith(path->string, "/"))
            dyStringAppend(path, "/");
        }
infile = mustOpen(argv[1], "r");
getTransFromFile(infile, path->string);
carefulClose(&infile);
freeDyString(&path);
return 0;
}
void populateXMLFile(FILE *outfile, int tmNumber, char *proteinID, char *path)
/** Adds the number of TM helices and sequence the the xml file */
{
struct dyString *filename = newDyString(128);
    if(path == NULL)
        dyStringPrintf(filename, "%s.seq", proteinID);
    else
        dyStringPrintf(filename, "%s%s.seq", path, proteinID);
fprintf(outfile, 
    "%d\" id-prefix=\"TM\" nterm-id=\"N-term\" cterm-id=\"C-term\" direction=\"down\" />\n\n"
    "\t</diagram-layout>\n\n\t<protein>\n\n\t\t<name>%s</name>\n\n\t\t<residue-codes>\n\n", 
    tmNumber, proteinID
       );
catSeqFile(outfile, filename->string);
fprintf(outfile, "\n\n\t\t</residue-codes>\n\n\t\t<secondary-structure>\n\n");
freeDyString(&filename);
}
void updatePath(struct hash *hash, char *userPath, 
	char *homeDir, char *sysPath)
/* Prepend userPath and system path to existing path. 
 * Add homeDir in front of all elements of user path. */
{
struct dyString *dy = newDyString(1024);
char *s, *e;
char *oldPath;

/* Go through user path - which is colon separated
 * and prepend homeDir to it. */
userPath = cloneString(userPath);
s = userPath;
for (;;)
    {
    if (s == NULL || s[0] == 0)
        break;
    e = strchr(s, ':');
    if (e != NULL)
       *e++ = 0;
    dyStringAppend(dy, homeDir);
    dyStringAppend(dy, "/");
    dyStringAppend(dy, s);
    dyStringAppend(dy, ":");
    s = e;
    }

/* Add system path next. */
if (sysPath != NULL && sysPath[0] != 0)
    {
    dyStringAppend(dy, sysPath);
    if (lastChar(sysPath) != ':')
	dyStringAppend(dy, ":");
    }

/* Add paths we inherited from root. */
oldPath = hashFindVal(hash, "PATH");
if (oldPath == NULL || oldPath[0] == 0)
    oldPath = "/bin:/usr/bin";
dyStringAppend(dy, oldPath);

hashUpdate(hash, "PATH", dy->string);
freez(&userPath);
dyStringFree(&dy);
}
char *associationCellVal(struct column *col, struct genePos *gp, 
	struct sqlConnection *conn)
/* Make comma separated list of matches to association table. */
{
char query[1024];
struct sqlResult *sr;
char **row;
boolean gotOne = FALSE;
struct dyString *dy = newDyString(512);
char *result = NULL;
char *key = (col->protKey 
    ? (kgVersion == KG_III ? lookupProtein(conn, gp->name) : gp->protein)
    : gp->name);
struct hash *uniqHash = NULL;

if (col->weedDupes) uniqHash = newHash(8);
safef(query, sizeof(query), col->queryOne, key);
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
    {
    char *s = row[0];
    boolean needQuote;
    if (uniqHash != NULL)
        {
	if (hashLookup(uniqHash, s))
	    continue;
	else
	    hashAdd(uniqHash, s, NULL);
	}
    needQuote = hasWhiteSpace(s);
    if (needQuote)
    	dyStringAppendC(dy, '\'');
    dyStringAppend(dy, s);
    if (needQuote)
    	dyStringAppendC(dy, '\'');
    dyStringAppend(dy, ",");
    gotOne = TRUE;
    }
sqlFreeResult(&sr);
if (gotOne)
    result = cloneString(dy->string);
dyStringFree(&dy);
freeHash(&uniqHash);
return result;
}
示例#16
0
void userSettingsSaveForm(struct userSettings *us)
/* Put up controls that let user name and save the current
 * set. */
{
char buf[1024];
struct hashEl *list = cartFindPrefix(us->cart, us->savePrefix);
safef(buf, sizeof(buf), "Save %s", us->formTitle);
makeTitle(buf, NULL);

/* Start form/save session/print title. */
hPrintf("<FORM ACTION=\"../cgi-bin/hgNear\" NAME=\"usForm\" METHOD=GET>\n");
cartSaveSession(us->cart);

/* Put up controls that are always there. */
hPrintf("Please name this setup:\n");
cartMakeTextVar(us->cart, us->nameVar, "", 16);
hPrintf(" ");
cgiMakeButton(us->formVar, "save");
hPrintf(" ");
cgiMakeButton(us->formVar, "cancel");

/* Put up additional controls if have saved settings already. */
if (list != NULL)
    {
    struct dyString *js = newDyString(0);

    htmlHorizontalLine();
    slSort(&list, hashElCmp);
    hPrintf("Existing Setups:");
    dyStringPrintf(js, "document.usForm.%s.value=", us->nameVar);
    dyStringPrintf(js, "document.usForm.%s.options", us->listDisplayVar);
    dyStringPrintf(js, "[document.usForm.%s.selectedIndex].value;", us->listDisplayVar);

    hPrintf("<SELECT NAME=\"%s\" SIZE=%d onchange=\"%s\">",
    	us->listDisplayVar, slCount(list), js->string);
    printLabelList(us, list);
    hPrintf("</SELECT>\n");

    cgiMakeButton(us->formVar, "delete existing setup");
    }

/* Cleanup. */
hPrintf("</FORM>\n");
slFreeList(&list);
}
示例#17
0
void warnWithBackTrace(char *format, ...)
/* Issue a warning message and append backtrace. */
{
va_list args;
va_start(args, format);
struct dyString *dy = newDyString(255);
dyStringAppend(dy, format);

#define STACK_LIMIT 20
char **strings = NULL;
int count = 0;

// developer: this is an occasionally useful means of getting stack info without crashing
// however, it is not supported on cygwin.  Conditionally compile this in when desired.
// The define is at top to include execinfo.h
#ifdef BACKTRACE_EXISTS
void *buffer[STACK_LIMIT];
count = backtrace(buffer, STACK_LIMIT);
strings = backtrace_symbols(buffer, count);
#endif///def BACKTRACE_EXISTS

if (strings == NULL)
    dyStringAppend(dy,"\nno backtrace_symbols available in errabort::warnWithBackTrace().");
else
    {
    int ix = 1;
    dyStringAppend(dy,"\nBACKTRACE (use on cmdLine):");
    if (strings[1] != NULL)
        {
        strSwapChar(strings[1],' ','\0');
        dyStringPrintf(dy,"\naddr2line -Cfise %s",strings[1]);
        strings[1] += strlen(strings[1]) + 1;
        }
    for (; ix < count && strings[ix] != NULL; ix++)
        {
        strings[ix] = skipBeyondDelimit(strings[ix],'[');
        strSwapChar(strings[ix],']','\0');
        dyStringPrintf(dy," %s",strings[ix]);
        }

    free(strings);
    }
vaWarn(dyStringCannibalize(&dy), args);
va_end(args);
}
FILE* createXMLFile(char* proteinID, char *path)
{
FILE* outfile;
struct dyString *filename = newDyString(128);
    if(path == NULL)
        dyStringPrintf(filename, "%s.xml", proteinID);
    else
        dyStringPrintf(filename, "%s%s.xml", path, proteinID);
outfile = mustOpen(filename->string, "w");
fprintf(outfile, 
    "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n\n"
    "<rbde-diagram xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
    " xsi:noNamespaceSchemaLocation=\"H:\\dev\\crover\\xml\\xsd\\residue-based-diagram.xsd\">\n\n"
    "\t<diagram-layout>\n\n\t\t<tm-bundle tm-number=\""
       );
freeDyString(&filename);
return outfile;
}
示例#19
0
static char *transcriptToCanonical(struct sqlConnection *conn, char *transcript)
/* Translate transcript to canonical ID if possible, otherwise just return 
 * a copy of transcript. */
{
struct dyString *dy = newDyString(1024);
char *cannon = genomeSetting("canonicalTable");
char *isoform = genomeSetting("isoformTable");
char buf[128];
char *result = NULL;
sqlDyStringPrintf(dy, "select %s.transcript from %s,%s where %s.transcript = '%s'",
	       cannon, isoform, cannon, isoform, transcript);
sqlDyStringPrintf(dy, " and %s.clusterId = %s.clusterId", isoform, cannon);
result = sqlQuickQuery(conn, dy->string, buf, sizeof(buf));
if (result != NULL)
    return(cloneString(result));
else
    return(cloneString(transcript));
}
示例#20
0
void encodeErgeSaveToDb(struct sqlConnection *conn, struct encodeErge *el, char *tableName, int updateSize)
/* Save encodeErge as a row to the table specified by tableName. 
 * As blob fields may be arbitrary size updateSize specifies the approx size
 * of a string that would contain the entire query. Arrays of native types are
 * converted to comma separated strings and loaded as such, User defined types are
 * inserted as NULL. Strings are automatically escaped to allow insertion into the database. */
{
struct dyString *update = newDyString(updateSize);
char  *blockSizesArray, *chromStartsArray;
blockSizesArray = sqlUnsignedArrayToString(el->blockSizes, el->blockCount);
chromStartsArray = sqlUnsignedArrayToString(el->chromStarts, el->blockCount);
sqlDyStringPrintf(update, "insert into %s values ( '%s',%u,%u,'%s',%u,'%s',%u,%u,%u,%u,'%s','%s','%s','%s')", 
	tableName,  el->chrom,  el->chromStart,  el->chromEnd,  el->name,  el->score,  el->strand,  el->thickStart,  el->thickEnd,  el->reserved,  el->blockCount,  blockSizesArray ,  chromStartsArray ,  el->Id,  el->color);
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&blockSizesArray);
freez(&chromStartsArray);
}
示例#21
0
void newStitch3(char *axtFile, char *output)
/* newStitch3 - Another stitching experiment - with kd-trees.. */
{
struct hash *pairHash = newHash(0);  /* Hash keyed by qSeq<strand>tSeq */
struct dyString *dy = newDyString(512);
struct lineFile *lf = lineFileOpen(axtFile, TRUE);
struct axt *axt;
struct seqPair *spList = NULL, *sp;
FILE *f = mustOpen(output, "w");

/* Read input file and divide alignments into various parts. */
while ((axt = axtRead(lf)) != NULL)
    {
    struct cBlock *block;
    if (axt->score < 500)
        {
	axtFree(&axt);
	continue;
	}
    dyStringClear(dy);
    dyStringPrintf(dy, "%s%c%s", axt->qName, axt->qStrand, axt->tName);
    sp = hashFindVal(pairHash, dy->string);
    if (sp == NULL)
        {
	AllocVar(sp);
	slAddHead(&spList, sp);
	hashAddSaveName(pairHash, dy->string, sp, &sp->name);
	}
    AllocVar(block);
    block->qStart = axt->qStart;
    block->qEnd = axt->qEnd;
    block->tStart = axt->tStart;
    block->tEnd = axt->tEnd;
    block->score = axt->score;
    slAddHead(&sp->blockList, block);
    axtFree(&axt);
    }
for (sp = spList; sp != NULL; sp = sp->next)
    {
    slReverse(&sp->blockList);
    chainPair(sp, f);
    }
dyStringFree(&dy);
}
boolean testingFileIdentical(char *file1, char *file2)
/** Check to see if two files are the same. */
{
struct dyString *command = newDyString(2048);
char *resultsFile = "_testingFileIdentical.tmp";
int result = 0;
boolean identical = FALSE;
int numDiff = 0;
dyStringPrintf(command,  "diff -b %s %s | wc > %s", file1, file2,resultsFile );
result = system(command->string);
if(result != 0)
    errAbort("testing::testingFileIdentical() - Failed running diff on %s and %s", file1, file2);
numDiff = countWcDiff(resultsFile);
if(numDiff ==0)
    identical = TRUE;
freeDyString(&command);
remove(resultsFile);
return identical;
}
示例#23
0
struct kgProtAlias *findKGProtAlias(char *dataBase, char *spec, char *mode)
{
/* findKGProtAlias looks up protein aliases for Known Genes, given a seach spec 

	mode "E" is for Exact match
 	mode "F" is for Fuzzy match
 	mode "P" is for Prefix match

   it returns a link list of kgProtAlias nodes, which contain kgID, displayID, and alias 
*/
struct sqlConnection *conn  = hAllocConn(dataBase);
struct dyString      *ds    = newDyString(256);
struct kgProtAlias *kapList = NULL;
char   fullTableName[256];

safef(fullTableName, 250, "%s.%s", dataBase, "kgProtAlias");
if (!sqlTableExists(conn, fullTableName))
    {
    errAbort("Table %s.kgProtAlias does not exist.\n", dataBase);
    }

if (sameString(mode, "E"))
    {
    sqlDyStringPrintf(ds, "select * from %s.kgProtAlias where alias = '%s'", dataBase, spec);
    }
else if (sameString(mode, "F"))
    {
    sqlDyStringPrintf(ds, "select * from %s.kgProtAlias where alias like '%%%s%%'", dataBase, spec);
    }
else if (sameString(mode, "P"))
    {
    sqlDyStringPrintf(ds, "select * from %s.kgProtAlias where alias like '%s%%'", dataBase, spec);
    }
else
    {
    errAbort("%s is not a valid mode for findKGAlias()\n", mode);
    }

addKGProtAlias(conn, ds, &kapList);
hFreeConn(&conn);

return(kapList);
}
struct hash *readInfoFile(char *fileName)
/* Read in 'info' file into hash keyed by gene field and
 * containing a partial sanger22extra. */
{
    struct hash *infoHash = newHash(0);
    struct lineFile *lf = lineFileOpen(fileName, TRUE);
    char *line, *type, *val;
    struct dyString *dy = newDyString(512);
    struct sanger22extra *sx = NULL;

    while (lineFileNext(lf, &line, NULL))
    {
        line = skipLeadingSpaces(line);
        if (line[0] == 0)
        {
            finishRecord(sx, dy);
            sx = NULL;
        }
        else
        {
            if (sx == NULL)
                AllocVar(sx);
            type = nextWord(&line);
            val = strchr(line, '"');
            if (val == NULL)
                errAbort("No quoted value line %d of %s\n", lf->lineIx, lf->fileName);
            parseQuotedString(val, val, &line);
            if (sameString("Gene", type))
            {
                sx->name = cloneString(val);
                hashAdd(infoHash, val, sx);
            }
            else if (sameString("Remark", type))
            {
                dyStringAppend(dy, val);
                dyStringAppend(dy, ". ");
            }
        }
    }
    finishRecord(sx, dy);
    lineFileClose(&lf);
    return infoHash;
}
void affy10KSaveToDbEscaped(struct sqlConnection *conn, struct affy10K *el, char *tableName, int updateSize)
/* Save affy10K as a row to the table specified by tableName. 
 * As blob fields may be arbitrary size updateSize specifies the approx size.
 * of a string that would contain the entire query. Automatically 
 * escapes all simple strings (not arrays of string) but may be slower than affy10KSaveToDb().
 * For example automatically copies and converts: 
 * "autosql's features include" --> "autosql\'s features include" 
 * before inserting into database. */ 
{
struct dyString *update = newDyString(updateSize);
char  *chrom;
chrom = sqlEscapeString(el->chrom);

dyStringPrintf(update, "insert into %s values ( '%s',%u,%u,%u)", 
	tableName,  chrom, el->chromStart , el->chromEnd , el->affyId );
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&chrom);
}
void cnpSharpCutoffSaveToDbEscaped(struct sqlConnection *conn, struct cnpSharpCutoff *el, char *tableName, int updateSize)
/* Save cnpSharpCutoff as a row to the table specified by tableName. 
 * As blob fields may be arbitrary size updateSize specifies the approx size.
 * of a string that would contain the entire query. Automatically 
 * escapes all simple strings (not arrays of string) but may be slower than cnpSharpCutoffSaveToDb().
 * For example automatically copies and converts: 
 * "autosql's features include" --> "autosql\'s features include" 
 * before inserting into database. */ 
{
struct dyString *update = newDyString(updateSize);
char  *sample;
sample = sqlEscapeString(el->sample);

dyStringPrintf(update, "insert into %s values ( '%s',%u,%g)", 
	tableName,  sample, el->batch , el->value );
sqlUpdate(conn, update->string);
freeDyString(&update);
freez(&sample);
}
示例#27
0
void loadDatabase(char *database, char *track, char *tabName)
/* Load up database from tab-file. */
{
struct sqlConnection *conn = sqlConnect(database);
struct dyString *dy = newDyString(1024);


if (!cgiBoolean("add"))
    {
    sqlDyStringPrintf(dy, createString, track);
    sqlRemakeTable(conn, track, dy->string);
    dyStringClear(dy);
    }
sqlDyStringPrintf(dy, "load data local infile '%s' into table %s",
	tabName, track);
sqlUpdate(conn, dy->string);
dyStringFree(&dy);
sqlDisconnect(&conn);
}
示例#28
0
int main(int argc, char *argv[])
/* Process command line. */
{
struct dyString *ds = newDyString(1024);
int i;

optionInit(&argc, argv, options);
cgi = optionExists("cgi");
jkhgap = optionExists("jkhgap");
if (argc < 3)
     usage();
for (i=2; i<argc; ++i)
    {
    dyStringAppend(ds, argv[i]);
    if (i != argc-1)
       dyStringAppend(ds, " ");
    }
newProg(argv[1], ds->string);
return 0;
}
示例#29
0
int main(int argc, char *argv[])
/* Process command line. */
{
long enteredMainTime = clock1000();
struct dyString *headText = newDyString(512);
char *destination = cgiUsualString("destination", defaultDestination);
if (strstr(destination, "://"))
    errAbort("To stop Open Redirect abuse, only relative URLs are supported. "
	    "Request for destination=[%s] rejected.\n", destination);

dyStringPrintf(headText,
	       "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0;URL=%s\">"
	       "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">"
	       "<META HTTP-EQUIV=\"Expires\" CONTENT=\"-1\">"
	       ,destination);
htmShellWithHead("Reset Cart", headText->string, doMiddle, NULL);
dyStringFree(&headText);
cgiExitTime("cartReset", enteredMainTime);
return 0;
}
void tigrCmrGeneSaveToDbEscaped(struct sqlConnection *conn, struct tigrCmrGene *el, char *tableName, int updateSize)
/* Save tigrCmrGene as a row to the table specified by tableName.
 * As blob fields may be arbitrary size updateSize specifies the approx size.
 * of a string that would contain the entire query. Automatically
 * escapes all simple strings (not arrays of string) but may be slower than tigrCmrGeneSaveToDb().
 * For example automatically copies and converts:
 * "autosql's features include" --> "autosql\'s features include"
 * before inserting into database. */
{
    struct dyString *update = newDyString(updateSize);
    char  *chrom, *name, *strand, *tigrCommon, *tigrGene, *tigrECN, *primLocus, *tigrMainRole, *tigrSubRole, *swissProt, *genbank, *goTerm;
    chrom = sqlEscapeString(el->chrom);
    name = sqlEscapeString(el->name);
    strand = sqlEscapeString(el->strand);
    tigrCommon = sqlEscapeString(el->tigrCommon);
    tigrGene = sqlEscapeString(el->tigrGene);
    tigrECN = sqlEscapeString(el->tigrECN);
    primLocus = sqlEscapeString(el->primLocus);
    tigrMainRole = sqlEscapeString(el->tigrMainRole);
    tigrSubRole = sqlEscapeString(el->tigrSubRole);
    swissProt = sqlEscapeString(el->swissProt);
    genbank = sqlEscapeString(el->genbank);
    goTerm = sqlEscapeString(el->goTerm);

    dyStringPrintf(update, "insert into %s values ( %d,'%s',%u,%u,'%s',%u,'%s','%s','%s','%s','%s',%u,%u,'%s','%s','%s','%s',%f,%f,%f,'%s')",
                   tableName, el->bin ,  chrom, el->chromStart , el->chromEnd ,  name, el->score ,  strand,  tigrCommon,  tigrGene,  tigrECN,  primLocus, el->tigrLength , el->tigrPepLength ,  tigrMainRole,  tigrSubRole,  swissProt,  genbank, el->tigrMw , el->tigrPi , el->tigrGc ,  goTerm);
    sqlUpdate(conn, update->string);
    freeDyString(&update);
    freez(&chrom);
    freez(&name);
    freez(&strand);
    freez(&tigrCommon);
    freez(&tigrGene);
    freez(&tigrECN);
    freez(&primLocus);
    freez(&tigrMainRole);
    freez(&tigrSubRole);
    freez(&swissProt);
    freez(&genbank);
    freez(&goTerm);
}