Exemple #1
0
static boolean ctdExists(struct section *section, 
	struct sqlConnection *conn, char *geneId)
/* Return TRUE if CTD database exists and it has an entry with the gene symbol */
{
char query[1024];
char *geneSymbol;
if (isRgdGene(conn))
    {
    if (sqlTableExists(conn, "rgdGene2Xref") == FALSE) return FALSE;
    }
else
    {
    if (sqlTableExists(conn, "kgXref") == FALSE) return FALSE;
    }

if (sqlTableExists(conn, "hgFixed.ctdSorted") == TRUE)
    {
    if (isRgdGene(conn))
	{
	sqlSafef(query, sizeof(query), "select ChemicalId from rgdGene2Xref x, hgFixed.ctdSorted c"
	" where x.info=c.GeneSymbol and infoType = 'Name' and rgdGeneId='%s' limit 1", geneId);
	geneSymbol = sqlQuickString(conn, query);
	}
    else
        {
	sqlSafef(query, sizeof(query), "select ChemicalId from kgXref x, hgFixed.ctdSorted c"
	" where x.geneSymbol=c.GeneSymbol and kgId='%s' limit 1", geneId);
	geneSymbol = sqlQuickString(conn, query);
	}

    if (geneSymbol != NULL) return(TRUE);
    }
return(FALSE);
}
Exemple #2
0
static boolean geneReviewsExists(struct section *section,
        struct sqlConnection *conn, char *geneId)
