boolean chromSeqFileExists(char *db, char *chrom)
/* Check whether chromInfo exists for a database, find the path of the */
/* sequence file for this chromosome and check if the file exists. */
{
char seqFile[512];
struct sqlConnection *conn = sqlConnect(db);
char query[256];
char *res = NULL;
boolean exists = FALSE;

/* if the database exists, check for the chromInfo file */
if (sqlDatabaseExists(db))
    {
    safef(query, sizeof(query), "select fileName from chromInfo where chrom = '%s'", chrom);
    res = sqlQuickQuery(conn, query, seqFile, 512);
    sqlDisconnect(&conn);
    }

/* if there is not table or no information in the table or if the table */
/* exists but the file can not be opened return false, otherwise sequence */
/* file exists and return true */
if (res != NULL)
    {
    /* chromInfo table exists so check that sequence file can be opened */
    FILE *f = fopen(seqFile, "rb");
    if (f != NULL)
        {
        exists = TRUE;
        fclose(f);
        }
    }
return exists;
}
Пример #2
0
boolean chromSeqFileExists(char *db, char *chrom)
/* Check whether chromInfo exists for a database, find the path of the */
/* sequence file for this chromosome and check if the file exists. */
{
char seqFile[512];
struct sqlConnection *conn = sqlConnect(db);
char query[256];
char *res = NULL;
boolean exists = FALSE;

/* if the database exists, check for the chromInfo file */
if (sqlDatabaseExists(db))
    {
    sqlSafef(query, sizeof(query), "select fileName from chromInfo where chrom = '%s'", chrom);
    res = sqlQuickQuery(conn, query, seqFile, 512);
    sqlDisconnect(&conn);
    }

/* if there is not table or no information in the table or if the table */
/* exists but the file can not be opened return false, otherwise sequence */
/* file exists and return true */
if (res != NULL)
    {
    char *seqFile2 = hReplaceGbdb(seqFile);
    exists = udcExists(seqFile2);
    freeMem(seqFile2);
    }
return exists;
}
Пример #3
0
void printAllAssemblyListHtmlParm(char *db, struct dbDb *dbList,
                            char *dbCgi, bool allowInactive, char *javascript)
/* Prints to stdout the HTML to render a dropdown list containing the list
 * of assemblies for the current genome to choose from.  By default,
 * this includes only active assemblies with a database (with the
 * exception of the default assembly, which will be included even
 * if it isn't active).
 *  param db - The default assembly (the database name) to choose as selected.
 *             If NULL, no default selection.
 *  param allowInactive - if set, print all assemblies for this genome,
 *                        even if they're inactive or have no database
 */
{

char *assemblyList[128];
char *values[128];
int numAssemblies = 0;
struct dbDb *cur = NULL;
char *genome = hGenomeOrArchive(db);
char *selAssembly = NULL;

if (genome == NULL)
#ifdef LOWELAB
    genome = "Pyrococcus furiosus";
#else
    genome = "Human";
#endif
for (cur = dbList; cur != NULL; cur = cur->next)
    {
    /* Only for this genome */
    if (!sameWord(genome, cur->genome))
        continue;

    /* Save a pointer to the current assembly */
    if (sameWord(db, cur->name))
        selAssembly = cur->name;

    if (allowInactive ||
        ((cur->active || sameWord(cur->name, db))
                && (trackHubDatabase(db) || sqlDatabaseExists(cur->name))))
        {
        assemblyList[numAssemblies] = cur->description;
        values[numAssemblies] = cur->name;
        numAssemblies++;
	if (numAssemblies >= ArraySize(assemblyList))
	    internalErr();
        }

    }
cgiMakeDropListFull(dbCgi, assemblyList, values, numAssemblies,
                                selAssembly, javascript);
}
Пример #4
0
boolean checkDatabases(char *databases)
/* Check all databases in space delimited string exist. */
{
char *dupe = cloneString(databases);
char *s = dupe, *word;
boolean ok = TRUE;
while ((word = nextWord(&s)) != NULL)
     {
     if (!sqlDatabaseExists(word))
         {
	 ok = FALSE;
	 break;
	 }
     }
freeMem(dupe);
return ok;
}
static char *otherOrgPosition(struct otherOrg *otherOrg,
			      struct sqlConnection *conn, char *geneId)
