Example #1
0
void doPathwayLinks(char *spAcc, char *mrnaName)
/* Show pathway links */
/* spAcc is a place holder for future extension */
{
struct sqlConnection *conn  = hAllocConn(database);
struct sqlConnection *conn2 = hAllocConn(database);
struct sqlResult *sr;
char **row;
char query[256];
char cond_str[128];
char *mapID, *locusID, *mapDescription;
char *geneID;
char *geneSymbol;
char *cgapID, *biocMapID;
boolean hasPathway;

if (hTableExists(database, "kgXref"))
    {
    sqlSafefFrag(cond_str, sizeof(cond_str), "kgID='%s'", mrnaName);
    geneSymbol = sqlGetField(database, "kgXref", "geneSymbol", cond_str);
    if (geneSymbol == NULL)
        {
        geneSymbol = mrnaName;
        }
    }
else
    {
    geneSymbol = mrnaName;
    }

/* Show Pathway links if any exist */
hasPathway = FALSE;
cgapID     = NULL;

/*Process BioCarta Pathway link data */
if (sqlTableExists(conn, "cgapBiocPathway"))
    {
    sqlSafefFrag(cond_str, sizeof(cond_str), "alias='%s'", geneSymbol);
    cgapID = sqlGetField(database, "cgapAlias", "cgapID", cond_str);

    if (cgapID != NULL)
	{
    	sqlSafef(query, sizeof(query), "select mapID from %s.cgapBiocPathway where cgapID = '%s'", database, cgapID);
    	sr = sqlGetResult(conn, query);
    	row = sqlNextRow(sr);
    	if (row != NULL)
	    {
	    if (!hasPathway)
	        {
	        hPrintf("<B>Pathways:</B>\n<UL>");
	        hasPathway = TRUE;
	    	}
	    }
    	while (row != NULL)
	    {
	    biocMapID = row[0];
	    hPrintf("<LI>BioCarta - &nbsp");
	    sqlSafefFrag(cond_str, sizeof(cond_str), "mapID=%c%s%c", '\'', biocMapID, '\'');
	    mapDescription = sqlGetField(database, "cgapBiocDesc", "description",cond_str);
	    hPrintf("<A HREF = \"");
	    hPrintf("http://cgap.nci.nih.gov/Pathways/BioCarta/%s", biocMapID);
	    hPrintf("\" TARGET=_blank>%s</A> - %s <BR>\n", biocMapID, mapDescription);
	    row = sqlNextRow(sr);
	    }
        sqlFreeResult(&sr);
	}
    }

/* Process KEGG Pathway link data */
if (sqlTableExists(conn, "keggPathway"))
    {
    sqlSafef(query, sizeof(query),
	  "select * from %s.keggPathway where kgID = '%s'", database, mrnaName);
    sr = sqlGetResult(conn, query);
    row = sqlNextRow(sr);
    if (row != NULL)
	{
	if (!hasPathway)
	    {
	    hPrintf("<B>Pathways:</B>\n<UL>");
	    hasPathway = TRUE;
	    }
        while (row != NULL)
            {
            locusID = row[1];
	    mapID   = row[2];
	    hPrintf("<LI>KEGG - &nbsp");
	    sqlSafefFrag(cond_str, sizeof(cond_str), "mapID=%c%s%c", '\'', mapID, '\'');
	    mapDescription = sqlGetField(database, "keggMapDesc", "description", cond_str);
	    hPrintf("<A HREF = \"");
	    hPrintf("http://www.genome.ad.jp/dbget-bin/show_pathway?%s+%s", mapID, locusID);
	    hPrintf("\" TARGET=_blank>%s</A> - %s <BR>\n",mapID, mapDescription);
            row = sqlNextRow(sr);
	    }
	}
    sqlFreeResult(&sr);
    }

/* Process SRI BioCyc link data */
if (sqlTableExists(conn, "bioCycPathway"))
    {
    sqlSafef(query, sizeof(query), "select * from %s.bioCycPathway where kgID = '%s'", database, mrnaName);
    sr = sqlGetResult(conn, query);
    row = sqlNextRow(sr);
    if (row != NULL)
	{
	if (!hasPathway)
	    {
	    hPrintf("<BR><B>Pathways:</B>\n<UL>");
	    hasPathway = TRUE;
	    }
        while (row != NULL)
            {
            geneID  = row[1];
	    mapID   = row[2];
	    hPrintf("<LI>BioCyc - &nbsp");
	    sqlSafefFrag(cond_str, sizeof(cond_str), "mapID=%c%s%c", '\'', mapID, '\'');
	    mapDescription = sqlGetField(database, "bioCycMapDesc", "description", cond_str);
	    hPrintf("<A HREF = \"");

	    hPrintf("http://biocyc.org/HUMAN/new-image?type=PATHWAY&object=%s&detail-level=2",
		   mapID);
	    hPrintf("\" TARGET=_blank>%s</A> %s <BR>\n",mapID, mapDescription);
            row = sqlNextRow(sr);
	    }
	}
    sqlFreeResult(&sr);
    }

if (hasPathway)
    {
    hPrintf("</UL>\n");
    }

hFreeConn(&conn);
hFreeConn(&conn2);
}
void doMiddle(struct cart *theCart)
/* Set up pretty web display. */
{
struct sqlConnection *conn, *conn2;
struct sqlConnection *connCentral = hConnectCentral();
char query[256], query2[256];
struct sqlResult *sr, *sr2;
char **row, **row2;
char buf[128];
char *answer;
char *database;
char *genome, *genomeDesc;  
char *kgID, *chrom, *txStart, *txEnd;
int iCnt = 1;

cart = theCart;
cartWebStart(theCart, database, "UCSC Known Genes List \n");

getDbAndGenome(cart, &database, &genome, oldVars);
if (!hTableExistsDb(database, "knownGene"))
    {
    printf("<br>Database %s currently does not have UCSC Known Genes.", database);
    cartWebEnd();
    return;
    }

sprintf(query, "select description from dbDb where name = '%s'", database);
genomeDesc = strdup(sqlQuickQuery(connCentral, query, buf, sizeof(buf)));
hDisconnectCentral(&connCentral);

printf("<H2>%s Genome (%s Assembly)</H2>\n", genome, genomeDesc);

conn = hAllocConn(database);
conn2= hAllocConn(database);

sprintf(query2,"select kgID from %s.kgXref order by geneSymbol;",
	database);

/* use the following for quck testing */
/*sprintf(query2,"select kgID, geneSymbol, description, spID, refseq from %s.kgXref order by geneSymbol limit 10;", database);
*/
sr2 = sqlMustGetResult(conn2, query2);
row2 = sqlNextRow(sr2);
while (row2 != NULL)
    {
    kgID = row2[0];
    
    sprintf(query,"select chrom, txSTart, txEnd  from %s.knownGene where name='%s'", database, kgID);
    sr = sqlMustGetResult(conn, query);
    row = sqlNextRow(sr);
    chrom 	= row[0];
    txStart 	= row[1];
    txEnd   	= row[2];

    printf("<A href=\"/cgi-bin/hgGene?db=%s&hgg_gene=%s", 
    	   database, kgID);
    printf("&hgg_chrom=%s&hgg_start=%s&hgg_end=%s\">", chrom, txStart, txEnd);
    printf("%d</A><BR>\n", iCnt);
    iCnt++;
    if ((iCnt % 1000) == 0) fflush(stdout);
    
    sqlFreeResult(&sr);
    row2 = sqlNextRow(sr2);
    }
    
sqlFreeResult(&sr2);
cartWebEnd();
}
Example #3
0
int main(int argc, char *argv[])
{
    char *database;
    char *outFn;
    char *errFn;

    struct sqlConnection *conn2;
    char query2[256];
    struct sqlResult *sr2;
    char **row2;

    struct aaReplacement aaRepl;

    char *repl2;
    char *chp;
    char *dbSnpId;
    char *desc;

    boolean successful;

    if (argc != 4) usage();

    aaInit();

    database = argv[1];
    conn2= hAllocConn(database);

    outFn   = argv[2];
    errFn   = argv[3];
    outf    = mustOpen(outFn, "w");
    errf    = mustOpen(errFn, "w");

    sqlSafef(query2, sizeof query2, "select avId, omimId, dbSnpId, repl2, description from omimAvNew");
    sr2 = sqlMustGetResult(conn2, query2);
    row2 = sqlNextRow(sr2);
    while (row2 != NULL)
    {
        avId    = row2[0];
        omimId  = row2[1];
        dbSnpId = row2[2];
        repl2   = row2[3];
        desc    = row2[4];

        if (repl2 != NULL)
        {
            if (!sameWord(repl2, "-"))
            {
                chp = strstr(repl2, " AND ");
                if (chp != NULL) *chp = '\0';

                successful = processRepl(avId, omimId, dbSnpId, repl2, &aaRepl, desc);
                if (!successful) fprintf(errf, "!!! %s\t%s\n", avId, repl2);

                // disable the processing of subsequent non-single replacement AA string case for now, until OMIM really fix their data
                /*
                if (chp != NULL)
                   {
                   chp = chp + strlen(" AND ");
                   processRepl(avId, omimId, dbSnpId, chp, &aaRepl, desc);
                   if (!successful) fprintf(errf, "!!! %s\t%s\n", avId, chp);
                   }
                */
            }
        }

        row2 = sqlNextRow(sr2);
    }
    sqlFreeResult(&sr2);

    fclose(outf);
    fclose(errf);
    hFreeConn(&conn2);
    return(0);
}
Example #4
0
static void filterControlsForTableDb(char *db, char *rootTable)
/* Put up filter controls for a single database table. */
{
struct sqlConnection *conn =  NULL;
if (!trackHubDatabase(db))
    conn = hAllocConn(db);
char *table = chromTable(conn, rootTable);
struct trackDb *tdb = findTdbForTable(db, curTrack, rootTable, ctLookupName);
boolean isSmallWig = isWiggle(db, table);
boolean isBigWig = tdb ? tdbIsBigWig(tdb) : isBigWigTable(table);
boolean isWig = isSmallWig || isBigWig;
boolean isBedGr = tdb ? tdbIsBedGraph(tdb) : isBedGraph(rootTable);
boolean isBb = tdb ? tdbIsBigBed(tdb) : isBigBed(database, table, curTrack, ctLookupName);
boolean isBam = tdb ? tdbIsBam(tdb) : isBamTable(rootTable);
boolean isVcf = tdb ? tdbIsVcf(tdb) : isVcfTable(rootTable, NULL);
int bedGraphColumn = 5;		/*	default score column	*/

if (isBedGr)
    {
    int wordCount;
    char *words[8];
    char *typeLine = cloneString(tdb->type);

    wordCount = chopLine(typeLine,words);
    if (wordCount > 1)
        bedGraphColumn = sqlUnsigned(words[1]);
    freez(&typeLine);
    }

if (isWig)
    {
    hPrintf("<TABLE BORDER=0>\n");
    if ((tdb != NULL) && (tdb->type != NULL))
        {
        double min, max;
        wiggleMinMax(tdb,&min,&max);
        numericFilterWithLimits(db, rootTable, filterDataValueVar,filterDataValueVar,min,max,"");

        hPrintf("<TR><TD COLSPAN=3 ALIGN=RIGHT> (dataValue range: [%g:%g]) "
                "</TD></TR></TABLE>\n", min, max);
        }
    else
        {
        numericFilter(db, rootTable, filterDataValueVar,filterDataValueVar, "");
        hPrintf("</TABLE>\n");
        }
    }
else
    {
    struct sqlFieldType *ftList;
    if (isBb)
        ftList = bigBedListFieldsAndTypes(tdb, conn);
    else if (isBam)
	ftList = bamListFieldsAndTypes();
    else if (isVcf)
	ftList = vcfListFieldsAndTypes();
    else
        ftList = sqlListFieldsAndTypes(conn, table);
    printSqlFieldListAsControlTable(ftList, db, rootTable, tdb, isBedGr);
    }

/* Printf free-form query row. */
if (!(isWig||isBedGr||isBam||isVcf))
    {
    char *name;
    hPrintf("<TABLE BORDER=0><TR><TD>\n");
    name = filterFieldVarName(db, rootTable, "", filterRawLogicVar);
    cgiMakeDropList(name, logOpMenu, logOpMenuSize,
		cartUsualString(cart, name, logOpMenu[0]));
    hPrintf(" Free-form query: ");
    name = filterFieldVarName(db, rootTable, "", filterRawQueryVar);
    char *val = cartUsualString(cart, name, "");
    // escape double quotes to avoid HTML parse trouble in the text input.
    val = htmlEncodeText(val, FALSE);
    cgiMakeTextVar(name, val, 50);
    hPrintf("</TD></TR></TABLE>\n");
    }

if (isWig||isBedGr||isBam||isVcf)
    {
    char *name;
    hPrintf("<TABLE BORDER=0><TR><TD> Limit data output to:&nbsp\n");
    name = filterFieldVarName(db, rootTable, "_", filterMaxOutputVar);
    cgiMakeDropList(name, maxOutMenu, maxOutMenuSize,
		cartUsualString(cart, name, maxOutMenu[0]));
    hPrintf("&nbsp;lines</TD></TR></TABLE>\n");
    }

freez(&table);
hFreeConn(&conn);
hPrintf("<BR>\n");
cgiMakeButton(hgtaDoFilterSubmit, "submit");
hPrintf(" ");
cgiMakeButton(hgtaDoMainPage, "cancel");
}
Example #5
0
int main(int argc, char *argv[])
{
FILE *inf;

char *mrnaDate;
int  months;
char dirName[PATH_MAX];

struct sqlConnection *conn, *conn3;
char query[256];
struct sqlResult *sr;
char **row;

char *protAcc, *mrnaAcc, *matchStr;
char *protSizeStr, *mrnaSizeStr;
int  protSize, mrnaSize, match;
char *protRefTableName;

char condStr[255];
int score;

if (argc != 5) usage();
    
proteinDataDate = argv[1];
kgTempDb = argv[2];
genomeReadOnly = argv[3];
protRefTableName = argv[4];

sprintf(spDB, "sp%s", proteinDataDate);
sprintf(proteinsDB, "proteins%s", proteinDataDate);
sprintf(gbTempDB, "%sTemp", kgTempDb);
  
inf = fopen("protRef.lis", "r"); 
if ((FILE *) NULL == inf)
    errAbort("ERROR: Can not open input file: protRef.lis");
o3  = fopen("kgBestRef.out",   "w");
if ((FILE *) NULL == o3)
    errAbort("ERROR: Can not open output file: kgBestRef.out");

conn = hAllocConn(genomeReadOnly);
conn3= hAllocConn(genomeReadOnly);
   
proteinCount = 0; 
snprintf(dirName, (size_t) sizeof(dirName), "%s", "./clusterRun" );

sqlSafef(query, sizeof query,"select qName, tName, matches, qSize, tSize from %s.%s", kgTempDb, protRefTableName);
sr = sqlMustGetResult(conn, query);
row = sqlNextRow(sr);
while (row != NULL)
    {
    protAcc 	= row[0];
    mrnaAcc 	= row[1];
    matchStr    = row[2];
    protSizeStr = row[3];
    mrnaSizeStr = row[4];

    sscanf(matchStr, "%d", &match);
    sscanf(protSizeStr, "%d", &protSize);
    sscanf(mrnaSizeStr, "%d", &mrnaSize);
    sscanf(matchStr, "%d", &match);
  
    if ((float)match/(float)protSize > 0.3)
    	{
        sqlSafefFrag(cond_str, sizeof cond_str, "acc='%s'", mrnaAcc);
        mrnaDate = sqlGetField(genomeReadOnly, "gbCdnaInfo", "moddate", condStr);
	if (mrnaDate != NULL)
	{
        months = cal_months(mrnaDate);
		
        score  = mrnaSize + months*2 - (protSize - match) *50;
    
        printf("%s\t%s\t%d\n", protAcc, mrnaAcc, score);fflush(stdout);
        }
	}
    row = sqlNextRow(sr);
    }    

hFreeConn(&conn);
hFreeConn(&conn3);
fclose(o3);
return(0);
}
struct mafAli *hgMafFrag(
	char *database,     /* Database, must already have hSetDb to this */
	char *track, 	    /* Name of MAF track */
	char *chrom, 	    /* Chromosome (in database genome) */
	int start, int end, /* start/end in chromosome */
	char strand, 	    /* Chromosome strand. */
	char *outName, 	    /* Optional name to use in first component */
	struct slName *orderList /* Optional order of organisms. */
	)