/* Return TRUE if geneReviewsDetail table exist and have GeneReviews articles
 * on this one. */
{
char query[256];
char * geneSymbol;
char * grSymbol;

if (sqlTableExists(conn, "geneReviewsDetail"))
    {
       sqlSafef(query, sizeof(query), "select geneSymbol from kgXref where kgId = '%s'", geneId);
       geneSymbol = sqlQuickString(conn, query);
       if (geneSymbol != NULL)
          {
             sqlSafef(query, sizeof(query), "select  geneSymbol from geneReviewsDetail where geneSymbol='%s'", geneSymbol);
             grSymbol = sqlQuickString(conn, query);
             if (grSymbol != NULL)
                {
                  return TRUE;
                }
           }
     }
return FALSE;
}
Exemple #3
0
char *bamFileNameFromTable(struct sqlConnection *conn, char *table, char *bamSeqName)
/* Return file name from table.  If table has a seqName column, then grab the 
 * row associated with bamSeqName (which can be e.g. '1' not 'chr1' if that is the
 * case in the bam file). */
{
boolean checkSeqName = (sqlFieldIndex(conn, table, "seqName") >= 0);
if (checkSeqName && bamSeqName == NULL)
    errAbort("bamFileNameFromTable: table %s has seqName column, but NULL seqName passed in",
	     table);
char query[512];
if (checkSeqName)
    sqlSafef(query, sizeof(query), "select fileName from %s where seqName = '%s'",
	  table, bamSeqName);
else
    sqlSafef(query, sizeof(query), "select fileName from %s", table);
char *fileName = sqlQuickString(conn, query);
if (fileName == NULL && checkSeqName)
    {
    if (startsWith("chr", bamSeqName))
	sqlSafef(query, sizeof(query), "select fileName from %s where seqName = '%s'",
	      table, bamSeqName+strlen("chr"));
    else
	sqlSafef(query, sizeof(query), "select fileName from %s where seqName = 'chr%s'",
	      table, bamSeqName);
    fileName = sqlQuickString(conn, query);
    }
if (fileName == NULL)
    {
    if (checkSeqName)
	errAbort("Missing fileName for seqName '%s' in %s table", bamSeqName, table);
    else
	errAbort("Missing fileName in %s table", table);
    }
return fileName;
}
void findClosestServer(char **pDb, char **pOrg)
/* If db doesn't have a blat server, look for the closest db (or org) that has one,
 * as hgPcr does. */
{
char *db = *pDb, *org = *pOrg;
struct sqlConnection *conn = hConnectCentral();
char query[256];
safef(query, sizeof(query), "select db from blatServers where db = '%s'", db);
if (!sqlExists(conn, query))
    {
    safef(query, sizeof(query), "select blatServers.db from blatServers,dbDb "
	  "where blatServers.db = dbDb.name and dbDb.genome = '%s'", org);
    char *db = sqlQuickString(conn, query);
    if (db == NULL)
	{
	safef(query, sizeof(query), "select blatServers.db from blatServers,dbDb "
	      "where blatServers.db = dbDb.name order by dbDb.orderKey,dbDb.name desc");
	char *db = sqlQuickString(conn, query);
	if (db == NULL)
	    errAbort("central database tables blatServers and dbDb are disjoint/empty");
	else
	    {
	    *pDb = db;
	    *pOrg = hGenome(db);
	    }
	}
    else
	{
	*pDb = db;
	*pOrg = hGenome(db);
	}
    }
hDisconnectCentral(&conn);
}
Exemple #5
0
char *docIdSubmit(struct sqlConnection *conn, char *docIdTable, struct docIdSub *docIdSub, 
    char *docIdDir, char *type)
{

verbose(2, "Submitting------\n");
verbose(2, "status %d\n", docIdSub->status);
verbose(2, "assembly %s\n", docIdSub->assembly);
verbose(2, "submitDate %s\n", docIdSub->submitDate);
verbose(2, "md5sum %s\n", docIdSub->md5sum);
verbose(2, "valReport %s\n", docIdSub->valReport);
verbose(2, "valVersion %s\n", docIdSub->valVersion);
verbose(2, "metaData %s\n", docIdSub->metaData);
verbose(2, "submitPath %s\n", docIdSub->submitPath);
verbose(2, "submitter %s\n", docIdSub->submitter);
verbose(2, "type %s\n", type);

char query[1024 * 1024];

fillNull(&docIdSub->valReport);
fillNull(&docIdSub->md5sum);

sqlSafef(query, sizeof query, "insert into %s (status, assembly, submitDate, md5sum, valReport, valVersion, metaData, submitPath, submitter) values (\"%d\",\"%s\",\"%s\",\"%s\", \"%s\", \"%s\", \"%s\",\"%s\",\"%s\")\n", docIdTable,
    docIdSub->status, docIdSub->assembly, docIdSub->submitDate, docIdSub->md5sum, docIdSub->valReport, docIdSub->valVersion, docIdSub->metaData, docIdSub->submitPath, docIdSub->submitter);
    //docIdSub->submitDate, docIdSub->md5sum, docIdSub->valReport, "null", docIdSub->submitPath, docIdSub->submitter);
//printf("query is %s\n", query);
char *response = sqlQuickString(conn, query);

printf("submitted got response %s\n", response);

sqlSafef(query, sizeof query, "select last_insert_id()");
char *docId = cloneString(sqlQuickString(conn, query));

printf("submitted got docId %s\n", docId);


if (!fileExists(docIdSub->submitPath))
    errAbort("cannot open %s\n", docIdSub->submitPath);
char *linkToFile = docIdGetPath(docId, docIdDir, type, docIdSub->submitPath);

printf("linking %s to file %s\n", docIdSub->submitPath, linkToFile);
char *slash = strrchr(linkToFile, '/');
if (slash == NULL)
    errAbort("can't find slash in path %s\n", linkToFile);

*slash = 0;
makeDirsOnPath(linkToFile);
*slash = '/';
if (link(docIdSub->submitPath, linkToFile) < 0)
    errnoAbort("can't link %s to file %s\n", docIdSub->submitPath, linkToFile);

return docId;
}
Exemple #6
0
static char *findGeneId(struct sqlConnection *conn, char *name)
/* Given some sort of gene name, see if it is in our primary gene table, and if not
 * look it up in alias table if we have one. */
{
/* Just check if it's in the main gene table, and if so return input name. */
char *mainTable = genomeSetting("knownGene");
char query[256];
sqlSafef(query, sizeof(query), "select count(*) from %s where name = '%s'", mainTable, name);
if (sqlQuickNum(conn, query) > 0)
    return name;
else
    {
    /* check OMIM gene symbol table first */
    if (sqlTableExists(conn, "omimGeneSymbol"))
    	{
    	sqlSafef(query, sizeof(query), "select geneSymbol from omimGeneSymbol where geneSymbol= '%s'", name);
    	char *symbol = sqlQuickString(conn, query);
    	if (symbol != NULL)
	    {
    	    sqlSafef(query, sizeof(query), "select kgId from kgXref where geneSymbol = '%s'", symbol);
    	    char *kgId = sqlQuickString(conn, query);
	    if (kgId != NULL)
	    	{
    	    	/* The canonical gene is preferred */
	        sqlSafef(query, sizeof(query), 
		"select c.transcript from knownCanonical c,knownIsoforms i where i.transcript = '%s' and i.clusterId=c.clusterId", kgId);
    	        char *canonicalKgId = sqlQuickString(conn, query);
	    	if (canonicalKgId != NULL) 
		    {
		    return canonicalKgId;
		    }
		else
                    return(kgId);
		}
	    }
	}
    }

char *alias = genomeOptionalSetting("kgAlias");
if (alias != NULL && sqlTableExists(conn, alias))
     {
     sqlSafef(query, sizeof(query), "select kgID from %s where alias = '%s'", alias, name);
     char *id = sqlQuickString(conn, query);
     if (id == NULL)
         hUserAbort("Couldn't find %s in %s.%s or %s.%s", name, database, mainTable, database, alias);
     return id;
     }
else
     hUserAbort("Couldn't find %s in %s.%s", name, database, mainTable);
return NULL;
}
char *spCommentVal(struct sqlConnection *conn, int valId)
/* Look up text associated with valId. freeMem result when done. */
{
char query[256];
safef(query, sizeof(query), "select val from commentVal where id=%d", valId);
return sqlQuickString(conn, query);
}
static char *otherOrgPositionFromDb(struct otherOrg *otherOrg, char *id)
/* Get position of id from other organism database, if possible. */
{
struct hTableInfo *hti = hFindTableInfo(otherOrg->db, NULL,
                                        otherOrg->geneTable);
if (hti == NULL)
    return NULL;  // table  not found

struct sqlConnection *conn = hAllocConn(otherOrg->db);
char query[512];
safef(query, sizeof(query),
      "select concat(%s, ':', %s+1, '-', %s) from %s "
      "where %s = '%s'",
      hti->chromField, hti->startField, hti->endField,
      otherOrg->geneTable, hti->nameField, id);
char *pos = sqlQuickString(conn, query);
if (pos != NULL)
    {
    char posPlus[2048];
    safef(posPlus, sizeof(posPlus), "%s&%s=%s&hgFind.matches=%s",
          pos,
          otherOrg->geneTable, hTrackOpenVis(sqlGetDatabase(conn), otherOrg->geneTable),
          id);
    hFreeConn(&conn);
    freez(&pos);
    return cloneString(posPlus);
    }
else
    {
    hFreeConn(&conn);
    return NULL;
    }
}
Exemple #9
0
void addImagesMatchingStage(struct visiSearcher *searcher,
	struct sqlConnection *conn, int schemeId, int taxon,
	char *minAge, int wordIx, int wordCount)
