static rc_t Run(const CmdLine* args)
{
    rc_t rc = 0;

    Db db;
    SpotIterator it;

    assert(args);

    if (!SpotIteratorFileExists(args->file)) {
        rc = RC(rcExe, rcFile, rcOpening, rcFile, rcNotFound);
        PLOGERR(klogErr,
            (klogErr, rc, "Cannot find '$(path)'", "path=%s", args->file));
    }
    else if (!SpotIteratorFileExists(args->table)) {
        rc = RC(rcExe, rcTable, rcOpening, rcTable, rcNotFound);
        PLOGERR(klogErr,
            (klogErr, rc, "Cannot find '$(path)'", "path=%s", args->table));
    }

    {
        rc_t rc2 = DbInit(rc, args, &db);
        if (rc == 0)
        {   rc = rc2; }
    }

    if (rc == 0) {
        rc = SpotIteratorInit(args->file, &db, &it);
    }

    if (rc == 0) {
        rc = Work(&db, &it);
    }

    if (rc == 0) {
        PLOGMSG(klogInfo, (klogInfo,
            "Success: redacted $(redacted) spots out of $(all)",
            "redacted=%d,all=%d", db.redactedSpots, db.nSpots));
    }

    {
        rc_t rc2 = SpotIteratorDestroy(&it);
        if (rc == 0)
        {   rc = rc2; }
    }

    {
        rc_t rc2 = DbDestroy(&db);
        if (rc == 0)
        {   rc = rc2; }
    }

    return rc;
}
Beispiel #2
0
static rc_t SDataUpdate(struct SData* self,
    const char* newColName, const char* redactFileName,
    spotid_t* redactedSpots, spotid_t* all)
{
    struct SBlob blob;
    uint8_t filter[32];
    rc_t rc = 0, rc2 = 0;
    uint32_t colIdx = 0;
    spotid_t spot = 0, last = 0;
    bool toRedact = false;
    struct SpotIterator it;

    assert(self && redactedSpots && all);

    memset(filter, SRA_READ_FILTER_REDACTED, sizeof filter);

    if ((rc = SpotIteratorInit(&it, self->_rdTbl, redactFileName))
        == 0)
    {
        rc = SRATableOpenColumnWrite
            (self->_wrTbl, &colIdx, NULL, newColName, sra_read_filter_t);
        if (rc != 0) {
            plogerr(klogErr, rc,
                "cannot open Column $(path) for Write", "path=%s", newColName);
            return rc;
        }
    }
    else {
        return rc;
    }

    rc = SBlobInit(&blob, self, &it);
    if (rc != 0) {
        return rc;
    }

    while (rc == 0 && SpotIteratorNext(&it, &rc, &spot, &toRedact)) {
        bitsz_t offset = 0, size = 0;
        const void *base = NULL;
        uint8_t nReads = 0;

        if (rc != 0) {
            break;
        }

        plogmsg(klogDebug2, "Spot $(spot): $(action)",
            PLOG_U32(spot) ",action=%s",
            spot, toRedact ? "redact" : "original");

        /* GET NEXT BLOB RANGE */
        if (spot == 1 || spot > last) {
            rc = SBlobGetRange(&blob, spot, &last);
            if (rc != 0) {
                break;
            }
        }

        assert(spot <= last);

        /* GET NREADS */
        if ((rc = SRAColumnRead
            (self->_NReadsCol, spot, &base, &offset, &size)) != 0)
        {
            logerr(klogErr, rc, "cannot SRAColumnRead");
            break;
        }
        else if (offset != 0 || size != sizeof nReads * 8) {
            rc = RC(rcExe, rcColumn, rcReading, rcData, rcInvalid);
            plogerr(klogErr, rc,
                "Bad SRAColumnRead(\"NREADS\", $(spot)) result",
                PLOG_U32(spot), spot);
        }
        else {
            nReads = *((uint8_t*) base);
            if (spot == 1) {
                if (nReads == 1) {
                    plogmsg(klogInfo, "The first spot has $(nreads) read",
                        "nreads=%d", nReads);
                }
                else {
                    plogmsg(klogInfo, "The first spot has $(nreads) reads",
                        "nreads=%d", nReads);
                }
            }
        }

        /* GET READ_FILTER */
        if (toRedact) {
            base = filter;
            ++(*redactedSpots);
        }
        else {
            if ((rc = SRAColumnRead(self->_origFilterCol,
                spot, &base, &offset, &size)) != 0)
            {
                plogerr(klogErr, rc,
                    "while calling SRAColumnRead($(name))", "name=%s",
                    "READ_FILTER");
                break;
            }
            else if (offset != 0
                  || size != sizeof (uint8_t) * 8 * nReads)
            {
                rc = RC(rcExe, rcColumn, rcReading, rcData, rcInvalid);
                plogerr(klogErr, rc, "Bad SRAColumnRead($(spot)) result",
                    PLOG_U32(spot), spot);
            }
        }

        if ((rc = SRATableOpenSpot(self->_wrTbl, spot)) != 0) {
            plogerr(klogErr, rc, "cannot open Spot $(id)", PLOG_U32(id), spot);
            break;
        }
        if ((rc = SRATableWriteIdxColumn(self->_wrTbl,
            colIdx, base, 0, sizeof (uint8_t) * 8 * nReads)) != 0)
        {
            logerr(klogErr, rc, "cannot SRATableWriteIdxColumn");
            break;
        }
        if ((rc = SRATableCloseSpot(self->_wrTbl)) != 0) {
            logerr(klogErr, rc, "cannot SRATableCloseSpot");
            break;
        }

        /* CUT THE BLOB */
        if (spot == last) {
            rc = SRATableCloseCursor(self->_wrTbl);
            if (rc != 0) {
                plogerr(klogErr, rc, "cannot SRATableCloseCursor $(id)",
                    PLOG_U32(id), spot);
                break;
            }
        }
    }

    rc2 = SpotIteratorDestroy(&it);
    if (rc == 0)
    {   rc = rc2; }

    *all = spot;

    return rc;
}