Esempio n. 1
0
static
rc_t copy_table ( const vtblcp_parms *pb, VCursor *dcurs, const VCursor *scurs,
    const vtblcp_column_map *cm, uint32_t count, uint32_t rdfilt_idx )
{
    /* open source */
    rc_t rc = VCursorOpen ( scurs );
    if ( rc != 0 )
        LOGERR ( klogErr, rc, "failed to open source cursor" );
    else
    {
        /* get row range */
        int64_t row, last;
        uint64_t range_count;
        
        rc = VCursorIdRange ( scurs, 0, & row, & range_count );
        last = row + range_count;
        if ( rc != 0 )
            LOGERR ( klogInt, rc, "failed to determine row range for source cursor" );
        else
        {
            /* open desination cursor */
            rc = VCursorOpen ( dcurs );
            if ( rc != 0 )
                LOGERR ( klogErr, rc, "failed to open destination cursor" );
            else
            {
                /* focus destination on initial source row */
                rc = VCursorSetRowId ( dcurs, row );
                if ( rc != 0 )
                    PLOGERR ( klogErr,  (klogErr, rc, "failed to set destination cursor row to id '$(row)'", "row=%" LD64, row ));
                else
                {
                    /* copy each row */
                    for ( ; row <= last; ++ row )
                    {
                        rc = copy_row ( pb, dcurs, scurs, cm, count, rdfilt_idx, row );
                        if ( rc != 0 )
                            break;
                    }

                    /* commit changes */
                    if ( rc == 0 )
                        rc = VCursorCommit ( dcurs );
                }
            }
        }
    }

    return rc;
}
Esempio n. 2
0
/* NewSpot
 *  creates a new spot record,
 *  returning spot id.
 *
 *  "id" [ OUT ] - return parameter for id of newly created spot
 */
