示例#1
0
/* GetSpotId
 *  convert spot name to spot id
 *
 *  "id" [ OUT ] - return parameter for min(spot_id)-max(spot_id)
 *
 *  "spot_name" [ IN ] - external spot name string
 *  in platform canonical format.
 */
LIB_EXPORT rc_t CC SRATableGetSpotId ( const SRATable *self,
        spotid_t *rslt, const char *spot_name )
{
    rc_t rc;
    if( self == NULL || spot_name == NULL){
        rc=RC(rcSRA, rcTable, rcListing, rcSelf, rcName);
    } else {
        rc=VCursorParamsSet((struct VCursorParams*)self->curs,"QUERY_BY_NAME" ,spot_name);
        if( rc == 0) {
            struct {
                uint64_t start_id;
                uint64_t id_count;
                int64_t x;
                int64_t y;
            } out;
            uint32_t idx,len;
            rc = VCursorAddColumn(self->curs, &idx, "SPOT_IDS_FOUND");
            if( rc == 0 || GetRCState(rc) == rcExists){
                rc = VCursorReadDirect(self->curs,1,idx,sizeof(out) * 8,&out, 1 , &len);
                if ( rc == 0 ) {
                    if(out.id_count==1) {
                        if(rslt) *rslt=out.start_id;
                        return 0;
                    } else if(out.id_count > 1) { /*** doing table range scan in Name space - not relying on X and Y***/
                        uint32_t x_idx;
                        rc = VCursorAddColumn(self->curs, &x_idx, "X");
                        if( rc == 0 || GetRCState(rc) == rcExists){
                            uint32_t y_idx;
                            rc = VCursorAddColumn(self->curs, &y_idx, "Y");
                            if(rc == 0 || GetRCState(rc) == rcExists){
                                spotid_t rowid;
                                for(rowid = out.start_id; rowid < out.start_id + out.id_count; rowid ++){
                                    int32_t x,y;
                                    rc = VCursorReadDirect(self->curs,rowid,x_idx,32,&x,1, &len);
                                    if(rc == 0){
                                        rc = VCursorReadDirect(self->curs,rowid,y_idx,32,&y,1, &len);
                                        if(rc == 0 && x==out.x && y==out.y){
                                            if(rslt) *rslt=rowid;
                                            return 0;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    rc = RC ( rcSRA, rcIndex, rcSearching, rcColumn, rcNotFound );
                }
            }
        }
    }
    return rc;
}
示例#2
0
static
rc_t SRATable_ReadColBack(const VTable* tbl, const char* col_name, uint32_t elem_bits, void *buffer, uint32_t blen)
{
    rc_t rc = 0;
    uint32_t idx;
    const VCursor* curs = NULL;
   
    if( (rc = VTableCreateCursorRead(tbl, &curs)) == 0 &&
        (rc = VCursorAddColumn(curs, &idx, "%s", col_name)) == 0 &&
        (rc = VCursorOpen(curs)) == 0 ) {
        uint32_t len;
        rc = VCursorReadDirect(curs, 1, idx, elem_bits, buffer, blen, &len);
    }
    VCursorRelease(curs);
    return rc;
}
示例#3
0
static
rc_t VCursor_ReadPseudoMeta(rc_t rc, const VCursor *self,
    const char *name, void *buffer, uint32_t blen, State *state)
{
    uint32_t idx = ~0;
    uint32_t row_len = ~0;

    assert(state);
    state->rc = 0;

    if (rc != 0)
    {   return rc; }

    state->state = eNotRead;

    rc = VCursorAddColumn(self, &idx, name);

    if (rc != 0) {
        state->rc = rc;

        if (GetRCObject(rc) == rcColumn && GetRCState(rc) == rcNotFound) {
            rc = 0;
            state->state = eNotFound;
        }
        else {
            state->state = eFailed;
        }
    }

    if (state->rc == 0) {
        rc = VCursorReadDirect(self, 1, idx, blen * 8, buffer, blen, &row_len);

        state->rc = rc;

        if (rc != 0)
        {   state->state = eFailed; }
        else
        {   state->state = eRead; }

    }

    return rc;
}
示例#4
0
static rc_t Work(Db* db, SpotIterator* it)
{
    rc_t rc = 0;
    bool toRedact = false;
    int64_t row_id = 0;
    spotid_t nSpots = 0;
    spotid_t redactedSpots = 0;

    uint8_t filter[64];
    memset(filter, SRA_READ_FILTER_REDACTED, sizeof filter);

    assert(it);

    while (rc == 0 && SpotIteratorNext(it, &rc, &row_id, &toRedact)) {
        uint8_t nreads = 0;
        char bufferIn[64];
        void* buffer = NULL;
        uint32_t row_len = 0;

        rc = Quitting();

        ++nSpots;

        if (rc == 0) {
            uint32_t elem_bits = 8;
            rc = VCursorReadDirect(db->rCursor, row_id, db->rFilterIdx,
                elem_bits, bufferIn, sizeof bufferIn, &row_len);
            DISP_RC(rc, "while reading READ_FILTER");
	    nreads = row_len;
        }
        if (toRedact) {
            buffer = filter;
            ++redactedSpots;
            DBGMSG(DBG_APP,DBG_COND_1,
                ("Redacting spot %d: %d reads\n",row_id,nreads));
        }
        else {
            buffer = bufferIn;
        }
        if (rc == 0) {
            rc = VCursorOpenRow(db->wCursor);
            DISP_RC(rc, "while opening row to write");
            if (rc == 0) {
                rc = VCursorWrite
                    (db->wCursor, db->wIdx, 8 * nreads, buffer, 0, 1);
                DISP_RC(rc, "while writing READ_FILTER");
            }
            if (rc == 0) {
                rc = VCursorCommitRow(db->wCursor);
                DISP_RC(rc, "while committing row");
            }
            if (rc == 0) {
                rc = VCursorCloseRow(db->wCursor);
                DISP_RC(rc, "while closing row");
            }
        }
    }

    db->nSpots = nSpots;
    db->redactedSpots = redactedSpots;

    if (rc == 0) {
        rc = VCursorCommit(db->wCursor);
        DISP_RC(rc, "while committing cursor");
    }

    return rc;
}
示例#5
0
文件: irvrfy.cpp 项目: ncbi/ncbi-vdb
static rc_t process(const char* dbname)
{
    rc_t rc;
    KHashFile* hf = NULL;
    rc = KHashFileMake(&hf, NULL);
    if (rc) {
        fprintf(stderr, "Couldn't create KHashFile\n");
        return rc;
    }

    KDirectory* srcdir = NULL;

    rc = KDirectoryNativeDir(&srcdir);
    if (rc) {
        fprintf(stderr, "Failed %d %d", __LINE__, rc);
        return rc;
    }

    VDBManager* mgr = NULL;
    rc = VDBManagerMakeUpdate(&mgr, NULL); // NULL=No working directory
    if (rc) {
        fprintf(stderr, "Failed %d %d", __LINE__, rc);
        return rc;
    }

    VDatabase* db = NULL;
    rc = VDBManagerOpenDBUpdate(mgr, &db, NULL, dbname);
    if (rc) {
        fprintf(stderr, "Failed %d %d", __LINE__, rc);
        return rc;
    }

    const VTable* tbl = NULL;
    rc = VDatabaseOpenTableRead(db, &tbl, "hdrs");
    if (rc) {
        fprintf(stderr, "Failed %d %d", __LINE__, rc);
        return rc;
    }

    const VCursor* curs = NULL;
    rc = VTableCreateCursorRead(tbl, &curs);
    if (rc) {
        fprintf(stderr, "Failed %d %d", __LINE__, rc);
        return rc;
    }
    uint32_t group_idx = 0; // HDR, TAG, VALUE
    uint32_t hdr_idx = 0;
    uint32_t tag_idx = 0;
    uint32_t value_idx = 0;
    rc = VCursorAddColumn(curs, &group_idx, "GROUP");
    if (rc) {
        fprintf(stderr, "Failed %d %d", __LINE__, rc);
        return rc;
    }
    rc = VCursorAddColumn(curs, &hdr_idx, "HDR");
    if (rc) {
        fprintf(stderr, "Failed %d %d", __LINE__, rc);
        return rc;
    }
    rc = VCursorAddColumn(curs, &tag_idx, "TAG");
    if (rc) {
        fprintf(stderr, "Failed %d %d", __LINE__, rc);
        return rc;
    }
    rc = VCursorAddColumn(curs, &value_idx, "VALUE");
    if (rc) {
        fprintf(stderr, "Failed %d %d", __LINE__, rc);
        return rc;
    }

    rc = VCursorOpen(curs);
    if (rc) {
        fprintf(stderr, "Failed %d %d", __LINE__, rc);
        return rc;
    }

    int64_t start = 0;
    uint64_t count = 0;
    rc = VCursorIdRange(curs, 0, &start, &count);
    if (rc) {
        fprintf(stderr, "Failed %d %d", __LINE__, rc);
        return rc;
    }
    printf("start=%ld,count=%lu\n", start, count);

    while (count--) {
        uint64_t group;
        uint32_t row_len = 0;
        rc = VCursorReadDirect(curs, start, group_idx, 64, &group, 1,
                               &row_len);
        if (rc) {
            fprintf(stderr, "Failed %d %d", __LINE__, rc);
            return rc;
        }
        printf("group=%lu, row_len=%d\n", group, row_len);

        char hdr[8];
        rc = VCursorReadDirect(curs, start, hdr_idx, 8, &hdr, sizeof(hdr),
                               &row_len);
        if (rc) {
            fprintf(stderr, "Failed %d %d", __LINE__, rc);
            return rc;
        }
        hdr[row_len] = '\0';
        printf("hdr=%s, row_len=%d\n", hdr, row_len);

        char tag[8];
        rc = VCursorReadDirect(curs, start, tag_idx, 8, &tag, sizeof(tag),
                               &row_len);
        if (rc) {
            fprintf(stderr, "Failed %d %d", __LINE__, rc);
            return rc;
        }
        tag[row_len] = '\0';
        printf("tag=%s, row_len=%d\n", tag, row_len);

        char value[8192];
        rc = VCursorReadDirect(curs, start, value_idx, 8, &value,
                               sizeof(value), &row_len);
        if (rc) {
            fprintf(stderr, "Failed %d %d", __LINE__, rc);
            return rc;
        }
        value[row_len] = '\0';
        printf("value=%s, row_len=%d\n", value, row_len);

        if (!strcmp(hdr, "SQ") && !strcmp(tag, "SN")) {
            if (check_dup(hf, "SQ:SN", value)) {
                fprintf(stderr, "Duplicate SQ:SN value '%s'\n", value);
            }
        }

        if (!strcmp(hdr, "RG") && !strcmp(tag, "ID")) {
            if (check_dup(hf, "RG:ID", value)) {
                fprintf(stderr, "Duplicate RG:ID value '%s'\n", value);
            }
        }

        if (!strcmp(hdr, "PG") && !strcmp(tag, "ID")) {
            if (check_dup(hf, "PG:ID", value)) {
                fprintf(stderr, "Duplicate PG:ID value '%s'\n", value);
            }
        }

        start++;
        printf("\n");
    }
    printf("Set has %lu elements\n", KHashFileCount(hf));
    fprintf(stderr, "Made verifier for %s\n", dbname);

    KHashFileDispose(hf);

    VCursorRelease(curs);
    VTableRelease(tbl);
    VDatabaseRelease(db);
    VDBManagerRelease(mgr);
    KDirectoryRelease(srcdir);

    return 0;
}
示例#6
0
文件: main.c 项目: ImAWolf/ncbi-vdb
bool nextPileup (
    PileupIteratorState* pileup_state,
    VCursor const* cursor_ref, VCursor const* cursor_pa,
    char const* const* column_names_ref, uint32_t* column_index_ref, size_t column_count_ref,
    char const* const* column_names_pa, uint32_t* column_index_pa, size_t column_count_pa,
    char* error_buf,
    size_t error_buf_size
    )
{
    int64_t ref_row_id; /* current row_id */
    int64_t prev_ref_row_id;
    uint64_t ref_pos = pileup_state->ref_pos;
    rc_t rc;

    /* TODO: check the case when slice_end is beyond the reference end*/
    if ( pileup_state->slice_length && pileup_state->ref_pos == pileup_state->slice_start + pileup_state->slice_length )
    {
        error_buf[0] = '\0'; /* indicating that no error has occured */
        return false;
    }

    /* drop cached alignments that we will not need anymore */
    remove_unneeded_alignments ( pileup_state, ref_pos, error_buf, error_buf_size ); /* it's not an issue but this action is not rolled backed in the case of error below */

    /* Check if we moved to the next reference row_id,
       if yes - read it and add appropriate alignments to cache
    */

    prev_ref_row_id = pileup_state->reference_start_id + ref_pos / pileup_state->max_seq_len;
    ++ ref_pos;
    ref_row_id = pileup_state->reference_start_id + ref_pos / pileup_state->max_seq_len;

    if ( ref_row_id != prev_ref_row_id ) /* moved to the next row_id */
    {
        uint32_t dummy;
        uint32_t row_len;
        uint32_t seq_start;
#if USE_SINGLE_BLOB_FOR_ALIGNMENT_IDS != 1
        int64_t const* alignment_ids;
#endif

        char ref_name[ countof (pileup_state->ref_name) ];

        /* TODO: consider storing this in pileup_state (don't need to calculate every time)*/
        /*slice_start_id = pileup_state->reference_start_id + pileup_state->slice_start/pileup_state->max_seq_len;
        slice_end_id = pileup_state->slice_length != 0 ?
            pileup_state->reference_start_id + (pileup_state->slice_start + (int64_t)pileup_state->slice_length)/pileup_state->max_seq_len :
            (int64_t)pileup_state->total_row_count;*/
        
        if ( ref_row_id < pileup_state->slice_start_id || ref_row_id > pileup_state->slice_end_id )
        {
            error_buf[0] = '\0'; /* indicating that no error has occured */
            return false;
        }

        rc = VCursorReadDirect ( cursor_ref, ref_row_id, column_index_ref [COL_NAME],
            sizeof (ref_name[0]) * 8, ref_name, countof(ref_name), & row_len );
        if ( rc != 0 )
        {
            rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                "ERROR: VCursorReadDirect(ref) failed with error: 0x%08x (%u) [%R]", rc, rc, rc);
            if (res == rcBuffer || res == rcInsufficient)
                error_buf [ error_buf_size - 1 ] = '\0';

            return false;
        }
        ref_name[ min ( countof(ref_name) - 1, row_len) ] = '\0';
        if ( strcmp (ref_name, pileup_state->ref_name) )
        {
            /*Alignment_Init ( & pileup_state->cache_alignment);
            strncpy ( pileup_state->ref_name, ref_name, countof (pileup_state->ref_name) - 1 );
            pileup_state->reference_start_id = ref_row_id;*/

            error_buf[0] = '\0'; /* indicating that no error has occured */
            return false;
        }

#if USE_SINGLE_BLOB_FOR_ALIGNMENT_IDS == 1
        rc = open_blob_for_current_id ( ref_row_id,
            cursor_ref, & pileup_state->blob_alignment_ids,
            column_index_ref [COL_PRIMARY_ALIGNMENT_IDS],
            error_buf, error_buf_size );
        if (rc != 0)
            return false;
#endif

        /* Read new SEQ_START */
        rc = VCursorReadDirect ( cursor_ref, ref_row_id,
                                 column_index_ref [COL_SEQ_START],
                                 sizeof (seq_start) * 8, & seq_start, 1, & row_len );
        if ( rc != 0 )
        {
            rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                "ERROR: VCursorReadDirect(ref-seq_start) failed with error: 0x%08x (%u) [%R]",
                rc, rc, rc);
            if (res == rcBuffer || res == rcInsufficient)
                error_buf [ error_buf_size - 1 ] = '\0';

            return false;
        }
        pileup_state->current_seq_start = seq_start;

        /* Read REFERENCE row's PRIMARY_ALIGNMENT_IDS column to iterate through them */
        /* elem_bits = sizeof (*pileup_state->alignment_ids) * 8; */
#if USE_SINGLE_BLOB_FOR_ALIGNMENT_IDS == 1
        rc = VBlobCellData ( pileup_state->blob_alignment_ids, ref_row_id,
            & dummy, & pileup_state->alignment_ids, NULL, & row_len );
        if ( rc != 0 )
        {
            rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                "ERROR: VBlobCellData(ref-pa_ids) failed with error: 0x%08x (%u) [%R], row_len=%u",
                rc, rc, rc, row_len);
            if (res == rcBuffer || res == rcInsufficient)
                error_buf [ error_buf_size - 1 ] = '\0';

            return false;
        }
        pileup_state -> size_alignment_ids = row_len;
#else
        rc = VCursorCellDataDirect ( cursor_ref, ref_row_id,
                    column_index_ref [COL_PRIMARY_ALIGNMENT_IDS],
                    NULL,
                    (void const**)(& alignment_ids), 0, & row_len );

        /*rc = VCursorReadDirect ( cursor_ref, ref_row_id,
                                 column_index_ref [COL_PRIMARY_ALIGNMENT_IDS],
                                 sizeof (*pileup_state->alignment_ids) * 8,
                                 pileup_state->alignment_ids,
                                 countof (pileup_state->alignment_ids),
                                 & row_len );*/
        if ( rc != 0 )
        {
            rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                "ERROR: VCursorCellDataDirect(ref-pa_ids) failed with error: 0x%08x (%u) [%R], row_len=%u",
                rc, rc, rc, row_len);
            if (res == rcBuffer || res == rcInsufficient)
                error_buf [ error_buf_size - 1 ] = '\0';

            return false;
        }
        rc = PileupIteratorState_SetAlignmentIds ( pileup_state, alignment_ids, row_len );
        if ( rc != 0 )
        {
            rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                "ERROR: PileupIteratorState_SetAlignmentIds failed with error: 0x%08x (%u), row_len=%u",
                rc, rc, row_len);
            if (res == rcBuffer || res == rcInsufficient)
                error_buf [ error_buf_size - 1 ] = '\0';

            return rc;
        }
#endif
        pileup_state->next_alignment_idx = 0;
        /*pileup_state->size_alignment_ids = row_len;*/

        printf ("Read %lu PRIMARY_ALIGNMENT_IDS for REFERENCE row_id=%lld\n", row_len, ref_row_id);

        /* For each PRIMARY_ALIGNMENT_ID in pa_ids: read its start, length and
           cache it if it intersects the slice
        */
        rc = add_ref_row_to_cache ( pileup_state, cursor_pa, seq_start, ref_pos,
                pileup_state->alignment_ids, row_len,
                column_names_pa, column_index_pa, column_count_pa,
                error_buf, error_buf_size );
        if ( rc != 0 )
            return false;

        /*pileup_state -> seq_start = seq_start;*/
    }
    else
    {
        /* read remaining alignment_ids and check if they must be cached */
        size_t count = pileup_state->size_alignment_ids - pileup_state->next_alignment_idx;
        if (count > 0)
        {
            rc_t rc = add_ref_row_to_cache ( pileup_state, cursor_pa,
                pileup_state->current_seq_start, ref_pos,
                & pileup_state->alignment_ids[ pileup_state->next_alignment_idx ],
                (uint32_t)count,
                column_names_pa, column_index_pa, column_count_pa,
                error_buf, error_buf_size );
            if ( rc != 0 )
                return false;
        }
    }

    ++ pileup_state->ref_pos;
    return true;
}
示例#7
0
文件: main.c 项目: ImAWolf/ncbi-vdb
rc_t initialize_ref_pos (
    PileupIteratorState* pileup_state,
    VCursor const* cursor_ref, VCursor const* cursor_pa,
    char const* const* column_names_ref, uint32_t* column_index_ref, size_t column_count_ref,
    char const* const* column_names_pa, uint32_t* column_index_pa, size_t column_count_pa,
    char* error_buf,
    size_t error_buf_size
    )
{
    int64_t row_id;
    uint64_t row_count;

    uint32_t max_seq_len, row_len;

    rc_t rc = VCursorIdRange ( cursor_ref, 0, & row_id, & row_count );

    /*printf ("REFERENCE table: row_id=%lld, row_count=%llu\n", row_id, row_count);*/


    if ( row_count < 1 )
    {
        rc_t res = string_printf ( error_buf, error_buf_size, NULL,
            "There is no rows in REFERENCE table");
        if (res == rcBuffer || res == rcInsufficient)
            error_buf [ error_buf_size - 1 ] = '\0';

        return (rc_t)(-1);
    }
    pileup_state->total_row_count = row_count;

    /* We don't know the reference end id use its name to notice the moment when it changes - this will be the end */
    rc = VCursorReadDirect ( cursor_ref, pileup_state->reference_start_id, column_index_ref [COL_NAME],
        sizeof (pileup_state->ref_name[0]) * 8, pileup_state->ref_name, countof(pileup_state->ref_name), & row_len );
    if ( rc != 0 )
    {
        rc_t res = string_printf ( error_buf, error_buf_size, NULL,
            "ERROR: VCursorReadDirect(ref) failed with error: 0x%08x (%u) [%R]", rc, rc, rc);
        if (res == rcBuffer || res == rcInsufficient)
            error_buf [ error_buf_size - 1 ] = '\0';

        return rc;
    }
    pileup_state->ref_name[ min ( countof(pileup_state->ref_name) - 1, row_len) ] = '\0';

    /* Read MAX_SEQ_LEN from the start_row_id and assume that it's the same for all the rest */
    rc = VCursorReadDirect ( cursor_ref, pileup_state->reference_start_id, column_index_ref [COL_MAX_SEQ_LEN],
                             sizeof (max_seq_len) * 8, & max_seq_len, 1, & row_len );
    if ( rc != 0 )
    {
        rc_t res = string_printf ( error_buf, error_buf_size, NULL,
            "ERROR: VCursorReadDirect(ref) failed with error: 0x%08x (%u) [%R]", rc, rc, rc);
        if (res == rcBuffer || res == rcInsufficient)
            error_buf [ error_buf_size - 1 ] = '\0';

        return rc;
    }
    pileup_state->max_seq_len = max_seq_len;

    if ( row_len < 1 )
    {
        rc_t res = string_printf ( error_buf, error_buf_size, NULL,
            "There is no MAX_SEQ_LEN column for row_id=%lld in REFERENCE table", row_id);
        if (res == rcBuffer || res == rcInsufficient)
            error_buf [ error_buf_size - 1 ] = '\0';

        return (rc_t)(-1);
    }

    printf ("MAX_SEQ_LEN=%lu\n", max_seq_len);

    pileup_state->slice_start_id = pileup_state->reference_start_id + pileup_state->slice_start/max_seq_len;
    pileup_state->slice_end_id = pileup_state->slice_length != 0 ?
        pileup_state->reference_start_id + (pileup_state->slice_start + (int64_t)pileup_state->slice_length)/max_seq_len :
        (int64_t)pileup_state->total_row_count;

    printf ("slice position range: [%lld, %llu]\n", pileup_state->slice_start, pileup_state->slice_start + pileup_state->slice_length);
    /*printf ("slice id range: [%lld, %lld]\n", slice_start_id, slice_end_id);*/

    /* Read reference slice_start_id,
       read OVERLAP_*_POS to find out how
       many rows we need to read ahead of slice_start_id
       TODO: this is not implemented yet, insted we read just 10 rows ahead
    */


    /* Set cursor to <read_ahead_rows> rows ahead of slice_start_id
       and cache corresponding PRIMARY_ALIGNMENTS
    */


    {
        int64_t current_id = max (pileup_state->reference_start_id, pileup_state->slice_start_id - 10);
        int64_t stop_id = pileup_state->slice_start_id;
        uint32_t seq_start;
        uint32_t dummy;
#if USE_SINGLE_BLOB_FOR_ALIGNMENT_IDS != 1
        int64_t const* alignment_ids;
#endif

        for (; ; ++current_id)
        {
            /* We don't know the current reference end_id
               read it's name and break when it changes
            */
            char ref_name[ countof (pileup_state->ref_name) ];
            rc = VCursorReadDirect ( cursor_ref, current_id, column_index_ref [COL_NAME],
                sizeof (ref_name[0]) * 8, ref_name, countof(ref_name), & row_len );
            if ( rc != 0 )
            {
                rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                    "ERROR: VCursorReadDirect(ref) failed with error: 0x%08x (%u) [%R]", rc, rc, rc);
                if (res == rcBuffer || res == rcInsufficient)
                    error_buf [ error_buf_size - 1 ] = '\0';

                return rc;
            }
            ref_name[ min ( countof(ref_name) - 1, row_len) ] = '\0';
            if ( current_id > stop_id || strcmp (ref_name, pileup_state->ref_name) )
                break;

#if USE_SINGLE_BLOB_FOR_ALIGNMENT_IDS == 1
            rc = open_blob_for_current_id ( current_id,
                cursor_ref, & pileup_state->blob_alignment_ids,
                column_index_ref [COL_PRIMARY_ALIGNMENT_IDS],
                error_buf, error_buf_size );
            if (rc != 0)
                return rc;
#endif

            /* Read REFERENCE row's SEQ_START column to know the offset */
            rc = VCursorReadDirect ( cursor_ref, current_id,
                                     column_index_ref [COL_SEQ_START],
                                     sizeof (seq_start) * 8, & seq_start, 1, & row_len );
            if ( rc != 0 )
            {
                rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                    "ERROR: VCursorReadDirect(ref-seq_start) failed with error: 0x%08x (%u) [%R]",
                    rc, rc, rc);
                if (res == rcBuffer || res == rcInsufficient)
                    error_buf [ error_buf_size - 1 ] = '\0';

                return rc;
            }
            pileup_state->current_seq_start = seq_start;

            /* Read REFERENCE row's PRIMARY_ALIGNMENT_IDS column to iterate through them */
            /* elem_bits = sizeof (*pileup_state->alignment_ids) * 8;*/
#if USE_SINGLE_BLOB_FOR_ALIGNMENT_IDS == 1
            rc = VBlobCellData ( pileup_state->blob_alignment_ids, current_id,
                & dummy, & pileup_state->alignment_ids, NULL, & row_len );
            if ( rc != 0 )
            {
                rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                    "ERROR: VBlobCellData(ref-pa_ids) failed with error: 0x%08x (%u) [%R], row_len=%u",
                    rc, rc, rc, row_len);
                if (res == rcBuffer || res == rcInsufficient)
                    error_buf [ error_buf_size - 1 ] = '\0';

                return rc;
            }
            pileup_state -> size_alignment_ids = row_len;
#else

            rc = VCursorCellDataDirect ( cursor_ref, current_id,
                        column_index_ref [COL_PRIMARY_ALIGNMENT_IDS],
                        NULL,
                        (void const**)(& alignment_ids), 0, & row_len );

            /*rc = VCursorReadDirect ( cursor_ref, current_id,
                        column_index_ref [COL_PRIMARY_ALIGNMENT_IDS],
                        sizeof (*pileup_state->alignment_ids) * 8,
                        pileup_state->alignment_ids,
                        countof (pileup_state->alignment_ids), & row_len );*/
            if ( rc != 0 )
            {
                rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                    "ERROR: VCursorCellDataDirect(ref-pa_ids) failed with error: 0x%08x (%u) [%R], row_len=%u",
                    rc, rc, rc, row_len);
                if (res == rcBuffer || res == rcInsufficient)
                    error_buf [ error_buf_size - 1 ] = '\0';

                return rc;
            }
            rc = PileupIteratorState_SetAlignmentIds ( pileup_state, alignment_ids, row_len );
            if ( rc != 0 )
            {
                rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                    "ERROR: PileupIteratorState_SetAlignmentIds failed with error: 0x%08x (%u), row_len=%u",
                    rc, rc, row_len);
                if (res == rcBuffer || res == rcInsufficient)
                    error_buf [ error_buf_size - 1 ] = '\0';

                return rc;
            }