/* Given a developmental stage scheme (schemeId) and a specific
 * stage, return all images that match stage */
{
struct dyString *dy = dyStringNew(0);
char *maxAge;
// note in the code below minAge and maxAge are strings
//  but they should contain float values.  Putting single-quotes
//  around them and escaping their contents is something that will 
//  protect against sql injection.
dyStringClear(dy);
sqlDyStringPrintf(dy, 
    "select age from lifeStage where lifeStageScheme = %d ", 
    schemeId);
sqlDyStringPrintf(dy,
    "and age > '%s' order by age", minAge);
maxAge = sqlQuickString(conn, dy->string);

dyStringClear(dy);
sqlDyStringPrintf(dy, "select image.id from specimen,image ");
sqlDyStringPrintf(dy, "where specimen.age >= '%s' ", minAge);
if (maxAge != NULL)
    sqlDyStringPrintf(dy, "and specimen.age < '%s' ", maxAge);
dyStringPrintf(dy, "and specimen.taxon = %d ", taxon);
dyStringPrintf(dy, "and specimen.id = image.specimen");
addImagesMatchingQuery(searcher, conn, dy->string, NULL, NULL,
	wordIx, wordCount);

dyStringFree(&dy);
}
Exemple #10
0
struct visiMatch *removeMutants(struct sqlConnection *conn,
	struct visiMatch *matchList)
