void *socket_listen_main_multi_threaded(void *ptr) { struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr; web_server_mode = WEB_SERVER_MODE_MULTI_THREADED; info("Multi-threaded WEB SERVER thread created with task id %d", gettid()); struct web_client *w; int retval, counter = 0; if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0) error("Cannot set pthread cancel type to DEFERRED."); if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) error("Cannot set pthread cancel state to ENABLE."); if(!api_sockets.opened) fatal("LISTENER: No sockets to listen to."); struct pollfd *fds = callocz(sizeof(struct pollfd), api_sockets.opened); size_t i; for(i = 0; i < api_sockets.opened ;i++) { fds[i].fd = api_sockets.fds[i]; fds[i].events = POLLIN; fds[i].revents = 0; info("Listening on '%s'", (api_sockets.fds_names[i])?api_sockets.fds_names[i]:"UNKNOWN"); } int timeout = 10 * 1000; for(;;) { // debug(D_WEB_CLIENT, "LISTENER: Waiting..."); retval = poll(fds, api_sockets.opened, timeout); if(unlikely(retval == -1)) { error("LISTENER: poll() failed."); continue; } else if(unlikely(!retval)) { debug(D_WEB_CLIENT, "LISTENER: select() timeout."); counter = 0; cleanup_web_clients(); continue; } for(i = 0 ; i < api_sockets.opened ; i++) { short int revents = fds[i].revents; // check for new incoming connections if(revents & POLLIN || revents & POLLPRI) { fds[i].revents = 0; w = web_client_create(fds[i].fd); if(unlikely(!w)) { // no need for error log - web_client_create already logged the error continue; } if(pthread_create(&w->thread, NULL, web_client_main, w) != 0) { error("%llu: failed to create new thread for web client.", w->id); WEB_CLIENT_IS_OBSOLETE(w); } else if(pthread_detach(w->thread) != 0) { error("%llu: Cannot request detach of newly created web client thread.", w->id); WEB_CLIENT_IS_OBSOLETE(w); } } } // cleanup unused clients counter++; if(counter >= CLEANUP_EVERY_EVENTS) { counter = 0; cleanup_web_clients(); } } debug(D_WEB_CLIENT, "LISTENER: exit!"); listen_sockets_close(&api_sockets); freez(fds); static_thread->enabled = 0; pthread_exit(NULL); return NULL; }
void doKeyChecks(char *db, struct joiner *joiner, struct joinerSet *js, struct hash *keyHash, struct keyHitInfo *khiList, struct joinerField *keyField, struct joinerField *jf) /* Check that at least minimum is covered, and that full and * unique tags are respected. */ { struct sqlConnection *conn = sqlMayConnect(db); if (conn != NULL) { boolean okFlag = FALSE; int total = 0, hits = 0, hitsNeeded; char *miss = NULL; struct slName *table; struct slName *tableList = getTablesForField(conn,jf->splitPrefix, jf->table, jf->splitSuffix); keyHitInfoClear(khiList); for (table = tableList; table != NULL; table = table->next) { char query[256], **row; struct sqlResult *sr; safef(query, sizeof(query), "select %s from %s", jf->field, table->name); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { if (jf->separator == NULL) { addHitMiss(keyHash, row[0], jf, &hits, &miss, &total); } else { /* Do list. */ struct slName *el, *list; int ix; list = slNameListFromString(row[0], jf->separator[0]); for (el = list, ix=0; el != NULL; el = el->next, ++ix) { char *id = el->name; char buf[16]; if (jf->indexOf) { safef(buf, sizeof(buf), "%d", ix); id = buf; } addHitMiss(keyHash, id, jf, &hits, &miss, &total); } slFreeList(&list); } } sqlFreeResult(&sr); } if (tableList != NULL) { okFlag = FALSE; if (hits==total) okFlag = TRUE; if (jf->minCheck < 0.999999) /* Control for rounding error */ hitsNeeded = round(total * jf->minCheck); else hitsNeeded = total; if (jf->minCheck < 1.0 && hits >= hitsNeeded) okFlag = TRUE; verbose(1, " %s.%s.%s - hits %d of %d%s\n", db, jf->table, jf->field, hits, total, okFlag ? " ok" : js->isFuzzy ? " fuzzy" : ""); if (hits < hitsNeeded && !js->isFuzzy) { warn("Error: %d of %d elements of %s.%s.%s are not in key %s.%s line %d of %s\n" "Example miss: %s" , total - hits, total, db, jf->table, jf->field , keyField->table, keyField->field , jf->lineIx, joiner->fileName, miss); } if (jf->unique || jf->full) checkUniqueAndFull(joiner, js, db, jf, keyField, khiList); } freez(&miss); slFreeList(&tableList); sqlDisconnect(&conn); } }
void faFreeFastBuf() /* Free up buffers used in fa fast and speedreading. */ { freez(&faFastBuf); faFastBufSize = 0; }
void txCdsToGene(char *txBed, char *txFa, char *txCds, char *outGtf, char *outFa) /* txCdsToGene - Convert transcript bed and best cdsEvidence to genePred and * protein sequence. */ { struct hash *txSeqHash = faReadAllIntoHash(txFa, dnaLower); verbose(2, "Read %d transcript sequences from %s\n", txSeqHash->elCount, txFa); struct hash *cdsHash = cdsEvidenceReadAllIntoHash(txCds); verbose(2, "Read %d cdsEvidence from %s\n", cdsHash->elCount, txCds); struct lineFile *lf = lineFileOpen(txBed, TRUE); FILE *fGtf = mustOpen(outGtf, "w"); FILE *fFa = mustOpen(outFa, "w"); char *row[12]; while (lineFileRow(lf, row)) { struct bed *bed = bedLoad12(row); verbose(2, "processing %s\n", bed->name); struct cdsEvidence *cds = hashFindVal(cdsHash, bed->name); struct dnaSeq *txSeq = hashFindVal(txSeqHash, bed->name); char *cdsSource = NULL; boolean freeOfCdsErrors = TRUE; if (txSeq == NULL) errAbort("%s is in %s but not %s", bed->name, txBed, txFa); if (cds != NULL) { freeOfCdsErrors = outputProtein(cds, txSeq, fFa); if (cds->cdsCount > 1) { struct bed *newBed = breakUpBedAtCdsBreaks(cds, bed); if (fTweaked) fprintf(fTweaked, "%s\n", newBed->name); bedFree(&bed); bed = newBed; } cdsSource = cds->accession; if (sameString(cds->accession, ".")) cdsSource = cds->source; } /* Set bed CDS bounds and optionally output bed. */ cdsEvidenceSetBedThick(cds, bed, freeOfCdsErrors); if (fBed) bedTabOutN(bed, 12, fBed); /* Parse out bed name, which is in format chrom.geneId.txId.accession */ char *geneName = cloneString(bed->name); char *accession = strrchr(geneName, '.'); assert(accession != NULL); *accession++ = 0; chopSuffix(geneName); /* Output as GTF */ bedToGtf(bed, accession, cdsSource, geneName, fGtf); /* Clean up for next iteration of loop. */ freez(&geneName); bedFree(&bed); } lineFileClose(&lf); carefulClose(&fFa); carefulClose(&fGtf); }
void _pf_err_catch_free(struct _pf_err_catch **pErrCatch) /* Free up memory associated with error catcher. */ { freez(pErrCatch); }
static void makeTestFile(int size) /* make a tmp test file as input to mime parser */ { int i = 0; FILE *f = mustOpen(TESTFILENAME,"w"); char *dna = NULL; fprintf(f,"%s", "Content-type: multipart/form-data; boundary=----------0xKhTmLbOuNdArY\r\n" "\r\n" "------------0xKhTmLbOuNdArY\r\n" "Content-Disposition: form-data; name=\"hgsid\"\r\n" "\r\n" "63932244\r\n" "------------0xKhTmLbOuNdArY\r\n" "Content-Disposition: form-data; name=\"org\"\r\n" "\r\n" "Human\r\n" "------------0xKhTmLbOuNdArY\r\n" "Content-Disposition: form-data; name=\"db\"\r\n" "\r\n" "hg17\r\n" "------------0xKhTmLbOuNdArY\r\n" "Content-Disposition: form-data; name=\"type\"\r\n" "\r\n" "BLAT's guess\r\n" "------------0xKhTmLbOuNdArY\r\n" "Content-Disposition: form-data; name=\"sort\"\r\n" "\r\n" "query,score\r\n" "------------0xKhTmLbOuNdArY\r\n" "Content-Disposition: form-data; name=\"output\"\r\n" "\r\n" "hyperlink\r\n" "------------0xKhTmLbOuNdArY\r\n" "Content-Disposition: form-data; name=\"userSeq\"\r\n" "\r\n" ">NM_000230 (LEP)\n" ); dna = needMem(size+1); for(i=0;i<size;++i) { dna[i] = 'A'; } dna[size] = 0; fprintf(f,"%s",dna); freez(&dna); fprintf(f,"%s", "\r\n" "------------0xKhTmLbOuNdArY\r\n" "Content-Disposition: form-data; name=\"Submit\"\r\n" "\r\n" "Submit\r\n" "------------0xKhTmLbOuNdArY\r\n" "Content-Disposition: form-data; name=\"seqFile\"; filename=\"\"\r\n" "\r\n" "\r\n" "------------0xKhTmLbOuNdArY--\r\n" ); carefulClose(&f); }
void doGetText(struct sqlConnection *conn, struct column *colList, struct subjInfo *subjList) /* Put up great big table. */ { struct subjInfo *si; struct column *col; boolean first = TRUE; char *chp, *chp9; if (subjList == NULL) { hPrintf("empty table"); return; } hPrintf("<TT><PRE>"); /* Print labels. */ hPrintf("#"); for (col = colList; col != NULL; col = col->next) { if (col->on) { if (first) first = FALSE; else hPrintf("\t"); hPrintf("%s", col->shortLabel); } } hPrintf("\n"); for (si = subjList; si != NULL; si = si->next) { first = TRUE; for (col = colList; col != NULL; col = col->next) { if (col->on) { boolean special; char *val = col->cellVal(col, si, conn); if (first) first = FALSE; else hPrintf("\t"); if (val == NULL) hPrintf("n/a"); else { special = FALSE; if (sameWord(col->name, "cd4Count")) { if (sameWord(val, "-1") || sameWord(val, "0")) { hPrintf("N/A"); special = TRUE; } } if (sameWord(col->name, "hivQuan")) { if (sameWord(val, "-1")) { hPrintf("N/A"); special = TRUE; } } if (sameWord(col->name, "DAEI")) { if (sameWord(val, "-1")) { hPrintf("N/A"); special = TRUE; } } if (sameWord(col->name, "esdi")) { if (sameWord(val, "-1")) { hPrintf("N/A"); special = TRUE; } } if (sameWord(col->name, "hivQuan")) { if (sameWord(val, "1000000")) { hPrintf("> 1000000"); special = TRUE; } } if (sameWord(col->name, "hivQuan")) { if (sameWord(val, "200")) { hPrintf("< 400"); special = TRUE; } } if ((sameWord(col->name, "dnaSeqIds")) || (sameWord(col->name, "aaSeqIds"))) { chp = val; chp = strstr(chp, "#35;"); while (chp != NULL) { chp = chp +strlen("#35;"); chp9 = strstr(chp, " "); *chp9 = '\0'; hPrintf("%s ", chp); chp9++; chp = strstr(chp9, "#35;"); } special = TRUE; } if (!special) { hPrintf("%s", val); } } freez(&val); } } hPrintf("\n"); } hPrintf("</PRE></TT>"); }
void jpegSize(char *fileName, int *width, int *height) /* Read image width and height. * Parse marker stream until SOS or EOI; */ { FILE * infile = mustOpen(fileName, "r"); int sectionsRead = 0; boolean done = FALSE; boolean foundJFIF = FALSE; /* Scan the JPEG headers. */ if (fgetc(infile) != 0xff || fgetc(infile) != M_SOI) errAbort("error reading jpg header: %s",fileName); while(!done) { int itemlen; int marker = 0; int ll,lh, got; int a=0; uchar * data; if (sectionsRead >= MAX_SECTIONS) errAbort("Too many sections in jpg file: %s",fileName); for (a=0;a<7;a++) { marker = fgetc(infile); if (marker != 0xff) break; if (a >= 6) errAbort("too many padding bytes: %s",fileName); } /* 0xff is legal padding, but if we get that many, something's wrong. */ if (marker == 0xff) errAbort("too many padding bytes: %s",fileName); /* Read the length of the section. */ lh = fgetc(infile); ll = fgetc(infile); itemlen = (lh << 8) | ll; if (itemlen < 2) errAbort("invalid jpeg marker: %s",fileName); data = (uchar *)needMem(itemlen); if (data == NULL) errAbort("Could not allocate %d bytes memory", itemlen); /* Store first two pre-read bytes. */ data[0] = (uchar)lh; data[1] = (uchar)ll; got = fread(data+2, 1, itemlen-2, infile); /* Read the whole section. */ if (got != itemlen-2) errAbort("Premature end of file?: %s",fileName); ++sectionsRead; switch(marker) { case M_SOS: /* stop before hitting compressed data */ done = TRUE; break; case M_EOI: /* in case it's a tables-only JPEG stream */ errAbort("No image in jpeg!: %s",fileName); case M_JFIF: /* Regular jpegs always have this tag, exif images have the exif marker instead or in addition - could add check to make sure this is present */ foundJFIF = TRUE; break; case M_SOF0: case M_SOF1: case M_SOF2: case M_SOF3: case M_SOF5: case M_SOF6: case M_SOF7: case M_SOF9: case M_SOF10: case M_SOF11: case M_SOF13: case M_SOF14: case M_SOF15: *height = data[3]*256+data[4]; *width = data[5]*256+data[6]; done = TRUE; break; default: /* Skip any other sections. */ break; } freez(&data); } fclose(infile); if (!foundJFIF) errAbort("JFIF marker not found jpeg: %s",fileName); return; }
/********************************************************************* * * Function : pcrs_compile_dynamic_command * * Description : Takes a dynamic pcrs command, fills in the * values of the variables and compiles it. * * Parameters : * 1 : pcrs_command = The dynamic pcrs command to compile * 2 : v = NULL terminated array of variables and their values. * 3 : error = pcrs error code * * Returns : NULL in case of hard errors, otherwise the * compiled pcrs job. * *********************************************************************/ pcrs_job* pcrs::pcrs_compile_dynamic_command(char *pcrs_command, const pcrs_variable v[], int *error) { char buf[PCRS_BUFFER_SIZE]; const char *original_pcrs_command = pcrs_command; char *pcrs_command_tmp = NULL; pcrs_job *job = NULL; int truncation = 0; char d; int ret; while ((NULL != v->_name) && (NULL != pcrs_command)) { assert(NULL != v->_value); if (NULL == strstr(pcrs_command, v->_name)) { /* * Skip the substitution if the variable * name isn't part of the pattern. */ v++; continue; } /* Use pcrs to replace the variable with its value. */ d = pcrs::pcrs_get_delimiter(v->_value); if ('\0' == d) { /* No proper delimiter found */ *error = PCRS_ERR_CMDSYNTAX; return NULL; } /* * Variable names are supposed to contain alpha * numerical characters plus '_' only. */ assert(NULL == strchr(v->_name, d)); ret = snprintf(buf, sizeof(buf), "s%c\\$%s%c%s%cgT", d, v->_name, d, v->_value, d); assert(ret >= 0); if ((size_t)ret >= sizeof(buf)) { /* * Value didn't completely fit into buffer, * overwrite the end of the substitution text * with a truncation message and close the pattern * properly. */ const size_t trailer_size = sizeof(warning) + 3; /* 3 for d + "gT" */ char *trailer_start = buf + sizeof(buf) - trailer_size; ret = snprintf(trailer_start, trailer_size, "%s%cgT", warning, d); assert(ret == trailer_size - 1); assert(sizeof(buf) == strlen(buf) + 1); truncation = 1; } pcrs_command_tmp = pcrs::pcrs_execute_single_command(pcrs_command, buf, error); if (NULL == pcrs_command_tmp) { return NULL; } if (pcrs_command != original_pcrs_command) { freez(pcrs_command); } pcrs_command = pcrs_command_tmp; v++; } job = pcrs::pcrs_compile_command(pcrs_command, error); if (pcrs_command != original_pcrs_command) { freez(pcrs_command); } if (truncation) { *error = PCRS_WARN_TRUNCATION; } return job; }
void bitFree(Bits **pB) /* Free bits. */ { freez(pB); }
void submitRefToFiles(struct sqlConnection *conn, struct sqlConnection *conn2, struct sqlConnection *connSp, char *ref, char *fileRoot, char *inJax) /* Create a .ra and a .tab file for given reference. */ { /* Initially the tab file will have some duplicate lines, so * write to temp file, and then filter. */ char raName[PATH_LEN], tabName[PATH_LEN], capName[PATH_LEN]; FILE *ra = NULL, *tab = NULL, *cap = NULL; struct dyString *query = dyStringNew(0); struct sqlResult *sr; char **row; char *pubMed; struct slName *list, *el; boolean gotAny = FALSE; struct hash *uniqImageHash = newHash(0); struct hash *captionHash = newHash(0); int imageWidth = 0, imageHeight = 0; char path[PATH_LEN]; struct dyString *caption = dyStringNew(0); struct dyString *copyright = dyStringNew(0); struct dyString *probeNotes = dyStringNew(0); boolean lookedForCopyright = FALSE; safef(raName, sizeof(raName), "%s.ra", fileRoot); safef(tabName, sizeof(tabName), "%s.tab", fileRoot); safef(capName, sizeof(capName), "%s.txt", fileRoot); tab = mustOpen(tabName, "w"); cap = mustOpen(capName, "w"); sqlDyStringPrintf(query, "select authors,journal,title,year from BIB_Refs where "); sqlDyStringPrintf(query, "_Refs_key = '%s'", ref); sr = sqlGetResultVerbose(conn, query->string); row = sqlNextRow(sr); if (row == NULL) errAbort("Can't find _Refs_key %s in BIB_Refs", ref); /* Make ra file with stuff common to whole submission set. */ ra = mustOpen(raName, "w"); fprintf(ra, "submissionSource MGI\n"); fprintf(ra, "acknowledgement Thanks to the Gene Expression Database group at " "Mouse Genome Informatics (MGI) for collecting, annotating and sharing " "this image. The MGI images were last updated in VisiGene on March 28, 2006. " "Additional and more up to date annotations and images may be available " "directly at <A HREF='http://www.informatics.jax.org' target='_blank'>MGI.</A>\n"); fprintf(ra, "submitSet jax%s\n", ref); fprintf(ra, "taxon 10090\n"); /* Mus musculus taxon */ fprintf(ra, "fullDir http://hgwdev.gi.ucsc.edu/visiGene/full/inSitu/Mouse/jax\n"); fprintf(ra, "thumbDir http://hgwdev.gi.ucsc.edu/visiGene/200/inSitu/Mouse/jax\n"); fprintf(ra, "setUrl http://www.informatics.jax.org/\n"); fprintf(ra, "itemUrl http://www.informatics.jax.org/searches/image.cgi?%%s\n"); fprintf(ra, "abUrl http://www.informatics.jax.org/searches/antibody.cgi?%%s\n"); fprintf(ra, "journal %s\n", row[1]); fprintf(ra, "publication %s\n", row[2]); fprintf(ra, "year %s\n", row[3]); /* The contributor (author) list is in format Kent WJ; Haussler DH; format in * Jackson. We convert it to Kent W.J.,Haussler D.H., format for visiGene. */ fprintf(ra, "contributor "); list = charSepToSlNames(row[0], ';'); for (el = list; el != NULL; el = el->next) { char *lastName = skipLeadingSpaces(el->name); char *initials = strrchr(lastName, ' '); if (initials == NULL) initials = ""; else *initials++ = 0; fprintf(ra, "%s", lastName); if (initials[0] != 0) { char c; fprintf(ra, " "); while ((c = *initials++) != 0) fprintf(ra, "%c.", c); } fprintf(ra, ","); } fprintf(ra, "\n"); slNameFreeList(&list); sqlFreeResult(&sr); /* Add in link to PubMed record on publication. */ dyStringClear(query); sqlDyStringPrintf(query, "select ACC_Accession.accID from ACC_Accession,ACC_LogicalDB " "where ACC_Accession._Object_key = %s " "and ACC_Accession._LogicalDB_key = ACC_LogicalDB._LogicalDB_key " "and ACC_LogicalDB.name = 'PubMed'", ref); pubMed = sqlQuickStringVerbose(conn, query->string); if (pubMed != NULL) fprintf(ra, "pubUrl https://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=pubmed&dopt=Abstract&list_uids=%s\n", pubMed); freez(&pubMed); dyStringClear(query); sqlDyStringPrintf(query, "select distinct MRK_Marker.symbol as gene," "GXD_Specimen.sex as sex," "GXD_Specimen.age as age," "GXD_Specimen.ageMin as ageMin," "GXD_Specimen.ageMax as ageMax," "IMG_ImagePane.paneLabel as paneLabel," "ACC_Accession.numericPart as fileKey," "IMG_Image._Image_key as imageKey," "GXD_Assay._ProbePrep_key as probePrepKey," "GXD_Assay._AntibodyPrep_key as antibodyPrepKey," "GXD_Assay._ReporterGene_key as reporterGeneKey," "GXD_FixationMethod.fixation as fixation," "GXD_EmbeddingMethod.embeddingMethod as embedding," "GXD_Assay._Assay_key as assayKey," "GXD_Specimen.hybridization as sliceType," "GXD_Specimen._Genotype_key as genotypeKey," "IMG_ImagePane._ImagePane_key as imagePaneKey\n" "from MRK_Marker," "GXD_Assay," "GXD_Specimen," "GXD_InSituResult," "GXD_InSituResultImage," "GXD_FixationMethod," "GXD_EmbeddingMethod," "IMG_ImagePane," "IMG_Image," "ACC_Accession\n" "where MRK_Marker._Marker_key = GXD_Assay._Marker_key " "and GXD_Assay._Assay_key = GXD_Specimen._Assay_key " "and GXD_Specimen._Specimen_key = GXD_InSituResult._Specimen_key " "and GXD_InSituResult._Result_key = GXD_InSituResultImage._Result_key " "and GXD_InSituResultImage._ImagePane_key = IMG_ImagePane._ImagePane_key " "and GXD_FixationMethod._Fixation_key = GXD_Specimen._Fixation_key " "and GXD_EmbeddingMethod._Embedding_key = GXD_Specimen._Embedding_key " "and IMG_ImagePane._Image_key = IMG_Image._Image_key " "and IMG_Image._Image_key = ACC_Accession._Object_key " "and ACC_Accession.prefixPart = 'PIX:' " "and GXD_Assay._ImagePane_key is NULL " ); sqlDyStringPrintf(query, "and GXD_Assay._Refs_key = '%s'", ref); sr = sqlGetResultVerbose(conn, query->string); fprintf(tab, "#"); fprintf(tab, "gene\t"); fprintf(tab, "probeColor\t"); fprintf(tab, "sex\t"); fprintf(tab, "age\t"); fprintf(tab, "ageMin\t"); fprintf(tab, "ageMax\t"); fprintf(tab, "paneLabel\t"); fprintf(tab, "fileName\t"); fprintf(tab, "submitId\t"); fprintf(tab, "fPrimer\t"); fprintf(tab, "rPrimer\t"); fprintf(tab, "abName\t"); fprintf(tab, "abTaxon\t"); fprintf(tab, "abSubmitId\t"); fprintf(tab, "fixation\t"); fprintf(tab, "embedding\t"); fprintf(tab, "bodyPart\t"); fprintf(tab, "sliceType\t"); fprintf(tab, "genotype\t"); fprintf(tab, "strain\t"); fprintf(tab, "priority\t"); fprintf(tab, "captionId\t"); fprintf(tab, "imageWidth\t"); fprintf(tab, "imageHeight\n"); while ((row = sqlNextRow(sr)) != NULL) { char *gene = row[0]; char *sex = row[1]; char *age = row[2]; char *ageMin = row[3]; char *ageMax = row[4]; char *paneLabel = row[5]; char *fileKey = row[6]; char *imageKey = row[7]; char *probePrepKey = row[8]; char *antibodyPrepKey = row[9]; char *reporterGeneKey = row[10]; char *fixation = row[11]; char *embedding = row[12]; char *assayKey = row[13]; char *sliceType = row[14]; char *genotypeKey = row[15]; char *imagePaneKey = row[16]; double calcAge = -1; char *probeColor = ""; char *bodyPart = ""; char *abName = NULL; char *rPrimer = NULL, *fPrimer = NULL; char *genotype = NULL; char *strain = NULL; char *priority = NULL; char abTaxon[32]; char *captionId = ""; char *abSubmitId = NULL; verbose(3, " "); dumpRow(row, 16); if (age == NULL) continue; if (!lookedForCopyright) { struct sqlResult *sr = NULL; char **row; lookedForCopyright = TRUE; dyStringClear(query); sqlDyStringPrintf(query, "select note from MGI_NoteChunk,MGI_Note,MGI_NoteType,ACC_MGIType " "where MGI_Note._Object_key = %s " "and ACC_MGIType.name = 'Image' " "and ACC_MGIType._MGIType_key = MGI_Note._MGIType_key " "and MGI_NoteType.noteType='Copyright' " "and MGI_Note._NoteType_key = MGI_NoteType._NoteType_key " "and MGI_Note._Note_key = MGI_NoteChunk._Note_key " "order by sequenceNum" , imageKey); sr = sqlGetResultVerbose(conn2, query->string); while ((row = sqlNextRow(sr)) != NULL) dyStringAppend(copyright, row[0]); sqlFreeResult(&sr); verbose(2,"imageKey=%s\n",imageKey); if (copyright->stringSize != 0) { fprintf(ra, "copyright %s\n", copyright->string); } } /* Massage sex */ { if (sameString(sex, "Male")) sex = "male"; else if (sameString(sex, "Female")) sex = "female"; else sex = ""; } /* Massage age */ { char *embryoPat = "embryonic day "; char *newbornPat = "postnatal newborn"; char *dayPat = "postnatal day "; char *weekPat = "postnatal week "; char *adultPat = "postnatal adult"; double calcMinAge = atof(ageMin); double calcMaxAge = atof(ageMax); double mouseBirthAge = 21.0; //double mouseAdultAge = 63.0; /* Relative to conception, not birth */ if (age[0] == 0) { warn("age null, ageMin %s, ageMax %s\n", ageMin, ageMax); calcAge = (calcMinAge + calcMaxAge) * 0.5; } else if (startsWith(embryoPat, age)) calcAge = atof(age+strlen(embryoPat)); else if (sameString(newbornPat, age)) calcAge = mouseBirthAge; else if (startsWith(dayPat, age)) calcAge = atof(age+strlen(dayPat)) + mouseBirthAge; else if (startsWith(weekPat, age)) calcAge = 7.0 * atof(age+strlen(weekPat)) + mouseBirthAge; else if (sameString(adultPat, age) && calcMaxAge - calcMinAge > 1000 && calcMinAge < 365) calcAge = 365; /* Most adult mice are relatively young */ else { warn("Calculating age from %s", age); calcAge = (calcMinAge + calcMaxAge) * 0.5; } if (calcAge < calcMinAge) calcAge = calcMinAge; if (calcAge > calcMaxAge) calcAge = calcMaxAge; } /* Massage probeColor */ { if (!isStrNull(reporterGeneKey)) { /* Fixme: make sure that reporterGene's end up in probeType table. */ char *name = NULL; dyStringClear(query); sqlDyStringPrintf(query, "select term from VOC_Term where _Term_key = %s", reporterGeneKey); name = sqlQuickStringVerbose(conn2, query->string); if (name == NULL) warn("Can't find _ReporterGene_key %s in VOC_Term", reporterGeneKey); else if (sameString(name, "GFP")) probeColor = "green"; else if (sameString(name, "lacZ")) probeColor = "blue"; else warn("Don't know color of reporter gene %s", name); freez(&name); } if (!isStrNull(probePrepKey)) { char *name = NULL; dyStringClear(query); sqlDyStringPrintf(query, "select GXD_VisualizationMethod.visualization " "from GXD_VisualizationMethod,GXD_ProbePrep " "where GXD_ProbePrep._ProbePrep_key = %s " "and GXD_ProbePrep._Visualization_key = GXD_VisualizationMethod._Visualization_key" , probePrepKey); name = sqlQuickStringVerbose(conn2, query->string); if (name == NULL) warn("Can't find visualization from _ProbePrep_key %s", probePrepKey); probeColor = colorFromLabel(name, gene); freez(&name); if (probeColor[0] == 0) { dyStringClear(query); sqlDyStringPrintf(query, "select GXD_Label.label from GXD_Label,GXD_ProbePrep " "where GXD_ProbePrep._ProbePrep_key = %s " "and GXD_ProbePrep._Label_key = GXD_Label._Label_key" , probePrepKey); name = sqlQuickStringVerbose(conn2, query->string); if (name == NULL) warn("Can't find label from _ProbePrep_key %s", probePrepKey); probeColor = colorFromLabel(name, gene); } freez(&name); } if (!isStrNull(antibodyPrepKey) && probeColor[0] == 0 ) { char *name = NULL; dyStringClear(query); sqlDyStringPrintf(query, "select GXD_Label.label from GXD_Label,GXD_AntibodyPrep " "where GXD_AntibodyPrep._AntibodyPrep_key = %s " "and GXD_AntibodyPrep._Label_key = GXD_Label._Label_key" , antibodyPrepKey); name = sqlQuickStringVerbose(conn2, query->string); if (name == NULL) warn("Can't find label from _AntibodyPrep_key %s", antibodyPrepKey); probeColor = colorFromLabel(name, gene); freez(&name); } } /* Get abName, abTaxon, abSubmitId */ abTaxon[0] = 0; if (!isStrNull(antibodyPrepKey)) { struct sqlResult *sr = NULL; int orgKey = 0; char **row; dyStringClear(query); sqlDyStringPrintf(query, "select antibodyName,_Organism_key,GXD_Antibody._Antibody_key " "from GXD_AntibodyPrep,GXD_Antibody " "where GXD_AntibodyPrep._AntibodyPrep_key = %s " "and GXD_AntibodyPrep._Antibody_key = GXD_Antibody._Antibody_key" , antibodyPrepKey); sr = sqlGetResultVerbose(conn2, query->string); row = sqlNextRow(sr); if (row != NULL) { abName = cloneString(row[0]); orgKey = atoi(row[1]); abSubmitId = cloneString(row[2]); } sqlFreeResult(&sr); if (orgKey > 0) { char *latinName = NULL, *commonName = NULL; int spTaxon = 0; dyStringClear(query); sqlDyStringPrintf(query, "select latinName from MGI_Organism " "where _Organism_key = %d", orgKey); latinName = sqlQuickStringVerbose(conn2, query->string); if (latinName != NULL && !sameString(latinName, "Not Specified") && !sameString(latinName, "Not Applicable")) { char *e = strchr(latinName, '/'); if (e != NULL) *e = 0; /* Chop off / and after. */ spTaxon = spBinomialToTaxon(connSp, latinName); } else { dyStringClear(query); sqlDyStringPrintf(query, "select commonName from MGI_Organism " "where _Organism_key = %d", orgKey); commonName = sqlQuickStringVerbose(conn2, query->string); if (commonName != NULL && !sameString(commonName, "Not Applicable") && !sameString(commonName, "Not Specified")) { spTaxon = spCommonToTaxon(connSp, commonName); } } if (spTaxon != 0) safef(abTaxon, sizeof(abTaxon), "%d", spTaxon); freez(&latinName); freez(&commonName); } } if (abName == NULL) abName = cloneString(""); if (abSubmitId == NULL) abSubmitId = cloneString(""); /* Get rPrimer, lPrimer */ if (!isStrNull(probePrepKey)) { struct sqlResult *sr = NULL; char **row; dyStringClear(query); sqlDyStringPrintf(query, "select primer1sequence,primer2sequence " "from PRB_Probe,GXD_ProbePrep " "where PRB_Probe._Probe_key = GXD_ProbePrep._Probe_key " "and GXD_ProbePrep._ProbePrep_key = %s" , probePrepKey); sr = sqlGetResultVerbose(conn2, query->string); row = sqlNextRow(sr); if (row != NULL) { fPrimer = cloneString(row[0]); rPrimer = cloneString(row[1]); } sqlFreeResult(&sr); } /* Note Jackson database actually stores the primers very * erratically. In all the cases I can find for in situs * the primers are actually stored in free text in the PRB_Notes * e.g. ... primers CGCGGATCCAGGGGAAACAGAAGGGCTGCG and CCCAAGCTTAGACTGTACAGGCTGAGCC ... */ if (fPrimer == NULL || fPrimer[0]==0) { struct sqlResult *sr = NULL; char **row; dyStringClear(query); sqlDyStringPrintf(query, "select PRB_Notes.note from GXD_ProbePrep, PRB_Notes" " where GXD_ProbePrep._ProbePrep_key = %s" " and GXD_ProbePrep._Probe_key = PRB_Notes._Probe_key" " order by PRB_Notes.sequenceNum" , probePrepKey); sr = sqlGetResultVerbose(conn2, query->string); dyStringClear(probeNotes); while ((row = sqlNextRow(sr)) != NULL) dyStringAppend(probeNotes, row[0]); sqlFreeResult(&sr); if (probeNotes->stringSize > 0) { char f[256]; char r[256]; int i = 0; char *s = strstr(probeNotes->string," primers "); if (s) { s += strlen(" primers "); i = 0; while (strchr("ACGT",*s) && (i<sizeof(f))) f[i++] = *s++; f[i]=0; if (strstr(s," and ")==s) { s += strlen(" and "); i = 0; while (strchr("ACGT",*s) && (i<sizeof(r))) r[i++] = *s++; r[i]=0; if (strlen(f) >= 10 && strlen(r) >= 10) { fPrimer = cloneString(f); rPrimer = cloneString(r); } else { verbose(1, "bad primer parse:_ProbePrep_key=%s fPrimer=[%s], rPrimer=[%s]\n", probePrepKey,f,r); } } } } } if (fPrimer == NULL) fPrimer = cloneString(""); if (rPrimer == NULL) rPrimer = cloneString(""); fixation = blankOutUnknown(fixation); embedding = blankOutUnknown(embedding); /* Massage body part and slice type. We only handle whole mounts. */ if (sameString(sliceType, "whole mount")) { bodyPart = "whole"; priority = "100"; } else { sliceType = ""; priority = "1000"; } genotypeAndStrainFromKey(genotypeKey, conn2, &genotype, &strain); if (isStrNull(paneLabel)) paneLabel = cloneString(""); /* trying to suppress nulls in output */ stripChar(paneLabel, '"'); /* Get rid of a difficult quote to process. */ /* Fetch image dimensions from file. */ imageWidth=0; imageHeight=0; safef(path, sizeof(path), "%s/%s.jpg", inJax, fileKey); if (fileExists(path)) jpegSize(path,&imageWidth,&imageHeight); /* will errAbort if no valid .jpeg exists */ else warn("Picture Missing! %s ",path); /* Deal caption if any. Most of the work only happens the * first time see the image. */ if (!hashLookup(uniqImageHash, imageKey)) { struct sqlResult *sr = NULL; char **row; hashAdd(uniqImageHash, imageKey, NULL); dyStringClear(caption); dyStringClear(query); sqlDyStringPrintf(query, "select note from MGI_NoteChunk,MGI_Note,MGI_NoteType,ACC_MGIType " "where MGI_Note._Object_key = %s " "and ACC_MGIType.name = 'Image' " "and ACC_MGIType._MGIType_key = MGI_Note._MGIType_key " "and MGI_NoteType.noteType='Caption' " "and MGI_Note._NoteType_key = MGI_NoteType._NoteType_key " "and MGI_Note._Note_key = MGI_NoteChunk._Note_key " "order by sequenceNum" , imageKey); sr = sqlGetResultVerbose(conn2, query->string); while ((row = sqlNextRow(sr)) != NULL) dyStringAppend(caption, row[0]); sqlFreeResult(&sr); if (caption->stringSize > 0) { subChar(caption->string, '\t', ' '); subChar(caption->string, '\n', ' '); fprintf(cap, "%s\t%s\n", imageKey, caption->string); hashAdd(captionHash, imageKey, imageKey); } } if (hashLookup(captionHash, imageKey)) captionId = imageKey; else captionId = ""; fprintf(tab, "%s\t", gene); fprintf(tab, "%s\t", probeColor); fprintf(tab, "%s\t", sex); fprintf(tab, "%3.2f\t", calcAge); fprintf(tab, "%s\t", ageMin); fprintf(tab, "%s\t", ageMax); fprintf(tab, "%s\t", paneLabel); /* may have to change NULL to empty string or "0" ? */ fprintf(tab, "%s.jpg\t", fileKey); fprintf(tab, "%s\t", imageKey); fprintf(tab, "%s\t", fPrimer); fprintf(tab, "%s\t", rPrimer); fprintf(tab, "%s\t", abName); fprintf(tab, "%s\t", abTaxon); fprintf(tab, "%s\t", abSubmitId); fprintf(tab, "%s\t", fixation); fprintf(tab, "%s\t", embedding); fprintf(tab, "%s\t", bodyPart); fprintf(tab, "%s\t", sliceType); fprintf(tab, "%s\t", genotype); fprintf(tab, "%s\t", strain); fprintf(tab, "%s\t", priority); fprintf(tab, "%s\t", captionId); fprintf(tab, "%d\t", imageWidth); fprintf(tab, "%d\n", imageHeight); printExpression(tab, conn2, imagePaneKey, assayKey); gotAny = TRUE; freez(&genotype); freez(&abName); freez(&abSubmitId); freez(&rPrimer); freez(&fPrimer); } sqlFreeResult(&sr); carefulClose(&ra); carefulClose(&tab); carefulClose(&cap); if (!gotAny) { remove(raName); remove(capName); remove(tabName); } dyStringFree(&probeNotes); dyStringFree(©right); dyStringFree(&caption); dyStringFree(&query); hashFree(&uniqImageHash); hashFree(&captionHash); }
void configPageSetTrackVis(int vis) /* Do config page after setting track visibility. If vis is -2, then visibility * is unchanged. If -1 then set visibility to default, otherwise it should * be tvHide, tvDense, etc. */ { struct dyString *title = dyStringNew(0); char *groupTarget = NULL; struct track *trackList = NULL; struct track *ideoTrack = NULL; struct group *groupList = NULL; withPriorityOverride = cartUsualBoolean(cart, configPriorityOverride, FALSE); /* Get track list and group them. */ ctList = customTracksParseCart(database, cart, &browserLines, &ctFileName); trackList = getTrackList(&groupList, vis); /* The ideogram for some reason is considered a track. * We don't really want to process it as one though, so * we see if it's there, and if necessary remove it. */ ideoTrack = chromIdeoTrack(trackList); if (ideoTrack != NULL) removeTrackFromGroup(ideoTrack); /* Fetch group to change on if any from CGI, * and remove var so it doesn't get used again. */ groupTarget = cloneString(cartUsualString(cart, configGroupTarget, "")); cartRemove(cart, configGroupTarget); if (sameString(groupTarget, "none")) freez(&groupTarget); dyStringPrintf(title, "Configure Image"); hPrintf("<FORM ACTION=\"%s\" NAME=\"mainForm\" METHOD=%s>\n", hgTracksName(), cartUsualString(cart, "formMethod", "POST")); webStartWrapperDetailedNoArgs(cart, database, "", title->string, FALSE, FALSE, FALSE, FALSE); cartSaveSession(cart); hPrintf("<INPUT TYPE=HIDDEN NAME=\"hgTracksConfigPage\" VALUE=\"\">"); /* do not want all the submit buttons named the same thing, this one is: */ cgiMakeButton("topSubmit", "submit"); // 3 column table hPrintf("<TABLE style=\"border:0px; \">\n"); hPrintf("<TR><TD>image width:"); hPrintf("<TD style=\"text-align: right\">"); hIntVar("pix", tl.picWidth, 4); hPrintf("<TD>pixels</TR>"); hPrintf("<TR><TD>label area width:"); hPrintf("<TD style=\"text-align: right\">"); hIntVar("hgt.labelWidth", leftLabelWidthChars, 2); hPrintf("<TD>characters<TD></TR>"); hPrintf("<TR><TD>text size:"); hPrintf("<TD style=\"text-align: right\">"); textSizeDropDown(); hPrintf("<TD>"); if (trackLayoutInclFontExtras()) { char *defaultStyle = cartUsualString(cart, "fontType", "medium"); cartMakeRadioButton(cart, "fontType", "medium", defaultStyle); hPrintf(" medium "); cartMakeRadioButton(cart, "fontType", "fixed", defaultStyle); hPrintf(" fixed "); cartMakeRadioButton(cart, "fontType", "bold", defaultStyle); hPrintf(" bold "); hPrintf(" "); } hPrintf("<TR><BR>"); hTableStart(); if (ideoTrack != NULL) { hPrintf("<TR><TD>"); hCheckBox("ideogram", cartUsualBoolean(cart, "ideogram", TRUE)); hPrintf("</TD><TD>"); hPrintf("Display chromosome ideogram above main graphic"); hPrintf("</TD></TR>\n"); } hPrintf("<TR><TD>"); hCheckBox("guidelines", cartUsualBoolean(cart, "guidelines", TRUE)); hPrintf("</TD><TD>"); hPrintf("Show light blue vertical guidelines"); hPrintf("</TD></TR>\n"); hPrintf("<TR><TD>"); hCheckBox("leftLabels", cartUsualBoolean(cart, "leftLabels", TRUE)); hPrintf("</TD><TD>"); hPrintf("Display labels to the left of items in tracks"); hPrintf("</TD></TR>\n"); hPrintf("<TR><TD>"); hCheckBox("centerLabels", cartUsualBoolean(cart, "centerLabels", TRUE)); hPrintf("</TD><TD>"); hPrintf("Display description above each track"); hPrintf("</TD></TR>\n"); hPrintf("<TR><TD>"); hCheckBox("trackControlsOnMain", cartUsualBoolean(cart, "trackControlsOnMain", TRUE)); hPrintf("</TD><TD>"); hPrintf("Show track controls under main graphic"); hPrintf("</TD></TR>\n"); hPrintf("<TR><TD>"); hCheckBox("nextItemArrows", cartUsualBoolean(cart, "nextItemArrows", FALSE)); hPrintf("</TD><TD>"); hPrintf("Next/previous item navigation"); hPrintf("</TD></TR>\n"); hPrintf("<TR><TD>"); hCheckBox("nextExonArrows", cartUsualBoolean(cart, "nextExonArrows", TRUE)); hPrintf("</TD><TD>"); hPrintf("Next/previous exon navigation"); hPrintf("</TD></TR>\n"); #ifdef PRIORITY_CHANGES_IN_CONFIG_UI hPrintf("<TR><TD>"); char *javascript="onClick=\"document.mainForm.hgTracksConfigPage.value='configure';document.mainForm.submit();\""; hCheckBoxJS(configPriorityOverride, cartUsualBoolean(cart, configPriorityOverride , FALSE), javascript); hPrintf("</TD><TD>"); hPrintf("Enable track re-ordering"); hPrintf("</TD></TR>\n"); #endif///def PRIORITY_CHANGES_IN_CONFIG_UI hPrintf("<TR><TD>"); hCheckBox("enableAdvancedJavascript", advancedJavascriptFeaturesEnabled(cart)); hPrintf("</TD><TD>"); hPrintf("Enable advanced javascript features"); hPrintf("</TD></TR>\n"); hTableEnd(); char *freeze = hFreezeFromDb(database); char buf[128]; if (stringIn(database, freeze)) safef(buf, sizeof buf, "Configure Tracks on %s %s: %s %s", organization, browserName, organism, freeze); else safef(buf, sizeof buf, "Configure Tracks on %s %s: %s %s (%s)", organization, browserName, organism, freeze, database); webNewSection(buf); hPrintf("Tracks: "); if(isSearchTracksSupported(database,cart)) { cgiMakeButtonWithMsg(TRACK_SEARCH, TRACK_SEARCH_BUTTON,TRACK_SEARCH_HINT); hPrintf(" "); } cgiMakeButtonWithMsg(configHideAll, "hide all","Hide all tracks in this genome assembly"); hPrintf(" "); cgiMakeButtonWithMsg(configShowAll, "show all","Show all tracks in this genome assembly"); hPrintf(" "); cgiMakeButtonWithMsg(configDefaultAll, "default","Display only default tracks"); hPrintf(" Groups: "); hButtonWithOnClick("hgt.collapseGroups", "collapse all", "Collapse all track groups", "return setAllTrackGroupVisibility(false)"); hPrintf(" "); hButtonWithOnClick("hgt.expandGroups", "expand all", "Expand all track groups", "return setAllTrackGroupVisibility(true)"); hPrintf("<P STYLE=\"margin-top:5;\">Control track and group visibility more selectively below.<P>"); trackConfig(trackList, groupList, groupTarget, vis); dyStringFree(&title); freez(&groupTarget); webEndSectionTables(); hPrintf("</FORM>"); }
static void loadDatabase(char *database, char *track, int bedSize, struct bedStub *bedList) /* Load database from bedList. */ { struct sqlConnection *conn; struct dyString *dy = newDyString(1024); char *tab = (char *)NULL; int loadOptions = (optionExists("onServer") ? SQL_TAB_FILE_ON_SERVER : 0); if ( ! noLoad ) conn = sqlConnect(database); if ((char *)NULL != tmpDir) tab = cloneString(rTempName(tmpDir,"loadBed",".tab")); else tab = cloneString("bed.tab"); if (bedDetail && sqlTable == NULL) errAbort("bedDetail format requires sqlTable option"); if (bedDetail && !strictTab) errAbort("bedDetail format must be tab separated"); if (bedDetail && !noBin) noBin = TRUE; /* First make table definition. */ if (sqlTable != NULL && !oldTable) { /* Read from file. */ char *sql, *s; readInGulp(sqlTable, &sql, NULL); /* Chop off end-of-statement semicolon if need be. */ s = strchr(sql, ';'); if (s != NULL) *s = 0; if ( !noLoad ) { if (renameSqlTable) { char *pos = stringIn("CREATE TABLE ", sql); if (pos == NULL) errAbort("Can't find CREATE TABLE in %s\n", sqlTable); char *oldSql = cloneString(sql); nextWord(&pos); nextWord(&pos); char *tableName = nextWord(&pos); sql = replaceChars(oldSql, tableName, track); } verbose(1, "Creating table definition for %s\n", track); sqlRemakeTable(conn, track, sql); if (!noBin) addBinToEmptyTable(conn, track); adjustSqlTableColumns(conn, track, bedSize); } freez(&sql); } else if (!oldTable) { int minLength; if (noLoad) minLength=6; else if (maxChromNameLength) minLength = maxChromNameLength; else minLength = hGetMinIndexLength(database); verbose(2, "INDEX chrom length: %d\n", minLength); /* Create definition statement. */ verbose(1, "Creating table definition for %s\n", track); dyStringPrintf(dy, "CREATE TABLE %s (\n", track); if (!noBin) dyStringAppend(dy, " bin smallint unsigned not null,\n"); dyStringAppend(dy, " chrom varchar(255) not null,\n"); dyStringAppend(dy, " chromStart int unsigned not null,\n"); dyStringAppend(dy, " chromEnd int unsigned not null,\n"); if (bedSize >= 4) maybeBedGraph(4, dy, " name varchar(255) not null,\n"); if (bedSize >= 5) { if (allowNegativeScores) maybeBedGraph(5, dy, " score int not null,\n"); else maybeBedGraph(5, dy, " score int unsigned not null,\n"); } if (bedSize >= 6) maybeBedGraph(6, dy, " strand char(1) not null,\n"); if (bedSize >= 7) maybeBedGraph(7, dy, " thickStart int unsigned not null,\n"); if (bedSize >= 8) maybeBedGraph(8, dy, " thickEnd int unsigned not null,\n"); /* As of 2004-11-22 the reserved field is used as itemRgb in code */ if (bedSize >= 9) maybeBedGraph(9, dy, " reserved int unsigned not null,\n"); if (bedSize >= 10) maybeBedGraph(10, dy, " blockCount int unsigned not null,\n"); if (bedSize >= 11) maybeBedGraph(11, dy, " blockSizes longblob not null,\n"); if (bedSize >= 12) maybeBedGraph(12, dy, " chromStarts longblob not null,\n"); if (bedSize >= 13) maybeBedGraph(13, dy, " expCount int unsigned not null,\n"); if (bedSize >= 14) maybeBedGraph(14, dy, " expIds longblob not null,\n"); if (bedSize >= 15) maybeBedGraph(15, dy, " expScores longblob not null,\n"); dyStringAppend(dy, "#Indices\n"); if (nameIx && (bedSize >= 4) && (0 == bedGraph)) dyStringAppend(dy, " INDEX(name(16)),\n"); if (noBin) { dyStringPrintf(dy, " INDEX(chrom(%d),chromStart)\n", minLength); } else { dyStringPrintf(dy, " INDEX(chrom(%d),bin)\n", minLength); } dyStringAppend(dy, ")\n"); if (noLoad) verbose(2,"%s", dy->string); else sqlRemakeTable(conn, track, dy->string); } verbose(1, "Saving %s\n", tab); writeBedTab(tab, bedList, bedSize); if ( ! noLoad ) { verbose(1, "Loading %s\n", database); if (customTrackLoader) sqlLoadTabFile(conn, tab, track, loadOptions|SQL_TAB_FILE_WARN_ON_WARN); else sqlLoadTabFile(conn, tab, track, loadOptions); if (! noHistory) { char comment[256]; /* add a comment to the history table and finish up connection */ safef(comment, sizeof(comment), "Add %d element(s) from bed list to %s table", slCount(bedList), track); hgHistoryComment(conn, comment); } if(fillInScoreColumn != NULL) { char query[500]; char buf[500]; struct sqlResult *sr; safef(query, sizeof(query), "select sum(score) from %s", track); if(sqlQuickQuery(conn, query, buf, sizeof(buf))) { unsigned sum = sqlUnsigned(buf); if (!sum) { safef(query, sizeof(query), "select min(%s), max(%s) from %s", fillInScoreColumn, fillInScoreColumn, track); if ((sr = sqlGetResult(conn, query)) != NULL) { char **row = sqlNextRow(sr); if(row != NULL) { float min = sqlFloat(row[0]); float max = sqlFloat(row[1]); if ( !(max == -1 && min == -1)) // if score is -1 then ignore, as if it werent present { if (max == min || sameString(row[0],row[1])) // this will lead to 'inf' score value in SQL update causing an error errAbort("Could not set score in table %s max(%s)=min(%s)=%s\n", track, fillInScoreColumn, fillInScoreColumn, row[0]); sqlFreeResult(&sr); // Calculate a, b s/t f(x) = ax + b maps min-max => minScore-1000 float a = (1000-minScore) / (max - min); float b = 1000 - ((1000-minScore) * max) / (max - min); safef(query, sizeof(query), "update %s set score = round((%f * %s) + %f)", track, a, fillInScoreColumn, b); int changed = sqlUpdateRows(conn, query, NULL); verbose(2, "update query: %s; changed: %d\n", query, changed); } else { sqlFreeResult(&sr); verbose(2, "score not updated; all values for column %s are -1\n", fillInScoreColumn); } } } } } } sqlDisconnect(&conn); /* if temp dir specified, unlink file to make it disappear */ if ((char *)NULL != tmpDir) unlink(tab); } else verbose(1, "No load option selected, see file: %s\n", tab); } /* static void loadDatabase() */
// read the whole mountinfo into a linked list struct mountinfo *mountinfo_read(int do_statvfs) { char filename[FILENAME_MAX + 1]; snprintfz(filename, FILENAME_MAX, "%s/proc/self/mountinfo", netdata_configured_host_prefix); procfile *ff = procfile_open(filename, " \t", PROCFILE_FLAG_DEFAULT); if(unlikely(!ff)) { snprintfz(filename, FILENAME_MAX, "%s/proc/1/mountinfo", netdata_configured_host_prefix); ff = procfile_open(filename, " \t", PROCFILE_FLAG_DEFAULT); if(unlikely(!ff)) return NULL; } ff = procfile_readall(ff); if(unlikely(!ff)) return NULL; struct mountinfo *root = NULL, *last = NULL, *mi = NULL; unsigned long l, lines = procfile_lines(ff); for(l = 0; l < lines ;l++) { if(unlikely(procfile_linewords(ff, l) < 5)) continue; mi = mallocz(sizeof(struct mountinfo)); unsigned long w = 0; mi->id = str2ul(procfile_lineword(ff, l, w)); w++; mi->parentid = str2ul(procfile_lineword(ff, l, w)); w++; char *major = procfile_lineword(ff, l, w), *minor; w++; for(minor = major; *minor && *minor != ':' ;minor++) ; if(unlikely(!*minor)) { error("Cannot parse major:minor on '%s' at line %lu of '%s'", major, l + 1, filename); freez(mi); continue; } *minor = '\0'; minor++; mi->flags = 0; mi->major = str2ul(major); mi->minor = str2ul(minor); mi->root = strdupz(procfile_lineword(ff, l, w)); w++; mi->root_hash = simple_hash(mi->root); mi->mount_point = strdupz_decoding_octal(procfile_lineword(ff, l, w)); w++; mi->mount_point_hash = simple_hash(mi->mount_point); mi->persistent_id = strdupz(mi->mount_point); netdata_fix_chart_id(mi->persistent_id); mi->persistent_id_hash = simple_hash(mi->persistent_id); mi->mount_options = strdupz(procfile_lineword(ff, l, w)); w++; if(unlikely(is_read_only(mi->mount_options))) mi->flags |= MOUNTINFO_READONLY; // count the optional fields /* unsigned long wo = w; */ mi->optional_fields_count = 0; char *s = procfile_lineword(ff, l, w); while(*s && *s != '-') { w++; s = procfile_lineword(ff, l, w); mi->optional_fields_count++; } /* if(unlikely(mi->optional_fields_count)) { // we have some optional fields // read them into a new array of pointers; mi->optional_fields = mallocz(mi->optional_fields_count * sizeof(char *)); int i; for(i = 0; i < mi->optional_fields_count ; i++) { *mi->optional_fields[wo] = strdupz(procfile_lineword(ff, l, w)); wo++; } } else mi->optional_fields = NULL; */ if(likely(*s == '-')) { w++; mi->filesystem = strdupz(procfile_lineword(ff, l, w)); w++; mi->filesystem_hash = simple_hash(mi->filesystem); mi->mount_source = strdupz_decoding_octal(procfile_lineword(ff, l, w)); w++; mi->mount_source_hash = simple_hash(mi->mount_source); mi->super_options = strdupz(procfile_lineword(ff, l, w)); w++; if(unlikely(is_read_only(mi->super_options))) mi->flags |= MOUNTINFO_READONLY; if(unlikely(ME_DUMMY(mi->mount_source, mi->filesystem))) mi->flags |= MOUNTINFO_IS_DUMMY; if(unlikely(ME_REMOTE(mi->mount_source, mi->filesystem))) mi->flags |= MOUNTINFO_IS_REMOTE; // mark as BIND the duplicates (i.e. same filesystem + same source) if(do_statvfs) { struct stat buf; if(unlikely(stat(mi->mount_point, &buf) == -1)) { mi->st_dev = 0; mi->flags |= MOUNTINFO_NO_STAT; } else { mi->st_dev = buf.st_dev; struct mountinfo *mt; for(mt = root; mt; mt = mt->next) { if(unlikely(mt->st_dev == mi->st_dev && !(mt->flags & MOUNTINFO_IS_SAME_DEV))) { if(strlen(mi->mount_point) < strlen(mt->mount_point)) mt->flags |= MOUNTINFO_IS_SAME_DEV; else mi->flags |= MOUNTINFO_IS_SAME_DEV; } } } } else { mi->st_dev = 0; } } else { mi->filesystem = NULL; mi->filesystem_hash = 0; mi->mount_source = NULL; mi->mount_source_hash = 0; mi->super_options = NULL; mi->st_dev = 0; } // check if it has size if(do_statvfs && !(mi->flags & MOUNTINFO_IS_DUMMY)) { struct statvfs buff_statvfs; if(unlikely(statvfs(mi->mount_point, &buff_statvfs) < 0)) { mi->flags |= MOUNTINFO_NO_STAT; } else if(unlikely(!buff_statvfs.f_blocks /* || !buff_statvfs.f_files */)) { mi->flags |= MOUNTINFO_NO_SIZE; } } // link it if(unlikely(!root)) root = mi; else last->next = mi; last = mi; mi->next = NULL; /* #ifdef NETDATA_INTERNAL_CHECKS fprintf(stderr, "MOUNTINFO: %ld %ld %lu:%lu root '%s', persistent id '%s', mount point '%s', mount options '%s', filesystem '%s', mount source '%s', super options '%s'%s%s%s%s%s%s\n", mi->id, mi->parentid, mi->major, mi->minor, mi->root, mi->persistent_id, (mi->mount_point)?mi->mount_point:"", (mi->mount_options)?mi->mount_options:"", (mi->filesystem)?mi->filesystem:"", (mi->mount_source)?mi->mount_source:"", (mi->super_options)?mi->super_options:"", (mi->flags & MOUNTINFO_IS_DUMMY)?" DUMMY":"", (mi->flags & MOUNTINFO_IS_BIND)?" BIND":"", (mi->flags & MOUNTINFO_IS_REMOTE)?" REMOTE":"", (mi->flags & MOUNTINFO_NO_STAT)?" NOSTAT":"", (mi->flags & MOUNTINFO_NO_SIZE)?" NOSIZE":"", (mi->flags & MOUNTINFO_IS_SAME_DEV)?" SAMEDEV":"" ); #endif */ } /* find if the mount options have "bind" in them { FILE *fp = setmntent(MOUNTED, "r"); if (fp != NULL) { struct mntent mntbuf; struct mntent *mnt; char buf[4096 + 1]; while ((mnt = getmntent_r(fp, &mntbuf, buf, 4096))) { char *bind = hasmntopt(mnt, "bind"); if(unlikely(bind)) { struct mountinfo *mi; for(mi = root; mi ; mi = mi->next) { if(unlikely(strcmp(mnt->mnt_dir, mi->mount_point) == 0)) { fprintf(stderr, "Mount point '%s' is BIND\n", mi->mount_point); mi->flags |= MOUNTINFO_IS_BIND; break; } } #ifdef NETDATA_INTERNAL_CHECKS if(unlikely(!mi)) { error("Mount point '%s' not found in /proc/self/mountinfo", mnt->mnt_dir); } #endif } } endmntent(fp); } } */ procfile_close(ff); return root; }
void correlateFree(struct correlate **pC) /* Free up correlator. */ { freez(pC); }
/********************************************************************* * * Function : pcrs_compile_command * * Description : Parses a string with a Perl-style s/// command, * calls pcrs_compile, and returns a corresponding * pcrs_job, or NULL if parsing or compiling the job * fails. * * Parameters : * 1 : command = string with perl-style s/// command * 2 : errptr = pointer to an integer in which error * conditions can be returned. * * Returns : a corresponding pcrs_job data structure, or NULL * if an error was encountered. In that case, *errptr * has the reason. * *********************************************************************/ pcrs_job* pcrs::pcrs_compile_command(const char *command, int *errptr) { int i, k, l, quoted = FALSE; size_t limit; char delimiter; char *tokens[4]; pcrs_job *newjob; k = l = 0; /* * Tokenize the perl command */ limit = strlen(command); if (limit < 4) { *errptr = PCRS_ERR_CMDSYNTAX; return NULL; } else { delimiter = command[1]; } tokens[l] = (char *) malloc(limit + 1); for (i = 0; i <= (int)limit; i++) { if (command[i] == delimiter && !quoted) { if (l == 3) { l = -1; break; } tokens[0][k++] = '\0'; tokens[++l] = tokens[0] + k; continue; } else if (command[i] == '\\' && !quoted) { quoted = TRUE; if (command[i+1] == delimiter) continue; } else { quoted = FALSE; } tokens[0][k++] = command[i]; } /* * Syntax error ? */ if (l != 3) { *errptr = PCRS_ERR_CMDSYNTAX; freez(tokens[0]); return NULL; } newjob = pcrs::pcrs_compile(tokens[1], tokens[2], tokens[3], errptr); freez(tokens[0]); return newjob; }
void doRun(char *line, struct sockaddr_in *hubIp) /* Execute command. */ { char *jobMessage = cloneString(line); static char *args[1024]; int argCount; char hubDottedQuad[17]; nextRandom(); if (line == NULL) warn("Executing nothing..."); else if (!internetIpToDottedQuad(ntohl(hubIp->sin_addr.s_addr), hubDottedQuad)) warn("Can't convert ipToDottedQuad"); else { struct runJobMessage rjm; if (parseRunJobMessage(line, &rjm)) { int jobId = atoi(rjm.jobIdString); if (findRunningJob(jobId) == NULL && findFinishedJob(jobId) == NULL) { if (busyProcs < maxProcs) { int childPid; argCount = chopLine(rjm.command, args); if (argCount >= ArraySize(args)) warn("Too many arguments to run"); else { args[argCount] = NULL; if ((childPid = forkOrDie()) == 0) { /* Do JOB_ID substitutions */ struct subText *st = subTextNew("$JOB_ID", rjm.jobIdString); int i; rjm.in = subTextString(st, rjm.in); rjm.out = subTextString(st, rjm.out); rjm.err = subTextString(st, rjm.err); for (i=0; i<argCount; ++i) args[i] = subTextString(st, args[i]); execProc(hubDottedQuad, rjm.jobIdString, rjm.reserved, rjm.user, rjm.dir, rjm.in, rjm.out, rjm.err, rjm.ram, args[0], args); exit(0); } else { struct job *job; AllocVar(job); job->jobId = atoi(rjm.jobIdString); job->pid = childPid; job->startMessage = jobMessage; jobMessage = NULL; /* No longer own memory. */ job->node = dlAddValTail(jobsRunning, job); ++busyProcs; } } } else { warn("Trying to run when busy."); } } else { warn("Duplicate run-job %d\n", jobId); } } } freez(&jobMessage); }
void hashElFree(struct hashEl **pEl) /* Free hash el list returned from hashListAll. (Don't use * this internally.) */ { freez(pEl); }
void printMimeInfo(struct mimePart *mp, FILE *out, int level) /* print mimeParts recursively if needed */ { char *cd = NULL, *cdMain = NULL, *cdName = NULL, *cdFileName = NULL, *ct = NULL, *ce = NULL; char *margin = needMem(level+1); int i = 0; for(i=0;i<level;++i) margin[i] = ' '; margin[level] = 0; cd = hashFindVal(mp->hdr,"content-disposition"); ct = hashFindVal(mp->hdr,"content-type"); ce = hashFindVal(mp->hdr,"content-transfer-encoding"); if (cd) { fprintf(out,"%scontent-disposition: %s\n",margin,cd); cdMain=getMimeHeaderMainVal(cd); cdName=getMimeHeaderFieldVal(cd,"name"); fprintf(out,"%smain:[%s]\n",margin,cdMain); fprintf(out,"%sname:[%s]\n",margin,cdName); cdFileName=getMimeHeaderFieldVal(cd,"filename"); if (cdFileName) fprintf(out,"%sfilename:[%s]\n",margin,cdFileName); } if (ct) fprintf(out,"%scontent-type: %s\n",margin,ct); if (ce) fprintf(out,"%scontent-transer-encoding: %s\n",margin,ce); if (cd) { fprintf(out,"%ssize:[%llu]\n",margin,(unsigned long long) mp->size); if (mp->binary) fprintf(out,"%sbinary (contains zeros)\n",margin); if (mp->fileName) fprintf(out,"%sfileName=[%s]\n",margin, mp->fileName); fprintf(out,"%sdata:[%s]\n",margin, mp->binary && mp->data ? "<binary data not safe to print>" : mp->data); fprintf(out,"\n"); } if (mp->data) { } else if (mp->fileName) { } else if (mp->multi) { fprintf(out,"%snested MIME structure\n\n",margin); for(mp=mp->multi;mp;mp=mp->next) printMimeInfo(mp, out, level+1); } else { errAbort("mp-> type not data,fileName, or multi - unexpected MIME structure"); } freez(&cdMain); freez(&cdName); freez(&cdFileName); freez(&margin); }
static inline void rrdhost_init_hostname(RRDHOST *host, const char *hostname) { freez(host->hostname); host->hostname = strdupz(hostname); host->hash_hostname = simple_hash(host->hostname); }
static void pslShowAlignmentStranded2(struct psl *psl, boolean isProt, char *qName, bioSeq *qSeq, int qStart, int qEnd, char *tName, bioSeq *tSeq, int tStart, int tEnd, int exnStarts[], int exnEnds[], int exnCnt, FILE *f) /* Show stamper gene and stamp elements alignment using genomic sequence. * The aligned exons' sequence of stamper gene are shown in colors as usual, but the * the unaligned exon's sequence of stamper gene are shown in red color. */ { boolean tIsRc = (psl->strand[1] == '-'); boolean qIsRc = (psl->strand[0] == '-'); int mulFactor = (isProt ? 3 : 1); DNA *dna = NULL; /* Mixed case version of genomic DNA. */ int qSize = qSeq->size; char *qLetters = cloneString(qSeq->dna); int qbafStart, qbafEnd, tbafStart, tbafEnd; int qcfmStart, qcfmEnd, tcfmStart, tcfmEnd; tbafStart = psl->tStart; tbafEnd = psl->tEnd; tcfmStart = psl->tStart; tcfmEnd = psl->tEnd; qbafStart = qStart; qbafEnd = qEnd; qcfmStart = qStart; qcfmEnd = qEnd; /* Deal with minus strand. */ if (tIsRc) { int temp; reverseComplement(tSeq->dna, tSeq->size); temp = psl->tSize - tEnd; tEnd = psl->tSize - tStart; tStart = temp; tbafStart = psl->tEnd; tbafEnd = psl->tStart; tcfmStart = psl->tEnd; tcfmEnd = psl->tStart; } if (qIsRc) { int temp, j; reverseComplement(qSeq->dna, qSeq->size); reverseComplement(qLetters, qSeq->size); qcfmStart = qEnd; qcfmEnd = qStart; qbafStart = qEnd; qbafEnd = qStart; temp = psl->qSize - qEnd; qEnd = psl->qSize - qStart; qStart = temp; for(j = 0; j < exnCnt; j++) { temp = psl->qSize - exnStarts[j]; exnStarts[j] = psl->qSize - exnEnds[j]; exnEnds[j] = temp; } reverseInts(exnEnds, exnCnt); reverseInts(exnStarts, exnCnt); } dna = cloneString(tSeq->dna); if (qName == NULL) qName = psl->qName; if (tName == NULL) tName = psl->tName; fputs("Matching bases are colored blue and capitalized. " "Light blue bases mark the boundaries of gaps in either aligned sequence. " "Red bases are unaligned exons' bases of the query gene. \n", f); fprintf(f, "<H4><A NAME=cDNA></A>%s%s</H4>\n", qName, (qIsRc ? " (reverse complemented)" : "")); fprintf(f, "<PRE><TT>"); tolowers(qLetters); /* Display query sequence. */ { struct cfm *cfm; char *colorFlags = needMem(qSeq->size); int i = 0, j = 0, exnIdx = 0; int preStop = 0; for (i=0; i<psl->blockCount; ++i) { int qs = psl->qStarts[i] - qStart; int ts = psl->tStarts[i] - tStart; int sz = psl->blockSizes[i]-1; int end = 0; bool omitExon = FALSE; while(exnIdx < exnCnt && psl->qStarts[i] > exnEnds[exnIdx]) { if(omitExon) { for( j = exnStarts[exnIdx] - qStart; j < exnEnds[exnIdx]-qStart; j++) { colorFlags[j] = socRed; } } exnIdx++; preStop = exnStarts[exnIdx] - qStart; omitExon = TRUE; } /*mark the boundary bases */ colorFlags[qs] = socBrightBlue; qLetters[qs] = toupper(qLetters[qs]); colorFlags[qs+sz] = socBrightBlue; qLetters[qs+sz] = toupper(qLetters[qs+sz]); /* determine block end */ if( i < psl->blockCount -1) end = psl->qStarts[i+1] < exnEnds[exnIdx] ? psl->qStarts[i+1] - qStart : exnEnds[exnIdx] - qStart; else end = qs + sz; for (j=preStop; j < end; j++) { if(j == 82) fprintf(stderr, "right here\n"); if (j > qs && j < qs+sz) { if (qSeq->dna[j] == tSeq->dna[ts+j-qs]) { colorFlags[j] = socBlue; qLetters[j] = toupper(qLetters[j]); } } else if(colorFlags[j] != socBrightBlue && colorFlags[j] != socBlue) colorFlags[j] = socRed; } preStop = end; } cfm = cfmNew(10, 60, TRUE, qIsRc, f, qcfmStart); for (i=0; i<qSize; ++i) cfmOut(cfm, qLetters[i], seqOutColorLookup[(int)colorFlags[i]]); cfmFree(&cfm); freez(&colorFlags); htmHorizontalLine(f); } fprintf(f, "</TT></PRE>\n"); fprintf(f, "<H4><A NAME=genomic></A>%s %s:</H4>\n", tName, (tIsRc ? "(reverse strand)" : "")); fprintf(f, "<PRE><TT>"); /* Display DNA sequence. */ { struct cfm *cfm; char *colorFlags = needMem(tSeq->size); int i,j; int curBlock = 0; for (i=0; i<psl->blockCount; ++i) { int qs = psl->qStarts[i] - qStart; int ts = psl->tStarts[i] - tStart; int sz = psl->blockSizes[i]; if (isProt) { for (j=0; j<sz; ++j) { AA aa = qSeq->dna[qs+j]; int codonStart = ts + 3*j; DNA *codon = &tSeq->dna[codonStart]; AA trans = lookupCodon(codon); if (trans != 'X' && trans == aa) { colorFlags[codonStart] = socBlue; colorFlags[codonStart+1] = socBlue; colorFlags[codonStart+2] = socBlue; toUpperN(dna+codonStart, 3); } } } else { for (j=0; j<sz; ++j) { if (qSeq->dna[qs+j] == tSeq->dna[ts+j]) { colorFlags[ts+j] = socBlue; dna[ts+j] = toupper(dna[ts+j]); } } } colorFlags[ts] = socBrightBlue; colorFlags[ts+sz*mulFactor-1] = socBrightBlue; } cfm = cfmNew(10, 60, TRUE, tIsRc, f, tcfmStart); for (i=0; i<tSeq->size; ++i) { /* Put down "anchor" on first match position in haystack * so user can hop here with a click on the needle. */ if (curBlock < psl->blockCount && psl->tStarts[curBlock] == (i + tStart) ) { fprintf(f, "<A NAME=%d></A>", ++curBlock); /* Watch out for (rare) out-of-order tStarts! */ while (curBlock < psl->blockCount && psl->tStarts[curBlock] <= tStart + i) curBlock++; } cfmOut(cfm, dna[i], seqOutColorLookup[(int)colorFlags[i]]); } cfmFree(&cfm); freez(&colorFlags); htmHorizontalLine(f); } /* Display side by side. */ fprintf(f, "</TT></PRE>\n"); fprintf(f, "<H4><A NAME=ali></A>Side by Side Alignment*</H4>\n"); fprintf(f, "<PRE><TT>"); { struct baf baf; int i,j; bafInit(&baf, qSeq->dna, qbafStart, qIsRc, tSeq->dna, tbafStart, tIsRc, f, 60, isProt); if (isProt) { for (i=0; i<psl->blockCount; ++i) { int qs = psl->qStarts[i] - qStart; int ts = psl->tStarts[i] - tStart; int sz = psl->blockSizes[i]; bafSetPos(&baf, qs, ts); bafStartLine(&baf); for (j=0; j<sz; ++j) { AA aa = qSeq->dna[qs+j]; int codonStart = ts + 3*j; DNA *codon = &tSeq->dna[codonStart]; bafOut(&baf, ' ', codon[0]); bafOut(&baf, aa, codon[1]); bafOut(&baf, ' ', codon[2]); } bafFlushLine(&baf); } fprintf( f, "<I>*when aa is different, BLOSUM positives are in green, BLOSUM negatives in red</I>\n"); } else { int lastQe = psl->qStarts[0] - qStart; int lastTe = psl->tStarts[0] - tStart; int maxSkip = 20; bafSetPos(&baf, lastQe, lastTe); bafStartLine(&baf); for (i=0; i<psl->blockCount; ++i) { int qs = psl->qStarts[i] - qStart; int ts = psl->tStarts[i] - tStart; int sz = psl->blockSizes[i]; boolean doBreak = TRUE; int qSkip = qs - lastQe; int tSkip = ts - lastTe; if (qSkip >= 0 && qSkip <= maxSkip && tSkip == 0) { for (j=0; j<qSkip; ++j) bafOut(&baf, qSeq->dna[lastQe+j], '-'); doBreak = FALSE; } else if (tSkip > 0 && tSkip <= maxSkip && qSkip == 0) { for (j=0; j<tSkip; ++j) bafOut(&baf, '-', tSeq->dna[lastTe+j]); doBreak = FALSE; } if (doBreak) { bafFlushLine(&baf); bafSetPos(&baf, qs, ts); bafStartLine(&baf); } for (j=0; j<sz; ++j) bafOut(&baf, qSeq->dna[qs+j], tSeq->dna[ts+j]); lastQe = qs + sz; lastTe = ts + sz; } bafFlushLine(&baf); fprintf( f, "<I>*Aligned Blocks with gaps <= %d bases are merged for this display</I>\n", maxSkip); } } fprintf(f, "</TT></PRE>"); if (qIsRc) reverseComplement(qSeq->dna, qSeq->size); if (tIsRc) reverseComplement(tSeq->dna, tSeq->size); freeMem(dna); freeMem(qLetters); }
static inline void rrdhost_init_os(RRDHOST *host, const char *os) { freez(host->os); host->os = strdupz(os?os:"unknown"); }
/* called to re-update the buddy list to the pathfinder */ static int sipp_buddy_perform_buddylist_update(ident_t *from) { char *postdata = 0, *tmp = 0; int len = 0, size = 0; int ret = -1; char buf[128]; time_t exp, now; char *xml = 0; buddy_t* buddy = 0; void *ptr = 0; char *x = 0, *x2 = 0; /* construct the xml package of all still-valid subscribes */ time(&now); exp = now; while ((buddy = ship_list_next(from->buddy_list, &ptr))) { int valid = buddy->created + buddy->expire; if (valid > now) { ASSERT_TRUE((x = append_str("<buddy><hash>", xml, &size, &len)) && (xml = x), berr); ASSERT_TRUE(x2 = ship_hash_sha1_base64(buddy->sip_aor, strlen(buddy->sip_aor)), berr); ASSERT_TRUE((x = append_str(x2, xml, &size, &len)) && (xml = x), berr); freez(x2); ASSERT_TRUE((x = append_str("</hash></buddy>", xml, &size, &len)) && (xml = x), berr); if (valid < exp || exp == now) exp = valid; } } berr: freez(x2); if (!x) freez(xml); if (!xml) { ASSERT_TRUE(xml = strdup(""), err); } /* construct complete xml - timestamps */ len = 0; size = 0; ASSERT_TRUE((tmp = append_str("<buddylistdoc><payload><![CDATA[<load><timestamp>", postdata, &size, &len)) && (postdata = tmp), err); ship_format_time(now, buf, sizeof(buf)); ASSERT_TRUE((tmp = append_str(buf, postdata, &size, &len)) && (postdata = tmp), err); ASSERT_TRUE((tmp = append_str("</timestamp><expires>", postdata, &size, &len)) && (postdata = tmp), err); ship_format_time(exp, buf, sizeof(buf)); ASSERT_TRUE((tmp = append_str(buf, postdata, &size, &len)) && (postdata = tmp), err); /* self hash */ ASSERT_TRUE((tmp = append_str("</expires><self><hash>", postdata, &size, &len)) && (postdata = tmp), err); ASSERT_TRUE(x2 = ship_hash_sha1_base64(from->sip_aor, strlen(from->sip_aor)), err); ASSERT_TRUE((tmp = append_str(x2, postdata, &size, &len)) && (postdata = tmp), err); freez(x2); /* buddies */ ASSERT_TRUE((tmp = append_str("</hash><cert></cert></self><buddies>", postdata, &size, &len)) && (postdata = tmp), err); ASSERT_TRUE((tmp = append_str(xml, postdata, &size, &len)) && (postdata = tmp), err); ASSERT_TRUE((tmp = append_str("</buddies></load>]]></payload><signature /></buddylistdoc>", postdata, &size, &len)) && (postdata = tmp), err); freez(xml); xml = postdata; /* url-encode & post */ len = 0; size = 0; postdata = 0; x2 = ship_urlencode(xml); ASSERT_TRUE((tmp = append_str("submission.xml=", postdata, &size, &len)) && (postdata = tmp), err); ASSERT_TRUE((tmp = append_str(x2, postdata, &size, &len)) && (postdata = tmp), err); ret = netio_http_post_host(trustman_get_pathfinder(), "/postbuddylist", "", "application/x-www-form-urlencoded", postdata, strlen(postdata), sipp_buddy_pf_cb, NULL); err: freez(x2); freez(xml); freez(postdata); return ret; }
static struct bigBedInterval *bigBedIntervalsMatchingName(struct bbiFile *bbi, struct fileOffsetSize *fosList, BbFirstWordMatch matcher, int fieldIx, void *target, struct lm *lm) /* Return list of intervals inside of sectors of bbiFile defined by fosList where the name * matches target somehow. */ { struct bigBedInterval *interval, *intervalList = NULL; struct fileOffsetSize *fos; boolean isSwapped = bbi->isSwapped; for (fos = fosList; fos != NULL; fos = fos->next) { /* Read in raw data */ udcSeek(bbi->udc, fos->offset); char *rawData = needLargeMem(fos->size); udcRead(bbi->udc, rawData, fos->size); /* Optionally uncompress data, and set data pointer to uncompressed version. */ char *uncompressedData = NULL; char *data = NULL; int dataSize = 0; if (bbi->uncompressBufSize > 0) { data = uncompressedData = needLargeMem(bbi->uncompressBufSize); dataSize = zUncompress(rawData, fos->size, uncompressedData, bbi->uncompressBufSize); } else { data = rawData; dataSize = fos->size; } /* Set up for "memRead" routines to more or less treat memory block like file */ char *blockPt = data, *blockEnd = data + dataSize; struct dyString *dy = dyStringNew(32); // Keep bits outside of chrom/start/end here /* Read next record into local variables. */ while (blockPt < blockEnd) { bits32 chromIx = memReadBits32(&blockPt, isSwapped); bits32 s = memReadBits32(&blockPt, isSwapped); bits32 e = memReadBits32(&blockPt, isSwapped); int c; dyStringClear(dy); // TODO - can simplify this probably just to for (;;) {if ((c = *blockPt++) == 0) ... while ((c = *blockPt++) >= 0) { if (c == 0) break; dyStringAppendC(dy, c); } if ((*matcher)(dy->string, fieldIx, target)) { lmAllocVar(lm, interval); interval->start = s; interval->end = e; interval->rest = cloneString(dy->string); interval->chromId = chromIx; slAddHead(&intervalList, interval); } } /* Clean up temporary buffers. */ dyStringFree(&dy); freez(&uncompressedData); freez(&rawData); } slReverse(&intervalList); return intervalList; }
struct hash *readKeyHash(char *db, struct joiner *joiner, struct joinerField *keyField, struct keyHitInfo **retList) /* Read key-field into hash. Check for dupes if need be. */ { struct sqlConnection *conn = sqlWarnConnect(db); struct hash *keyHash = NULL; struct keyHitInfo *khiList = NULL, *khi; if (conn == NULL) { return NULL; } else { struct slName *table; struct slName *tableList = getTablesForField(conn,keyField->splitPrefix, keyField->table, keyField->splitSuffix); int rowCount = totalTableRows(conn, tableList); int hashSize = digitsBaseTwo(rowCount)+1; char query[256], **row; struct sqlResult *sr; int itemCount = 0; int dupeCount = 0; char *dupe = NULL; if (rowCount > 0) { if (hashSize > hashMaxSize) hashSize = hashMaxSize; keyHash = hashNew(hashSize); for (table = tableList; table != NULL; table = table->next) { safef(query, sizeof(query), "select %s from %s", keyField->field, table->name); sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { char *id = doChopsAndUpper(keyField, row[0]); if (hashLookup(keyHash, id)) { if (keyField->unique) { if (keyField->exclude == NULL || !slNameInList(keyField->exclude, id)) { if (dupeCount == 0) dupe = cloneString(id); ++dupeCount; } } } else { AllocVar(khi); hashAddSaveName(keyHash, id, khi, &khi->name); slAddHead(&khiList, khi); ++itemCount; } } sqlFreeResult(&sr); } if (dupe != NULL) { warn("Error: %d duplicates in %s.%s.%s including '%s'", dupeCount, db, keyField->table, keyField->field, dupe); freez(&dupe); } verbose(2, " %s.%s.%s - %d unique identifiers\n", db, keyField->table, keyField->field, itemCount); } slFreeList(&tableList); } sqlDisconnect(&conn); *retList = khiList; return keyHash; }
void trimUniq(bioSeq *seqList) /* Check that all seq's in list have a unique name. Try and * abbreviate longer sequence names. */ { struct hash *hash = newHash(0); bioSeq *seq; for (seq = seqList; seq != NULL; seq = seq->next) { char *saferString = needMem(strlen(seq->name)+1); char *c, *s; /* Some chars are safe to allow through, other chars cause * problems. It isn't necessarily a URL safe string that is * being calculated here. The original problem was a user had * the fasta header line of: * chr8|59823648:59825047|+ * The plus sign was being taken as the query name and this * created problems as that name was passed on to hgc via * the ss cart variable. The + sign became part of a URL * eventually. This loop allows only isalnum and =_/.:;_| * to get through as part of the header name. These characters * all proved to be safe as single character names, or all * together. */ s = saferString; for (c = seq->name; *c != '\0'; ++c) { if (c && (*c != '\0')) { if ( isalnum(*c) || (*c == '=') || (*c == '-') || (*c == '/') || (*c == '.') || (*c == ':') || (*c == ';') || (*c == '_') || (*c == '|') ) *s++ = *c; } } *s = '\0'; freeMem(seq->name); if (*saferString == '\0') { freeMem(saferString); saferString = cloneString("YourSeq"); } seq->name = saferString; if (strlen(seq->name) > 14) /* Try and get rid of long NCBI .fa cruft. */ { char *nameClone = NULL; char *abbrv = NULL; char *words[32]; int wordCount; boolean isEns = (stringIn("ENSEMBL:", seq->name) != NULL); nameClone = cloneString(seq->name); wordCount = chopString(nameClone, "|", words, ArraySize(words)); if (wordCount > 1) /* Looks like it's an Ensembl/NCBI * long name alright. */ { if (isEns) { abbrv = words[0]; if (abbrv[0] == 0) abbrv = words[1]; } else if (sameString(words[1], "dbSNP")) { if (wordCount > 2) abbrv = words[2]; else abbrv = nameClone; } else { abbrv = words[wordCount-1]; if (abbrv[0] == 0) abbrv = words[wordCount-2]; } if (hashLookup(hash, abbrv) == NULL) { freeMem(seq->name); seq->name = cloneString(abbrv); } freez(&nameClone); } } hashAddUnique(hash, seq->name, hash); } freeHash(&hash); }
void hierSort(char *inputList) /* Do a hierarchical merge sort so we don't run out of system file handles */ { int level = 0; char thisName[PATH_LEN]; char nextName[PATH_LEN]; char sortName[PATH_LEN]; char tmpNameBuf[PATH_LEN]; struct lineFile *thisLf = NULL; FILE *nextF = NULL; int sortCount = 0; FILE *sortF = NULL; int fileCount = 0; char *files[MAXFILES]; boolean more = FALSE; int block=0; char *line=NULL; safef(nextName, sizeof(nextName), "%s", inputList); do { block=0; safef(thisName, sizeof(thisName), "%s", nextName); safef(tmpNameBuf, sizeof(tmpNameBuf), "inputList%d-", level+1); safecpy(nextName, sizeof(nextName), rTempName(tempDir, tmpNameBuf, ".tmp")); thisLf = lineFileOpen(thisName,TRUE); if (!thisLf) errAbort("error lineFileOpen(%s) returned NULL\n",thisName); more = lineFileNext(thisLf, &line, NULL); while (more) { int i=0; fileCount = 0; while (more && fileCount < MAXFILES) { files[fileCount++]=cloneString(line); more = lineFileNext(thisLf, &line, NULL); } if (!more && block==0) { /* last level */ sortF = stdout; } else { if (!nextF) nextF = mustOpen(nextName,"w"); safef(tmpNameBuf, sizeof(tmpNameBuf), "sort%d-", sortCount++); safecpy(sortName, sizeof(sortName), rTempName(tempDir, tmpNameBuf, ".tmp")); fprintf(nextF, "%s\n", sortName); sortF = mustOpen(sortName,"w"); } chainMergeSort(fileCount, files, sortF, level); if (sortF != stdout) carefulClose(&sortF); for(i=0;i<fileCount;++i) freez(&files[i]); verboseDot(); verbose(2,"block=%d\n",block); ++block; } lineFileClose(&thisLf); if (nextF) carefulClose(&nextF); if (level > 0) { remove(thisName); } verbose(1,"\n"); verbose(2,"level=%d, block=%d\n",level,block); ++level; } while (block > 1); }
static void filterBed(struct track *tg, struct linkedFeatures **pLfList) /* Apply filters if any to mRNA linked features. */ { struct linkedFeatures *lf, *next, *newList = NULL, *oldList = NULL; struct mrnaUiData *mud = tg->extraUiData; struct mrnaFilter *fil; char *type; boolean anyFilter = FALSE; boolean colorIx = 0; boolean isExclude = FALSE; boolean andLogic = TRUE; if (*pLfList == NULL || mud == NULL) return; /* First make a quick pass through to see if we actually have * to do the filter. */ for (fil = mud->filterList; fil != NULL; fil = fil->next) { fil->pattern = cartUsualString(cart, fil->key, ""); if (fil->pattern[0] != 0) anyFilter = TRUE; } if (!anyFilter) return; type = cartUsualString(cart, mud->filterTypeVar, "red"); if (sameString(type, "exclude")) isExclude = TRUE; else if (sameString(type, "include")) isExclude = FALSE; else colorIx = getFilterColor(type, MG_BLACK); type = cartUsualString(cart, mud->logicTypeVar, "and"); andLogic = sameString(type, "and"); /* Make a pass though each filter, and start setting up search for * those that have some text. */ for (fil = mud->filterList; fil != NULL; fil = fil->next) { fil->pattern = cartUsualString(cart, fil->key, ""); if (fil->pattern[0] != 0) { fil->hash = newHash(10); } } /* Scan tables id/name tables to build up hash of matching id's. */ for (fil = mud->filterList; fil != NULL; fil = fil->next) { struct hash *hash = fil->hash; int wordIx, wordCount; char *words[128]; if (hash != NULL) { boolean anyWild; char *dupPat = cloneString(fil->pattern); wordCount = chopLine(dupPat, words); for (wordIx=0; wordIx <wordCount; ++wordIx) { char *pattern = cloneString(words[wordIx]); if (lastChar(pattern) != '*') { int len = strlen(pattern)+1; pattern = needMoreMem(pattern, len, len+1); pattern[len-1] = '*'; } anyWild = (strchr(pattern, '*') != NULL || strchr(pattern, '?') != NULL); touppers(pattern); for(lf = *pLfList; lf != NULL; lf=lf->next) { char copy[SMALLBUF]; boolean gotMatch; safef(copy, sizeof(copy), "%s", lf->name); touppers(copy); if (anyWild) gotMatch = wildMatch(pattern, copy); else gotMatch = sameString(pattern, copy); if (gotMatch) { hashAdd(hash, lf->name, NULL); } } freez(&pattern); } freez(&dupPat); } } /* Scan through linked features coloring and or including/excluding ones that * match filter. */ for (lf = *pLfList; lf != NULL; lf = next) { boolean passed = andLogic; next = lf->next; for (fil = mud->filterList; fil != NULL; fil = fil->next) { if (fil->hash != NULL) { if (hashLookup(fil->hash, lf->name) == NULL) { if (andLogic) passed = FALSE; } else { if (!andLogic) passed = TRUE; } } } if (passed ^ isExclude) { slAddHead(&newList, lf); if (colorIx > 0) lf->filterColor = colorIx; } else { slAddHead(&oldList, lf); } } slReverse(&newList); slReverse(&oldList); if (colorIx > 0) { /* Draw stuff that passes filter first in full mode, last in dense. */ if (tg->visibility == tvDense) { newList = slCat(oldList, newList); } else { newList = slCat(newList, oldList); } } *pLfList = newList; tg->limitedVisSet = FALSE; /* Need to recalculate this after filtering. */ /* Free up hashes, etc. */ for (fil = mud->filterList; fil != NULL; fil = fil->next) { hashFree(&fil->hash); } }
struct bigBedInterval *bigBedIntervalQuery(struct bbiFile *bbi, char *chrom, bits32 start, bits32 end, int maxItems, struct lm *lm) /* Get data for interval. Return list allocated out of lm. Set maxItems to maximum * number of items to return, or to 0 for all items. */ { struct bigBedInterval *el, *list = NULL; int itemCount = 0; bbiAttachUnzoomedCir(bbi); bits32 chromId; struct fileOffsetSize *blockList = bbiOverlappingBlocks(bbi, bbi->unzoomedCir, chrom, start, end, &chromId); struct fileOffsetSize *block, *beforeGap, *afterGap; struct udcFile *udc = bbi->udc; boolean isSwapped = bbi->isSwapped; struct dyString *dy = dyStringNew(32); /* Set up for uncompression optionally. */ char *uncompressBuf = NULL; if (bbi->uncompressBufSize > 0) uncompressBuf = needLargeMem(bbi->uncompressBufSize); for (block = blockList; block != NULL; ) { /* Find contigious blocks and read them into mergedBuf. */ fileOffsetSizeFindGap(block, &beforeGap, &afterGap); bits64 mergedOffset = block->offset; bits64 mergedSize = beforeGap->offset + beforeGap->size - mergedOffset; udcSeek(udc, mergedOffset); char *mergedBuf = needLargeMem(mergedSize); udcMustRead(udc, mergedBuf, mergedSize); char *blockBuf = mergedBuf; /* Loop through individual blocks within merged section. */ for (;block != afterGap; block = block->next) { /* Uncompress if necessary. */ char *blockPt, *blockEnd; if (uncompressBuf) { blockPt = uncompressBuf; int uncSize = zUncompress(blockBuf, block->size, uncompressBuf, bbi->uncompressBufSize); blockEnd = blockPt + uncSize; } else { blockPt = blockBuf; blockEnd = blockPt + block->size; } while (blockPt < blockEnd) { /* Read next record into local variables. */ bits32 chr = memReadBits32(&blockPt, isSwapped); // Read and discard chromId bits32 s = memReadBits32(&blockPt, isSwapped); bits32 e = memReadBits32(&blockPt, isSwapped); int c; dyStringClear(dy); // TODO - can simplify this probably just to for (;;) {if ((c = *blockPt++) == 0) ... while ((c = *blockPt++) >= 0) { if (c == 0) break; dyStringAppendC(dy, c); } /* If we're actually in range then copy it into a new element and add to list. */ if (chr == chromId && s < end && e > start) { ++itemCount; if (maxItems > 0 && itemCount > maxItems) break; lmAllocVar(lm, el); el->start = s; el->end = e; if (dy->stringSize > 0) el->rest = lmCloneString(lm, dy->string); el->chromId = chromId; slAddHead(&list, el); } } if (maxItems > 0 && itemCount > maxItems) break; blockBuf += block->size; } if (maxItems > 0 && itemCount > maxItems) break; freez(&mergedBuf); } freeMem(uncompressBuf); dyStringFree(&dy); slFreeList(&blockList); slReverse(&list); return list; }
static jb_socket no_rfc2553_connect_to(const char *host, int portnum, struct client_state *csp) { struct sockaddr_in inaddr; jb_socket fd; unsigned int addr; fd_set wfds; struct timeval tv[1]; #if !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__) int flags; #endif #ifdef FEATURE_ACL struct access_control_addr dst[1]; #endif /* def FEATURE_ACL */ /* Don't leak memory when retrying. */ freez(csp->http->host_ip_addr_str); memset((char *)&inaddr, 0, sizeof inaddr); if ((addr = resolve_hostname_to_ip(host)) == INADDR_NONE) { csp->http->host_ip_addr_str = strdup("unknown"); return(JB_INVALID_SOCKET); } #ifdef FEATURE_ACL dst->addr = ntohl(addr); dst->port = portnum; if (block_acl(dst, csp)) { #ifdef __OS2__ errno = SOCEPERM; #else errno = EPERM; #endif return(JB_INVALID_SOCKET); } #endif /* def FEATURE_ACL */ inaddr.sin_addr.s_addr = addr; inaddr.sin_family = AF_INET; csp->http->host_ip_addr_str = strdup(inet_ntoa(inaddr.sin_addr)); #ifndef _WIN32 if (sizeof(inaddr.sin_port) == sizeof(short)) #endif /* ndef _WIN32 */ { inaddr.sin_port = htons((unsigned short) portnum); } #ifndef _WIN32 else { inaddr.sin_port = htonl((unsigned long)portnum); } #endif /* ndef _WIN32 */ fd = socket(inaddr.sin_family, SOCK_STREAM, 0); #ifdef _WIN32 if (fd == JB_INVALID_SOCKET) #else if (fd < 0) #endif { return(JB_INVALID_SOCKET); } #ifndef _WIN32 if (fd >= FD_SETSIZE) { log_error(LOG_LEVEL_ERROR, "Server socket number too high to use select(): %d >= %d", fd, FD_SETSIZE); close_socket(fd); return JB_INVALID_SOCKET; } #endif set_no_delay_flag(fd); int yes = 1; setsockopt (fd, SOL_SOCKET, SO_NOSIGPIPE, (char *) &yes, sizeof (yes)); #if !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__) if ((flags = fcntl(fd, F_GETFL, 0)) != -1) { flags |= O_NDELAY; fcntl(fd, F_SETFL, flags); #ifdef FEATURE_EXTERNAL_FILTERS mark_socket_for_close_on_execute(fd); #endif } #endif /* !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__) */ while (connect(fd, (struct sockaddr *) & inaddr, sizeof inaddr) == JB_INVALID_SOCKET) { #ifdef _WIN32 if (errno == WSAEINPROGRESS) #elif __OS2__ if (sock_errno() == EINPROGRESS) #else /* ifndef _WIN32 */ if (errno == EINPROGRESS) #endif /* ndef _WIN32 || __OS2__ */ { break; } #ifdef __OS2__ if (sock_errno() != EINTR) #else if (errno != EINTR) #endif /* __OS2__ */ { close_socket(fd); return(JB_INVALID_SOCKET); } } #if !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__) if (flags != -1) { flags &= ~O_NDELAY; fcntl(fd, F_SETFL, flags); } #endif /* !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) && !defined(__OS2__) */ /* wait for connection to complete */ FD_ZERO(&wfds); FD_SET(fd, &wfds); tv->tv_sec = 30; tv->tv_usec = 0; /* MS Windows uses int, not SOCKET, for the 1st arg of select(). Weird! */ if (select((int)fd + 1, NULL, &wfds, NULL, tv) <= 0) { close_socket(fd); return(JB_INVALID_SOCKET); } return(fd); }