/* mafFrag- Extract maf sequences for a region from database.
 * This creates a somewhat unusual MAF that extends from start
 * to end whether or not there are actually alignments.  Where
 * there are no alignments (or alignments missing a species)
 * a . character fills in.   The score is always zero, and
 * the sources just indicate the species.  You can mafFree this
 * as normal. */
{
int chromSize = hChromSize(database, chrom);
struct sqlConnection *conn = hAllocConn(database);
struct dnaSeq *native = hChromSeq(database, chrom, start, end);
struct mafAli *maf, *mafList = mafLoadInRegion(conn, track, chrom, start, end);
char masterSrc[128];
struct hash *orgHash = newHash(10);
struct oneOrg *orgList = NULL, *org, *nativeOrg = NULL;
int curPos = start, symCount = 0;
struct slName *name;
int order = 0;

/* Check that the mafs are really copacetic, the particular
 * subtype we think is in the database that this (relatively)
 * simple code can handle. */
safef(masterSrc, sizeof(masterSrc), "%s.%s", database, chrom);
mafCheckFirstComponentSrc(mafList, masterSrc);
mafCheckFirstComponentStrand(mafList, '+');
slSort(&mafList, mafCmp);

/* Prebuild organisms if possible from input orderList. */
for (name = orderList; name != NULL; name = name->next)
    {
    AllocVar(org);
    slAddHead(&orgList, org);
    hashAddSaveName(orgHash, name->name, org, &org->name);
    org->dy = dyStringNew(native->size*1.5);
    org->order = order++;
    if (nativeOrg == NULL)
        nativeOrg = org;
    }
if (orderList == NULL)
    {
    AllocVar(org);
    slAddHead(&orgList, org);
    hashAddSaveName(orgHash, database, org, &org->name);
    org->dy = dyStringNew(native->size*1.5);
    if (nativeOrg == NULL)
        nativeOrg = org;
    }

/* Go through all mafs in window, mostly building up
 * org->dy strings. */
for (maf = mafList; maf != NULL; maf = maf->next)
    {
    struct mafComp *mc, *mcMaster = maf->components;
    struct mafAli *subMaf = NULL;
    order = 0;
    if (curPos < mcMaster->start)
	{
	fillInMissing(nativeOrg, orgList, native, start,
		curPos, mcMaster->start);
	symCount += mcMaster->start - curPos;
	}
    if (curPos < mcMaster->start + mcMaster->size) /* Prevent worst
    						    * backtracking */
	{
	if (mafNeedSubset(maf, masterSrc, curPos, end))
	    {
	    subMaf = mafSubset(maf, masterSrc, curPos, end);
	    if (subMaf == NULL)
	        continue;
	    }
	else
	    subMaf = maf;
	for (mc = subMaf->components; mc != NULL; mc = mc->next, ++order)
	    {
	    /* Extract name up to dot into 'orgName' */
	    char buf[128], *e, *orgName;

	    if ((mc->size == 0) || (mc->srcSize == 0)) /* skip over components without sequence */
		continue;

	    mc->leftStatus = mc->rightStatus = 0; /* squash annotation */

	    e = strchr(mc->src, '.');
	    if (e == NULL)
		orgName = mc->src;
	    else
		{
		int len = e - mc->src;
		if (len >= sizeof(buf))
		    errAbort("organism/database name %s too long", mc->src);
		memcpy(buf, mc->src, len);
		buf[len] = 0;
		orgName = buf;
		}

	    /* Look up dyString corresponding to  org, and create a
	     * new one if necessary. */
	    org = hashFindVal(orgHash, orgName);
	    if (org == NULL)
		{
		if (orderList != NULL)
		   errAbort("%s is not in orderList", orgName);
		AllocVar(org);
		slAddHead(&orgList, org);
		hashAddSaveName(orgHash, orgName, org, &org->name);
		org->dy = dyStringNew(native->size*1.5);
		dyStringAppendMultiC(org->dy, '.', symCount);
		if (nativeOrg == NULL)
		    nativeOrg = org;
		}
	    if (orderList == NULL && order > org->order)
		org->order = order;
	    org->hit = TRUE;

	    /* Fill it up with alignment. */
	    dyStringAppendN(org->dy, mc->text, subMaf->textSize);
	    }
	for (org = orgList; org != NULL; org = org->next)
	    {
	    if (!org->hit)
		dyStringAppendMultiC(org->dy, '.', subMaf->textSize);
	    org->hit = FALSE;
	    }
	symCount += subMaf->textSize;
	curPos = mcMaster->start + mcMaster->size;
	if (subMaf != maf)
	    mafAliFree(&subMaf);
	}
    }
if (curPos < end)
    {
    fillInMissing(nativeOrg, orgList, native, start, curPos, end);
    symCount += end - curPos;
    }
mafAliFreeList(&mafList);

slSort(&orgList, oneOrgCmp);
if (strand == '-')
    {
    for (org = orgList; org != NULL; org = org->next)
	reverseComplement(org->dy->string, org->dy->stringSize);
    }

/* Construct our maf */
AllocVar(maf);
maf->textSize = symCount;
for (org = orgList; org != NULL; org = org->next)
    {
    struct mafComp *mc;
    AllocVar(mc);
    if (org == orgList)
        {
	if (outName != NULL)
	    {
	    mc->src = cloneString(outName);
	    mc->srcSize = native->size;
	    mc->strand = '+';
	    mc->start = 0;
	    mc->size = native->size;
	    }
	else
	    {
	    mc->src = cloneString(masterSrc);
	    mc->srcSize = chromSize;
	    mc->strand = strand;
	    if (strand == '-')
	       reverseIntRange(&start, &end, chromSize);
	    mc->start = start;
	    mc->size = end-start;
	    }
	}
    else
        {
	int size = countAlpha(org->dy->string);
	mc->src = cloneString(org->name);
	mc->srcSize = size;
	mc->strand = '+';
	mc->start = 0;
	mc->size = size;
	}
    mc->text = cloneString(org->dy->string);
    dyStringFree(&org->dy);
    slAddHead(&maf->components, mc);
    }
slReverse(&maf->components);

slFreeList(&orgList);
freeHash(&orgHash);
hFreeConn(&conn);
return maf;
}
Example #7
0
char *filterClause(char *db, char *table, char *chrom, char *extraClause)
/* Get filter clause (something to put after 'where')
 * for table */
{
struct sqlConnection *conn = NULL;
char varPrefix[128];
int varPrefixSize, fieldNameSize;
struct hashEl *varList, *var;
struct dyString *dy = NULL;
boolean needAnd = FALSE;
char oldDb[128];
char dbTableBuf[256];
char explicitDb[128];
char splitTable[256];
char explicitDbTable[512];

/* Return just extraClause (which may be NULL) if no filter on us. */
if (! (anyFilter() && filteredOrLinked(db, table)))
    return cloneString(extraClause);
safef(oldDb, sizeof(oldDb), "%s", db);
dbOverrideFromTable(dbTableBuf, &db, &table);
if (!sameString(oldDb, db))
     safef(explicitDb, sizeof(explicitDb), "%s.", db);
else
     explicitDb[0] = 0;

/* Cope with split table and/or custom tracks. */
if (isCustomTrack(table))
    {
    conn = hAllocConn(CUSTOM_TRASH);
    struct customTrack *ct = ctLookupName(table);
    safef(explicitDbTable, sizeof(explicitDbTable), "%s", ct->dbTableName);
    }
else
    {
    conn = hAllocConn(db);
    safef(splitTable, sizeof(splitTable), "%s_%s", chrom, table);
    if (!sqlTableExists(conn, splitTable))
	safef(splitTable, sizeof(splitTable), "%s", table);
    safef(explicitDbTable, sizeof(explicitDbTable), "%s%s",
	  explicitDb, splitTable);
    }

/* Get list of filter variables for this table. */
safef(varPrefix, sizeof(varPrefix), "%s%s.%s.", hgtaFilterVarPrefix, db, table);
varPrefixSize = strlen(varPrefix);
varList = cartFindPrefix(cart, varPrefix);
if (varList == NULL)
    {
    hFreeConn(&conn);
    return cloneString(extraClause);
    }

/* Create filter clause string, stepping through vars. */
dy = dyStringNew(0);
for (var = varList; var != NULL; var = var->next)
    {
    /* Parse variable name into field and type. */
    char field[64], *s, *type;
    s = var->name + varPrefixSize;
    type = strchr(s, '.');
    if (type == NULL)
        internalErr();
    fieldNameSize = type - s;
    if (fieldNameSize >= sizeof(field))
        internalErr();
    memcpy(field, s, fieldNameSize);
    field[fieldNameSize] = 0;
    sqlCkId(field);
    type += 1;
    /* rawLogic and rawQuery are handled below;
     * filterMaxOutputVar is not really a filter variable and is handled
     * in wiggle.c. */
    if (startsWith("raw", type) || sameString(filterMaxOutputVar, type))
	continue;
    /*	Any other variables that are missing a name:
     *		<varPrefix>..<type>
     *	are illegal
     */
    if (fieldNameSize < 1)
	{
	warn("Missing name in cart variable: %s\n", var->name);
	continue;
	}
    if (sameString(type, filterDdVar))
        {
	char *patVar = filterPatternVarName(db, table, field);
	struct slName *patList = cartOptionalSlNameList(cart, patVar);
	normalizePatList(&patList);
	if (slCount(patList) > 0)
	    {
	    char *ddVal = cartString(cart, var->name);
	    boolean neg = sameString(ddVal, ddOpMenu[1]);
	    char *fieldType = getSqlType(conn, explicitDbTable, field);
	    boolean needOr = FALSE;
	    if (needAnd) dyStringAppend(dy, " and ");
	    needAnd = TRUE;
	    if (neg) dyStringAppend(dy, "not ");
	    boolean composite = (slCount(patList) > 1);
	    if (composite || neg) dyStringAppendC(dy, '(');
	    struct slName *pat;
	    for (pat = patList;  pat != NULL;  pat = pat->next)
		{
		char *sqlPat = sqlLikeFromWild(pat->name);
		if (needOr)
		    dyStringAppend(dy, " OR ");
		needOr = TRUE;
		if (isSqlSetType(fieldType))
		    {
		    sqlDyStringPrintfFrag(dy, "FIND_IN_SET('%s', %s.%s)>0 ",
				   sqlPat, explicitDbTable , field);
		    }
		else
		    {
		    sqlDyStringPrintfFrag(dy, "%s.%s ", explicitDbTable, field);
		    if (sqlWildcardIn(sqlPat))
			dyStringAppend(dy, "like ");
		    else
			dyStringAppend(dy, "= ");
		    sqlDyStringPrintf(dy, "'%s'", sqlPat);
		    }
		freez(&sqlPat);
		}
	    if (composite || neg) dyStringAppendC(dy, ')');
	    }
	}
    else if (sameString(type, filterCmpVar))
        {
	char *patVar = filterPatternVarName(db, table, field);
	char *pat = trimSpaces(cartOptionalString(cart, patVar));
	char *cmpVal = cartString(cart, var->name);
	if (cmpReal(pat, cmpVal))
	    {
	    if (needAnd) dyStringAppend(dy, " and ");
	    needAnd = TRUE;
	    if (sameString(cmpVal, "in range"))
	        {
		char *words[2];
		int wordCount;
		char *dupe = cloneString(pat);

		wordCount = chopString(dupe, ", \t\n", words, ArraySize(words));
		if (wordCount < 2)	/* Fake short input */
		    words[1] = "2000000000";
		if (strchr(pat, '.')) /* Assume floating point */
		    {
		    double a = atof(words[0]), b = atof(words[1]);
		    sqlDyStringPrintfFrag(dy, "%s.%s >= %f && %s.%s <= %f",
		    	explicitDbTable, field, a, explicitDbTable, field, b);
		    }
		else
		    {
		    int a = atoi(words[0]), b = atoi(words[1]);
		    sqlDyStringPrintfFrag(dy, "%s.%s >= %d && %s.%s <= %d",
		    	explicitDbTable, field, a, explicitDbTable, field, b);
		    }
		freez(&dupe);
		}
	    else
	        {
		// cmpVal has been checked already above in cmpReal for legal values.
		sqlDyStringPrintfFrag(dy, "%s.%s %-s ", explicitDbTable, field, cmpVal);
		if (strchr(pat, '.'))	/* Assume floating point. */
		    dyStringPrintf(dy, "%f", atof(pat));
		else
		    dyStringPrintf(dy, "%d", atoi(pat));
		}
	    }
	}
    }
/* Handle rawQuery if any */
    {
    char *varName;
    char *logic, *query;
    varName = filterFieldVarName(db, table, "", filterRawLogicVar);
    logic = cartUsualString(cart, varName, logOpMenu[0]);
    varName = filterFieldVarName(db, table, "", filterRawQueryVar);
    query = trimSpaces(cartOptionalString(cart, varName));
    if (query != NULL && query[0] != 0)
        {
	if (needAnd) dyStringPrintf(dy, " %s ", logic);
	sqlSanityCheckWhere(query, dy);
	}
    }

/* Clean up and return */
hFreeConn(&conn);
hashElFreeList(&varList);
if (dy->stringSize == 0)
    {
    dyStringFree(&dy);
    return cloneString(extraClause);
    }
else
    {
    if (isNotEmpty(extraClause))
	dyStringPrintf(dy, " and %s", extraClause);
    return dyStringCannibalize(&dy);
    }
}
void tjLoadSome(struct region *regionList,
                struct joinedTables *joined, int fieldOffset, int keyOffset,
                char *idField, struct hash *idHash,
                struct slName *chopBefore, struct slName *chopAfter,
                struct tableJoiner *tj, boolean isPositional, boolean isFirst)