/* Remove images that are associated with mutant genotypes
 * from list. */
{
struct visiMatch *match, *next, *newList = NULL;
for (match = matchList; match != NULL; match = next)
    {
    char *genotype;
    char query[256];
    next = match->next;
    sqlSafef(query, sizeof(query),
        "select genotype.alleles from image,specimen,genotype "
	"where image.id=%d and image.specimen=specimen.id "
	"and specimen.genotype=genotype.id", match->imageId);
    genotype = sqlQuickString(conn, query);
    if (genotype == NULL || genotype[0] == 0 ||
    	startsWith("wild type", genotype))
	{
	slAddHead(&newList, match);
	}
    freeMem(genotype);
    }
slReverse(&newList);
return newList;
}
void doLabContacts(struct cart *theCart)
{
char *subId = cartString(theCart, "lab");
cartWebStart(cart, database, "ENCODE DCC:  Contacts for submission: %s",subId);
struct sqlConnection *conn = sqlConnect(database);
char query[10 * 1024];
struct sqlResult *sr;
char **row;

printf("<a href=docIdView?db=%s> Return </a><BR>", database);
safef(query, sizeof query, "select user_id from %s where id = %s ", "projects",subId);
char *userId = sqlQuickString(conn, query);

safef(query, sizeof query, "select name,email,pi from %s where id = '%s' ", "users",userId);
sr = sqlGetResult(conn, query);
printf("<pre>");
while ((row = sqlNextRow(sr)) != NULL)
    {
    printf("Name:  %s\nEmail: %s\nPI:    %s", row[0], row[1], row[2]);
    }

sqlFreeResult(&sr);
sqlDisconnect(&conn);
cartWebEnd();
}
void addImagesMatchingStage(struct visiSearcher *searcher,
	struct sqlConnection *conn, int schemeId, int taxon,
	char *minAge, int wordIx, int wordCount)
/* Given a developmental stage scheme (schemeId) and a specific
 * stage, return all images that match stage */
{
struct dyString *dy = dyStringNew(0);
char *maxAge;

dyStringClear(dy);
dyStringPrintf(dy, 
    "select age from lifeStage where lifeStageScheme = %d ", 
    schemeId);
dyStringPrintf(dy,
    "and age > %s order by age", minAge);
maxAge = sqlQuickString(conn, dy->string);

dyStringClear(dy);
dyStringPrintf(dy, "select image.id from specimen,image ");
dyStringPrintf(dy, "where specimen.age >= %s ", minAge);
if (maxAge != NULL)
    dyStringPrintf(dy, "and specimen.age < %s ", maxAge);
dyStringPrintf(dy, "and specimen.taxon = %d ", taxon);
dyStringPrintf(dy, "and specimen.id = image.specimen");
addImagesMatchingQuery(searcher, conn, dy->string, NULL, NULL,
	wordIx, wordCount);

dyStringFree(&dy);
}
static void mrnaDescriptionsPrint(struct section *section, 
	struct sqlConnection *conn, char *geneId)
