Exemple #1
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;
}
Exemple #2
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;
}
Exemple #3
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;
}
Exemple #4
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;
}
Exemple #5
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;
}
Exemple #6
0
static 
rc_t LoadObjects ( ObjectTable* data,  const VDatabase* db )
{
    const VTable* tbl;
    rc_t rc = VDatabaseOpenTableRead(db, &tbl, "OBJECTS");
    if (rc == 0)
    {
        rc_t rc2;
        const VCursor *cur;

        rc = VTableCreateCachedCursorRead( tbl, &cur, CursorCacheSize );
        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 && HasData(tbl))
            {
                rc = VCursorOpen( cur );
                if (rc == 0)
                {
                    int64_t  first;
                    uint64_t count;
                    rc = VCursorIdRange( cur, 0, &first, &count );
                    if (rc == 0)
                    {
                        uint64_t i;
                        for (i=0; i < count; ++i)
                        {
                            const void* ptr;
                            uint32_t elem_count;
                            uint32_t id;
                            String name;
                            String project;
                            String display_name;
                            uint64_t size;
                            String checksum;
                            String encryption_key;

                            rc = VCursorSetRowId(cur, first + i);
                            if (rc == 0) rc = VCursorOpenRow( cur );
                            
                            if (rc == 0) rc = VCursorCellData( cur, id_idx, NULL, &ptr, NULL, NULL);
                            if (rc == 0) id = *(uint32_t*)ptr;
                            
                            if (rc == 0) rc = VCursorCellData( cur, name_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&name, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = VCursorCellData( cur, proj_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&project, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = VCursorCellData( cur, dname_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&display_name, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = VCursorCellData( cur, size_idx, NULL, &ptr, NULL, NULL);
                            if (rc == 0) size = *(uint32_t*)ptr;
                            
                            if (rc == 0) rc = VCursorCellData( cur, enc_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&encryption_key, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = VCursorCellData( cur, csum_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&checksum, (const char*)ptr, elem_count, elem_count);

                            if (rc == 0) rc = KeyRingDataInsertObject(data, id, &name, &project, &display_name, size, &checksum, &encryption_key);
                            if (rc == 0) rc = VCursorCloseRow( cur );
                            if (rc != 0)
                                break;
                        }
                    }
                }
            }
            rc2 = VCursorRelease(cur);
            if (rc == 0)
                rc = rc2;
        }
        
        rc2 = VTableRelease(tbl);
        if (rc == 0)
            rc = rc2;
    }
    return rc;
}
Exemple #7
0
static 
rc_t LoadProjects( ProjectTable* data, const VDatabase* db )
{
    const VTable* tbl;
    rc_t rc = VDatabaseOpenTableRead(db, &tbl, "PROJECTS");
    if (rc == 0)
    {
        rc_t rc2;
        const VCursor *cur;

        rc = VTableCreateCachedCursorRead( tbl, &cur, CursorCacheSize );
        if (rc == 0)
        {
            uint32_t id_idx, name_idx, dl_idx, enc_idx;
            rc = VCursorAddColumn( cur, &id_idx,    "id" );
            if (rc == 0) rc = VCursorAddColumn( cur, &name_idx,  "name" );
            if (rc == 0) rc = VCursorAddColumn( cur, &dl_idx,    "download_ticket" );
            if (rc == 0) rc = VCursorAddColumn( cur, &enc_idx,   "encryption_key" );
            if (rc == 0 && HasData(tbl))
            {
                rc = VCursorOpen( cur );
                if (rc == 0)
                {
                    int64_t  first;
                    uint64_t count;
                    rc = VCursorIdRange( cur, 0, &first, &count );
                    if (rc == 0)
                    {
                        uint64_t i;
                        for (i=0; i < count; ++i)
                        {
                            const void* ptr;
                            uint32_t elem_count;
                            uint32_t id;
                            String name;
                            String download_ticket;
                            String encryption_key;

                            rc = VCursorSetRowId(cur, first + i);
                            if (rc == 0) rc = VCursorOpenRow( cur );
                            
                            if (rc == 0) rc = VCursorCellData( cur, id_idx, NULL, &ptr, NULL, NULL);
                            if (rc == 0) id = *(uint32_t*)ptr;
                            if (rc == 0) rc = VCursorCellData( cur, name_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&name, (const char*)ptr, elem_count, elem_count);
                            if (rc == 0) rc = VCursorCellData( cur, dl_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&download_ticket, (const char*)ptr, elem_count, elem_count);
                            if (rc == 0) rc = VCursorCellData( cur, enc_idx, NULL, &ptr, NULL, &elem_count);
                            if (rc == 0) StringInit(&encryption_key, (const char*)ptr, elem_count, elem_count);
                            
                            if (rc == 0) rc = KeyRingDataInsertProject(data, id, &name, &download_ticket, &encryption_key);
                            if (rc == 0) rc = VCursorCloseRow( cur );
                            if (rc != 0) 
                                break;
                        }
                    }
                }
            }
            rc2 = VCursorRelease(cur);
            if (rc == 0)
                rc = rc2;
        }
        
        rc2 = VTableRelease(tbl);
        if (rc == 0)
            rc = rc2;
    }
    return rc;
}
Exemple #8
0
static rc_t cg_dump_src_dst_rows_vdb( cg_dump_opts * opts, const VDBManager * mgr, const char * src, cg_dump_ctx * cg_ctx )
{
    const VDatabase * db;
    rc_t rc = VDBManagerOpenDBRead( mgr, &db, NULL, "%s", src );
    if ( rc != 0 )
    {
        (void)LOGERR( klogErr, rc, "cannot open database" );
    }
    else
    {
        rc = parse_sg_lookup( cg_ctx->lookup, db ); /* in sg_lookup.c */
        if ( rc == 0 )
        {
            const VTable * seq;
            rc = VDatabaseOpenTableRead( db, &seq, "SEQUENCE" );
            if ( rc != 0 )
            {
                (void)LOGERR( klogErr, rc, "cannot open SEQUENCE-table" );
            }
            else
            {
                const VTable * prim;
                rc = VDatabaseOpenTableRead( db, &prim, "PRIMARY_ALIGNMENT" );
                if ( rc != 0 )
                {
                    (void)LOGERR( klogErr, rc, "cannot open PRIMARY-ALIGNMENT-table" );
                }
                else
                {
                    if ( opts->cursor_cache > 0 )
                        rc = VTableCreateCachedCursorRead( seq, &cg_ctx->seq_cur, opts->cursor_cache );
                    else
                        rc = VTableCreateCursorRead( seq, &cg_ctx->seq_cur );
                    if ( rc != 0 )
                    {
                        (void)LOGERR( klogErr, rc, "cannot create cursor for SEQUENCE-table" );
                    }
                    else
                    {
    /*
                        if ( opts->cursor_cache > 0 )
                            rc = VTableCreateCachedCursorRead( prim, &cg_ctx->prim_cur, opts->cursor_cache );
                        else
                            rc = VTableCreateCursorRead( prim, &cg_ctx->prim_cur );
                        if ( rc != 0 )
                        {
                            (void)LOGERR( klogErr, rc, "cannot create cursor for PRIMARY_ALIGNMENT-table" );
                        }
    */

                        if ( rc == 0 )
                        {
                            rc = cg_dump_src_dst_rows_cur( opts, cg_ctx );  /* <================== */
                            /* VCursorRelease( cg_ctx->prim_cur ); */
                        }
                        VCursorRelease( cg_ctx->seq_cur );
                    }
                    /* VTableRelease( prim ); */
                }
                VTableRelease( seq );
            }
        }
        VDatabaseRelease( db );
    }
    return rc;
}