/* Load up rows. */
{
    struct region *region;
    struct dyString *sqlFields = dyStringNew(0);
    struct joinerDtf *dtf;
    struct slRef *ref;
    struct joinerPair *jp;
    int fieldCount = 0, keyCount = 0;
    int idFieldIx = -1;
    struct sqlConnection *conn = hAllocConn(tj->database);
    char *identifierFilter = NULL;
    char *filter;
    boolean needUpdateFilter = FALSE;
    struct joinedRow *jr;

    if (isFirst)
        identifierFilter = identifierWhereClause(idField, idHash);
    filter = filterClause(tj->database, tj->table, regionList->chrom, identifierFilter);

    /* Record combined filter. */
// Show only the SQL filter built from filter page options, not identifierFilter,
// because identifierFilter can get enormous (like 126kB for 12,500 rsIDs).
    char *filterNoIds = filterClause(tj->database, tj->table, regionList->chrom, NULL);
    if (filterNoIds != NULL)
    {
        if (joined->filter == NULL)
            joined->filter = dyStringNew(0);
        else
            dyStringAppend(joined->filter, " AND ");
        dyStringAppend(joined->filter, filterNoIds);
        if (!isFirst)
        {
            needUpdateFilter = TRUE;
            for (jr = joined->rowList; jr != NULL; jr = jr->next)
                jr->hitThisTable = FALSE;
        }
    }

    /* Create field spec for sql - first fields user will see, and
     * second keys if any. */
    for (dtf = tj->fieldList; dtf != NULL; dtf = dtf->next)
    {
        struct joinerDtf *dupe = joinerDtfClone(dtf);
        slAddTail(&joined->fieldList, dupe);
        dyStringAddList(sqlFields, dtf->field);
        ++fieldCount;
    }
    for (ref = tj->keysOut; ref != NULL; ref = ref->next)
    {
        struct joinerDtf *dupe;
        jp = ref->val;
        dupe = joinerDtfClone(jp->a);
        slAddTail(&joined->keyList, dupe);
        dyStringAddList(sqlFields, jp->a->field);
        ++keyCount;
    }
    if (idHash != NULL)
    {
        if (idField == NULL)
            internalErr();
        idFieldIx = fieldCount + keyCount;
        dyStringAddList(sqlFields, idField);
    }

    for (region = regionList; region != NULL; region = region->next)
    {
        char **row;
        /* We free at end of loop so we get new one for each chromosome. */
        char *filter = filterClause(tj->database, tj->table, region->chrom, identifierFilter);
        struct sqlResult *sr = regionQuery(conn, tj->table,
                                           sqlFields->string, region, isPositional, filter);
        while (sr != NULL && (row = sqlNextRow(sr)) != NULL)
        {
            if (idFieldIx < 0)
            {
                if (jrRowAdd(joined, row, fieldCount, keyCount) == NULL)
                    break;
            }
            else
            {
                char *id = row[idFieldIx];
                if (isFirst)
                {
                    if (hashLookup(idHash, id))
                    {
                        if (jrRowAdd(joined, row, fieldCount, keyCount) == NULL)
                            break;
                    }
                }
                else
                {
                    struct hashEl *bucket;
                    id = chopKey(chopBefore, chopAfter, id);
                    for (bucket = hashLookup(idHash, id); bucket != NULL;
                            bucket = hashLookupNext(bucket))
                    {
                        jr = bucket->val;
                        jr->hitThisTable = TRUE;
                        jrRowExpand(joined, jr, row,
                                    fieldOffset, fieldCount, keyOffset, keyCount);
                    }
                }
            }
        }
        sqlFreeResult(&sr);
        freez(&filter);
        if (!isPositional)
            break;
    }
    if (isFirst)
        slReverse(&joined->rowList);
    if (needUpdateFilter)
    {
        for (jr = joined->rowList; jr != NULL; jr = jr->next)
        {
            jr->passedFilter &= jr->hitThisTable;
        }
    }
    tj->loaded = TRUE;
    hFreeConn(&conn);
}
void hgLoadChromGraph(boolean doLoad, char *db, char *track, char *fileName)
/* hgLoadChromGraph - Load up chromosome graph. */
{
    double minVal,maxVal;
    struct chromGraph *el, *list;
    FILE *f;
    char *tempDir = ".";
    char path[PATH_LEN], gbdbPath[PATH_LEN];
    char *idTable = optionVal("idTable", NULL);
    char *pathPrefix = NULL;

    if (idTable == NULL)
        list = chromGraphLoadAll(fileName);
    else
        list = chromGraphListWithTable(fileName, db, idTable);
    if (list == NULL)
        errAbort("%s is empty", fileName);

    /* Figure out min/max values */
    minVal = maxVal = list->val;
    for (el = list->next; el != NULL; el = el->next)
    {
        if (optionExists("minusLog10"))
        {
            if (el->val == 1)
                el->val = 0;
            else if (el->val > 0)
                el->val = -1 * log(el->val)/log(10);
        }
        if (el->val < minVal)
            minVal = el->val;
        if (el->val > maxVal)
            maxVal = el->val;
    }


    /* Sort and write out temp file. */
    slSort(&list, chromGraphCmp);
    f = hgCreateTabFile(tempDir, track);
    for (el = list; el != NULL; el = el->next)
        chromGraphTabOut(el, f);

    if (doLoad)
    {
        struct dyString *dy = dyStringNew(0);
        struct sqlConnection *conn;

        /* Set up connection to database and create main table. */
        conn = hAllocConn(db);
        sqlDyStringPrintf(dy, createString, track, hGetMinIndexLength(db));
        sqlRemakeTable(conn, track, dy->string);

        /* Load main table and clean up file handle. */
        hgLoadTabFile(conn, tempDir, track, &f);
        hgRemoveTabFile(tempDir, track);

        /* If need be create meta table.  If need be delete old row. */
        if (!sqlTableExists(conn, "metaChromGraph"))
            sqlUpdate(conn, metaCreateString);
        else
        {
            dyStringClear(dy);
            sqlDyStringPrintf(dy, "delete from metaChromGraph where name = '%s'",
                              track);
            sqlUpdate(conn, dy->string);
        }

        /* Make chrom graph file */
        safef(path, sizeof(path), "%s.cgb", track);
        chromGraphToBin(list, path);
        safef(path, sizeof(path), "/gbdb/%s/chromGraph", db);
        pathPrefix = optionVal("pathPrefix", path);
        safef(gbdbPath, sizeof(gbdbPath), "%s/%s.cgb", pathPrefix, track);

        /* Create new line in meta table */
        dyStringClear(dy);
        sqlDyStringPrintf(dy, "insert into metaChromGraph values('%s',%f,%f,'%s');",
                          track, minVal, maxVal, gbdbPath);
        sqlUpdate(conn, dy->string);
    }
}
Example #10
0
void showSAM_h1n1(char *item)
{
char query2[256];
struct sqlResult *sr2;
char **row2;
struct sqlConnection *conn2 = hAllocConn(database);
char cond_str[256];
char *predFN;
char *homologID;
char *SCOPdomain;
char *chain;
char goodSCOPdomain[40];
int  first = 1;
float  eValue;
char *chp;
int homologCount;
int gotPDBFile = 0;

printf("<H3>Protein Structure Analysis and Prediction by ");
printf("<A HREF=\"http://www.soe.ucsc.edu/research/compbio/SAM_T02/sam-t02-faq.html\"");
printf(" TARGET=_blank>SAM-T02</A></H3>\n");

printf("<B>Multiple Alignment:</B> ");
printf("<A HREF=\"%s/%s/summary.html#alignment", getH1n1StructUrl(), item);
printf("\" TARGET=_blank>%s</A><BR>\n", item);

printf("<B>Secondary Structure Predictions:</B> ");
printf("<A HREF=\"%s/%s/summary.html#secondary-structure", getH1n1StructUrl(), item);
printf("\" TARGET=_blank>%s</A><BR>\n", item);

printf("<B>3D Structure Prediction (PDB file):</B> ");
char pdbUrl[PATH_LEN];
safef(pdbUrl, sizeof(pdbUrl), "%s/%s/decoys/%s.try1-opt3.pdb.gz", getH1n1StructUrl(), item, item);
struct tempName chimerax;
mkChimerax(item, pdbUrl, NULL, &chimerax);

printf("<A HREF=\"%s\" TARGET=_blank>%s</A>, view with <A HREF=\"%s\">Chimera</A><BR>\n", pdbUrl, item, chimerax.forHtml);

gotPDBFile = 0;
sqlSafefFrag(cond_str, sizeof(cond_str), "proteinID='%s' and evalue <1.0e-5;", item);

printf("<TABLE>\n");
printf("<TR><TD ALIGN=\"center\">Front</TD>\n");
printf("<TD ALIGN=\"center\">Top</TD>\n");
printf("<TD ALIGN=\"center\">Side</TD>\n");
printf("</TR>\n");
printf("<TR>\n");
printf("<TD ALIGN=\"center\"><img src=\"%s/%s/%s.undertaker-align.view1_200.jpg\"></TD>", getH1n1StructUrl(), item, item);
printf("<TD ALIGN=\"center\"><img src=\"%s/%s/%s.undertaker-align.view2_200.jpg\"></TD>", getH1n1StructUrl(), item, item);
printf("<TD ALIGN=\"center\"><img src=\"%s/%s/%s.undertaker-align.view3_200.jpg\"></TD>", getH1n1StructUrl(), item, item);
printf("</TR>\n");
printf("<TR>\n");
printf("<TD ALIGN=\"center\"><A HREF=\"%s/%s/%s.undertaker-align.view1_500.jpg\">500x500</A></TD>",
	getH1n1StructUrl(), item, item);
printf("<TD ALIGN=\"center\"><A HREF=\"%s/%s/%s.undertaker-align.view2_500.jpg\">500x500</A></TD>",
	getH1n1StructUrl(), item, item);
printf("<TD ALIGN=\"center\"><A HREF=\"%s/%s/%s.undertaker-align.view3_500.jpg\">500x500</A></TD>",
	getH1n1StructUrl(), item, item);
printf("</TR>\n");
printf("</TABLE>\n");

printf("<BR><B>Detailed results of SAM-T02:</B> ");
printf("<A HREF=\"%s/%s/summary.html", getH1n1StructUrl(), item);
printf("\" TARGET=_blank>%s</A><BR>\n", item);

/* by pass the following additional processing for now, until two necessary tables are built */
hFreeConn(&conn2);
return;

if (sqlGetField(database, "protHomolog", "proteinID", cond_str) != NULL)
    {
    sqlSafefFrag(cond_str, sizeof(cond_str), "proteinID='%s'", item);
    predFN = sqlGetField(database, "protPredFile", "predFileName", cond_str);
    if (predFN != NULL)
	{
	printf("<A HREF=\"../SARS/%s/", item);
	/* printf("%s.t2k.undertaker-align.pdb\">%s</A><BR>\n", item,item); */
	printf("%s\">%s</A><BR>\n", predFN,item);
	gotPDBFile = 1;
	}
    }
if (!gotPDBFile)
    {
    printf("No high confidence level structure prediction available for this sequence.");
    printf("<BR>\n");
    }
printf("<B>3D Structure of Close Homologs:</B> ");
homologCount = 0;
strcpy(goodSCOPdomain, "dummy");

conn2= hAllocConn(database);
sqlSafef(query2, sizeof(query2),
	"select homologID,eValue,SCOPdomain,chain from sc1.protHomolog where proteinID='%s' and evalue <= 0.01;",
	item);
sr2 = sqlMustGetResult(conn2, query2);
row2 = sqlNextRow(sr2);
if (row2 != NULL)
    {
    while (row2 != NULL)
	{
	homologID = row2[0];
	sscanf(row2[1], "%e", &eValue);
	SCOPdomain = row2[2];
	chp = SCOPdomain+strlen(SCOPdomain)-1;
	while (*chp != '.') chp--;
	*chp = '\0';
	chain = row2[3];
	if (eValue <= 1.0e-10)
	    strcpy(goodSCOPdomain, SCOPdomain);
	else
	    {
	    if (strcmp(goodSCOPdomain,SCOPdomain) != 0)
		goto skip;
	    else
		if (eValue > 0.1) goto skip;
	    }
	if (first)
	    first = 0;
	else
	    printf(", ");

	printf("<A HREF=\"http://www.rcsb.org/pdb/cgi/explore.cgi?job=graphics&pdbId=%s",
	       homologID);
	if (strlen(chain) >= 1)
	    printf("\"TARGET=_blank>%s(chain %s)</A>", homologID, chain);
	else
	    printf("\"TARGET=_blank>%s</A>", homologID);
	homologCount++;

	skip:
	row2 = sqlNextRow(sr2);
	}
    }
hFreeConn(&conn2);
sqlFreeResult(&sr2);
if (homologCount == 0)
    printf("None<BR>\n");

printf("<BR><B>Details:</B> ");
printf("<A HREF=\"../SARS/%s/summary.html", item);
printf("\" TARGET=_blank>%s</A><BR>\n", item);

htmlHorizontalLine();
}
void loadCodeBlast(struct track *tg)
/* from the bed 6+1 codeBlast table, make a linkedFeaturesSeries and load it.  */
{
struct linkedFeaturesSeries *lfs = NULL, *originalLfs, *codeLfs, *lfsList = NULL;
struct linkedFeatures *lf;
struct slName *codes = NULL, *track=NULL, *scores=NULL;
struct codeBlast *bedList;
struct codeBlast *cb, *list=NULL;
struct sqlConnection *conn = hAllocConn(database);
struct sqlResult *sr;

char **temparray3;
char *temparray[32];
char *temparray2;
char **row;
char *tempstring;
int x;
int cutoff;
char cMode[64];

/*The most common names used to display method*/
char *codeNames[18] = {"within genus", "\t", "crenarchaea", "euryarchaea", "\t", "bacteria", 
		       "\t", "eukarya", "\t", "thermophile", "hyperthermophile","acidophile",
		       "alkaliphile", "halophile", "methanogen", "strict aerobe",
		       "strict anaerobe", "anaerobe or aerobe"}; int i;
safef(cMode, sizeof(cMode), "%s.scoreFilter", tg->tdb->track);
cutoff=cartUsualInt(cart, cMode,0 );
sr=hRangeQuery(conn, tg->table, chromName, winStart, winEnd, NULL, 0);

while ((row = sqlNextRow(sr)) != NULL)
    {
    cb = codeBlastLoad(row);
    slAddHead(&list, cb);
    }
sqlFreeResult(&sr);
hFreeConn(&conn);
slReverse(&list);
if(list == NULL)
    return;
for(cb = list; cb != NULL; cb = cb->next)
    {
    AllocVar(lfs);
    AllocVar(lf);
    lfs->name = cloneString(cb->name);
    lf = lfFromBed6(cb,0,1000);
    lf->score = cb->score;
    tempstring=cloneString(cb->code);
    
    chopString(tempstring, "," , temparray, ArraySize(temparray));
    if(sameWord(database, "pyrFur2"))
	{
	temparray3=(char**)calloc(19*8,sizeof(char**));
	for(x=0; x<19; x++)
	    {
	    temparray3[x]=(char *)calloc(256, sizeof(char*));
	    /* Fix to cloneString problem when both patricia and my track was showing at the same time */
	    if(temparray[x]!=NULL)
		{
		if(atoi(temparray[x])==1000)
		    temparray3[x]="1000";
		else if(atoi(temparray[x])==900)
		    temparray3[x]="900";
		else if(atoi(temparray[x])==800)
		    temparray3[x]="800";
		else if(atoi(temparray[x])==700)
		    temparray3[x]="700";
		else if(atoi(temparray[x])==600)
		    temparray3[x]="600";
		else if(atoi(temparray[x])==500)
		    temparray3[x]="500";
		else if(atoi(temparray[x])==400)
		    temparray3[x]="400";
		else if(atoi(temparray[x])==300)
		    temparray3[x]="300";
		else if(atoi(temparray[x])==200)
		    temparray3[x]="200";
		else if(atoi(temparray[x])==100)
		    temparray3[x]="100";
		else
		    temparray3[x]="0";
		}
	    }
	}
    else
	{
	temparray3=(char**)calloc(18*8,sizeof(char**));
	for(x=0; x<18; x++)
	    {
	    temparray3[x]=(char *)calloc(256, sizeof(char*));
	    /* Fix to cloneString problem when both patricia and my track was showing at the same time */
	    if(temparray[x]!=NULL)
		{
		if(atoi(temparray[x])==1000)
		    temparray3[x]="1000";
		else if(atoi(temparray[x])==900)
		    temparray3[x]="900";
		else if(atoi(temparray[x])==800)
		    temparray3[x]="800";
		else if(atoi(temparray[x])==700)
		    temparray3[x]="700";
		else if(atoi(temparray[x])==600)
		    temparray3[x]="600";
		else if(atoi(temparray[x])==500)
		    temparray3[x]="500";
		else if(atoi(temparray[x])==400)
		    temparray3[x]="400";
		else if(atoi(temparray[x])==300)
		    temparray3[x]="300";
		else if(atoi(temparray[x])==200)
		    temparray3[x]="200";
		else if(atoi(temparray[x])==100)
		    temparray3[x]="100";
		else
		    temparray3[x]="0";
		}
	    }
	}
    lf->extra = temparray3;
    lfs->start = lf->start;
    lfs->end = lf->end;
    lfs->features= lf;  
    slAddHead(&lfsList, lfs);
    }

tg->items=lfsList;
bedList=tg->items;
lfsList=NULL;

if(tg->limitedVis != tvDense)
    {
    originalLfs = tg->items;
    if(sameWord(database, "pyrFur2"))
	{
	for (i = 0; i < 19; i++)
            {
	    struct linkedFeatures *lfList = NULL;
	    AllocVar(codeLfs);
	    /*When doing abyssi displays differnt names at the begining*/
	    if(i == 0)
		codeLfs->name="within Pho";
	    else if (i==1)
		codeLfs->name="within Pab";
	    else if (i==2)
		codeLfs->name="\t";
	    else
		codeLfs->name = cloneString(codeNames[i-1]);
	    codeLfs->noLine = TRUE;
	    for (lfs = originalLfs; lfs != NULL; lfs = lfs->next)
            	{
		lf = lfsToLf(lfs);
		if(i>2)
            	    temparray2=((char**)(lfs->features->extra))[i-0];
		else temparray2=((char**)(lfs->features->extra))[i];
		if (i!=2 && i!=5 && i!=7 && i!=9 && atoi(temparray2)>-9997 && atoi(temparray2)!=0 && atoi(temparray2)>=cutoff)
                    {
		    lf->score=atoi(temparray2);
		    slAddHead(&lfList,lf);
		    }
                }
	    slReverse(&lfList);
	    codeLfs->features = lfList;   
	    slAddHead(&lfsList,codeLfs);
            }
	}
    else
	{   
	for (i = 0; i < 18; i++)
            {
	    struct linkedFeatures *lfList = NULL;
	    AllocVar(codeLfs);
	    codeLfs->name = cloneString(codeNames[i]);
	    codeLfs->noLine = TRUE;
	    for (lfs = originalLfs; lfs != NULL; lfs = lfs->next)
                {
		lf = lfsToLf(lfs);
		temparray2=((char**)(lfs->features->extra))[i];
		if (i!=1 && i!=4 && i!=6 && i!=8 && atoi(temparray2)>-9997 && atoi(temparray2)!=0 && atoi(temparray2)>=cutoff)
        	    {
		    lf->score=atoi(temparray2);
		    slAddHead(&lfList,lf);
	      	    }
                }
	    slReverse(&lfList);
	    codeLfs->features = lfList;   
	    slAddHead(&lfsList,codeLfs);
            }
	}
    freeLinkedFeaturesSeries(&originalLfs);
    slReverse(&lfsList);
    tg->items=lfsList;
    }
slFreeList(&track);
slFreeList(&scores);
slFreeList(&codes);
codeBlastFree(&list);
}
Example #12
0
static void showProtH1n1(char *item, char *geneSymbol)
{
char query2[256];
struct sqlResult *sr2;
char **row2;
struct sqlConnection *conn2 = hAllocConn(database);

char *subjId, *dnaSeqId;
char *aaSeqId= NULL;
char *gene=NULL;

char cond_str[256];
char *predFN;
char *homologID;
char *SCOPdomain;
char *chain;
char goodSCOPdomain[40];
int  first = 1;
float  eValue;
char *chp;
int homologCount;
int gotPDBFile = 0;

sqlSafef(query2, sizeof(query2),
	"select subjId, dnaSeqId, aaSeqId, gene from gisaidXref where dnaSeqId='%s'", item);
sr2 = sqlMustGetResult(conn2, query2);
row2 = sqlNextRow(sr2);
if (row2 != NULL)
    {
    subjId = strdup(row2[0]);
    dnaSeqId = strdup(row2[1]);
    aaSeqId  = strdup(row2[2]);
    gene     = strdup(row2[3]);
    }
else
    {
    errAbort("%s not found.", item);
    }
sqlFreeResult(&sr2);

printf("<H3>Protein Structure Analysis and Prediction</H3>");

printf("<B>Comparison to 1918 Flu Virus:</B> ");
printf("<A HREF=\"%s/%s/%s/1918_%s.mutate", getH1n1StructUrl(), gene, aaSeqId, aaSeqId);
printf("\" TARGET=_blank>%s</A><BR>\n", aaSeqId);

printf("<B>Comparison to A H1N1 gene %s concensus:</B> ", gene);
printf("<A HREF=\"%s/%s/%s/consensus_%s.mutate", getH1n1StructUrl(), gene, aaSeqId, aaSeqId);
printf("\" TARGET=_blank>%s</A><BR>\n", aaSeqId);

printf("<BR><B>3D Structure Prediction of %s concensus sequence (with variation of sequence %s highlighted):", geneSymbol, item);
printf("<BR>PDB file:</B> ");
char pdbUrl[PATH_LEN];
safef(pdbUrl, sizeof(pdbUrl), "%s/%s/decoys/%s.try1-opt3.pdb.gz", getH1n1StructUrl(), item, item);


// Modeller stuff
char modelPdbUrl[PATH_LEN];
if (getH1n1Model(gene, modelPdbUrl))
    {
    struct tempName imageFile, chimeraScript, chimerax;
    mkH1n1StructData(gene, NULL, aaSeqId, &imageFile, &chimeraScript);
    mkChimerax(gene, modelPdbUrl, chimeraScript.forCgi, &chimerax);
    printf("<A HREF=\"%s\" TARGET=_blank>%s</A>, view with <A HREF=\"%s\">Chimera</A><BR>\n", modelPdbUrl, gene, chimerax.forHtml);
    printf("<TABLE>\n");
    printf("<TR>\n");
    printf("<TD ALIGN=\"center\"><img src=\"%s\"></TD>", imageFile.forHtml);
    printf("</TR>\n");
    printf("</TABLE>\n");
    }
return;

gotPDBFile = 0;
sqlSafefFrag(cond_str, sizeof(cond_str), "proteinID='%s' and evalue <1.0e-5;", item);

printf("<TABLE>\n");
printf("<TR><TD ALIGN=\"center\">Front</TD>\n");
printf("<TD ALIGN=\"center\">Top</TD>\n");
printf("<TD ALIGN=\"center\">Side</TD>\n");
printf("</TR>\n");
printf("<TR>\n");
printf("<TD ALIGN=\"center\"><img src=\"%s/%s/%s.undertaker-align.view1_200.jpg\"></TD>", getH1n1StructUrl(), item, item);
printf("<TD ALIGN=\"center\"><img src=\"%s/%s/%s.undertaker-align.view2_200.jpg\"></TD>", getH1n1StructUrl(), item, item);
printf("<TD ALIGN=\"center\"><img src=\"%s/%s/%s.undertaker-align.view3_200.jpg\"></TD>", getH1n1StructUrl(), item, item);
printf("</TR>\n");
printf("<TR>\n");
printf("<TD ALIGN=\"center\"><A HREF=\"%s/%s/%s.undertaker-align.view1_500.jpg\">500x500</A></TD>",
	getH1n1StructUrl(), item, item);
printf("<TD ALIGN=\"center\"><A HREF=\"%s/%s/%s.undertaker-align.view2_500.jpg\">500x500</A></TD>",
	getH1n1StructUrl(), item, item);
printf("<TD ALIGN=\"center\"><A HREF=\"%s/%s/%s.undertaker-align.view3_500.jpg\">500x500</A></TD>",
	getH1n1StructUrl(), item, item);
printf("</TR>\n");
printf("</TABLE>\n");

printf("<BR><B>Detailed results of SAM-T02:</B> ");
printf("<A HREF=\"%s/%s/summary.html", getH1n1StructUrl(), item);
printf("\" TARGET=_blank>%s</A><BR>\n", item);

/* by pass the following additional processing for now, until two necessary tables are built */
hFreeConn(&conn2);
return;

if (sqlGetField(database, "protHomolog", "proteinID", cond_str) != NULL)
    {
    sqlSafefFrag(cond_str, sizeof(cond_str), "proteinID='%s'", item);
    predFN = sqlGetField(database, "protPredFile", "predFileName", cond_str);
    if (predFN != NULL)
	{
	printf("<A HREF=\"../SARS/%s/", item);
	/* printf("%s.t2k.undertaker-align.pdb\">%s</A><BR>\n", item,item); */
	printf("%s\">%s</A><BR>\n", predFN,item);
	gotPDBFile = 1;
	}
    }
if (!gotPDBFile)
    {
    printf("No high confidence level structure prediction available for this sequence.");
    printf("<BR>\n");
    }
printf("<B>3D Structure of Close Homologs:</B> ");
homologCount = 0;
strcpy(goodSCOPdomain, "dummy");

conn2= hAllocConn(database);
sqlSafef(query2, sizeof(query2),
	"select homologID,eValue,SCOPdomain,chain from sc1.protHomolog where proteinID='%s' and evalue <= 0.01;",
	item);
sr2 = sqlMustGetResult(conn2, query2);
row2 = sqlNextRow(sr2);
if (row2 != NULL)
    {
    while (row2 != NULL)
	{
	homologID = row2[0];
	sscanf(row2[1], "%e", &eValue);
	SCOPdomain = row2[2];
	chp = SCOPdomain+strlen(SCOPdomain)-1;
	while (*chp != '.') chp--;
	*chp = '\0';
	chain = row2[3];
	if (eValue <= 1.0e-10)
	    strcpy(goodSCOPdomain, SCOPdomain);
	else
	    {
	    if (strcmp(goodSCOPdomain,SCOPdomain) != 0)
		goto skip;
	    else
		if (eValue > 0.1) goto skip;
	    }
	if (first)
	    first = 0;
	else
	    printf(", ");

	printf("<A HREF=\"http://www.rcsb.org/pdb/cgi/explore.cgi?job=graphics&pdbId=%s",
	       homologID);
	if (strlen(chain) >= 1)
	    printf("\"TARGET=_blank>%s(chain %s)</A>", homologID, chain);
	else
	    printf("\"TARGET=_blank>%s</A>", homologID);
	homologCount++;

	skip:
	row2 = sqlNextRow(sr2);
	}
    }
hFreeConn(&conn2);
sqlFreeResult(&sr2);
if (homologCount == 0)
    printf("None<BR>\n");

printf("<BR><B>Details:</B> ");
printf("<A HREF=\"../SARS/%s/summary.html", item);
printf("\" TARGET=_blank>%s</A><BR>\n", item);

htmlHorizontalLine();
}
Example #13
0
int main(int argc, char *argv[])
{
char *database;
char *outFn;
char pqc;
boolean has2Bands;

char gapTableName[255];

struct sqlConnection *conn,*conn2;
char query[1024];
char query2[1024];
struct sqlResult *sr;
struct sqlResult *sr2;
char **row;
char **row2;

int startPos;
int endPos;
int startPosBand1;
int endPosBand1;
int startPosBand2;
int endPosBand2;

char locSav[255];

char *chp;
char *chpTer;
char *chpCen;
char chrom[255];

char band1[255];
char band2[255];

if (argc != 3) usage();

database = argv[1];
conn= hAllocConn(database);
conn2= hAllocConn(database);

outFn   = argv[2];
outf    = mustOpen(outFn, "w");

/* process omimGeneMap records with *p* or *q* locations */
sqlSafef(query2, sizeof query2, 
        "select omimId, location from omimGeneMapNew where location like '\%cp%c' or location like '%cq%c'", 
        '%','%', '%','%');
sr2 = sqlMustGetResult(conn2, query2);
row2 = sqlNextRow(sr2);
while (row2 != NULL)
    {
    boolean band1Success;
    
    boolean band1HasTer;
    boolean band2HasTer;
    boolean band1HasCen;
    boolean band2HasCen;
    
    band1Success      = FALSE;
    band1HasTer       = FALSE;
    band2HasTer       = FALSE;
    band1HasCen       = FALSE;
    band2HasCen       = FALSE;

    omimId   = row2[0];
    location = row2[1];

    /* save original location string */
    strcpy(locSav, location);
    
    /* break band1 and band2 if there is one */
    chp = strstr(location, "-");
    if (chp != NULL)
    	{
        has2Bands = TRUE;
	*chp = '\0';
	chp++;
	strncpy(band2, chp, (size_t)(sizeof(band2)));
	}
    else
    	{
	has2Bands = FALSE;
	}

    /* construct chrom first */	
    safef(chrom, sizeof(chrom), "chr%s", location);
    chp = chrom;
    
    /* skip "chr" */
    chp++; 
    chp++; 
    chp++; 
   
    /* get the end position of "chrX" */
    while (! ( (*chp == 'p') || (*chp == 'q') || \
               (*chp == 'c') || (*chp == '\0') ) ) chp++;
    
    if (*chp == '\0')
    	{
	/* something is wrong, skip this record */
	fprintf(stderr, "in chrom processing, did not get p, q, or c got %s, locSav=%s, omimId=%s\n", location, locSav, omimId);
	goto skip1;
	}

    /* now we have p or q or c (first char of "cen") */
    pqc = *chp;

    /* construct band1 */
    strncpy(band1, chp, sizeof(band1));
    
    /* terminate the chrom str*/
    *chp = '\0';
    
    // process band1 first 
    
    strcpy(gapTableName, "gap");

    if (sameWord(database, "hg18")) 
    	safef(gapTableName, sizeof(gapTableName), "%s_gap", chrom);

    band1Success  = FALSE;
    chpTer = strstr(band1, "ter");
    if (chpTer != NULL)
    	{
	band1HasTer = TRUE;
	*chpTer = '\0';
	}
    
    if (band1HasTer == TRUE)
    	{
	sqlSafef(query, sizeof query,
                "select chromStart, chromEnd from %s where chrom = '%s' and type ='telomere' and chromStart = 0", gapTableName, chrom);
    	}
    else
        {
    	/* process "cen" */
    	if (pqc == 'c') 
    	    {
	    band1HasCen  = TRUE;
	    sqlSafef(query, sizeof query,
                    "select chromStart, chromEnd from %s where chrom = '%s' and type ='centromere'", gapTableName, chrom);
	    }
	else
	    {
	    /* process p or q */
	    if ((pqc == 'p') || (pqc == 'q'))
	    	{
		sqlSafef(query, sizeof query,
                        "select chromStart, chromEnd from cytoBand where chrom = '%s' and name = '%s'", 
		        chrom, band1);
		}
	    else
	    	{
		fprintf(stderr, "can not deal with omimId=%s locaSav=%s band1=%s\n", omimId, locSav, band1);
		goto skip1;
		}
    	    }
	}

    sr = sqlMustGetResult(conn, query);
    row = sqlNextRow(sr);
    if (row != NULL) 
    	{
	startPosBand1 = atoi(row[0]);
	endPosBand1   = atoi(row[1]);
	band1Success  = TRUE;
	}
    else
	{
    	sqlFreeResult(&sr);
    	sqlSafef(query, sizeof query,
                "select min(chromStart), max(chromEnd) from cytoBand where chrom = '%s' and name like '%s%c'", chrom, band1, '%');
	sr = sqlMustGetResult(conn, query);
    	row = sqlNextRow(sr);
    	if ((row != NULL) && (row[0] != NULL) && (row[1] != NULL))
    	    {
	    startPosBand1 = atoi(row[0]);
	    endPosBand1   = atoi(row[1]);
	    
	    // special treatment for "...ter" band1 location
	    if ((band1HasTer) && (pqc == 'p') && (has2Bands))
	    	{
		endPosBand1   = 0;
		}
	    
	    band1Success  = TRUE;
	    }
	else
	    {
	    band1Success  = FALSE;
	    fprintf(stderr, "band1 processing failed and skipped: band1=%s, locSav=%s, omimId=%s\n", band1, locSav, omimId);
	    }
	}
    sqlFreeResult(&sr);
  
    /* now process band2 */
    if (band1Success && has2Bands)
    	{
	boolean band2Success;
	band2Success = FALSE;

	// do a special processing here for cases like "2q32-34" 
	if (isdigit(band2[0]) && pqc == 'q')
	    {
	    char temp[300];
	    safef(temp, sizeof(temp), "q%s", band2);
	    safef(band2, sizeof(band2), "%s", temp);
	    }

	chpTer = strstr(band2, "ter");
	if (chpTer != NULL) 
	    {
	    band2HasTer = TRUE;
	    *chpTer = '\0';
    	    sqlSafef(query, sizeof query,
            		"select max(chromEnd), max(chromEnd) from cytoBand where chrom = '%s' and name like '%s%c'", chrom, band2, '%');
	    }
	else
	    {
	    chpCen = strstr(band2, "cen");
	    if (chpCen != NULL) 
	    	{
	    	band2HasCen = TRUE;
    		sqlSafef(query, sizeof query,
            		"select chromStart, chromEnd from %s where chrom = '%s' and type = 'centromere'", gapTableName, chrom);
	    	}
	    else
	    	{
    		sqlSafef(query, sizeof query,
            		"select chromStart, chromEnd from cytoBand where chrom = '%s' and name = '%s'", chrom, band2);
    		}
	    }

	sr = sqlMustGetResult(conn, query);
    	row = sqlNextRow(sr);
    	if (row != NULL) 
    	    {
	    startPosBand2 = atoi(row[0]);
	    endPosBand2   = atoi(row[1]);
	    band2Success  = TRUE;
	    }  
	else
	    {
    	    sqlFreeResult(&sr);
            sqlSafef(query, sizeof query, 
	    	    "select min(chromStart), max(chromEnd) from cytoBand where chrom = '%s' and name like '%s%c'", chrom, band2, '%');

	    sr = sqlMustGetResult(conn, query);
    	    row = sqlNextRow(sr);
    	    if ((row != NULL) && (row[0] != NULL) && (row[1] != NULL))
    	    	{
	    	startPosBand2 = atoi(row[0]);
	    	endPosBand2   = atoi(row[1]);
	    	endPos   = atoi(row[1]);
	    	band2Success = TRUE;
	    	}
	    else
	    	{
	    	band2Success  = FALSE;
		fprintf(stderr, "band2 processing failed and skipped: band2=%s, locSav=%s, omimId=%s\n", band2, locSav, omimId);
	    	}
	    }
	
	if (band2Success) 
	    {
	    startPos = min(startPosBand1, startPosBand2);
	    endPos   = max(endPosBand1,   endPosBand2);

	    fprintf(outf, "%s\t%d\t%d\t%s\n", chrom, startPos, endPos, omimId);
	    }

	}
    else
    	{
	if (band1Success) 
	    {
	    fprintf(outf, "%s\t%d\t%d\t%s\n", chrom, startPosBand1, endPosBand1, omimId);
	    }
	}
    sqlFreeResult(&sr);
skip1:    
    row2 = sqlNextRow(sr2);
    }
sqlFreeResult(&sr2);

fclose(outf);
hFreeConn(&conn2);
return(0);
}
Example #14
0
int main(int argc, char *argv[])
{
struct sqlConnection *conn2;
char condStr[500];

FILE *inf;
FILE   *outf;

char line[1000];

char *chrStart;

char *inFileName, *outFileName;
char contig[100], start[100], end[100];
char num[100], code[100], id[100], oStart[100], oEnd[100], strnd[100];
char *database;

char *oldContig;
int  oldNum = 0;

int lastNum = 0;
int lastEnd = 0;

if (argc != 4)usage();

database    = argv[1];
inFileName  = argv[2];
outFileName = argv[3];

hSetDb(database);

outf = fopen(outFileName, "w");
conn2= hAllocConn();

inf   = mustOpen(inFileName, "r");

oldContig = strdup("");
while (fgets(line, 1000, inf) != NULL)
    {
    sscanf(line, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
    	   contig, start, end, num, code, id, oStart, oEnd, strnd);
    sqlSafefFrag(condStr, sizeof condStr, "ctg_acc='%s'", contig);
    chrStart =  sqlGetField(database, "seq_contig", "chr_start", condStr);
    if (!sameWord(oldContig, contig)) 
    	{
    	if (!sameWord(oldContig, ""))
    	    {
	    lastNum++;
	    fprintf(outf, "%s\t%d\t%d\t", 
    	    	    oldContig, lastEnd+1, atoi(chrStart)+atoi(start)-2);
    	    fprintf(outf, "%d\t%s\t%d\t%s\t%s\n", 
    	    	    lastNum, "N", atoi(chrStart)+atoi(start)-2 - (lastEnd+1) +1, "contig", "no");
	    }
	oldContig = strdup(contig);
	oldNum = lastNum;
	}
    lastNum = atoi(num) + oldNum;    
    fprintf(outf, "%s\t%d\t%d\t", 
    	    contig, atoi(chrStart)+atoi(start)-1, atoi(chrStart)+atoi(end)-1);
    fprintf(outf, "%d\t%s\t%s\t%s\t%s\t%s\n", 
    	    lastNum, code, id, oStart, oEnd, strnd);
    lastEnd = atoi(chrStart)+atoi(end)-1;
    }
hFreeConn(&conn2);
	
fclose(outf);
return(0);
}
Example #15
0
void doGvf(struct trackDb *tdb, char *item)
/* Show details for variants represented as GVF, stored in a bed8Attrs table */
{
struct sqlConnection *conn = hAllocConn(database);
int start = cartInt(cart, "o");
char query[1024];
sqlSafef(query, sizeof(query),
      "select * from %s where name = '%s' and chrom = '%s' and chromStart = %d",
      tdb->table, item, seqName, start);
struct sqlResult *sr = sqlGetResult(conn, query);
char **row;
if ((row = sqlNextRow(sr)) == NULL)
    errAbort("doGvfDetails: can't find item '%s' in %s at %s:%d", item, database, seqName, start);
int rowOffset = hOffsetPastBin(database, seqName, tdb->table);
struct bed8Attrs *ba = bed8AttrsLoad(row+rowOffset);
bedPrintPos((struct bed *)ba, 3, tdb);
int i = 0;
// Note: this loop modifies ba->attrVals[i], assuming we won't use them again:
for (i = 0;  i < ba->attrCount;  i++)
    {
    // The ID is the bed8Attrs name and has already been displayed:
    if (sameString(ba->attrTags[i], "ID"))
	continue;
    cgiDecode(ba->attrVals[i], ba->attrVals[i], strlen(ba->attrVals[i]));
    char *tag = ba->attrTags[i];
    // User-defined keywords used in dbVar's GVF:
    if (sameString(tag, "var_type")) // This one isn't anymore, but I add it back (hg18.txt).
	tag = "Variant type";
    else if (sameString(tag, "clinical_int"))
	tag = "Clinical interpretation";
    else if (sameString(tag, "var_origin"))
	tag = "Variant origin";
    else if (islower(tag[0]))
	// Uppercase for nice display, assuming user doesn't care which keywords are
	// user-defined vs. GVF standard:
	tag[0] = toupper(tag[0]);
    // GVF standard Start_range and End_range tags (1-based coords):
    if (sameString(tag, "Start_range") || sameString(tag, "End_range"))
	{
	char *copy = cloneString(ba->attrVals[i]);
	char *words[3];
	int wordCount = chopCommas(copy, words);
	if (wordCount == 2 &&
	    (sameString(".", words[0]) || isInteger(words[0])) &&
	    (sameString(".", words[1]) || isInteger(words[1])))
	    {
	    boolean isStartRange = sameString(tag, "Start_range");
	    char *rangeStart = words[0], *rangeEnd = words[1];
	    if (sameString(".", rangeStart))
		rangeStart = "unknown";
	    if (sameString(".", rangeEnd))
		rangeEnd = "unknown";
	    if (isStartRange)
		printf("<B>Start range</B>: outer start %s, inner start %s<BR>\n",
		       rangeStart, rangeEnd);
	    else
		printf("<B>End range</B>: inner end %s, outer end %s<BR>\n",
		       rangeStart, rangeEnd);
	    }
	else
	    // not formatted as expected, just print as-is:
	    printf("<B>%s</B>: %s<BR>\n", tag, htmlEncode(ba->attrVals[i]));
	}
    // Parent sounds like mom or dad (as in var_origin)... tweak it too:
    else if (sameString(tag, "Parent"))
	{
	printf("<B>Variant region:</B> "
	       "<A HREF=\"http://www.ncbi.nlm.nih.gov/dbvar/variants/%s/\" "
	       "TARGET=_BLANK>%s</A><BR>\n", ba->attrVals[i], htmlEncode(ba->attrVals[i]));
	}
    else if (sameString(tag, "Name"))
	{
	char *url = trackDbSetting(tdb, "url");
	// Show the Name only if it hasn't already appeared in the URL:
	if (url == NULL || !stringIn("$$", url))
	    printf("<B>%s</B>: %s<BR>\n", tag, htmlEncode(ba->attrVals[i]));
	}
    else if (sameWord(tag, "Phenotype_id") && startsWith("HPO:HP:", ba->attrVals[i]))
	{
	subChar(tag, '_', ' ');
	printf("<B>%s</B>: <A HREF=\"http://www.berkeleybop.org/obo/%s\" "
	       "TARGET=_BLANK>%s</A><BR>\n", tag, ba->attrVals[i]+strlen("HPO:"),
	       htmlEncode(ba->attrVals[i]));
	}
    else
	{
	subChar(tag, '_', ' ');
	printf("<B>%s</B>: %s<BR>\n", tag, htmlEncode(ba->attrVals[i]));
	}
    }
sqlFreeResult(&sr);
hFreeConn(&conn);
/* printTrackHtml is done in genericClickHandlerPlus. */
}
Example #16
0
void showSchemaVcf(char *table, struct trackDb *tdb, boolean isTabix)
/* Show schema on vcf. */
{
struct sqlConnection *conn = hAllocConn(database);
char *fileName = vcfFileName(tdb, conn, table, hDefaultChrom(database));

struct asObject *as = vcfAsObj();
hPrintf("<B>Database:</B> %s", database);
hPrintf("&nbsp;&nbsp;&nbsp;&nbsp;<B>Primary Table:</B> %s<br>", table);
hPrintf("<B>VCF File:</B> %s", fileName);
hPrintf("<BR>\n");
hPrintf("<B>Format description:</B> %s<BR>", as->comment);
hPrintf("See the <A HREF=\"%s\" target=_blank>Variant Call Format specification</A> for  more details<BR>\n",
	"http://www.1000genomes.org/wiki/analysis/vcf4.0");

/* Put up table that describes fields. */
hTableStart();
hPrintf("<TR><TH>field</TH>");
hPrintf("<TH>description</TH> ");
puts("</TR>\n");
struct asColumn *col;
int colCount = 0;
for (col = as->columnList; col != NULL; col = col->next)
    {
    hPrintf("<TR><TD><TT>%s</TT></TD>", col->name);
    hPrintf("<TD>%s</TD></TR>", col->comment);
    ++colCount;
    }
hTableEnd();

/* Put up another section with sample rows. */
webNewSection("Sample Rows");
hTableStart();

/* Fetch sample rows. */
struct lineFile *lf = isTabix ? lineFileTabixMayOpen(fileName, TRUE) :
				lineFileMayOpen(fileName, TRUE);
if (lf == NULL)
    noWarnAbort();
char *row[VCF_MAX_SCHEMA_COLS];
int i;
for (i = 0;  i < 10;  i++)
    {
    int colCount = lineFileChop(lf, row);
    int colIx;
    if (i == 0)
	{
	// Print field names as column headers, using colCount to compute genotype span
	hPrintf("<TR>");
	for (colIx = 0, col = as->columnList; col != NULL && colIx < colCount;
	     colIx++, col = col->next)
	    {

	    if (sameString("genotypes", col->name) && colCount > colIx+1)
		hPrintf("<TH colspan=%d>%s</TH>", colCount - colIx, col->name);
	    else
		hPrintf("<TH>%s</TH>", col->name);
	    }
	hPrintf("</TR>\n");
	}
    hPrintf("<TR>");
    for (colIx=0; colIx < colCount; ++colIx)
	{
	if (colCount > VCFDATALINE_NUM_COLS && colIx == colCount - 1)
	    hPrintf("<TD>...</TD>");
	else
	    writeHtmlCell(row[colIx]);
	}
    hPrintf("</TR>\n");
    }
hTableEnd();
printTrackHtml(tdb);

/* Clean up and go home. */
lineFileClose(&lf);
freeMem(fileName);
hFreeConn(&conn);
}
Example #17
0
int main(int argc, char *argv[])
{
struct sqlConnection *conn, *conn2, *conn3;
char query[256], query2[256], query3[256];
struct sqlResult *sr, *sr2, *sr3;
char **row, **row2, **row3;

char *chp;
FILE *o1, *o2;

char *locusID;	/* LocusLink ID */
char *gbAC;		/* GenBank accession.version */
char *locusID2;	/* LocusLink ID */
char *refAC;	/* Refseq accession.version */
char *dbName; 
char cond_str[200];
char *kgID;
char *mapID;
char *desc;

if (argc != 2) usage();
dbName = argv[1];

conn = hAllocConn(dbName);
conn2= hAllocConn(dbName);
conn3= hAllocConn(dbName);

o1 = fopen("j.dat",  "w");
o2 = fopen("jj.dat", "w");
    
sqlSafef(query2, sizeof query2, "select * from %sTemp.locus2Ref0;", dbName);
sr2 = sqlMustGetResult(conn2, query2);
row2 = sqlNextRow(sr2);
while (row2 != NULL)
    {
    locusID2 	= row2[0];
    refAC 	= row2[1];
    
    sqlSafef(query, sizeof query, "select * from %sTemp.locus2Acc0 where locusID=%s and seqType='m';", 
		   dbName, locusID2);
    sr = sqlMustGetResult(conn, query);
    row = sqlNextRow(sr);
    while (row != NULL)
    	{
	locusID 	= row[0];
	gbAC 		= row[1];
	
	chp = strstr(gbAC, ".");
	if (chp != NULL) *chp = '\0';
	chp = strstr(refAC, ".");
	if (chp != NULL) *chp = '\0';
    
	sqlSafefFrag(cond_str, sizeof cond_str, "name='%s'", gbAC);
        kgID = sqlGetField(dbName, "knownGene", "name", cond_str);
	if (kgID != NULL)
	    {
            sqlSafef(query3, sizeof query3, "select * from %sTemp.keggList where locusID = '%s'", dbName, locusID);
            sr3 = sqlGetResult(conn3, query3);
            while ((row3 = sqlNextRow(sr3)) != NULL)
                {
                mapID   = row3[1];
		desc    = row3[2];
		fprintf(o1, "%s\t%s\t%s\n", kgID, locusID, mapID);
		fprintf(o2, "%s\t%s\n", mapID, desc);
		row3 = sqlNextRow(sr3);
                }
            sqlFreeResult(&sr3);
	    }
	row = sqlNextRow(sr);
	}
    row2 = sqlNextRow(sr2);
    }
sqlFreeResult(&sr2);

fclose(o1);
fclose(o2);
hFreeConn(&conn);
hFreeConn(&conn2);

mustSystem("cat j.dat|sort|uniq >keggPathway.tab");
mustSystem("cat jj.dat|sort|uniq >keggMapDesc.tab");
mustSystem("rm j.dat");
mustSystem("rm jj.dat");
return(0);
}
Example #18
0
int main(int argc, char *argv[])
{
struct sqlConnection *conn, *conn2, *conn3;
struct sqlConnection *connCentral = hConnectCentral();
char query[256], query2[256], query3[256];
struct sqlResult *sr, *sr2;
char **row, **row2;
char buf[128];
char *answer;
char *kgID, *chrom, *txStart, *txEnd;
char *mRNA;
int i;
int geneCnt  = 0;
int pageNum  = 0;
int topLevel = 1;

char *geneSymbol, *proteinID, *spID, *desc;
FILE *outf, *outf2;
char fileName[255];
database = strdup("hg17");
boolean newPage;
int totalKgId, totalKgCnt;
int totalKgPage;
int kgIdCnt = 0;

if (argc != 2) usage();
database = argv[1];

sqlSafef(query, sizeof query, "select genome from dbDb where name = '%s'", database);
answer = sqlQuickQuery(connCentral, query, buf, sizeof(buf));
if (answer == NULL)
    {
    fprintf(stderr,"'%s' is not a valid genome database name.", database);
    exit(1);
    }
else
    {
    genome = strdup(answer);
    }

if (!hTableExists(database, "knownGene"))
    {
    fprintf(stderr,"Database %s currently does not have UCSC Known Genes.", database);
    exit(1);
    }

sqlSafef(query, sizeof query, "select description from dbDb where name = '%s'", database);

genomeDesc = strdup(sqlQuickQuery(connCentral, query, buf, sizeof(buf)));
hDisconnectCentral(&connCentral);

/* create first top level subdirectory */
safef(command, sizeof(command), "mkdir -p knownGeneList/%s/%d", database, topLevel);
mustSystem(command);

conn = hAllocConn(database);
conn2= hAllocConn(database);
conn3= hAllocConn(database);

newPage  = TRUE;

currentPage = 0;

/* put this in to avoid compiler complaining */
outf = NULL;
geneSymbol = NULL;
char *protAcc = NULL;

/* figure out how many pages in total */
sqlSafef(query2, sizeof(query2), "select count(k.name) from %s.knownGene k, %s.kgXref x where k.name=x.kgId and geneSymbol != ''", database, database);
sr2  = sqlMustGetResult(conn2, query2);
row2 = sqlNextRow(sr2);
totalKgCnt = atoi(row2[0]);
sqlFreeResult(&sr2);

/* figure out how many KG IDs in total */
sqlSafef(query2, sizeof(query2), "select count(*) from %s.kgXref where geneSymbol !=''", database);
sr2  = sqlMustGetResult(conn2, query2);
row2 = sqlNextRow(sr2);
totalKgId = atoi(row2[0]);
sqlFreeResult(&sr2);
totalKgPage = totalKgId/LINKSPERPAGE + 1;

sqlSafef(query2, sizeof(query2),
      "select kgID, geneSymbol, description from %s.kgXref where geneSymbol!= '' order by geneSymbol",
      database);

      /* for debugging */
      /* "select kgID, geneSymbol, description from %s.kgXref order by geneSymbol limit %d",
      database, TESTSIZE);*/
sr2  = sqlMustGetResult(conn2, query2);
row2 = sqlNextRow(sr2);

/* for debugging */
/* while (kgIdCnt < TESTSIZE) */

while (kgIdCnt < totalKgId)
    {
    kgIdCnt++;

    kgID 	= row2[0];
    geneSymbol  = strdup(row2[1]);
    desc 	= row2[2];
    sqlSafef(query, sizeof(query),
    "select chrom,txSTart,txEnd,proteinID from %s.knownGene where name='%s'", database, kgID);
    sr = sqlMustGetResult(conn, query);
    row = sqlNextRow(sr);
    if (row != NULL)
    	{
	geneCnt++;
    	chrom     = row[0];
    	txStart   = row[1];
    	txEnd     = row[2];
    	proteinID = row[3];

	if (newPage)
	    {
	    /* create a KG links page */
	    pageNum++;
	    currentPage++;

	    /* use mkdir -p to make sure the subdirectory exists */
	    safef(command, sizeof(command), "mkdir -p knownGeneList/%s/%d", database, topLevel);
	    mustSystem(command);
	    safef(fileName, sizeof(fileName),
	    	  "knownGeneList/%s/%d/kgList%d.html", database, topLevel, pageNum);
  	    outf = fopen(fileName, "w");
	    printHtmlHead(outf);

	    fprintf(outf,"<H2>UCSC %s Known Genes List (page %d of %d)</H2>\n",
	    	    genome, pageNum, totalKgPage);
	    fprintf(outf, "<TABLE BORDER=1=CELLSPACING=1 CELLPADDING=3 BGCOLOR=\"#D9F8E4\"><TR>\n");
	    fprintf(outf,
	    "<TR><TH>Gene Symbol</TH><TH>Known Gene ID</TH><TH>mRNA</TH><TH>UniProt</TH><TH>RefSeq Protein</TH><TH>Description</TH>\n");
	    strcpy(startSymbol[pageNum], geneSymbol);
	    strcpy(pageStartSymbol[currentPage], geneSymbol);
	    newPage = FALSE;
	    }

	fprintf(outf,"<TR>");
    	fprintf(outf,"<TD>%s</TD>", geneSymbol);
    	/*fprintf(outf,"<TD>%d:%s</TD>", geneCnt, geneSymbol);*/
    	fprintf(outf,"<TD>");
    	fprintf(outf,"<A href=\"/cgi-bin/hgGene?db=%s&hgg_gene=%s", database, kgID);
    	fprintf(outf,"&hgg_chrom=%s&hgg_start=%s&hgg_end=%s\">", chrom, txStart, txEnd);
    	fprintf(outf,"%s", kgID);
    	fprintf(outf,"</A>");
    	fprintf(outf,"</TD>\n");

	sqlSafef(query3,sizeof(query3),"select spID from %s.kgXref where kgID = '%s'", database, kgID);
	spID = cloneString(sqlQuickQuery(conn3, query3, buf, sizeof(buf)));
	if (spID == NULL)
	    {
	    spID = emptyString;
	    }
	else
	    {
	    if (sameWord(spID,"")) spID = emptyString;
	    }

	sqlSafef(query3,sizeof(query3),"select mRNA from %s.kgXref where kgID = '%s'", database, kgID);
	mRNA = cloneString(sqlQuickQuery(conn3, query3, buf, sizeof(buf)));
	if (mRNA == NULL)
	    {
	    mRNA = emptyString;
	    }
	else
	    {
	    if (sameWord(mRNA,"")) mRNA = emptyString;
	    }

	sqlSafef(query3,sizeof(query3),"select protAcc from %s.kgXref where kgID = '%s'", database, kgID);
	protAcc = sqlQuickQuery(conn3, query3, buf, sizeof(buf));
	if (protAcc == NULL)
	    {
	    protAcc = emptyString;
	    }
	else
	    {
	    if (sameWord(protAcc,"")) protAcc = emptyString;
	    }

	fprintf(outf,"<TD>%s</TD>", mRNA);
	fprintf(outf,"<TD>%s</TD>", spID);
	fprintf(outf,"<TD>%s</TD>", protAcc);
    	fprintf(outf,"<TD>%s</TD>", desc );
    	fprintf(outf,"</TR>\n");

	if ((geneCnt % LINKSPERPAGE) == 0)
    	    {
	    /* flush out and close the page if a page is filled, and start a new page */
	    fprintf(outf,"</TABLE>");
	    strcpy(endSymbol[pageNum], geneSymbol);
	    strcpy(pageEndSymbol[currentPage], endSymbol[pageNum]);
	    fprintf(outf, "<BR>");
	    fprintf(outf, "<A href=\"/knownGeneList/%s/%d/kgIndex%d.html\">",
	    	    database, topLevel,topLevel);
	    fprintf(outf, "Up");
	    fprintf(outf,"</A><BR>\n");
	    printHtmlEnd(outf);
	    newPage = TRUE;
	    fclose(outf);
	    outf = NULL;

	    if ((pageNum % LINKSPERPAGE) == 0 )
	    	{
	    	printf("Processing topLevel %d ...\n", topLevel);fflush(stdout);
	    	safef(fileName, sizeof(fileName),
	    	      "knownGeneList/%s/%d/kgIndex%d.html", database, topLevel, topLevel);
	    	outf2 = fopen(fileName, "w");
	    	printHtmlHead(outf2);
		//fprintf(outf2,"<H2>UCSC %s Known Genes List</H2>\n", genome);
		fprintf(outf2,"<H2>UCSC %s Known Genes List (Group %d)</H2>\n", genome, topLevel);
	    	for (i=1; i<= currentPage; i++)
	      	    {
	      	    fprintf(outf2, "Page %d: ", (topLevel-1)*LINKSPERPAGE+i);
	            fprintf(outf2,
	      	    	    "<A href=\"/knownGeneList/%s/%d/kgList%d.html\">",
	             	    database, topLevel, (topLevel-1)*LINKSPERPAGE+i);
	      	    fprintf(outf2, "%s to %s", pageStartSymbol[i], pageEndSymbol[i]);
    	      	    fprintf(outf2,"</A><BR>\n");
	      	    }
		fprintf(outf2, "<BR>");
		fprintf(outf2, "<A href=\"/knownGeneList/%s/top.html\">",database);
		fprintf(outf2, "Up");
		fprintf(outf2,"</A><BR>\n");
	    	printHtmlEnd(outf2);
	    	fclose(outf2);

	    strcpy(topStartSymbol[topLevel], pageStartSymbol[1]);
	    strcpy(  topEndSymbol[topLevel], pageEndSymbol[currentPage]);
	    currentPage = 0;
	    topLevel++;
	    }
    	}
	row = sqlNextRow(sr);
    	}
    sqlFreeResult(&sr);
    row2 = sqlNextRow(sr2);
    }
sqlFreeResult(&sr2);

/* flush out and close the last list page */
if (outf != NULL)
    {
    fprintf(outf,"</TABLE>");
    strcpy(endSymbol[pageNum], geneSymbol);
    strcpy(pageEndSymbol[currentPage], endSymbol[pageNum]);
    fprintf(outf, "<BR>");
    fprintf(outf, "<A href=\"/knownGeneList/%s/%d/kgIndex%d.html\">",
    database, topLevel,topLevel);
    fprintf(outf, "Up");
    fprintf(outf,"</A><BR>\n");
    printHtmlEnd(outf);
    fclose(outf);
    }

/* generate the last index page */
safef(command, sizeof(command), "mkdir -p knownGeneList/%s/%d", database, topLevel);
mustSystem(command);
safef(fileName, sizeof(fileName),
      "knownGeneList/%s/%d/kgIndex%d.html", database, topLevel, topLevel);
outf2 = fopen(fileName, "w");
printHtmlHead(outf2);
fprintf(outf2,"<H2>UCSC %s Known Genes List (Group %d)</H2>\n", genome, topLevel);
for (i=1; i<= currentPage; i++)
    {
    fprintf(outf2, "Page %d: ", (topLevel-1)*LINKSPERPAGE+i);
    fprintf(outf2, "<A href=\"/knownGeneList/%s/%d/kgList%d.html\">",
	    database, topLevel, (topLevel-1)*LINKSPERPAGE+i);
    fprintf(outf2, "%s to %s", pageStartSymbol[i], pageEndSymbol[i]);
    fprintf(outf2,"</A><BR>\n");
    fflush(outf2);
    }

fprintf(outf2, "<BR>");
fprintf(outf2, "<A href=\"/knownGeneList/%s/top.html\">",database);
fprintf(outf2, "Up");
fprintf(outf2,"</A><BR>\n");
strcpy(topStartSymbol[topLevel], pageStartSymbol[1]);
strcpy(  topEndSymbol[topLevel], pageEndSymbol[currentPage]);

fclose(outf2);

currentPage = 0;

/* generate the top HTML page */
safef(fileName, sizeof(fileName), "knownGeneList/%s/top.html", database);
outf2 = fopen(fileName, "w");
printHtmlHead(outf2);
fprintf(outf2,"<H2>UCSC %s Known Genes List</H2>\n", genome);
for (i=1; i<= topLevel; i++)
    {
    fprintf(outf2, "Group %d: ", i);
    fprintf(outf2, "<A href=\"/knownGeneList/%s/%d/kgIndex%d.html\">", database, i, i);
    fprintf(outf2, " %s to %s", topStartSymbol[i], topEndSymbol[i]);
    fprintf(outf2,"</A><BR>\n");
    fflush(outf2);
    }

fprintf(outf2, "<BR>");
fprintf(outf2, "<A href=\"/knownGeneLists.html\">");
fprintf(outf2, "Up");
fprintf(outf2,"</A><BR>\n");

printHtmlEnd(outf2);
printHtmlEnd(outf2);
fclose(outf2);

return(0);
}
Example #19
0
static void filterControlsForTableCt(char *db, char *table)
/* Put up filter controls for a custom track. */
{
struct customTrack *ct = ctLookupName(table);
char *type = ct->dbTrackType;
puts("<TABLE BORDER=0>");

if (type != NULL && startsWithWord("maf", type))
    {
    stringFilterOption(db, table, "chrom", " AND ");
    integerFilter(db, table, "chromStart", "chromStart", " AND ");
    integerFilter(db, table, "chromEnd", "chromEnd", " AND ");
    }
else if (type != NULL && (startsWithWord("makeItems", type) || sameWord("bedDetail", type) || sameWord("pgSnp", type)))
    {
    struct sqlConnection *conn = hAllocConn(CUSTOM_TRASH);
    struct sqlFieldType *ftList = sqlListFieldsAndTypes(conn, ct->dbTableName);
    printSqlFieldListAsControlTable(ftList, db, table, ct->tdb, FALSE);
    hFreeConn(&conn);
    }
else if (ct->wiggle || isBigWigTable(table))
    {
    if ((ct->tdb != NULL) && (ct->tdb != NULL))
        {
        double min, max;
        wiggleMinMax(ct->tdb,&min,&max);

        numericFilterWithLimits("ct", table, filterDataValueVar, filterDataValueVar,min,max,"");
        hPrintf("<TR><TD COLSPAN=3 ALIGN=RIGHT> (dataValue range: [%g,%g]) "
                "</TD></TR>\n", min, max);
        }
    else
        {
        numericFilter("ct", table, filterDataValueVar, filterDataValueVar,"");
        }
    }
else if (isBigBed(db, table, curTrack, ctLookupName))
    {
    struct sqlFieldType *ftList = bigBedListFieldsAndTypes(ct->tdb, NULL);
    printSqlFieldListAsControlTable(ftList, db, table, ct->tdb, FALSE);
    }
else if (isBamTable(table))
    {
    struct sqlFieldType *ftList = bamListFieldsAndTypes();
    printSqlFieldListAsControlTable(ftList, db, table, ct->tdb, FALSE);
    }
else if (isVcfTable(table, NULL))
    {
    struct sqlFieldType *ftList = vcfListFieldsAndTypes();
    printSqlFieldListAsControlTable(ftList, db, table, ct->tdb, FALSE);
    }
else
    {
    if (ct->fieldCount >= 3)
        {
        stringFilterOption(db, table, "chrom", " AND ");
        integerFilter(db, table, "chromStart", "chromStart", " AND ");
        integerFilter(db, table, "chromEnd", "chromEnd", " AND ");
        }
    if (ct->fieldCount >= 4)
        {
        stringFilterOption(db, table, "name", " AND ");
        }
    if (ct->fieldCount >= 5)
        {
        numericFilter(db, table, "score", "score", " AND ");
        }
    if (ct->fieldCount >= 6)
        {
        stringFilterOption(db, table, "strand", " AND ");
        }
    if (ct->fieldCount >= 8)
        {
        integerFilter(db, table, "thickStart", "thickStart", " AND ");
        integerFilter(db, table, "thickEnd", "thickEnd", " AND ");
        }
    if (ct->fieldCount >= 12)
        {
        integerFilter(db, table, "blockCount", "blockCount", " AND ");
        }
    /* These are not bed fields, just extra constraints that we offer: */
    if (ct->fieldCount >= 3)
        {
        integerFilter(db, table, "chromLength", "(chromEnd - chromStart)",
                      (ct->fieldCount >= 8) ? " AND " : "");
        }
    if (ct->fieldCount >= 8)
        {
        integerFilter( db, table, "thickLength",  "(thickEnd - thickStart)", " AND ");
        eqFilterOption(db, table, "compareStarts","chromStart","thickStart", " AND ");
        eqFilterOption(db, table, "compareEnds",  "chromEnd",  "thickEnd",   "");
        }
    }

puts("</TABLE>");

if (ct->wiggle || isBigWigTable(table) || isBamTable(table) || isVcfTable(table, NULL))
    {
    char *name;
    hPrintf("<TABLE BORDER=0><TR><TD> Limit data output to:&nbsp\n");
    name = filterFieldVarName("ct", table, "_", filterMaxOutputVar);
    cgiMakeDropList(name, maxOutMenu, maxOutMenuSize,
		cartUsualString(cart, name, maxOutMenu[0]));
    hPrintf("&nbsp;lines</TD></TR></TABLE>\n");
    }

hPrintf("<BR>\n");
cgiMakeButton(hgtaDoFilterSubmit, "submit");
hPrintf(" ");
cgiMakeButton(hgtaDoMainPage, "cancel");
}
Example #20
0
int main(int argc, char *argv[])
{
struct sqlConnection *conn, *conn2;

char query2[256];
struct sqlResult *sr2;
char **row2;
    
char *chp0, *chp;
char *kgID;
FILE *o1, *o2;
char cond_str[256];
char *database;
char *proteinDB;
boolean doingAlias, bothDone;

char *answer;
char *symbol, *alias, *aliases;

if (argc != 3) usage();
database  = cloneString(argv[1]);
proteinDB = cloneString(argv[2]);

conn = hAllocConn(database);
conn2= hAllocConn(database);
o1 = fopen("j.dat", "w");
o2 = fopen("jj.dat", "w");

doingAlias = TRUE;
bothDone   = FALSE;

while (!bothDone)
    {
    if (doingAlias)
	{
    	sqlSafef(query2, sizeof query2, "select symbol, aliases from %s.hgnc;", proteinDB);
	}
    else
	{
        sqlSafef(query2, sizeof query2, "select symbol, prvSymbols from %s.hgnc;", proteinDB);
    	}
    
    sr2 = sqlMustGetResult(conn2, query2);
    row2 = sqlNextRow(sr2);
    while (row2 != NULL)
	{
	symbol		= row2[0];
	aliases		= row2[1];

	if ( (symbol  != NULL) && (strlen(symbol) != 0) )
	    {
            sqlSafefFrag(cond_str, sizeof cond_str, "geneSymbol = '%s'", symbol);
            answer = sqlGetField(database, "kgXref", "kgID", cond_str);
	    if (answer != NULL)
		{
		kgID = strdup(answer);
		fprintf(o2, "%s\t%s\n", kgID, symbol);
		}
	    if ( (aliases  != NULL) && (strlen(aliases) != 0) && (answer != NULL) )
		{
		kgID = strdup(answer);
    
		chp0 = aliases; 
	    	while (chp0 != NULL)
		    {
		    while (*chp0 == ' ') chp0++;
		    chp = strstr(chp0, ",");
		    if (chp == NULL)
			{
			alias = strdup(chp0);
			
			/* get rid of quote character in some aliases */
			if (*alias == '"') 
			    {
			    *(alias + strlen(alias) - 1) = '\0';
			    alias++;
			    printf("%s\n", alias);fflush(stdout);
			    }
			chp0 = NULL;
			}
		    else
			{
			*chp = '\0';
			
			/* get rid of quote character in some aliases */
			if (*chp0 == '"') 
			    {
			    *(chp0 + strlen(chp0) - 1) = '\0';
			    chp0++;
			    printf("%s\n", chp0);fflush(stdout);
			    }
			alias = strdup(chp0);
			chp0 = chp+1;
			}
		    if (kgID != NULL)
			{
			fprintf(o1, "%s\t%s\t%s\n", kgID, symbol, alias);
			fprintf(o2, "%s\t%s\n", kgID, alias);
			}
		    }
		}
	    }
	row2 = sqlNextRow(sr2);
	}
    sqlFreeResult(&sr2);

    if (doingAlias) 
	{
	doingAlias = FALSE;
	}
    else
	{
	bothDone = TRUE;
	}
    }
fclose(o1);
fclose(o2);

/* geneAlias.tab has 3 columns, the 2nd is HUGO.symbol 
   and 3rd contains aliases and withdraws */

mustSystem("cat  j.dat|sort|uniq  >geneAlias.tab");

/*  kgAliasM.tab has 2 columns, all entries from HUGO.symbol, HUGO.aliass, 
    and HUGO.withdraws are listed in the 2nd column. */
mustSystem("cat jj.dat|sort|uniq  >kgAliasM.tab");
mustSystem("rm j.dat");
mustSystem("rm jj.dat");
    
return(0);
}
Example #21
0
static void showLinkedTables(struct joiner *joiner, struct dbTable *inList,
	char *varPrefix, char *buttonName, char *buttonText)