/* Print out mrna descriptions annotations. */
{
struct psl *psl, *pslList = section->items;
for (psl = pslList; psl != NULL; psl = psl->next)
    {
    if (basesShared(curGenePred, psl) > 12)	/* Filter out possible little noisy flecks. */
        {
	char query[512];
	char *description;
	safef(query, sizeof(query),
	    "select description.name from gbCdnaInfo,description"
	    " where gbCdnaInfo.acc='%s' and gbCdnaInfo.description = description.id"
	    , psl->qName);
	description = sqlQuickString(conn, query);
	if (description != NULL)
	    {
	    char *url = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi"
	    		"?cmd=Search&db=Nucleotide&term=%s&doptcmdl=GenBank"
			"&tool=genome.ucsc.edu";
	    hPrintf("<A HREF=\"");
	    hPrintf(url, psl->qName);
	    hPrintf("\" TARGET=_blank>");
	    hPrintf("%s</A> - ", psl->qName);
	    hPrintf("%s<BR>", description);
	    }
	freeMem(description);
	}
    }
}
Exemple #14
0
Fichier : ec.c Projet : bowhan/kent
void getEcHtml(char *ecNumber)
/* fetch ec codes and descriptions and output html */
{
char query[1024];
struct sqlConnection *conn = hAllocConn("ec");
char *level1 = NULL;
char *level2 = NULL;
char *level3 = NULL;
//char *level4 = NULL;
struct ecAttribute attr;
char **row = NULL;
struct sqlResult *sr = NULL;

if (ecNumber == NULL)
    return;
if (conn == NULL)
    return;
sqlSafef(query,sizeof(query), "select distinct e.description from ecAttribute a , ecCode e where a.ec = \"%s\" and a.level1 = e.level1 and e.level2 = 0 ",ecNumber);
level1 = sqlQuickString(conn, query);
sqlSafef(query,sizeof(query), "select distinct e.description from ecAttribute a , ecCode e where a.ec = \"%s\" and a.level1 = e.level1 and a.level2 = e.level2 and e.level3 = 0 ",ecNumber);
level2 = sqlQuickString(conn, query);
sqlSafef(query,sizeof(query), "select distinct e.description from ecAttribute a , ecCode e where a.ec = \"%s\" and a.level1 = e.level1 and a.level2 = e.level2 and a.level3 = e.level3 and e.level4 = 0 ",ecNumber);
level3 = sqlQuickString(conn, query);
//sqlSafef(query,sizeof(query), "select distinct description from ecAttribute a where a.ec = \"%s\" ",ecNumber);
//level4 = sqlQuickString(conn, query);

printf("[ %s / %s / %s ] <BR>",
        (level1 != NULL) ? level1 :"n/a", 
        (level2 != NULL) ? level2 :"n/a", 
        (level3 != NULL) ? level3 :"n/a"
//        (level4 != NULL) ? level4 :"n/a"
        );
sqlSafef(query,sizeof(query), "select * from ecAttribute a where a.ec = \"%s\"",ecNumber);
sr = sqlGetResult(conn, query);
while ((row = sqlNextRow(sr)) != NULL)
    {
    char *attrDesc = NULL;
    struct sqlConnection *conn2 = hAllocConn("ec");
    ecAttributeStaticLoad(row, &attr);
    sqlSafef(query,sizeof(query), "select description from ecAttributeCode where type = \"%s\" ",attr.type);
    attrDesc = sqlQuickString(conn2, query);
    if (differentString(attr.type, "DR"))
        printf("<B>EC %s:</B> %s<BR>", attrDesc != NULL ? attrDesc : "n/a",attr.description);
    hFreeConn(&conn2);
    }
hFreeConn(&conn);
}
char *spRefTitle(struct sqlConnection *conn, int refId)
/* Get title of reference. This can be NULL legitimately. */
{
char query[256];
safef(query, sizeof(query), 
	"select title from reference where id=%d", refId);
return sqlQuickString(conn, query);
}
char *spRefPubMed(struct sqlConnection *conn, int refId)
/* Get PubMed id.  May be NULL legitimately. */
{
char query[256];
safef(query, sizeof(query), 
	"select pubMed from reference where id=%d", refId);
return sqlQuickString(conn, query);
}
Exemple #17
0
static char *getCgapId(struct sqlConnection *conn)
/* Get cgap ID. */
{
char query[256];
sqlSafef(query, sizeof(query), 
	"select cgapId from cgapAlias where alias=\"%s\"", curGeneName);
return sqlQuickString(conn, query);
}
char *xyzCellVal(struct column *col, struct genePos *gp,
                 struct sqlConnection *conn)