/* Return position of gene ID in other organism or NULL if it doesn't exist;
 * also make sure that the gene track is visible, and id highlighted, in 
 * hgTracks (the destination when this is used). */
{
char *id = otherOrgId(otherOrg, conn, geneId);
if (id != NULL)
    {
    if (otherOrg->db == NULL || otherOrg->geneTable == NULL
        || !sqlDatabaseExists(otherOrg->db))
	return id;
    else
        return otherOrgPositionFromDb(otherOrg, id);
    }
return NULL;
}
Пример #6
0
void doPasteIdentifiers(struct sqlConnection *conn)
/* Respond to paste identifiers button. */
{
struct sqlConnection *alternateConn = conn;
char *actualDb = database;
if (sameWord(curTable, WIKI_TRACK_TABLE))
    {
    alternateConn = wikiConnect();
    actualDb = wikiDbName();
    }

char *oldPasted = forCurTable() ?
    cartUsualString(cart, hgtaPastedIdentifiers, "") : "";
struct hTableInfo *hti = maybeGetHti(actualDb, curTable, conn);
char *idField = getIdField(actualDb, curTrack, curTable, hti);
htmlOpen("Paste In Identifiers for %s", curTableLabel());
if (idField == NULL)
    errAbort("Sorry, I can't tell which field of table %s to treat as the "
	     "identifier field.", curTable);
hPrintf("<FORM ACTION=\"%s\" METHOD=%s>\n", getScriptName(),
	cartUsualString(cart, "formMethod", "POST"));
cartSaveSession(cart);
hPrintf("Please paste in the identifiers you want to include.\n");
if (sqlDatabaseExists("hgTemp"))
    explainIdentifiers(actualDb, alternateConn, idField);
else
    warn("No hgTemp database found for temporary tables.<br>Please src/product/README.mysql.setup for more information.");
hPrintf("<BR>\n");
cgiMakeTextArea(hgtaPastedIdentifiers, oldPasted, 10, 70);
hPrintf("<BR>\n");
cgiMakeButton(hgtaDoPastedIdentifiers, "submit");
hPrintf(" ");
cgiMakeButton(hgtaDoClearPasteIdentifierText, "clear");
hPrintf(" ");
cgiMakeButton(hgtaDoMainPage, "cancel");
hPrintf("</FORM>");
cgiDown(0.9);
htmlClose();
if (sameWord(curTable, WIKI_TRACK_TABLE))
    wikiDisconnect(&alternateConn);
}
static void getItemLabel(struct sqlConnection *conn, char *transMapInfoTbl, 
                         struct sqlConnection *geneConn, char *transMapGeneTbl,
                         unsigned labelSet,
                         struct linkedFeatures *lf)
/* get label for a transMap item */
{
struct transMapInfo *info = NULL;
struct transMapGene *gene = NULL;
boolean srcDbExists = FALSE;
if (labelSet & (useOrgCommon|useOrgAbbrv|useOrgDb|useGene))
    {
    info = transMapInfoQuery(conn, transMapInfoTbl, lf->name);
    srcDbExists = sqlDatabaseExists(info->srcDb);
    }
if ((labelSet & useGene) && (geneConn != NULL))
    {
    gene = transMapGeneQuery(geneConn, transMapGeneTbl,
                             info->srcDb, transMapIdToAcc(info->srcId));
    }

struct dyString *label = dyStringNew(64);
if (labelSet & useOrgAbbrv && srcDbExists)
    addToLabel(label, orgShortForDb(info->srcDb));
if (labelSet & useOrgCommon && srcDbExists)
    addToLabel(label, hOrganism(info->srcDb));
if (labelSet & useOrgDb)
    addToLabel(label, info->srcDb);
if (labelSet & useGene) 
    {
    if ((gene != NULL) && (strlen(gene->geneName) > 0))
        addToLabel(label, gene->geneName);
    else
        labelSet |= useAcc;  // no gene, so force acc
    }
if (labelSet & useAcc)
    addToLabel(label, transMapIdToAcc(lf->name));

transMapInfoFree(&info);
transMapGeneFree(&gene);
lf->extra = dyStringCannibalize(&label);
}
static char *otherOrgProteinId(struct otherOrg *otherOrg, struct sqlConnection *conn,
    char *geneId)
/* Return protein ID in other organism or NULL if it doesn't exist. */
{
char *otherId = otherOrgId(otherOrg, conn, geneId);
char *protId = NULL;
if (otherOrg->db != NULL && otherId != NULL && otherOrg->idToProtIdSql != NULL
    && sqlDatabaseExists(otherOrg->db))
    {
    struct sqlConnection *conn = hAllocConn(otherOrg->db);
    char query[512];
    safef(query, sizeof(query), otherOrg->idToProtIdSql, otherId);
    protId = sqlQuickString(conn, query);
    hFreeConn(&conn);
    }
if (protId == NULL)
    {
    protId = otherId;
    otherId = NULL;
    }
freez(&otherId);
return protId;
}
static char *otherOrgExternalId(struct otherOrg *otherOrg, char *localId)
/* Convert other organism UCSC id to external database ID. */
{
char *otherId = NULL;
if (localId != NULL)
    {
    if (otherOrg->otherIdSql && sqlDatabaseExists(otherOrg->db))
	{
	struct sqlConnection *conn = hAllocConn(otherOrg->db);
	char query[512];
	safef(query, sizeof(query), otherOrg->otherIdSql, localId);
	otherId = sqlQuickString(conn, query);
	if (otherId == NULL && otherOrg->otherIdSql2 != NULL)
	    {
	    safef(query, sizeof(query), otherOrg->otherIdSql2, localId);
	    otherId = sqlQuickString(conn, query);
	    }
	hFreeConn(&conn);
	}
    else
        otherId = cloneString(localId);
    }
return otherId;
}