void loadMgcStatus(struct sqlConnection *conn, char *mgcStatusTab, char *statusTblName) /* load the mgcStatus or mgcFullStatus tables, return name loaded */ { struct lineFile* inLf; FILE *outFh; char tmpFile[PATH_LEN]; gbVerbEnter(2, "loading %s", statusTblName); /* uncompress to tmp file */ safef(tmpFile, sizeof(tmpFile), "%s/mgcStatus.%s.%d.tmp", workDir, getHost(), getpid()); inLf = gzLineFileOpen(mgcStatusTab); outFh = gzMustOpen(tmpFile, "w"); while (mgcStatusTblCopyRow(inLf, outFh)) continue; gzClose(&outFh); gzLineFileClose(&inLf); mgcStatusTblCreate(conn, statusTblName); sqlLoadTabFile(conn, tmpFile, statusTblName, SQL_TAB_FILE_ON_SERVER); unlink(tmpFile); gbVerbLeave(2, "loading %s", statusTblName); }
FILE* gbMustOpenOutput(char* path) /* Open an output file for atomic file creation. Create the directory if it * doesn't exist. If the path has one of the compress extensions (.gz, .Z, * .bz2) the output is compressed. File is opened under a tmp name until * installed. */ { char tmpPath[PATH_LEN]; gbGetOutputTmp(path, tmpPath); gbMakeFileDirs(tmpPath); return gzMustOpen(tmpPath, "w"); }
struct gbFa* gbFaOpen(char *fileName, char* mode) /* open a fasta file for reading or writing. Uses atomic file * creation for write.*/ { struct gbFa *fa; AllocVar(fa); strcpy(fa->fileName, fileName); if (!(sameString(mode, "r") || sameString(mode, "w") || sameString(mode, "a"))) errAbort("gbFaOpen only supports modes \"r\", \"w\" \"a\", got \"%s\"", mode); fa->mode[0] = mode[0]; if (mode[0] == 'w') fa->fh = gbMustOpenOutput(fileName); else fa->fh = gzMustOpen(fileName, mode); if (mode[0] == 'a') { /* line number is wrong on append */ fa->off = ftello(fa->fh); if (fa->off < 0) errnoAbort("can't get offset for append access for file: %s", fileName); } fa->fhBuf = needMem(FA_STDIO_BUFSIZ); setbuffer(fa->fh, fa->fhBuf, FA_STDIO_BUFSIZ); /* setup buffers if read access */ if (mode[0] == 'r') { fa->headerCap = 256; fa->headerBuf = needMem(fa->headerCap); fa->seqCap = 1024; fa->seqBuf = needMem(fa->seqCap); } return fa; }
void oiDataOpen(boolean inclVersion, char *outFile) /* open output file and set options. */ { gInclVersion = inclVersion; gOutOi = gzMustOpen(outFile, "w"); }
void extractAccFromGb(char *inName, char* outName, struct hash *accTbl) /* Parse records of genBank file and print ones that match accession names. * (yanked from gbOneAcc, changed to use stdio so we can access compressed). */ { enum {maxHeadLines=20, headLineSize=256 }; char *headLines[maxHeadLines]; /* Store stuff between locus and accession. */ char line[headLineSize]; FILE *inFh; FILE *outFh = NULL; int lineNum = 0; int i; char* acc; verbose(1, "copying from %s\n", inName); inFh = gzMustOpen(inName, "r"); for (i=0; i<maxHeadLines; ++i) headLines[i] = needMem(headLineSize); while (TRUE) { boolean gotAcc = FALSE; boolean gotMyAcc = FALSE; int headLineCount = 0; /* Seek to LOCUS */ for (;;) { if (!readData(inFh, inName, line, headLineSize, FALSE)) break; lineNum++; if (startsWith("LOCUS", line)) break; } if (feof(inFh)) break; for (i=0; i<maxHeadLines; ++i) { ++headLineCount; strcpy(headLines[i], line); readData(inFh, inName, line, headLineSize, TRUE); lineNum++; if (startsWith("ACCESSION", line)) { gotAcc = TRUE; break; } } if (!gotAcc) errAbort("LOCUS without ACCESSION in %d lines at line %d of %s", maxHeadLines, lineNum, inName); acc = lastWordInLine(line); gotMyAcc = (hashLookup(accTbl, acc) != NULL); if (gotMyAcc) { if (outFh == NULL) outFh = gbMustOpenOutput(outName); for (i=0; i<headLineCount; ++i) { fputs(headLines[i], outFh); fputc('\n', outFh); } fputs(line, outFh); fputc('\n', outFh); } for (;;) { readData(inFh, inName, line, headLineSize, TRUE); lineNum++; if (gotMyAcc) { fputs(line, outFh); fputc('\n', outFh); } if (startsWith("//", line)) break; } if ((outFh != NULL) && ferror(outFh)) break; /* write error */ } if (outFh != NULL) gbOutputRename(outName, &outFh); gzClose(&inFh); }