/* Make comma separated list of matches to association table. */
{
    char query[1000];
    sqlSafef(query, sizeof(query), "select %s from %s where %s = '%s'",
             col->valField, col->table, col->keyField, gp->name);
    return sqlQuickString(conn, query);
}
Exemple #19
0
char *genoQuery(char *id, char *settingName, struct sqlConnection *conn)
/* Look up sql query in genome.ra given by settingName,
 * plug id into it, and return. */
{
char query[256];
char *sql = genomeSetting(settingName);
sqlSafef(query, sizeof(query), sql, id);
return sqlQuickString(conn, query);
}
Exemple #20
0
void checkForGeoMirrorRedirect(struct cart *cart)
// Implement Geo/IP based redirection.
{
char *thisNodeStr = geoMirrorNode();
if (thisNodeStr)   // if geo-mirroring is enabled
    {
    char *redirectCookie = findCookieData("redirect");
    char *redirect = cgiOptionalString("redirect");

    // if we're not already redirected
    if (redirect == NULL && redirectCookie == NULL) 
        {
        int thisNode = sqlUnsigned(thisNodeStr);
        struct sqlConnection *centralConn = hConnectCentral();
        char *ipStr = cgiRemoteAddr();
        int node = defaultNode(centralConn, ipStr);

        // if our node is not the node that's closest.
        if (thisNode != node)
            {
	    char *geoSuffix = cfgOptionDefault("browser.geoSuffix","");
            char query[1056];
            sqlSafef(query, sizeof query, "select domain from gbNode%s where node = %d", geoSuffix, node);
            char *newDomain = sqlQuickString(centralConn, query);
            char *oldDomain = cgiServerName();
            char *port = cgiServerPort();
            char *uri = cgiRequestUri();
            char *sep = strchr(uri, '?') ? "&" : "?";
            int newUriSize = strlen(uri) + 1024;
            char *newUri = needMem(newUriSize);
            char *oldUri = needMem(newUriSize);
            safef(oldUri, newUriSize, "http%s://%s:%s%s%sredirect=manual&source=%s", 
		cgiServerHttpsIsOn() ? "s" : "", oldDomain, port, uri, sep, oldDomain);
            safef(newUri, newUriSize, "http%s://%s:%s%s%sredirect=manual&source=%s", 
		cgiServerHttpsIsOn() ? "s" : "", newDomain, port, uri, sep, oldDomain);

	    printf("<TR><TD COLSPAN=3 id='redirectTd' onclick=\"javascript:document.getElementById('redirectTd').innerHTML='';\">"
	    "<div style=\"margin: 10px 25%%; border-style:solid; border-width:thin; border-color:#97D897;\">"
	    "<h3 style=\"background-color: #97D897; text-align: left; margin-top:0px; margin-bottom:0px;\">"
	    "&nbsp;You might want to navigate to your nearest mirror - %s"
	    "</h3> "
	    "<ul style=\"margin:5px;\">",
	    newDomain);
	    
	    printf("<li>User settings (sessions and custom tracks) <B>will differ</B> between sites."
		"<idiv style=\"float:right;\"><a href=\"../goldenPath/help/genomeEuro.html#sessions\">Read more.</a></idiv>");
	    printf("<li>Take me to  <a href=\"%s\">%s</a> </li>",
		newUri, newDomain);
	    printf("<li>Let me stay here   <a href=\"%s\">%s</a>",
		oldUri, oldDomain );
	    printf("</div></TD></TR>\n");
            exit(0);
            }
        hDisconnectCentral(&centralConn);
        }
    }
}
Exemple #21
0
static struct slName* getExonFrames(char *table, struct sqlConnection *conn, struct bed *bedList)
/* get real exonFrames if they are available */
{
struct slName* list = NULL;
struct bed *bed;
for (bed = bedList;  bed != NULL;  bed = bed->next)
    {
    // be super specific, the same name may align to multiple locations
    //  or even the same location with alternate splicing or exon structure.
    
    // convert bed block coordinates to exonStarts, exonEnds
    int i;
    struct dyString *exonStarts = newDyString(256);
    struct dyString *exonEnds = newDyString(256);
    for( i = 0 ; i < bed->blockCount; i++ )
	{
	int exonStart = bed->chromStart + bed->chromStarts[i];
	int exonEnd = exonStart + bed->blockSizes[i];
	dyStringPrintf(exonStarts, "%d,", exonStart);
	dyStringPrintf(exonEnds,   "%d,", exonEnd);
	}
    char sql[4096+strlen(exonStarts->string)+strlen(exonEnds->string)];

    sqlSafef(sql, sizeof sql, "select exonFrames "
	"from %s where " 
	"name = '%s' and "  
	"chrom = '%s' and "
	"strand = '%c' and "
	"txStart = %d and "
	"txEnd = %d and "
	"cdsStart = %d and "
	"cdsEnd = %d and "
        "exonCount = %d and "
        "exonStarts = '%s' and "
        "exonEnds = '%s'"
	, 
	table, 
	bed->name,
	bed->chrom,
	bed->strand[0],
	bed->chromStart,
	bed->chromEnd,
	bed->thickStart,
	bed->thickEnd,
	bed->blockCount,
	exonStarts->string,
	exonEnds->string
	);
    char *exonFrames = sqlQuickString(conn, sql);
    slNameAddHead(&list, exonFrames);
    dyStringFree(&exonStarts);
    dyStringFree(&exonEnds);
    }
slReverse(&list);
return list;
}
Exemple #22
0
boolean edwSubmitShouldStop(struct sqlConnection *conn, unsigned submitId)
/* Return TRUE if there's an error message on submit, indicating we should stop. */
{
char query[256];
sqlSafef(query, sizeof(query), "select errorMessage from edwSubmit where id=%u", submitId);
char *errorMessage = sqlQuickString(conn, query);
boolean ret = isNotEmpty(errorMessage);
freez(&errorMessage);
return ret;
}
char *getCdsString(struct sqlConnection *conn, char *acc)
/* get the CDS string for an accession, or null if not found */
{
char query[256];

safef(query, sizeof(query),
      "SELECT cds.name FROM gbCdnaInfo,cds WHERE (gbCdnaInfo.acc = '%s') AND (gbCdnaInfo.cds != 0) AND (gbCdnaInfo.cds = cds.id)",
      acc);
return sqlQuickString(conn, query);
}
char *spIdToAcc(struct sqlConnection *conn, char *id)
/* Convert SwissProt ID (things like HXA1_HUMAN) to
 * accession. Returns NULL if the conversion fails. 
 * (doesn't abort). */
{
char query[256];
safef(query, sizeof(query), "select acc from displayId where val = '%s'",
	id);
return sqlQuickString(conn, query);
}
Exemple #25
0
char *hubNameFromUrl(char *hubUrl)
/* Given the URL for a hub, return its hub_# name. */
{
char query[PATH_LEN*4];
sqlSafef(query, sizeof(query), "select concat('hub_', id) from %s where hubUrl = '%s'",
         getHubStatusTableName(), hubUrl);
struct sqlConnection *conn = hConnectCentral();
char *name = sqlQuickString(conn, query);
hDisconnectCentral(&conn);
return name;
}
char *spOrganelle(struct sqlConnection *conn, char *acc)
/* Return text description of organelle.  FreeMem this when done. 
 * This may return NULL if it's not an organelle. */
{
char query[256];
safef(query, sizeof(query), 
	"select organelle.val from info,organelle "
	"where info.acc = '%s' and info.organelle = organelle.id"
	, acc);
return sqlQuickString(conn, query);
}
char *spAccFromEmbl(struct sqlConnection *conn, char *acc)
/* Get SwissProt accession associated with EMBL mRNA. */
{
char query[256];
int emblId;
safef(query, sizeof(query), "select id from extDb where val = 'EMBL'");
emblId = sqlNeedQuickNum(conn, query);
safef(query, sizeof(query),
    "select acc from extDbRef where extAcc1 = '%s' and extDb = %d"
    , acc, emblId);
return sqlQuickString(conn, query);
}
/*	Return is an array of integers, last one of value zero to indicate the
 *	end of the array.  In case of nothing found in trackDb, return
 *	a NULL pointer indicating no results. 
 *
 *      If the value is 'first' then use the first span value from the table.
 *      Assumes that all values in the table are the same. */