#endif

            pileup_state->next_alignment_idx = 0;
            /*pileup_state->size_alignment_ids = row_len;*/
            /*printf ("Read %lu PRIMARY_ALIGNMENT_IDS for REFERENCE row_id=%lld:", row_len, current_id);*/
            {
                /*size_t i = 0;

                for (; i < row_len; ++i)
                    printf(" %lld", pa_ids [i]);*/

                /*printf ("\n");*/
            }

            /* For each PRIMARY_ALIGNMENT_ID in alignment_ids: read its start, length and
               cache it if it intersects the starting position
            */
            rc = add_ref_row_to_cache ( pileup_state, cursor_pa, seq_start,
                        pileup_state->slice_start,
                        pileup_state->alignment_ids, row_len,
                        column_names_pa, column_index_pa, column_count_pa,
                        error_buf, error_buf_size );
            if ( rc != 0 )
                return rc;
        }
    }

    return rc;

}
示例#8
0
文件: main.c 项目: ImAWolf/ncbi-vdb
static rc_t add_ref_row_to_cache (
    PileupIteratorState* pileup_state,
    VCursor const* cursor_pa, uint32_t seq_start,
    uint64_t ref_pos,
    int64_t const* pa_ids, uint32_t pa_count,
    char const* const* column_names_pa, uint32_t* column_index_pa, size_t column_count_pa,
    char* error_buf,
    size_t error_buf_size
    )
{
    size_t i = 0;
    rc_t rc = 0;
    int32_t ref_start;
    uint32_t ref_len; /* TODO: fix types */
    uint32_t row_len; /* TODO: fix types */
    int64_t slice_start = pileup_state->slice_start;

    -- seq_start; /* SEQ_START is one-based coord, and we will need zero-based one */
    /* Making slice_start and slice_end relative to the current reference row_id */

    slice_start -= seq_start;
    ref_pos -= seq_start;

    for (; i < (size_t)pa_count; ++i)
    {
        /* Read current PRIMARY_ALIGNMENT: REF_START and REF_LEN
           if it intersects slice - add this primary allignment to the cache
        */
        int64_t ref_end;

#if USE_SINGLE_BLOB_FOR_ALIGNMENTS == 1
        rc = open_blob_for_current_id ( pa_ids[i],
            cursor_pa, & pileup_state->blob_alignments_ref_start,
            column_index_pa [COL_REF_START],
            error_buf, error_buf_size );
        if (rc != 0)
            return rc;

        rc = VBlobRead ( pileup_state->blob_alignments_ref_start,
            pa_ids[i], sizeof (ref_start) * 8, & ref_start, 1, & row_len );
        if ( rc != 0 )
        {
            rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                "ERROR: VBlobRead(pa, %s) failed with error: 0x%08x (%u) [%R]",
                column_names_pa[COL_REF_START], rc, rc, rc);
            if (res == rcBuffer || res == rcInsufficient)
                error_buf [ error_buf_size - 1 ] = '\0';

            return rc;
        }

        rc = open_blob_for_current_id ( pa_ids[i],
            cursor_pa, & pileup_state->blob_alignments_ref_len,
            column_index_pa [COL_REF_LEN],
            error_buf, error_buf_size );
        if (rc != 0)
            return rc;

        rc = VBlobRead ( pileup_state->blob_alignments_ref_len,
            pa_ids[i], sizeof (ref_len) * 8, & ref_len, 1, & row_len );
        if ( rc != 0 )
        {
            rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                "ERROR: VBlobRead(pa, %s) failed with error: 0x%08x (%u) [%R]",
                column_names_pa[COL_REF_LEN], rc, rc, rc);
            if (res == rcBuffer || res == rcInsufficient)
                error_buf [ error_buf_size - 1 ] = '\0';

            return rc;
        }