LIB_EXPORT rc_t CC SRATableNewSpot( SRATable *self, spotid_t *id ) {
    rc_t rc;
    
    if (self == NULL)
        return RC(RC_MODULE, RC_TARGET, rcInserting, rcSelf, rcNull);
    if (id == NULL)
        return RC(RC_MODULE, RC_TARGET, rcInserting, rcParam, rcNull);
    
    if (self->curs_open == false) {
        SRADBG(("opening cursor\n"));
        rc = VCursorOpen(self->curs);
        if (rc)
            return rc;
        self->curs_open = true;
    }
    
    rc = VCursorOpenRow(self->curs);
    if (rc == 0) {
        int64_t rowid;
        if( (rc = VCursorRowId(self->curs, &rowid)) == 0 ) {
            *id = rowid;
        }
    }
    return rc;
}
Esempio n. 3
0
static rc_t OpenTableAndCursor(VDatabase *db, VTable **ptbl, VCursor **pcurs, uint32_t cid[], unsigned ncols)
{
    rc_t rc = VDatabaseCreateTable(db, ptbl, "READ_STATS",
                                   kcmCreate | kcmMD5, "READ_STATS");
    
    if (rc == 0) {
        rc = VTableColumnCreateParams(*ptbl, kcmCreate, kcsCRC32, 0);
        if (rc == 0) {
            rc = VTableCreateCursorWrite(*ptbl, &pcurs, kcmInsert);
            if (rc == 0) {
                unsigned i;
                
                for (i = 0; i < ncols && rc == 0; ++i) {
                    rc = VCursorAddColumn(*pcurs, &cid[i], column_name[i]);
                }
                if (rc == 0) {
                    rc = VCursorOpen(*pcurs);
                    if (rc == 0)
                        return 0;
                }
                VCursorRelease(*pcurs);
            }
        }
        VTableRelease(*ptbl);
    }
    *pcurs = NULL;
    *ptbl = NULL;
    return rc;
}
Esempio n. 4
0
static rc_t passes_loader( ld_context * lctx, KDirectory * hdf5_src, VCursor * cursor, const char * table_name )
{
    uint32_t col_idx[ passes_tab_count ];
    rc_t rc = add_columns( cursor, passes_tab_count, -1, col_idx, passes_tab_names );
    if ( rc == 0 )
    {
        rc = VCursorOpen( cursor );
        if ( rc != 0 )
            LOGERR( klogErr, rc, "cannot open cursor on PASSES-tab" );
        else
        {
            Passes_src Passes;
            rc = open_Passes_src( hdf5_src, &Passes,
                                  "PulseData/ConsensusBaseCalls/Passes",
                                  lctx->cache_content );
            if ( rc == 0 )
            {
                if ( check_Passes_extents( &Passes ) )
                    rc = passes_load_loop( lctx, cursor, &Passes, col_idx );
                else
                    rc = RC( rcExe, rcNoTarg, rcAllocating, rcParam, rcInvalid );
                close_Passes_src( &Passes );
            }
        }
    }
    return rc;
}
Esempio n. 5
0
rc_t open_read_cursor (const VTable * table, const VCursor ** cursor,
                       uint32_t * idx1, uint32_t * idx2, uint32_t * idx3, uint32_t * idx4,
                       const char * name1, const char * name2, const char * name3, const char * name4)
{
    rc_t rc;

    rc = VTableCreateCursorRead (table, cursor);
    if (rc)
    {
        LOGERR (klogErr, rc, "Failed to create Cursor");
    }
    else
    {
        do
        {
            rc = VCursorAddColumn (*cursor, idx1, name1);
            if (rc)
            {
                pLOGERR (klogErr, rc, "Failed to add column $(C)", PLOG_S(C), name1);
                break;
            }

            rc = VCursorAddColumn (*cursor, idx2, name2);
            if (rc)
            {
                pLOGERR (klogErr, rc, "Failed to add column $(C)", PLOG_S(C), name2);
                break;
            }

            rc = VCursorAddColumn (*cursor, idx3, name3);
            if (rc)
            {
                pLOGERR (klogErr, rc, "Failed to add column $(C)", PLOG_S(C), name3);
                break;
            }

            rc = VCursorAddColumn (*cursor, idx4, name4);
            if (rc)
            {
                pLOGERR (klogErr, rc, "Failed to add column $(C)", PLOG_S(C), name4);
                break;
            }

            rc = VCursorOpen (*cursor);
            if (rc)
            {
                LOGERR (klogErr, rc, "Failed to open cursor");
                break;
            }

            return 0;
        }
        while (0);

        VCursorRelease (*cursor);
    }
    *idx1 = *idx2 = *idx3 = *idx4 = 0;
    *cursor = NULL;
    return rc;
}
Esempio n. 6
0
static void get_string_cell( char * buffer, size_t buffer_size, const VTable * tab, int64_t row, const char * column )
{
    if ( has_col( tab, column ) )
    {
        const VCursor * cur;
        rc_t rc = VTableCreateCursorRead( tab, &cur );
        if ( rc == 0 )
        {
            uint32_t idx;
            rc = VCursorAddColumn( cur, &idx, column );
            if ( rc == 0 )
            {
                rc = VCursorOpen( cur );
                if ( rc == 0 )
                {
                    const char * src;
                    uint32_t row_len;
                    rc = VCursorCellDataDirect( cur, row, idx, NULL, (const void**)&src, NULL, &row_len );
                    if ( rc == 0 )
                    {
                        size_t num_writ;
                        string_printf( buffer, buffer_size, &num_writ, "%.*s", row_len, src );
                    }
                }
            }
            VCursorRelease( cur );
        }
    }
}
Esempio n. 7
0
static uint64_t get_rowcount( const VTable * tab )
{
    uint64_t res = 0;
    col_defs *my_col_defs;
    if ( vdcd_init( &my_col_defs, 1024 ) )
    {
        if ( vdcd_extract_from_table( my_col_defs, tab ) > 0 )
        {
            const VCursor * cur;
            rc_t rc = VTableCreateCursorRead( tab, &cur );
            if ( rc == 0 )
            {
                if ( vdcd_add_to_cursor( my_col_defs, cur ) )
                {
                    rc = VCursorOpen( cur );
                    if ( rc == 0 )
                    {
                        uint32_t idx;
                        if ( vdcd_get_first_none_static_column_idx( my_col_defs, cur, &idx ) )
                        {
                            int64_t first;
                            rc = VCursorIdRange( cur, idx, &first, &res );
                        }
                    }
                }
                VCursorRelease( cur );
            }
        }
        vdcd_destroy( my_col_defs );
    }
    return res;
}
Esempio n. 8
0
static rc_t report_ref_cursor( const VCursor *cur, int64_t start, int64_t stop )
{
    report_row_ctx row_ctx;
    rc_t rc = VCursorAddColumn ( cur, &row_ctx.prim_idx, "PRIMARY_ALIGNMENT_IDS" );
    if ( rc != 0 )
    {
        (void)LOGERR( klogErr, rc, "cannot add column >PRIMARY_ALIGNMENT_IDS<" );
    }
    else
    {
        rc = VCursorAddColumn ( cur, &row_ctx.sec_idx, "SECONDARY_ALIGNMENT_IDS" );
        if ( rc != 0 )
        {
            (void)LOGERR( klogErr, rc, "cannot add column >SECONDARY_ALIGNMENT_IDS<" );
        }
        else
        {
            rc = VCursorOpen ( cur );
            if ( rc != 0 )
            {
                (void)LOGERR( klogErr, rc, "cannot open REFERENCE-CURSOR" );
            }
            else
            {
                for ( row_ctx.row_id = start; rc == 0 && row_ctx.row_id <= stop; ++row_ctx.row_id )
                {
                    rc = report_ref_row( cur, &row_ctx );
                }
            }
        }
    }
    return rc;
}
Esempio n. 9
0
/* detect min and max spot-id from a temp. cursor */
static rc_t SRATableGetMinMax( SRATable * self )
{
    const VCursor *temp_cursor;
    rc_t rc;

    assert( self != NULL );
    assert( self->vtbl != NULL);
    rc = VTableCreateCursorRead( self->vtbl, &temp_cursor );
    if ( rc == 0 )
    {
        uint32_t idx;
        rc = VCursorAddColumn ( temp_cursor, &idx, "READ" );
        if ( rc == 0 )
        {
            rc = VCursorOpen( temp_cursor );
            if ( rc == 0 )
            {
                int64_t  first;
                uint64_t count;
                rc = VCursorIdRange( temp_cursor, 0, &first, &count );
                if ( rc == 0 )
                {
                    self->min_spot_id = first;
                    self->max_spot_id = first + count;
                    self->spot_count = count;
                }
            }
        }
        VCursorRelease( temp_cursor );
    }
    return rc;
}
Esempio n. 10
0
static const char * get_platform( const VTable * tab )
{
    const char * res = PT_NONE;
    const VCursor * cur;
    rc_t rc = VTableCreateCursorRead( tab, &cur );
    if ( rc == 0 )
    {
        uint32_t idx;
        rc = VCursorAddColumn( cur, &idx, "PLATFORM" );
        if ( rc == 0 )
        {
            rc = VCursorOpen( cur );
            if ( rc == 0 )
            {
                const uint8_t * pf;
                rc = VCursorCellDataDirect( cur, 1, idx, NULL, (const void**)&pf, NULL, NULL );
                if ( rc == 0 )
                {
                    res = vdcd_get_platform_txt( *pf );
                }
            }
        }
        VCursorRelease( cur );
    }
    return res;
}
Esempio n. 11
0
static 
rc_t SaveObjects ( const ObjectTable* data,  VDatabase* db )
{
    VTable* tbl;
    rc_t rc = VDatabaseCreateTable(db, &tbl, "object_inst", kcmCreate | kcmMD5, "OBJECTS");
    if (rc == 0)
    {
        rc_t rc2;
        VCursor *cur;
        rc = VTableCreateCursorWrite( tbl, &cur, kcmInsert );
        if (rc == 0)
        {
            uint32_t id_idx, name_idx, proj_idx, dname_idx, size_idx, csum_idx, enc_idx;
            if (rc == 0) rc = VCursorAddColumn( cur, &id_idx,    "id" );
            if (rc == 0) rc = VCursorAddColumn( cur, &name_idx,  "name" );
            if (rc == 0) rc = VCursorAddColumn( cur, &proj_idx,    "project" );
            if (rc == 0) rc = VCursorAddColumn( cur, &dname_idx, "display_name" );
            if (rc == 0) rc = VCursorAddColumn( cur, &size_idx,  "size" );
            if (rc == 0) rc = VCursorAddColumn( cur, &csum_idx,  "checksum" );
            if (rc == 0) rc = VCursorAddColumn( cur, &enc_idx,   "encryption_key" );

            if (rc == 0)
            {
                rc = VCursorOpen( cur );
                if (rc == 0)
                {
                    const Object* obj = (const Object*)BSTreeFirst(data);
                    while (rc == 0 && obj != NULL)
                    {
                        rc = VCursorOpenRow( cur );
                        
                        if (rc == 0) rc = VCursorWrite( cur, id_idx,    sizeof(obj->id) * 8,                   &obj->id,                  0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, name_idx,  StringLength(obj->name) * 8,           obj->name->addr,           0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, proj_idx,  StringLength(obj->project) * 8,        obj->project->addr,        0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, dname_idx, StringLength(obj->display_name) * 8,   obj->display_name->addr,   0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, size_idx,  sizeof(obj->size) * 8,                 &obj->size,                0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, csum_idx,  StringLength(obj->encryption_key) * 8, obj->encryption_key->addr, 0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, enc_idx,   StringLength(obj->encryption_key) * 8, obj->encryption_key->addr, 0, 1);
                        
                        if (rc == 0) rc = VCursorCommitRow( cur );
                        if (rc == 0) rc = VCursorCloseRow( cur );
                        
                        obj = (const Object*)BSTNodeNext(&obj->dad);
                    }
                    if (rc == 0) rc = VCursorCommit( cur );
                }
            }
            rc2 = VCursorRelease(cur);
            if (rc == 0)
                rc = rc2;
        }
        
        rc2 = VTableRelease(tbl);
        if (rc == 0)
            rc = rc2;
    }
    return rc;
}
Esempio n. 12
0
static
rc_t RestoreReadMake ( RestoreRead **objp, const VTable *tbl, const VCursor* native_curs )
{
    rc_t rc;
    char name[]="PRIMARY_ALIGNMENT";

    /* create the object */
    RestoreRead *obj = malloc ( sizeof * obj );
    memset(obj,0,sizeof * obj);
    if ( obj == NULL )
    {
		*objp=0;
        rc = RC ( rcXF, rcFunction, rcConstructing, rcMemory, rcExhausted );
    }
    else
	{
		rc = VCursorLinkedCursorGet(native_curs,name,&obj->curs);
		if(rc == 0){
			VCursorAddRef(obj->curs);
		} else {
			/* get at the parent database */
			const VDatabase *db;
			rc = VTableOpenParentRead ( tbl, & db );
			if ( rc == 0 )
			{
				const VTable *patbl;
				/* open the primary alignment table */
				rc = VDatabaseOpenTableRead ( db, & patbl, name );
				VDatabaseRelease ( db );
				if ( rc == 0 )
				{
					/* create a cursor */
					rc = VTableCreateCachedCursorRead( patbl, &obj->curs, 32*1024*1024UL );
					VTableRelease ( patbl );
					if ( rc == 0 )
					{
						/* add columns to cursor */
						rc = VCursorAddColumn ( obj -> curs, & obj -> read_idx, "( INSDC:4na:bin ) READ" );
						if ( rc == 0 )
						{
							rc = VCursorOpen ( obj -> curs );
							if ( rc == 0 )
							{
								VCursorLinkedCursorSet( native_curs, name, obj->curs );
								SUB_DEBUG( ( "SUB.Make in 'seq-restore-read.c'\n" ) );
								* objp = obj;
								return 0;
							}
						}
						VCursorRelease ( obj -> curs );
					}
				}
			}
			free ( obj );
		}
	}
    return rc;
}
Esempio n. 13
0
static rc_t consensus_loader( ld_context *lctx, const char * table_name,
                              bool cache_content )
{
    uint32_t col_idx[ consensus_tab_count ];
    rc_t rc = add_columns( lctx->cursor, consensus_tab_count, -1,
                           col_idx, consensus_tab_names );
    if ( rc == 0 )
    {
        rc = VCursorOpen( lctx->cursor );
        if ( rc != 0 )
            LOGERR( klogErr, rc, "cannot open cursor on consensus-table" );

        else
        {
            BaseCalls_cmn ConsensusTab;
            const INSDC_SRA_platform_id platform = SRA_PLATFORM_PACBIO_SMRT;

            rc = VCursorDefault ( lctx->cursor, col_idx[ consensus_tab_PLATFORM ],
                                  sizeof platform * 8, &platform, 0, 1 );
            if ( rc != 0 )
                LOGERR( klogErr, rc, "cannot set cursor-default on consensus-table for platform-column" );
            else
            {
                const INSDC_SRA_read_filter filter = SRA_READ_FILTER_PASS;
                rc = VCursorDefault ( lctx->cursor, col_idx[ consensus_tab_READ_FILTER ],
                                  sizeof filter * 8, &filter, 0, 1 );
                if ( rc != 0 )
                    LOGERR( klogErr, rc, "cannot set cursor-default on consensus-table for read-filter-column" );
            }

            if ( rc == 0 )
                rc = open_BaseCalls_cmn( lctx->hdf5_dir, &ConsensusTab, true,
                                     "PulseData/ConsensusBaseCalls", cache_content, true );

            if ( rc == 0 )
            {
                uint64_t total_bases = zmw_total( &ConsensusTab.zmw );
                uint64_t total_spots = ConsensusTab.zmw.NumEvent.extents[ 0 ];

                KLogLevel tmp_lvl = KLogLevelGet();
                KLogLevelSet( klogInfo );
                PLOGMSG( klogInfo, ( klogInfo,
                         "loading consensus-table ( $(bases) bases / $(spots) spots ):",
                         "bases=%lu,spots=%lu", total_bases, total_spots ));
                KLogLevelSet( tmp_lvl );

                if ( check_Consensus_totalcount( &ConsensusTab, total_bases ) )
                    rc = zmw_for_each( &ConsensusTab.zmw, lctx, col_idx, NULL,
                                       true, consensus_load_spot, &ConsensusTab );
                else
                    rc = RC( rcExe, rcNoTarg, rcAllocating, rcParam, rcInvalid );
                close_BaseCalls_cmn( &ConsensusTab );
            }
        }
    }
    return rc;
}
Esempio n. 14
0
static rc_t cg_dump_open_cursor( const VCursor * cur, const char * cur_name )
{
    rc_t rc = VCursorOpen ( cur );
    if ( rc != 0 )
    {
        (void)PLOGERR( klogErr, ( klogErr, rc, "cannot open $(cur_name)", "cur_name=%s", cur_name ) );
    }
    return rc;
}
Esempio n. 15
0
static 
rc_t SaveProjects( const ProjectTable* data, VDatabase* db )
{
    VTable* tbl;
    rc_t rc = VDatabaseCreateTable(db, &tbl, "project_inst", kcmCreate | kcmMD5, "PROJECTS");
    if (rc == 0)
    {
        rc_t rc2;
        VCursor *cur;
        rc = VTableCreateCursorWrite( tbl, &cur, kcmInsert );
        if (rc == 0)
        {
            uint32_t id_idx, name_idx, dl_idx, enc_idx;
            rc = VCursorAddColumn( cur, &id_idx, "id" );
            rc = VCursorAddColumn( cur, &name_idx, "name" );
            rc = VCursorAddColumn( cur, &dl_idx, "download_ticket" );
            rc = VCursorAddColumn( cur, &enc_idx, "encryption_key" );
            if (rc == 0)
            {
                rc = VCursorOpen( cur );
                if (rc == 0)
                {
                    const Project* p = (const Project*)BSTreeFirst(data);
                    while (rc == 0 && p != NULL)
                    {
                        rc = VCursorOpenRow( cur );
                        
                        if (rc == 0) rc = VCursorWrite( cur, id_idx,    sizeof(p->id) * 8,                      &p->id,                     0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, name_idx,  StringLength(p->name) * 8,              p->name->addr,              0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, dl_idx,    StringLength(p->download_ticket) * 8,   p->download_ticket->addr,   0, 1);
                        if (rc == 0) rc = VCursorWrite( cur, enc_idx,   StringLength(p->encryption_key) * 8,    p->encryption_key->addr,    0, 1);
                        
                        if (rc == 0) rc = VCursorCommitRow( cur );
                        if (rc == 0) rc = VCursorCloseRow( cur );
                        
                        p = (const Project*)BSTNodeNext(&p->dad);
                    }
                    if (rc == 0)
                        rc = VCursorCommit( cur );
                }
            }
            rc2 = VCursorRelease(cur);
            if (rc == 0)
                rc = rc2;
        }
        
        rc2 = VTableRelease(tbl);
        if (rc == 0)
            rc = rc2;
    }
    return rc;
}
Esempio n. 16
0
static rc_t vdb_prepare_cursor( const p_dump_context ctx, const VTable * tbl, fastq_ctx * fctx )
{
    rc_t rc;

    /* first we try to open READ/QUALITY/NAME */
    rc = VTableCreateCachedCursorRead( tbl, &fctx->cursor, ctx->cur_cache_size );
    DISP_RC( rc, "VTableCreateCursorRead( 1st ) failed" );
    if ( rc == 0 )
    {
        rc = VCursorAddColumn( fctx->cursor, &fctx->idx_read, "(INSDC:dna:text)READ" );
        if ( rc == 0 && ctx->format == df_fastq )
            rc = VCursorAddColumn( fctx->cursor, &fctx->idx_qual, "(INSDC:quality:text:phred_33)QUALITY" );
        else
            fctx->idx_qual = INVALID_COLUMN;
        if ( rc == 0 )
            rc = VCursorAddColumn( fctx->cursor, &fctx->idx_name, "(ascii)NAME" );
        if ( rc == 0 )
            rc = VCursorOpen ( fctx->cursor );

        if ( rc != 0 )
        {
            VCursorRelease( fctx->cursor );
            rc = VTableCreateCachedCursorRead( tbl, &fctx->cursor, ctx->cur_cache_size );
            DISP_RC( rc, "VTableCreateCursorRead( 2nd ) failed" );
            if ( rc == 0 )
            {
                rc = VCursorAddColumn( fctx->cursor, &fctx->idx_read, "(INSDC:dna:text)READ" );
                if ( rc == 0 && ctx->format == df_fastq )
                    rc = VCursorAddColumn( fctx->cursor, &fctx->idx_qual, "(INSDC:quality:text:phred_33)QUALITY" );
                else
                    fctx->idx_qual = INVALID_COLUMN;
                if ( rc == 0 )
                    rc = VCursorOpen ( fctx->cursor );
                fctx->idx_name = INVALID_COLUMN;
            }
        }
    }
    return rc;
}
Esempio n. 17
0
rc_t AlignRefTableCursor(const VTable* table, const VCursor *native_curs, const VCursor** ref_cursor,const VTable **reftbl)
{
	rc_t rc = 0;
	char ref_tbl_name[512] =  "REFERENCE";
	const KMetadata* meta;
	const VCursor *curs;

	if( (rc = VTableOpenMetadataRead(table, &meta)) == 0 ) {
	    const KMDataNode* node;
            if( (rc = KMetadataOpenNodeRead(meta, &node, "CONFIG/REF_TABLE")) == 0 ) {
                size_t sz;
                rc = KMDataNodeReadCString(node, ref_tbl_name, sizeof(ref_tbl_name), &sz);
                ref_tbl_name[sz] = '\0';
                KMDataNodeRelease(node);
            }
            KMetadataRelease(meta);
        }
	rc = VCursorLinkedCursorGet(native_curs,ref_tbl_name,&curs);
	if(rc != 0){
		const VDatabase *db;
                const VTable *tbl;
                /* get at the parent database */
                rc = VTableOpenParentRead ( table, & db );
                if(rc != 0) return rc;
                /* open the table */
                rc = VDatabaseOpenTableRead ( db, &tbl, ref_tbl_name);
                VDatabaseRelease ( db );
                if(rc != 0) return rc;
                /* create a cursor */
                rc = VTableCreateCachedCursorRead(tbl, &curs,256*1024*1024);
		if(reftbl){
			*reftbl = tbl;
                } else {
			VTableRelease(tbl);
		}
                if(rc != 0) return rc;
                rc = VCursorPermitPostOpenAdd( curs );
                if(rc != 0) return rc;
                rc = VCursorOpen( curs );
                if(rc != 0) return rc;
                if(native_curs){
                    rc = VCursorLinkedCursorSet(native_curs,ref_tbl_name,curs);
                }
                if(rc != 0) return rc;
	} else {
		VCursorAddRef(curs);
	}
	*ref_cursor = curs;
	return 0;
}
Esempio n. 18
0
rc_t SRATableFillOut ( SRATable *self, bool update )
{
    rc_t rc;
    
    /* require these operations to succeed */
    rc = VCursorPermitPostOpenAdd(self->curs);
    if ( rc != 0 )
        return rc;
    rc = VCursorOpen(self->curs);
    if ( rc != 0 )
        return rc;
    self -> curs_open = true;
    if ( ! update )
        rc = SRATableLoadMetadata(self);
    return rc;
}
Esempio n. 19
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;
}
Esempio n. 20
0
/* special case for SEQUENCE: in order to prepare the cursor correctly, we have to know the first HDF5-source-obj !*/
rc_t prepare_seq( VDatabase * database, seq_ctx * sctx, KDirectory * hdf5_src, ld_context *lctx )
{
    rc_t rc = prepare_table( database, &sctx->cursor, seq_schema_template, seq_table_to_create ); /* pl-tools.c ... this creates the cursor */
    sctx->src_open = false;
    if ( rc == 0 )
    {
        rc = open_BaseCalls( hdf5_src, &sctx->BaseCallsTab, "PulseData/BaseCalls", lctx->cache_content, &sctx->rgn_present );
        if ( rc == 0 )
        {
            int32_t to_exclude;

            /* depending on the bit-size of the PulseIndex-table in HDF5
               exclude the opposite column from VDB */
            if ( sctx->BaseCallsTab.PulseIndex.element_bits == PULSE_INDEX_BITSIZE_16 )
                to_exclude = seq_tab_PULSE_INDEX_32;
            else
                to_exclude = seq_tab_PULSE_INDEX_16;

            /* add all columns to the vdb-cursor */
            rc = add_columns( sctx->cursor, seq_tab_count, to_exclude, sctx->col_idx, seq_tab_names );
            if ( rc == 0 )
            {
                rc = VCursorOpen( sctx->cursor );
                if ( rc != 0 )
                {
                    LOGERR( klogErr, rc, "cannot open cursor on seq-table" );
                }
                else
                {
                    const uint8_t platform = SRA_PLATFORM_PACBIO_SMRT;

                    rc = VCursorDefault ( sctx->cursor, sctx->col_idx[ seq_tab_PLATFORM ], 8, &platform, 0, 1 );
                    if ( rc != 0 )
                    {
                        LOGERR( klogErr, rc, "cannot set cursor-default on seq-table for platform-column" );
                    }
                    else
                    {
                        sctx->src_open = true;
                        sctx->lctx = lctx;
                    }
                }
            }
        }
    }
    return rc;
}
Esempio n. 21
0
static
rc_t init_self( self_t *self, VTable const * const srctbl, char const column[] )
{
    VDatabase const * db;
    rc_t rc = VTableOpenParentRead( srctbl, &db );
    if ( rc == 0 )
    {
        VTable const * tbl;
        rc = VDatabaseOpenTableRead( db, &tbl, "SEQUENCE" );
        VDatabaseRelease( db );
        if ( rc == 0 )
        {
            bool has_column = does_table_have_column( tbl, column );
            if ( !has_column )
                VTableRelease( tbl );
            else
            {
                VCursor const * curs;
#if CURSOR_CACHE_SIZE
                rc = VTableCreateCachedCursorRead( tbl, &curs, CURSOR_CACHE_SIZE );
#else
                rc = VTableCreateCursorRead( tbl, &curs );
#endif
                VTableRelease( tbl );
                if ( rc == 0 )
                {
                    uint32_t col_idx;
                    rc = VCursorAddColumn( curs, &col_idx, "%s", column );
                    if ( rc == 0 )
                    {
                        rc = VCursorOpen( curs );
                        if ( rc == 0 )
                        {
                            self->curs = curs;
                            self->col_idx = col_idx;
                            return 0;
                        }
                        if ( GetRCObject( rc ) == (enum RCObject)rcColumn && GetRCState( rc ) == rcUndefined )
                            rc = 0;
                    }
                    VCursorRelease( curs );
                }
            }
        }
    }
    return rc;
}
Esempio n. 22
0
rc_t open_write_cursor (VTable * table, VCursor ** cursor,
                        uint32_t * dat, uint32_t * len, 
                        const char * dat_name, const char* len_name)
{
    rc_t rc;

    rc = VTableCreateCursorWrite (table, cursor, kcmInsert);
    if (rc)
    {
        LOGERR (klogErr, rc, "Failed to create Cursor");
        *cursor = NULL;
    }
    else
    {
        do
        {
            rc = VCursorAddColumn (*cursor, dat, dat_name);
            if (rc)
            {
                pLOGERR (klogErr, rc, "Failed to add column $(C)", PLOG_S(C), dat_name);
                break;
            }

            rc = VCursorAddColumn (*cursor, len, len_name);
            if (rc)
            {
                pLOGERR (klogErr, rc, "Failed to add column $(C)", PLOG_S(C), len_name);
                break;
            }       

            rc = VCursorOpen (*cursor);
            if (rc)
            {
                LOGERR (klogErr, rc, "Failed to open cursor");
                break;
            }

            return 0;
        }
        while (0);
    }
    VCursorRelease (*cursor);
    *dat = 0;
    *len = 0;
    *cursor = NULL;
    return rc;
}
Esempio n. 23
0
/* Read - PRIVATE
 *  column message sent via table
 */
