Exemple #1
0
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");
}
Exemple #2
0
FILE *openSortOutput(char *fileName, char **sortSpec)
/* Open a pipeline to sort and compress output.  SortSpec is null-terminated
 * list of fields options to pass to sort.  gSortTmpDir maybe null.
 * gbOutputRename is used to install and close.
 */
{
struct gbPipeline *pipeline;
char tmpPath[PATH_LEN];
char **compressor;
char **sortCmd, **cmds[3];
int nSort, iSort = 0, i;

/* sort cmd, nSort includes cmd and NULL */
for (nSort = 0; sortSpec[nSort] != NULL; nSort++)
    continue;
if (gSortTmp != NULL)
    nSort += 2;
nSort += 2; /* for "sort" and  NULL */
sortCmd = alloca(nSort*sizeof(char*));
sortCmd[iSort++] = "sort";
if (gSortTmp != NULL)
    {
    sortCmd[iSort++] = "-T";
    sortCmd[iSort++] = gSortTmp;
    }
for (i = 0; sortSpec[i] != NULL; i++)
    sortCmd[iSort++] = sortSpec[i];
sortCmd[iSort] = NULL;
assert(iSort < nSort);
cmds[0] = sortCmd;
cmds[1] = NULL;

/* compress process, if needed */
compressor = gbGetCompressor(fileName, "w");
if (compressor != NULL)
    {
    cmds[1] = compressor;
    cmds[2] = NULL;
    }

/* tmp name to output to */
gbGetOutputTmp(fileName, tmpPath);
gbMakeFileDirs(tmpPath);

pipeline = gbPipelineCreate(cmds, PIPELINE_WRITE|PIPELINE_FDOPEN, NULL,
                            tmpPath);
return gbPipelineFile(pipeline);
}
Exemple #3
0
void getTestSubset(int numMrnas, int numEsts, char *accList,
                   char* selectAccFile, char* relName, char* database,
                   char* outDir)
/* Get the test subset. */
{
struct gbRelease* release;
struct hash* accTbl = hashNew(20);
unsigned types = 0;

/* note, we find mRNAs and ESTs seperately, but extract in one pass, as
 * daily updates have both in a single file */
if (numMrnas > 0)
    types |= GB_MRNA;
if (numEsts > 0)
    types |= GB_EST;

release = loadIndex(relName, types, database);

if (selectAccFile != NULL)
    getRequestedAccs(selectAccFile, release, accTbl);

if (numMrnas > 0)
    findAccs(numMrnas, GB_MRNA, release, accTbl);
if (numEsts > 0)
    findAccs(numEsts, GB_EST, release, accTbl);

copyAccs(release, types, accTbl, outDir);

if (accList != NULL)
    {
    FILE *accListFh;
    struct hashCookie cookie;
    struct hashEl* hel;
    
    gbMakeFileDirs(accList);
    accListFh = mustOpen(accList, "w");
    cookie = hashFirst(accTbl);
    while ((hel = hashNext(&cookie)) != NULL)
        fprintf(accListFh, "%s\n", hel->name);
    carefulClose(&accListFh);
    }

hashFree(&accTbl);
gbIndexFree(&release->index);
}