#else
        rc = VCursorReadDirect ( cursor_pa, pa_ids[i], column_index_pa [COL_REF_START],
                                 sizeof (ref_start) * 8, & ref_start, 1, & row_len );
        if ( rc != 0 )
        {
            rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                "ERROR: VCursorReadDirect(pa, %s) failed with error: 0x%08x (%u) [%R]",
                column_names_pa[COL_REF_START], rc, rc, rc);
            if (res == rcBuffer || res == rcInsufficient)
                error_buf [ error_buf_size - 1 ] = '\0';

            return rc;
        }
        rc = VCursorReadDirect ( cursor_pa, pa_ids[i], column_index_pa [COL_REF_LEN],
                                 sizeof (ref_len) * 8, & ref_len, 1, & row_len );
        if ( rc != 0 )
        {
            rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                "ERROR: VCursorReadDirect(pa, %s) failed with error: 0x%08x (%u) [%R]",
                column_names_pa[COL_REF_LEN], rc, rc, rc);
            if (res == rcBuffer || res == rcInsufficient)
                error_buf [ error_buf_size - 1 ] = '\0';

            return rc;
        }
#endif

        ref_end = ref_start + (int64_t)ref_len;
        /*printf ("alignment row_id=%lld, align interval: [%ld, %lu], slice: [%lld, %llu]",
            pa_ids[i], ref_start, ref_end, slice_start, slice_end);*/

        /* skip all alignments that are to the left of slice (if we have slice specified) */
        if ( pileup_state->slice_length && ref_end < slice_start)
            continue;

        /* stop processing current alignments that are to the right of slice (if we have slice specified) */
        if ( pileup_state->slice_length && ref_start > (slice_start + (int64_t)pileup_state->slice_length))
        {
            /*pileup_state->next_alignment_idx = pileup_state->size_alignment_ids;*/
            break;
        }

        /* if alignment intersects slice_start - cache it */
        if ( ref_start <= (int64_t)ref_pos && ref_end >= (int64_t)ref_pos )
        {
            rc = Alignment_Add ( & pileup_state->cache_alignment, pa_ids[i], ref_start, ref_len, seq_start );
            if ( rc != 0 )
            {
                rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                    "ERROR: Alignment_Add (%lld, %d, %u, %u) failed with error: 0x%08x (%u) [%R], cache_size=%zu, ref_start_id=%lld, name=\"%s\", len=%llu, ref_pos=%llu",
                    pa_ids[i], ref_start, ref_len, seq_start, rc, rc, rc,
                    pileup_state->cache_alignment.size,
                    pileup_state->reference_start_id,
                    pileup_state->ref_name,
                    /*pileup_state->reference_length,*/999,
                    pileup_state->ref_pos);
                if (res == rcBuffer || res == rcInsufficient)
                    error_buf [ error_buf_size - 1 ] = '\0';

                return rc;
            }
            /*printf (" CACHED\n");*/
        }
        else if ( ref_start > ref_pos )
        {
            /*Alignment_AddPrefetch ();*/
/*            rc = Alignment_Add ( & pileup_state->cache_alignment, pa_ids[i], ref_start, ref_len, seq_start );
            if ( rc != 0 )
            {
                rc_t res = string_printf ( error_buf, error_buf_size, NULL,
                    "ERROR: Alignment_Add failed with error: 0x%08x (%u)", rc, rc);
                if (res == rcBuffer || res == rcInsufficient)
                    error_buf [ error_buf_size - 1 ] = '\0';

                return rc;
            }
            ++i;*/
            break; /* This is only for alignments ordered by ref_start !!*/
            /*printf (" ignored\n");*/
        }
    }
    pileup_state->next_alignment_idx =
        & pa_ids[i] - pileup_state->alignment_ids; /* TODO: i-th alignment will be read again on the next step, so consider caching it here and ignoring it when looking it up for cached items relevant to current ref_pos */

    /*printf ("Updated cache size=%zu\n", pileup_state->cache_alignment.size);*/
    
    return rc;
}