/* Print section with list of linked tables and check boxes to turn them
 * on. */
{
struct dbTable *outList = NULL, *out, *in;
char dtName[256];
struct hash *uniqHash = newHash(0);
struct hash *inHash = newHash(8);

/* Build up list of tables we link to in outList. */
for (in = inList; in != NULL; in = in->next)
    {
    struct sqlConnection *conn = NULL;
    if (!trackHubDatabase(database))
	conn = hAllocConn(in->db);
    struct joinerPair *jpList, *jp;

    /* Keep track of tables in inList. */
    safef(dtName, sizeof(dtName), "%s.%s", inList->db, inList->table);
    hashAdd(inHash, dtName, NULL);

    /* First table in input is not allowed in output. */
    if (in == inList)
        hashAdd(uniqHash, dtName, NULL);

    /* Scan through joining information and add tables,
     * avoiding duplicate additions. */
    jpList = joinerRelate(joiner, in->db, in->table);
    for (jp = jpList; jp != NULL; jp = jp->next)
        {
	safef(dtName, sizeof(dtName), "%s.%s",
		jp->b->database, jp->b->table);
	if (!hashLookup(uniqHash, dtName) &&
	   !cartTrackDbIsAccessDenied(jp->b->database, jp->b->table))
	    {
	    hashAdd(uniqHash, dtName, NULL);
	    out = dbTableNew(jp->b->database, jp->b->table);
	    slAddHead(&outList, out);
	    }
	}
    joinerPairFreeList(&jpList);
    hFreeConn(&conn);
    }
slSort(&outList, dbTableCmp);

/* Print html. */
if (outList != NULL)
    {
    webNewSection("Linked Tables");
    hTableStart();
    for (out = outList; out != NULL; out = out->next)
	{
	struct sqlConnection *conn = hAllocConn(out->db);
	struct asObject *asObj = asForTable(conn, out->table);
	char *var = dbTableVar(varPrefix, out->db, out->table);
	hPrintf("<TR>");
	hPrintf("<TD>");
	cgiMakeCheckBox(var, varOn(var));
	hPrintf("</TD>");
	hPrintf("<TD>%s</TD>", out->db);
	hPrintf("<TD>%s</TD>", out->table);
	hPrintf("<TD>");
	if (asObj != NULL)
	    hPrintf("%s", asObj->comment);
	else
	    hPrintf("&nbsp;");
	hPrintf("</TD>");
	hPrintf("</TR>");
	hFreeConn(&conn);
	}
    hTableEnd();
    hPrintf("<BR>");

    cgiMakeButton(buttonName, buttonText);
    }
}
Example #22
0
void doSamT02(char *proteinId, char *database)
/* display the UCSC SAM-T02 Protein Structure Analysis and Prediction section */ 
{
char *itemName = NULL;
char query2[256];
struct sqlResult *sr2;
char **row2;
struct sqlConnection *conn, *conn2 = hAllocConn(database);
char condStr[256];
char *chp;

char *samSubDir;
char *samHttpStr0 = NULL; /* SAM server*/
char *samHttpStr  = NULL; /* UCSC GB site */
int  homologCount;

char *homologID;
char *SCOPdomain;
char *chain;
char *bestEValStr = NULL;
float eValue, bestEVal;

char goodSCOPdomain[40];
int  first = 1;

/* return if this genome does not have SAM protein analysis results */
/* defensive logic to guard against the situation that the binary program is pushed, but the data tables are not */
conn = sqlConnect(database);
if (!(sqlTableExists(conn, "samSubdir") && sqlTableExists(conn, "protHomolog")))
    {
    return;
    }
sqlDisconnect(&conn);
if (!sameWord(database, "sacCer1"))
    {
    return;
    }
    
itemName = proteinId;    
if (sameWord(database, "sacCer1"))
    {
    samHttpStr0 = strdup("http://www.soe.ucsc.edu/research/compbio/yeast-protein-predictions");
    samHttpStr  = strdup("../goldenPath/sacCer1/sam");
    
    /* SAM analysis of SGD proteins uses SGD ID, not Swiss-Prot AC */
    itemName = getSgdId(proteinId, database);
    }
    
if (itemName == NULL) return;

sqlSafefFrag(condStr, sizeof condStr, "proteinId='%s'", itemName);
samSubDir = sqlGetField(database, "samSubdir", "subdir", condStr);
if (samSubDir == NULL) return;

hPrintf("<B>UCSC ");
hPrintf("<A HREF=\"http://www.soe.ucsc.edu/research/compbio/SAM_T02/sam-t02-faq.html\"");
hPrintf(" TARGET=_blank>SAM-T02</A>\n");
hPrintf(" Protein Structure Analysis and Prediction on %s", proteinId);
if (!sameWord(proteinId, itemName)) hPrintf(" (aka %s)", itemName);
hPrintf("</B><BR>\n");

hPrintf("&nbsp;&nbsp;&nbsp;&nbsp;<B>Multiple Alignment (sequence logo):</B> \n");
hPrintf("<A HREF=\"%s/%s/%s/%s.t2k.w0.5-logo.pdf\"", samHttpStr, samSubDir, itemName, itemName);
hPrintf(" TARGET=_blank>%s</A> (pdf)<BR>\n", itemName);

hPrintf("<B>&nbsp;&nbsp;&nbsp;&nbsp;Secondary Structure Predictions:</B> \n");
hPrintf("<A HREF=\"%s/%s/%s/%s.t2k.dssp-ehl2-logo.pdf\"", samHttpStr, samSubDir, itemName, itemName);
hPrintf(" TARGET=_blank>%s</A> (pdf)<BR>\n", itemName);

hPrintf("<B>&nbsp;&nbsp;&nbsp;&nbsp;Close Homologs:</B> \n");

conn2= hAllocConn(database);
sqlSafef(query2, sizeof query2, 
    "select homologID,eValue,SCOPdomain,chain from %s.protHomolog where proteinID='%s' and evalue <= 0.01 order by evalue;",
    database, itemName);
sr2 = sqlMustGetResult(conn2, query2);
row2 = sqlNextRow(sr2);

homologCount = 0;
strcpy(goodSCOPdomain, "dummy");
bestEVal = 100;
while (row2 != NULL)
    {
    homologID = row2[0];
    sscanf(row2[1], "%e", &eValue);
    if (first)
	{
	bestEVal = eValue;
	bestEValStr = strdup(row2[1]);
	}

    SCOPdomain = row2[2];
    chp = SCOPdomain+strlen(SCOPdomain)-1;
    while (*chp != '.') chp--;
    *chp = '\0';
    chain = row2[3];
    
    if (eValue <= 1.0e-10) 
	{
	strcpy(goodSCOPdomain, SCOPdomain);
	}
    else
	{
	if (strcmp(goodSCOPdomain,SCOPdomain) != 0)
	    {
	    goto skip;
	    }
	else
	    {
	    if (eValue > 0.1) goto skip;
	    }
	}
    if (first)
    	{
	first = 0;
	}
    else
        {
        printf(", ");
	}
					   
    hPrintf("\n<A HREF=\"http://www.rcsb.org/pdb/cgi/explore.cgi?job=graphics&pdbId=%s", homologID);
    if (strlen(chain) >= 1) 
	{
	hPrintf("\"TARGET=_blank>%s</A>(chain %s)\n", homologID, chain);
	}
    else
	{
	hPrintf("\"TARGET=_blank>%s</A>\n", homologID);
	}
    homologCount++;
	
    skip:
    row2 = sqlNextRow(sr2);
    }
sqlFreeResult(&sr2);
hFreeConn(&conn2);

if (homologCount == 0)
    {
    hPrintf("None\n");
    }

hPrintf("<BR>&nbsp;&nbsp;&nbsp;&nbsp;<B>More Details:</B> \n");
hPrintf("<A HREF=\"%s/%s/%s/summary.html\"", samHttpStr0, samSubDir, itemName);
hPrintf("\" TARGET=_blank>%s</A><BR>\n", itemName);

if (homologCount > 0)
    {
    hPrintf("&nbsp;&nbsp;&nbsp;&nbsp;<B>3D Structure Prediction: </B> \n");
    hPrintf("<A HREF=\"%s/%s/%s/%s.t2k.undertaker-align.pdb.gz\"", 
    	    samHttpStr, samSubDir, itemName, itemName);
    hPrintf("\" TARGET=_blank>%s</A> (PDB format, gzipped)<BR>\n", itemName);

    hPrintf("&nbsp;&nbsp;&nbsp;&nbsp;<B>3D Pictures of the Best Model");
    hPrintf(" (E Value: %s):</B><BR>\n", bestEValStr);fflush(stdout);
    
    hPrintf("<TABLE><TR>\n");
    hPrintf("<TD>&nbsp;&nbsp;</TD>");
    hPrintf("<TD><IMG SRC=\"%s/%s/%s/%s.view1_200.jpg\"></A></TD>\n", 
    	    samHttpStr, samSubDir, itemName, itemName);
    hPrintf("<TD><IMG SRC=\"%s/%s/%s/%s.view2_200.jpg\"></A></TD>\n", 
    	    samHttpStr, samSubDir, itemName, itemName);
    hPrintf("<TD><IMG SRC=\"%s/%s/%s/%s.view3_200.jpg\"></A></TD>\n", 
    	    samHttpStr, samSubDir, itemName, itemName);
    hPrintf("</TR>\n");
    
    hPrintf("<TR>");
    hPrintf("<TD>&nbsp;&nbsp;</TD>");
    hPrintf("<TD ALIGN=CENTER>Front</TD>");
    hPrintf("<TD ALIGN=CENTER>Top</TD>");
    hPrintf("<TD ALIGN=CENTER>Side</TD>");
    hPrintf("</TR>\n");
    
    hPrintf("<TR>");
    hPrintf("<TD>&nbsp;&nbsp;</TD>");
    hPrintf("<TD ALIGN=CENTER><A HREF=\"%s/%s/%s/%s.view1_500.jpg\">500x500</A></TD>\n", 
    	    samHttpStr, samSubDir, itemName, itemName);
    hPrintf("<TD ALIGN=CENTER><A HREF=\"%s/%s/%s/%s.view2_500.jpg\">500x500</A></TD>\n",  
    	    samHttpStr, samSubDir, itemName, itemName);
    hPrintf("<TD ALIGN=CENTER><A HREF=\"%s/%s/%s/%s.view3_500.jpg\">500x500</A></TD>\n", 
    	    samHttpStr, samSubDir, itemName, itemName);
    hPrintf("</TR>\n");
    hPrintf("</TABLE>\n");
    }
else
    {
    hPrintf("&nbsp;&nbsp;&nbsp;&nbsp;<B>3D Structure Prediction: </B> \n");
    hPrintf("No models presented, because none has E-value <= 0.01.<BR>");
    }
hPrintf("<BR>");
}
Example #23
0
void processAlign(char *kgTempDb, char *spDb, char *alignID, int cdsCnt, FILE *outf)
{
struct sqlConnection *conn2, *conn3, *conn4;
char query2[256], query3[256];
struct sqlResult *sr2, *sr3;
char **row2, **row3;
char *score;
char *chrom;
char *protAcc;
char *mrnaID;
char *ranking;
int  protDbId;
char condStr[255];
int  i;
char *chp;
char *isCurated;

conn2= hAllocConn(kgTempDb);
conn3= hAllocConn(kgTempDb);
conn4= hAllocConn(kgTempDb);

sqlSafef(query2, sizeof(query2), "select * from %s.kgCandidate where alignID='%s'", kgTempDb, alignID);
sr2 = sqlMustGetResult(conn2, query2);
row2 = sqlNextRow(sr2);
while (row2 != NULL)
    {
    mrnaID = row2[0];
    chrom = row2[1];
    ranking = row2[11];
    
    /* check if it is a composite mrnaID */
    /* if yes, select from entries with both protein and mrna specified */
    if (alignID[0] == 'U') 
    	{
	chp = strstr(row2[0], "_");
	*chp = '\0';
	protAcc = row2[0];
	chp ++;
	mrnaID = chp;
    	sqlSafef(query3, sizeof(query3), 
    	      "select protAcc, score from %s.protMrnaScore where mrnaAcc='%s' and protAcc='%s'",
	      kgTempDb, mrnaID, protAcc);
	}
    else
    	{
    	sqlSafef(query3, sizeof(query3), 
    	      "select protAcc, score from %s.protMrnaScore where mrnaAcc='%s' order by score desc",
	      kgTempDb, mrnaID);
	}
	
    sr3  = sqlMustGetResult(conn3, query3);
    row3 = sqlNextRow(sr3);
	      
    while(row3 != NULL)
        {
	protAcc = row3[0];
	score   = row3[1];

	chp = strstr(protAcc, "-");
	if (chp == NULL)
	    {
            sqlSafefFrag(condStr, sizeof(condStr), "acc='%s'", protAcc);
	    isCurated = sqlGetField(spDb, "info", "isCurated", condStr);
	    if (sameWord(isCurated, "1"))
	    	{
		protDbId = 1;
		}
	    else
	    	{
		protDbId = 2;
		}
	    }
   	else
	    {
	    protDbId = 4;
	    }
	    
	fprintf(outf, "%s:", chrom);
	for (i=0; i<cdsCnt; i++) fprintf(outf, "%s", cdsBloc[i]);
	fprintf(outf, "\t%s\t%d\t%8s\t%s\t%s\t%s\n", 
		ranking, protDbId, score, mrnaID, protAcc, alignID);

	/* for composite type, process just one record */ 
        if (alignID[0] == 'U') break; 
	row3 = sqlNextRow(sr3);
	}
    sqlFreeResult(&sr3);
    row2 = sqlNextRow(sr2);
    }
sqlFreeResult(&sr2);
hFreeConn(&conn2);
hFreeConn(&conn3);
hFreeConn(&conn4);
}
Example #24
0
int main(int argc, char *argv[])
{
struct sqlConnection *conn, *conn2, *conn3;
char query2[256], query3[256];
struct sqlResult *sr2, *sr3;
char **row2, **row3;
char condStr[255];
char *answer;

char *kgTempDb;
char *outfileName;
FILE *outf;
int  i;
char *chp;
char *acc2;

char *name, *txStart, *txEnd;
char *chrom;
char *acc, *stat;
char *frame, *start, *stop;
char *causes;
char *genomeDb;
char *geneName;
char srcType;
int  alignCnt = 0;

char *candTable, *chkTable;
int  orfStop, cdsGap, cdsSplice, numCdsIntrons;
boolean passed;
float ranking;

if (argc != 6) usage();
kgTempDb    = argv[1];
genomeDb    = argv[2];
candTable   = argv[3];
chkTable    = argv[4];
outfileName = argv[5];

outf = mustOpen(outfileName, "w");
conn = hAllocConn(genomeDb);
conn2= hAllocConn(genomeDb);
conn3= hAllocConn(genomeDb);

/* go through each protein */
sqlSafef(query2, sizeof(query2), "select * from %s.%s", kgTempDb, candTable);
sr2 = sqlMustGetResult(conn2, query2);
row2 = sqlNextRow(sr2);
while (row2 != NULL)
    {
    name  = row2[0];
    chrom = row2[1];
    txStart = row2[3];
    txEnd   = row2[4];
    
    /* retrieve gene-check results */
    sqlSafef(query3, sizeof(query3), 
          "select * from %s.%s where acc='%s' and chrStart=%s and chrEnd = %s",
          kgTempDb, chkTable, name, txStart, txEnd);
    sr3  = sqlMustGetResult(conn3, query3);
    row3 = sqlNextRow(sr3);
	{
	passed = FALSE;
	ranking  = 3;
	
   	acc 	  = row3[0];
   	stat	  = row3[5];
   	frame     = row3[6];
   	start	  = row3[7];
   	stop	  = row3[8];
   	orfStop   = atoi(row3[9]);
   	cdsGap    = atoi(row3[10]);
   	cdsSplice = atoi(row3[12]);
	numCdsIntrons = atoi(row3[18]);
	causes    = row3[21];
	
	ranking = 9;
	/* all genes passed gene-check with status ok are considered good */
	if (sameWord(stat, "ok")) 
	    {
	    passed = TRUE;
	    ranking  = 1;
	    }
	else
	    {
	    /* frame, start, orfStop, and stop conditions must be met for KG candidates */
	    if ((sameWord(frame, "ok")) &&
		(sameWord(start, "ok")) &&
		(orfStop == 0) &&
		(sameWord(stop,  "ok")) )
		{
		ranking = 2;
		/* accept cdsSplice = 0 or (cdsSplice = 1 and numCdsIntrons > 1) */
		if ((cdsSplice == 0) || ((numCdsIntrons > 1) && (cdsSplice == 1)))
		    {
		    passed = TRUE;
		    }
		/* if cdsGap > 0, degrade it ranking by 1.  If cdsGap is not 
		   a multiple of 3, degrade its ranking further */
		if (cdsGap > 0)
		    {
		    ranking = ranking + 1;
		    if ((cdsGap - (cdsGap/3)*3) != 0) ranking = ranking + 1;
		    }
		}
	    }
	    
        /* give RefSeq entries 0.5 advantage in its ranking */  
	sqlSafefFrag(condStr, sizeof(condStr), "name='%s'", acc);
	answer = sqlGetField(genomeDb, "refGene", "name", condStr);
 	if (answer != NULL) 
	    {
	    ranking = ranking - 0.5;
	    }
	else
	    {	
            chp = strstr(acc, "_");
	    if (chp != NULL)
	    	{
		acc2 = chp + 1;
		}
	    else
	        {
		acc2 = acc;
		}
	    sqlSafefFrag(condStr, sizeof(condStr), "name='%s'", acc2);
	    
	    /* If it is an MGC gene, give it a 0.3 advantable */
	    answer = sqlGetField(genomeDb, "mgcGenes", "name", condStr);
 	    if (answer != NULL) 
	    	{
	    	ranking = ranking - 0.3;
	    	}
	    }

	/* print out entries, with their rankings, that passed the above criteria */    
	if (passed) 
	    {
	    /*for (i=0; i<10; i++)
	    	{
		fprintf(outf, "%s\t", row2[i]);
		}
	    */

	    geneName = strdup(row2[0]);
	    chp = strstr(geneName, "_");
	    if (chp != NULL)
	    	{
		if (strstr(geneName, "NM_") != NULL)
		    {
		    srcType = 'R';	/* src is RefSeq */
		    }
		else
		    {
		    chp++;
		    /* keep the composite name, so that kgGetCds can process correctly */
		    /* geneName = chp; */
		    srcType  = 'U';	/* src is UCSC prot/mrna alignment */
		    }
		}
	    else
	    	{
		srcType = 'G';		/* src is GenBank */
		}
	    alignCnt++;
	    fprintf(outf, "%s\t", geneName);
	    for (i= 1; i<10; i++) fprintf(outf, "%s\t", row2[i]);
	    fprintf(outf, "%c%d\t", srcType, alignCnt);

	    fprintf(outf, "%.2f\n", ranking);
	    }

        row3 = sqlNextRow(sr3);
	}
    sqlFreeResult(&sr3);
    row2 = sqlNextRow(sr2);
    }
sqlFreeResult(&sr2);

hFreeConn(&conn);
hFreeConn(&conn2);
hFreeConn(&conn3);
fclose(outf);
return(0);
}
void doMiddle(struct cart *theCart)
/* Print the body of an html file.   */
{
char cond_str[255];
struct sqlConnection *conn;
char *proteinAC;
char *chp, *chp1, *chp9;
char *debugTmp = NULL;
char *chromStr, *cdsStartStr, *cdsEndStr, posStr[255];

char *supportedGenomeDatabase;
  
char *answer;
char *queryID;

/* Initialize layout and database. */
cart = theCart;

/* Uncomment this to see parameters for debugging. */
/* Be careful though, it breaks if custom track
 * is more than 4k */
/* 
{ struct dyString *state = cgiUrlString();
  hPrintf("State: %s\n", state->string); 
}
*/

queryID = cartOptionalString(cart, "proteinID");
if (sameString(queryID, ""))
    {
    errAbort("Please go back and enter a gene symbol or a Swiss-Prot/TrEMBL protein ID.\n");
    }
	    
if (cgiVarExists("db"))
    {
    /* if db is known, get key variables set */
    proteinInSupportedGenome = TRUE;
    database = cgiOptionalString("db");
    organism = hDbOrganism(database);
    protDbName = hPdbFromGdb(database);
    proteinID  = strdup(queryID);
    }
else 
    {
    protCntInSwissByGene = searchProteinsInSwissProtByGene(queryID);
    /* no CGI 'db' variable means it did not come in from GB but from pbGateway */
    /* search existing GB databases to see if this protein can be found */
    protCntInSupportedGenomeDb = 
    	searchProteinsInSupportedGenomes(queryID, &supportedGenomeDatabase);
    if ((protCntInSupportedGenomeDb > 1) || protCntInSwissByGene >= 1)
    	{
	/* more than 1 proteins match the query ID, present selection web page */
	proteinInSupportedGenome = 1;
	presentProteinSelections(queryID, protCntInSwissByGene, protCntInSupportedGenomeDb);
	return;
	}
    else
        {
	if (protCntInSupportedGenomeDb == 1)
	    {
	    /* one and only one protein found in a genome DB that support KG and PB */
	    proteinInSupportedGenome = TRUE;
	    database = strdup(supportedGenomeDatabase);
	    organism = hDbOrganism(database);
	    protDbName = hPdbFromGdb(database);
            proteinID=strdup(queryID);
	    }
	else
	    {
	    /* not found in genome DBs that support KG/PB */
	    /* now search PROTEOME_DB_NAMES to see if this protein is there. */
	    answer = uniProtFindPrimAcc(queryID);
	    if (answer == NULL)
		{
	        if (hIsGsidServer())
		    {
		    errAbort(
		    "'%s' does not seem to be a valid protein ID.<br><br>Click <A HREF=\"../cgi-bin/gsidPbGateway\">here</A> to start another query."
		    	    , queryID);
		    }
		else
		    {
		    errAbort(
		    "'%s' does not seem to be a valid UniProt(Swiss-Prot/TrEMBL) protein ID or a gene symbol.<br><br>Click <A HREF=\"../cgi-bin/pbGateway\">here</A> to start another query."
		    	    , queryID);
		    }
	    	}
	    
	    proteinInSupportedGenome = FALSE;
	    database = strdup(GLOBAL_PB_DB);
	    organism = strdup("");
    	    protDbName = strdup(PROTEOME_DB_NAME);
	    proteinID = strdup(answer);
	    }
	}
    
    if (proteinInSupportedGenome)
        {
        spConn = sqlConnect(database);
        safef(cond_str, sizeof(cond_str), "alias='%s'", queryID);
        proteinID = sqlGetField(database, "kgSpAlias", "spID", cond_str);
    	
        safef(cond_str, sizeof(cond_str), "spID='%s'", proteinID);
        answer = sqlGetField(database, "kgXref", "spDisplayID", cond_str);
    	
	safef(cond_str, sizeof(cond_str), "proteinID='%s'", answer);
    	chromStr    = sqlGetField(database, "knownGene", "chrom", cond_str);
	if (chromStr)
	    {
	    cdsStartStr = sqlGetField(database, "knownGene", "cdsStart", cond_str);
	    cdsEndStr   = sqlGetField(database, "knownGene", "cdsEnd", cond_str);
	    safef(posStr, sizeof(posStr), "%s:%s-%s", chromStr, cdsStartStr, cdsEndStr);
	    positionStr = strdup(posStr);
	    cartSetString(cart, "position", positionStr);
	    cartSetString(cart, "organism", organism);
	    }
	}
    }
/* print out key variables for debugging */
/* printf("<br>before enter main section: <br>proteinInSupportedGenome=%d<br>proteinID=%s <br>database=%s <br>organism=%s <br>protDbName=%s\n",
proteinInSupportedGenome, proteinID, database, organism, protDbName);fflush(stdout);
*/

if (hTableExists(database, "kgProtMap2"))
    {
    kgVersion = KG_III;
    strcpy(kgProtMapTableName, "kgProtMap2");
    }
		
debugTmp = cartUsualString(cart, "hgDebug", "off");
if(sameString(debugTmp, "on"))
    hgDebug = TRUE;
else
    hgDebug = FALSE;
conn  = hAllocConn(database);
hgsid     = cartOptionalString(cart, "hgsid");
if (hgsid != NULL)
    {
    safef(hgsidStr, sizeof(hgsidStr), "&hgsid=%s", hgsid);
    }
else
    {
    strcpy(hgsidStr, "");
    }

/* check proteinID to see if it is a valid SWISS-PROT/TrEMBL accession or display ID */
/* then assign the accession number to global variable proteinID */
safef(cond_str, sizeof(cond_str), "accession='%s'", proteinID);
proteinAC = sqlGetField(protDbName, "spXref3", "accession", cond_str);
if (proteinAC == NULL)
    {
    safef(cond_str, sizeof(cond_str), "displayID='%s'", proteinID);
    proteinAC = sqlGetField(protDbName, "spXref3", "accession", cond_str);
    if (proteinAC == NULL)
	{
	if (hIsGsidServer())
	    {
    	    safef(cond_str, sizeof(cond_str), "acc='%s'", proteinID);
    	    proteinAC = sqlGetField(protDbName, "uniProtAlias", "acc", cond_str);
	    if (proteinAC != NULL)	
		{
		protDisplayID = proteinID;
		proteinID = proteinAC;
		}
	    else
	    	{
	    	errAbort("'%s' does not seem to be a valid protein ID.<br><br>Click <A HREF=\"../cgi-bin/pbGateway\">here</A> to start another query."
		, proteinID);
	    	}
	    }
	else
	    {
	    errAbort("'%s' does not seem to be a valid Swiss-Prot/TrEMBL protein ID or gene symbol.<br><br>Click <A HREF=\"../cgi-bin/pbGateway\">here</A> to start another query."
	, proteinID);
	    }
	}
    else
	{
	protDisplayID = proteinID;
	proteinID = proteinAC;
	}
    }
else
    {
    safef(cond_str, sizeof(cond_str), "accession='%s'", proteinID);
    protDisplayID = sqlGetField(protDbName, "spXref3", "displayID", cond_str);
    }
    
if (proteinInSupportedGenome)
    {
    if (kgVersion == KG_III)
    	{
    	safef(cond_str, sizeof(cond_str), "spId='%s'", proteinID);
    	mrnaID = sqlGetField(database, "kgXref", "kgId", cond_str);
	}
    else
    	{
    	safef(cond_str, sizeof(cond_str), "proteinID='%s'", protDisplayID);
    	mrnaID = sqlGetField(database, "knownGene", "name", cond_str);
    	}
    }
else
    {
    mrnaID = NULL;
    positionStr = NULL;
    }

safef(cond_str, sizeof(cond_str), "accession='%s'", proteinID);
description = sqlGetField(protDbName, "spXref3", "description", cond_str);

if (positionStr != NULL)
    {
    chp = strstr(positionStr, ":");
    *chp = '\0';
    prevGBChrom = cloneString(positionStr);
    
    chp1 = chp + 1;
    chp9 = strstr(chp1, "-");
    *chp9 = '\0';
    prevGBStartPos = atoi(chp1);
    chp1 = chp9 + 1;
    prevGBEndPos   = atoi(chp1);
    }
else
    {
    prevGBChrom    = NULL;
    prevGBStartPos = -1;
    prevGBEndPos   = -1;
    }

/* Do main display. */
if (cgiVarExists("pbt.psOutput"))
    handlePostscript();
else
    {
    doTrackForm(NULL, NULL);
    }
}
Example #26
0
int main(int argc, char *argv[])
{
struct sqlConnection *conn, *conn2, *conn3;
char query[256], query2[256], query3[256];
struct sqlResult *sr, *sr2, *sr3;
char **row, **row2, **row3;
char *r1, *r2, *r3, *r4;

FILE *o1;
char *proteinDataDate;
char *bio_dblink_id;
char *source_bioentry_id;
char *dbxref_id;

char *bioentry_id;
char *biodatabase_id;
char *display_id;
char *accession;
char *entry_version;
char *division;     

char *dbxref_id3;
char *dbname;
char *extAC;

if (argc != 2) usage();

proteinDataDate = argv[1];
o1 = fopen("temp_spXref2.dat", "w");

conn = hAllocConn();
conn2= hAllocConn();
conn3= hAllocConn();

sqlSafef(query2, sizeof query2, "select * from biosql%s.bioentry;", proteinDataDate);
sr2 = sqlMustGetResult(conn2, query2);
row2 = sqlNextRow(sr2);
while (row2 != NULL)
    {
    bioentry_id 	= row2[0];    
    biodatabase_id 	= row2[1]; 
    display_id		= row2[2];     
    accession		= row2[3];      
    entry_version	= row2[4];  
    division		= row2[5];
			       
    sqlSafef(query, sizeof query, "select * from biosql%s.bioentry_direct_links where source_bioentry_id='%s';",
	    proteinDataDate, bioentry_id);
    sr = sqlMustGetResult(conn, query);
    row = sqlNextRow(sr);
    while (row != NULL)
    	{
    	bio_dblink_id = row[0];
    	source_bioentry_id = row[1];
   	dbxref_id = row[2];
    
        sqlSafef(query3, sizeof query3,  "select * from biosql%s.dbxref where dbxref_id=%s;",
		proteinDataDate, dbxref_id);
	sr3  = sqlMustGetResult(conn3, query3);
    	row3 = sqlNextRow(sr3);

	dbxref_id3 	= row3[0];
	dbname 		= row3[1];
	extAC 		= row3[2];
			
	fprintf(o1, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", accession, display_id, division,
		    dbname, extAC,bioentry_id,biodatabase_id);
			
    	sqlFreeResult(&sr3);
	row = sqlNextRow(sr);
	}
   sqlFreeResult(&sr);
   row2 = sqlNextRow(sr2);
   }

fclose(o1);
sqlFreeResult(&sr2);
hFreeConn(&conn);
hFreeConn(&conn2);
hFreeConn(&conn3);

system("cat temp_spXref2.dat | sort |uniq > spXref2.tab");
system("rm temp_spXref2.dat");
return(0);
}
Example #27
0
void suggestGene(char *database, char *table, char *prefix)
/* Print out a Javascript list of objects describing genes that start with prefix. */
{
struct dyString *str = newDyString(10000);
dyStringPrintf(str, "[\n");

int exact = cgiOptionalInt("exact", 0);
boolean hasKnownCanonical = sameString(table, "knownCanonical");
initGenbankTableNames(database);
char query[2048];
if(exact)
    {
    // NOTE that exact is no longer used by the UI as of v271, but there are still some robots
    // using it so we still support it.
    if(hasKnownCanonical)
        sqlSafef(query, sizeof(query),
                 "select x.geneSymbol, k.chrom, kg.txStart, kg.txEnd, x.kgID, x.description "
                 "from knownCanonical k, knownGene kg, kgXref x "
                 "where k.transcript = x.kgID and k.transcript = kg.name and x.geneSymbol = '%s' "
                 "order by x.geneSymbol, k.chrom, kg.txEnd - kg.txStart desc", prefix);
    else
        sqlSafef(query, sizeof(query),
                 "select r.name2, r.chrom, r.txStart, r.txEnd, r.name, d.name "
                 "from %s r, %s g, %s d "
                 "where r.name2 = '%s' and g.acc = r.name and g.description = d.id "
                 "order by r.name2, r.chrom, r.txEnd - r.txStart desc",
                 table, gbCdnaInfoTable, descriptionTable, prefix);
    }
else
    {
    // We use a LIKE query b/c it uses the geneSymbol index (substr queries do not use indices in mysql).
    // Also note that we take advantage of the fact that searches are case-insensitive in mysql.
    // Unfortunately, knownCanonical sometimes has multiple entries for a given gene (e.g. 2 TTn's in mm9 knownCanonical;
    // 3 POU5F1's in hg19); we return all of them (#5962).
    if(hasKnownCanonical)
        sqlSafef(query, sizeof(query),
                 "select x.geneSymbol, k.chrom, kg.txStart, kg.txEnd, x.kgID, x.description "
                 "from knownCanonical k, knownGene kg, kgXref x "
                 "where k.transcript = x.kgID and k.transcript = kg.name "
                 "and x.geneSymbol LIKE '%s%%' "
                 "order by x.geneSymbol, k.chrom, kg.txStart", prefix);
    else
        sqlSafef(query, sizeof(query), "select r.name2, r.chrom, r.txStart, r.txEnd, r.name, d.name "
                 "from %s r, %s g, %s d "
                 "where r.name2 LIKE '%s%%' and g.acc = r.name and g.description = d.id "
                 "order by r.name2, r.chrom, r.txStart",
                 table, gbCdnaInfoTable, descriptionTable, prefix);
    }
struct sqlConnection *conn = hAllocConn(database);
struct sqlResult *sr = sqlGetResult(conn, query);
char **row;
int count = 0;
while ((row = sqlNextRow(sr)) != NULL)
    {
    // ignore funny chroms (e.g. _hap chroms. See redmine #4257.
    if(!strchr(row[1], '_'))
        {
        // We have some very long descriptions, e.g. 4277 chars for hg38 CLOCK, so truncate:
        const int maxDesc = 120;
        char *description = row[5];
        if (strlen(description) > maxDesc + 4)
            strcpy(description + maxDesc, "...");
        count++;
        dyStringPrintf(str, "%s{\"value\": \"%s (%s)\", "
                       "\"id\": \"%s:%d-%s\", "
                       "\"geneSymbol\": \"%s\", "
                       "\"internalId\": \"%s\"}",
                       count == 1 ? "" : ",\n", row[0], jsonStringEscape(description),
                       row[1], atoi(row[2])+1, row[3],
                       jsonStringEscape(row[0]),
                       jsonStringEscape(row[4]));
        }
    }
hFreeConn(&conn);
dyStringPrintf(str, "\n]\n");
puts(dyStringContents(str));
}
int main(int argc, char *argv[])
{
char *skippedKgId;
char *lastValidKgId;
    
struct sqlConnection *conn2, *conn3;
struct sqlResult *sr2;
char query2[256];
char **row2;
    
char *proteinID;
FILE   *o3, *o7;
char *name, *chrom, *strand, *txStart, *txEnd, *cdsStart, *cdsEnd,
     *exonCount, *exonStarts, *exonEnds;

char *alignID;

char *chp;
int  i, j;

int  isDuplicate;
    
char *genomeDBname;
char *proteinDataDate;
char proteinsDB[40];
char spDB[40];
char *acc;

#define MAX_EXON 1000
int exStart[MAX_EXON], exEnd[MAX_EXON];
int exCount;

int aaStart[MAX_EXON], aaEnd[MAX_EXON];
    
char *sp, *ep;

int  aalen;
int  cdsS, cdsE;
int  eS, eE;
 
if (argc != 3) usage();
    
proteinDataDate = argv[1];
genomeDBname    = argv[2];
  
safef(spDB, sizeof(spDB), "sp%s", proteinDataDate);
safef(proteinsDB, sizeof(proteinsDB), "proteins%s", proteinDataDate);
 
o3 = fopen("j.dat", "w");
o7 = fopen("jj.dat", "w");

conn2= hAllocConn(genomeDBname);
conn3= hAllocConn(genomeDBname);
    
inf  = mustOpen("sorted.lis", "r");

strcpy(oldInfo, "");

skippedKgId   = cloneString("");
lastValidKgId = cloneString("");

isDuplicate   = 0;
oldMrnaStr    = cloneString("");
oldAlignStr   = cloneString("");
oldProteinStr = cloneString("");

mrnaStr       = cloneString("");
proteinStr    = cloneString("");
alignStr      = cloneString("");

while (fgets(line_in, 10000, inf) != NULL)
    {
    strcpy(line, line_in);

    chp = strstr(line, "\t");	/* chrom */
    chp ++;

    chp = strstr(chp, "\t");	/* cds block start position */
    chp ++;

    chp = strstr(chp, "\t");	/* cds block end   position */
    *chp = '\0';
    chp++;
    strcpy(newInfo, line);

    if (sameString(oldInfo, newInfo))
	{
	isDuplicate = 1;
	}
    else
	{
	/* remember previous record as old only if it is not a duplicate */
	if (!isDuplicate)
	    {
	    oldMrnaStr 	  = mrnaStr;
	    oldProteinStr = proteinStr;
	    oldAlignStr	  = alignStr;
	    }
	strcpy(oldInfo, newInfo);
	isDuplicate = 0;
	}

    chp = strstr(chp, "\t");	/* priority score */
    chp ++;
		
    chp = strstr(chp, "\t");	/* mRNA transcription length */ 
    chp ++;
		
    chp = strstr(chp, "\t");	/* mRNA date */
    chp ++;
	
    mrnaStr = chp;	
    chp = strstr(chp, "\t");	/* mRNA ID */
    *chp = '\0';
    chp ++;
    mrnaStr = cloneString(mrnaStr);

    proteinStr = chp;	
    chp = strstr(chp, "\t");	/* protein ID */
    *chp = '\0';
    chp ++;
    proteinStr = cloneString(proteinStr);

    alignID = chp;

    /* get rid of "end-of-line" character at the end of the string */
    alignStr = trimSpaces(alignID);

    if (isDuplicate)
	{
	/* only put out records for valid KG entries */
	if (!sameString(oldMrnaStr, skippedKgId) || sameString(oldMrnaStr, lastValidKgId))
	    {
	    fprintf(o7, "%s\t%s\t%s\t%s\n", oldMrnaStr, oldProteinStr, mrnaStr, proteinStr);
	    }
	}
    else
	{
	safef(query2, sizeof(query2), "select * from %sTemp.knownGene0 where alignID='%s';", genomeDBname, alignID);
	sr2 = sqlMustGetResult(conn2, query2);
    	row2 = sqlNextRow(sr2);
    	while (row2 != NULL)
	    {
 	    name 	= row2[0];
	    chrom 	= row2[1];
	    strand	= row2[2];
 	    txStart 	= row2[3];
	    txEnd       = row2[4];
	    cdsStart    = row2[5]; 
	    cdsEnd	= row2[6];
	    exonCount   = row2[7]; 
	    exonStarts  = row2[8]; 
	    exonEnds    = row2[9];	

	    proteinID = row2[10];
	    alignID   = row2[11];

	    sscanf(exonCount, "%d", &exCount);
	    sp = cloneString(exonStarts);
	    ep = cloneString(exonEnds);
	
            sscanf(cdsStart, "%d", &cdsS);
            sscanf(cdsEnd, "%d", &cdsE);

	    aalen = 0;
	    j=0;
	    for (i=0; i<exCount; i++)
		{
		chp = strstr(sp, ",");
		*chp = '\0';
		sscanf(sp, "%d", &(exStart[i]));
		chp++;
		sp = chp;

		chp = strstr(ep, ",");
		*chp = '\0';
		sscanf(ep, "%d", &(exEnd[i]));
	
		eS = exStart[i];
		eE = exEnd[i];
		
		if (cdsS > eS)
		    {
		    eS = cdsS;
		    }
		if (cdsE < eE)
		    {
		    eE = cdsE;
		    }
		if (eS > eE) 
		    {
		    eS = 0;
		    eE = 0;
		    }
	        if (eS != eE)
		    {
		    aaStart[j] = aalen;
		    aaEnd[j] = aaStart[j] + (eE- eS +1)/3 -1;
		    aalen = aalen + (eE- eS +1)/3;
			
		    j++;
		    }
		
		chp++;
		ep = chp;
		}
		
	    cdsLen = aalen;

            safef(cond_str, sizeof(cond_str), "val='%s'", proteinID);
            acc = sqlGetField(spDB, "displayId", "acc", cond_str);

            safef(cond_str, sizeof(cond_str), "acc='%s'", acc);
            aaStr=sqlGetField(spDB, "protein", "val", cond_str);
    	    aaLen = strlen(aaStr);

            if ((cdsLen >  50) || ((cdsLen * 100)/aaLen > 50))
		{
		fprintf(o3,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
 		    	name,
			chrom,
		        strand,
 	    		txStart,
	    		txEnd,
	 	   	cdsStart,
	    		cdsEnd,
		    	exonCount,
		    	exonStarts,
	    		exonEnds,
			
			proteinID,
			alignID);
		lastValidKgId = cloneString(name);
		}
	    else
		{
		printf("skipping %s %d \n", name, cdsLen);
		skippedKgId = cloneString(name);
		} 
	    row2 = sqlNextRow(sr2);
	    }
	sqlFreeResult(&sr2);
	}
    }
hFreeConn(&conn2);
hFreeConn(&conn3);
fclose(o3);
fclose(o7);
    
mustSystem("cat j.dat|sort|uniq  >knownGene.tab");
mustSystem("cat jj.dat|sort|uniq >duplicate.tab");
mustSystem("rm j.dat");
mustSystem("rm jj.dat");
return(0);
}
Example #29
0
void affyCheck()
/* affyCheck - read in all Affy SNPs, compare to lookupTable. */
{
struct snpSimple *snps = NULL;
struct snpSimple *snp = NULL;
struct snpSimple *newSnp = NULL;
char query[512];
struct sqlConnection *conn = hAllocConn();
struct sqlResult *sr;
char **row;
int count = 0;
int obsLen = 0;

snps = readSnps();

verbose(1, "checking....\n");

for (snp = snps; snp != NULL; snp = snp->next)
    {
    count++;
    verbose(2, "----------------------\n");
    verbose(2, "%d: %s:%d-%d\n", count, snp->chrom, snp->chromStart, snp->chromEnd);
    sqlSafef(query, sizeof(query), "select name, chrom, chromStart, chromEnd, strand, observed from %s"
          " where chrom = '%s' and chromStart = %d and chromEnd = %d", lookupTable, snp->chrom, snp->chromStart, snp->chromEnd);
    sr = sqlGetResult(conn, query);
    row = sqlNextRow(sr);
    if (row == NULL) 
        {
	verbose(2, "no matches for %s %s\n", affyTable, snp->name);
	continue;
	}
    newSnp = snpSimpleLoad(row);
    verbose(2, "comparing %s %s to %s %s\n", affyTable, snp->name, lookupTable, newSnp->name);

    if (sameString(newSnp->observed, "n/a")) 
        {
        while ((row = sqlNextRow(sr)) != NULL) { }
        continue;
	}

    if (sameString(newSnp->observed, "t/n")) 
        {
        while ((row = sqlNextRow(sr)) != NULL) { }
        continue;
	}

    if (sameString(snp->observed, newSnp->observed)) 
        {
        while ((row = sqlNextRow(sr)) != NULL) { }
        continue;
	}

    obsLen = strlen(newSnp->observed);
    if (obsLen > 3)
        {
	verbose(2, "%s is not bi-allelic (%s)\n", newSnp->name, newSnp->observed);
        while ((row = sqlNextRow(sr)) != NULL)
            {
	    }
        continue;
	}

    verbose(1, "----------------------\n");
    verbose(1, "%d: %s:%d-%d\n", count, snp->chrom, snp->chromStart, snp->chromEnd);
    verbose(1, "comparing %s %s to %s %s\n", affyTable, snp->name, lookupTable, newSnp->name);
    verbose(1, "observed difference\n");
    verbose(1, "%s observed = %s, %s observed = %s\n", affyTable, snp->observed, lookupTable, newSnp->observed);

    if (snp->strand == '-' && newSnp->strand == '+')
        {
	verbose(1, "strand difference\n");
	verbose(1, "%s strand = %c, %s strand = %c\n", affyTable, snp->strand, lookupTable, newSnp->strand);
	}
    if (snp->strand == '+' && newSnp->strand == '-')
        {
	verbose(1, "strand difference\n");
	verbose(1, "%s strand = %c, %s strand = %c\n", affyTable, snp->strand, lookupTable, newSnp->strand);
	}
    /* check here for multiple matches */
    while ((row = sqlNextRow(sr)) != NULL)
        {
	}
    /* free newSnp */
    }

snpSimpleFreeList(&snps);

}
Example #30
0
void aaPropertyInit(int *hasResFreq)
/* initialize AA properties */
{
int i, j, ia, iaCnt;

struct sqlConnection *conn;
char query[56];
struct sqlResult *sr;
char **row;

for (i=0; i<256; i++)
    {
    aa_attrib[i] = 0;
    aa_hydro[i] = 0;
    }

aa_attrib['R'] = CHARGE_POS;
aa_attrib['H'] = CHARGE_POS;
aa_attrib['K'] = CHARGE_POS;
aa_attrib['D'] = CHARGE_NEG;
aa_attrib['E'] = CHARGE_NEG;
aa_attrib['C'] = POLAR;
aa_attrib['Q'] = POLAR;
aa_attrib['S'] = POLAR;
aa_attrib['Y'] = POLAR;
aa_attrib['N'] = POLAR;
aa_attrib['T'] = POLAR;
aa_attrib['M'] = POLAR;
aa_attrib['A'] = NEUTRAL;
aa_attrib['W'] = NEUTRAL;
aa_attrib['V'] = NEUTRAL;
aa_attrib['F'] = NEUTRAL;
aa_attrib['P'] = NEUTRAL;
aa_attrib['I'] = NEUTRAL;
aa_attrib['L'] = NEUTRAL;
aa_attrib['G'] = NEUTRAL;

/* Ala:  1.800  Arg: -4.500  Asn: -3.500  Asp: -3.500  Cys:  2.500  Gln: -3.500 */
aa_hydro['A'] =  1.800;
aa_hydro['R'] = -4.500;
aa_hydro['N'] = -3.500;
aa_hydro['D'] = -3.500;
aa_hydro['C'] =  2.500;
aa_hydro['Q'] = -3.500;
/* Glu: -3.500  Gly: -0.400  His: -3.200  Ile:  4.500  Leu:  3.800  Lys: -3.900 */
aa_hydro['E'] = -3.500;
aa_hydro['G'] = -0.400;
aa_hydro['H'] = -3.200;
aa_hydro['I'] =  4.500;
aa_hydro['L'] =  3.800;
aa_hydro['K'] = -3.900;
/* Met:  1.900  Phe:  2.800  Pro: -1.600  Ser: -0.800  Thr: -0.700  Trp: -0.900 */
aa_hydro['M'] =  1.900;
aa_hydro['F'] =  2.800;
aa_hydro['P'] = -1.600;
aa_hydro['S'] = -0.800;
aa_hydro['T'] = -0.700;
aa_hydro['W'] = -0.900;
/* Tyr: -1.300  Val:  4.200  Asx: -3.500  Glx: -3.500  Xaa: -0.490 */
aa_hydro['Y'] = -1.300;
aa_hydro['V'] =  4.200;
/* ?? Asx: -3.500 Glx: -3.500  Xaa: -0.490 ?? */

/* get average frequency distribution for each AA residue */
conn= hAllocConn(database);
if (!hTableExists(database, "pbResAvgStd"))
    {
    *hasResFreq = 0;
    return;
    }
else
    {
    *hasResFreq = 1;
    }
sqlSafef(query, sizeof(query), "select * from %s.pbResAvgStd", database);
iaCnt = 0;
sr = sqlMustGetResult(conn, query);
row = sqlNextRow(sr);

while (row != NULL)
    {
    for (j=0; j<20; j++)
        {
        if (row[0][0] == aaAlphabet[j])
            {
            iaCnt++;
            ia = j;
            aaChar[ia] = row[0][0];
            avg[ia] = (double)(atof(row[1]));
            stddev[ia] = (double)(atof(row[2]));
            break;
            }
        }
    row = sqlNextRow(sr);
    }
sqlFreeResult(&sr);
if (iaCnt != 20)
    {
    errAbort("in doAnomalies(), not all 20 amino acide residues are accounted for.");
    }
}