int *wiggleSpanList(struct sqlConnection *conn, struct trackDb *tdb)
{
char *tdbDefault = cloneString(trackDbSettingOrDefault(tdb, SPANLIST, "NONE"));
int *ret = (int *)NULL;


if (sameWord("NONE",tdbDefault))
    {
    struct hashEl *hel;
    /*	if not found in trackDb, maybe it is in tdb->settings
     *	(custom tracks keep settings here)
     */
    if ((tdb->settings != (char *)NULL) &&
	(tdb->settingsHash != (struct hash *)NULL))
	{
	if ((hel = hashLookup(tdb->settingsHash, SPANLIST)) != NULL)
	    {
	    freeMem(tdbDefault);
	    tdbDefault = cloneString((char *)hel->val);
	    }
	}
    }
/* if we still don't have a spanList, or we got "first" for spanList,
 * make up spanList by choosing the first span we find in the table */
//if (sameWord("NONE",tdbDefault) || sameWord("first",tdbDefault))
else if( sameWord("first",tdbDefault))
    {
    char query[1024];
    snprintf(query, sizeof(query), "SELECT span FROM %s limit 1", tdb->table );
    char *tmpSpan = sqlQuickString(conn, query);
    AllocArray(ret,2);
    ret[0] = sqlUnsigned(tmpSpan);
    ret[1] = 0;
    freeMem(tmpSpan);
    }
else 
    {
    /*	If something found, let's parse it	*/
    int i;
    char *words[MAX_SPAN_COUNT];
    int wc;
    wc = chopCommas(tdbDefault,words);
    AllocArray(ret,wc+1);	/*	+ 1 for the extra zero	*/
    for ( i = 0; i < wc; ++i )
	ret[i] = sqlUnsigned(words[i]);
    intSort(wc,ret);
    ret[wc] = 0;	/*	end of list	*/
    }

freeMem(tdbDefault);
return(ret);
}	/*	int *wiggleSpanList(struct trackDb *tdb)	*/
Exemple #29
0
void tellSubscribers(struct sqlConnection *conn, char *submitDir, char *submitFileName, unsigned id)
/* Tell subscribers that match about file of given id */
{
char query[256];
sqlSafef(query, sizeof(query), "select tags from edwFile where id=%u", id);
char *tagsString = sqlQuickString(conn, query);
struct hash *tagHash=NULL;
struct cgiVar *tagList=NULL;
if (!isEmpty(tagsString))
    cgiParseInputAbort(tagsString, &tagHash, &tagList);


char **row;
struct sqlResult *sr = sqlGetResult(conn, "NOSQLINJ select * from edwSubscriber order by runOrder,id");
while ((row = sqlNextRow(sr)) != NULL)
    {
    struct edwSubscriber *subscriber = edwSubscriberLoad(row);
    if (wildMatch(subscriber->filePattern, submitFileName)
        && wildMatch(subscriber->dirPattern, submitDir))
	{
	/* Might have to check for tags match, which involves db load and a cgi vs. cgi compare */
	boolean tagsOk = TRUE;
	if (!isEmpty(subscriber->tagPattern))
	    {
	    if (tagHash == NULL)  // if we're nonempty they better be too
	        tagsOk = FALSE;
	    else
	        {
		if (!allTagsWildMatch(subscriber->tagPattern, tagHash))
		    tagsOk = FALSE;
		}
	    }
	if (tagsOk)
	    {
	    int maxNumSize=16;	// more than enough digits base ten.
	    int maxCommandSize = strlen(subscriber->onFileEndUpload) + maxNumSize + 1;
	    char command[maxCommandSize];
	    safef(command, sizeof(command), subscriber->onFileEndUpload, id);
	    verbose(2, "system(%s)\n", command);
	    int err = system(command);
	    if (err != 0)
	        warn("err %d from system(%s)\n", err, command);
	    }
	}
    edwSubscriberFree(&subscriber);
    }

sqlFreeResult(&sr);
freez(&tagsString);
slFreeList(&tagList);
hashFree(&tagHash);
}
Exemple #30
0
void submitToDir(struct sqlConnection *conn, struct sqlConnection *conn2, struct sqlConnection *connSp,
    char *outDir, char *inJax)