rc_t SRATableRead ( const SRATable *self, spotid_t id, uint32_t idx,
    const void **base, bitsz_t *offset, bitsz_t *size )
{
    rc_t rc;

    if ( base == NULL || offset == NULL || size == NULL )
        rc = RC ( rcSRA, rcColumn, rcReading, rcParam, rcNull );
    else if ( self == NULL )
        rc = RC ( rcSRA, rcTable, rcAccessing, rcSelf, rcNull );
    else
    {
        rc = 0;

        /* open cursor */
        if ( ! self -> curs_open )
        {
            rc = VCursorOpen(self->curs);
            if ( rc == 0 )
                ((SRATable *)self)->curs_open = true;
        }

        if ( rc == 0 )
        {
            uint32_t elem_bits, elem_off, elem_cnt;
            rc = VCursorCellDataDirect ( self -> curs, id, idx,
                & elem_bits, base, & elem_off, & elem_cnt );
            if ( rc == 0 )
            {
                * offset = elem_off * elem_bits;
                * size   = elem_cnt * elem_bits;
                return 0;
            } else if( UIError(rc, NULL, self->vtbl) ) {
                UITableLOGError(rc, self->vtbl, true);
            }
        }
    }

    if ( base != NULL )
        * base = NULL;
    if ( offset != NULL )
        * offset = 0;
    if ( size != NULL )
        * size = 0;

    return rc;
}
Esempio n. 24
0
static rc_t open_writer_cursor( statistic_writer *writer )
{
    rc_t rc = 0;
    uint32_t idx;

    for ( idx = 0; idx < N_WIDX && rc == 0; ++idx )
    {
        rc = add_column( writer->cursor, &writer->wr_col[ idx ], widx_names[ idx ] );
    }
    if ( rc == 0 )
    {
        rc = VCursorOpen ( writer->cursor );
        if ( rc != 0 )
            LogErr( klogInt, rc, "VCursorOpen failed\n" );
    }
    return rc;
}
Esempio n. 25
0
rc_t prepare_consensus( VDatabase * database, con_ctx * sctx, ld_context *lctx )
{
    rc_t rc = prepare_table( database, &sctx->cursor,
            consensus_schema_template, consensus_table_to_create ); /* pl-tools.c ... this creates the cursor */
    if ( rc == 0 )
    {
        rc = add_columns( sctx->cursor, consensus_tab_count, -1, sctx->col_idx, consensus_tab_names );
        if ( rc == 0 )
        {
            rc = VCursorOpen( sctx->cursor );
            if ( rc != 0 )
            {
                LOGERR( klogErr, rc, "cannot open cursor on consensus-table" );
            }
            else
            {
                const INSDC_SRA_platform_id platform = SRA_PLATFORM_PACBIO_SMRT;

                rc = VCursorDefault ( sctx->cursor, sctx->col_idx[ consensus_tab_PLATFORM ],
                                      sizeof platform * 8, &platform, 0, 1 );
                if ( rc != 0 )
                {
                    LOGERR( klogErr, rc, "cannot set cursor-default on consensus-table for platform-column" );
                }
                else
                {
                    const INSDC_SRA_read_filter filter = SRA_READ_FILTER_PASS;
                    rc = VCursorDefault ( sctx->cursor, sctx->col_idx[ consensus_tab_READ_FILTER ],
                                      sizeof filter * 8, &filter, 0, 1 );
                    if ( rc != 0 )
                    {
                        LOGERR( klogErr, rc, "cannot set cursor-default on consensus-table for read-filter-column" );
                    }
                    else
                    {
                        sctx->lctx = lctx;
                    }
                }
            }
        }
    }
    return rc;
}
Esempio n. 26
0
rc_t prepare_passes( VDatabase * database, pas_ctx * sctx, ld_context *lctx )
{
    rc_t rc = prepare_table( database, &sctx->cursor,
            passes_schema_template, passes_table_to_create ); /* pl-tools.c ... this creates the cursor */
    if ( rc == 0 )
    {
        rc = add_columns( sctx->cursor, passes_tab_count, -1, sctx->col_idx, passes_tab_names );
        if ( rc == 0 )
        {
            rc = VCursorOpen( sctx->cursor );
            if ( rc != 0 )
            {
                LOGERR( klogErr, rc, "cannot open cursor on PASSES-tab" );
            }
            else
            {
                sctx->lctx = lctx;
            }
        }
    }
    return rc;
}
Esempio n. 27
0
void CVDBCursor::Init(const CVDBTable& table)
{
    if ( *this ) {
        NCBI_THROW2(CSraException, eInvalidState,
                    "Cannot init VDB cursor again",
                    RC(rcApp, rcCursor, rcConstructing, rcSelf, rcOpen));
    }
    if ( rc_t rc = VTableCreateCursorRead(table, x_InitPtr()) ) {
        *x_InitPtr() = 0;
        NCBI_THROW2(CSraException, eInitFailed,
                    "Cannot create VDB cursor", rc);
    }
    if ( rc_t rc = VCursorPermitPostOpenAdd(*this) ) {
        NCBI_THROW2(CSraException, eInitFailed,
                    "Cannot allow VDB cursor post open column add", rc);
    }
    if ( rc_t rc = VCursorOpen(*this) ) {
        NCBI_THROW2(CSraException, eInitFailed,
                    "Cannot open VDB cursor", rc);
    }
    m_Table = table;
}
Esempio n. 28
0
static
rc_t open_RR_cursor( Read_Restorer * obj, const VTable *tbl, const VCursor* native_curs, const char * tablename )
{
    rc_t rc = VCursorLinkedCursorGet( native_curs, tablename, &obj->curs );
    if ( rc != 0 )
    {
        /* get at the parent database */
        const VDatabase *db;
        rc = VTableOpenParentRead ( tbl, & db );
        if ( rc == 0 )
        {
            const VTable *patbl;
            /* open the primary alignment table */
            rc = VDatabaseOpenTableRead ( db, & patbl, tablename );
            VDatabaseRelease ( db );
            if ( rc == 0 )
            {
                /* create a cursor */
                rc = VTableCreateCachedCursorRead( patbl, &obj->curs, 32*1024*1024UL );
                /* rc = VTableCreateCursorRead( patbl, &obj->curs ); */
                VTableRelease ( patbl );
                if ( rc == 0 )
                    rc = VCursorLinkedCursorSet( native_curs, tablename, obj->curs );
            }
        }
    }
    if ( rc == 0 )
    {
        /* add columns to cursor */
        rc = VCursorAddColumn ( obj -> curs, & obj -> read_idx, "( INSDC:4na:bin ) READ" );
        if ( GetRCState(rc) == rcExists )
            rc = 0;
        if ( rc == 0 )
        {
            rc = VCursorOpen ( obj -> curs );
        }
    }
    return rc;
}
Esempio n. 29
0
static rc_t prepare_ref_node( ref_node * node )
{
    rc_t rc = VTableCreateCursorRead ( node->tab, &node->cur );
    if ( rc != 0 )
    {
        PLOGERR( klogInt, ( klogInt, rc, 
             "error to create cursor on table $(db_name).$(tab_name)",
             "db_name=%S,tab_name=%s",
             node->name, HITMAP_TAB ) );
    }
    else
    {
        rc = VCursorAddColumn ( node->cur, &node->hits_idx, HITS_COLUMN );
        if ( rc != 0 )
        {
            PLOGERR( klogInt, ( klogInt, rc, 
                 "error to add column $(col_name) to cursor for table $(db_name).$(tab_name)",
                 "col_name=%s,db_name=%S,tab_name=%s",
                 HITS_COLUMN, node->name, HITMAP_TAB ) );
        }
        else
        {
            rc = VCursorOpen( node->cur );
            if ( rc != 0 )
            {
                PLOGERR( klogInt, ( klogInt, rc, 
                     "error to open cursor for table $(tab_name)",
                     "tab_name=%S", node->name ) );
            }
            else
            {
                node->valid = true;
            }
        }
    }
    return rc;
}
Esempio n. 30
0
static rc_t report_deletes_db( const VDBManager *vdb_mgr,
                               const char * path,
                               uint32_t min_len )
{
    const VDatabase *db;
    rc_t rc = VDBManagerOpenDBRead( vdb_mgr, &db, NULL, "%s", path );
    if ( rc != 0 )
    {
        (void)PLOGERR( klogErr,
                 ( klogInt, rc, "cannot open database $(db_name)", "db_name=%s", path ) );
    }
    else
    {
        const VTable *tab;
        rc = VDatabaseOpenTableRead( db, &tab, "PRIMARY_ALIGNMENT" );
        if ( rc != 0 )
        {
            (void)LOGERR( klogErr, rc, "cannot open table PRIMARY_ALIGNMENT" );
        }
        else
        {
            const VCursor *cur;
            rc = VTableCreateCursorRead( tab, &cur );
            if ( rc != 0 )
            {
                (void)LOGERR( klogErr, rc, "cannot open cursor on table PRIMARY_ALIGNMENT" );
            }
            else
            {
                uint32_t cigar_idx;
                rc = VCursorAddColumn( cur, &cigar_idx, "CIGAR_SHORT" );
                if ( rc != 0 )
                {
                    (void)LOGERR( klogErr, rc, "cannot add CIGAR_SHORT to cursor" );
                }
                else
                {
                    rc = VCursorOpen( cur );
                    if ( rc != 0 )
                    {
                        (void)LOGERR( klogErr, rc, "cannot open cursor" );
                    }
                    else
                    {
                        int64_t first;
                        uint64_t count;
                        rc = VCursorIdRange ( cur, cigar_idx, &first, &count );
                        if ( rc != 0 )
                        {
                            (void)LOGERR( klogErr, rc, "cannot detect row-range" );
                        }
                        else
                        {
                            rc = cigar_loop( cur, cigar_idx, first, count, min_len );
                        }
                    }
                }
                VCursorRelease( cur );
            }
            VTableRelease( tab );
        }
        VDatabaseRelease( db );
    }
    return rc;
}