/* Create directory full of visiGeneLoad .ra/.tab files from
 * jackson database connection.  Creates a pair of files for
 * each submission set.   Returns outDir. */
{
struct dyString *query = dyStringNew(0);
struct slName *ref, *refList = sqlQuickList(conn, NOSQLINJ "select distinct(_Refs_key) from GXD_Assay");
int refCount = 0;

makeDir(outDir);

for (ref = refList; ref != NULL; ref = ref->next)
    {
    char path[PATH_LEN];
    char *pub=NULL;
    boolean skip;

    /* Check that it isn't on our skip list - one that we
     * have already in the database from a higher resolution
     * source. */
    dyStringClear(query);
    sqlDyStringPrintf(query, "select title from BIB_Refs where _Refs_key = %s", 
    	ref->name);

    pub = sqlQuickString(conn, query->string);

    if (!pub)
	{
	verbose(1,"ref %s: missing title from BIB_Refs, ref skipped\n",ref->name);
	continue;
	}

    skip = oneSubmissionSet ?  oneSubmissionSet != sqlSigned(ref->name) : FALSE;

    if (!skip)
	{
	safef(path, sizeof(path), "%s/%s", outDir, ref->name);
	submitRefToFiles(conn, conn2, connSp, ref->name, path, inJax);
	refCount += 1;
	if (testMax != 0 && refCount >= testMax)
	     errAbort("Reached testMax %d output dirs [%s]\n", testMax, path);
	}
    freeMem(pub);
    }

    verbose(1,"refCount=%d\n",refCount);

slNameFreeList(&refList);
dyStringFree(&query);

}