Exemplo n.º 1
0
static rc_t RefSeq_WGS_open(RefSeq *const super, RefSeqMgr const *const mgr)
{
    struct RefSeq_WGS *const self = &super->u.wgs;
    VDatabase const *db;
    rc_t rc = VDBManagerOpenDBRead(mgr->vmgr, &db, NULL, self->name);

    if (db) {
        char scheme[1024];
        
        get_db_schema_info(db, sizeof(scheme), scheme);
        if (strcmp(scheme, "NCBI:WGS:db:contig") == 0) {
            VTable const *tbl;
            
            rc = VDatabaseOpenTableRead(db, &tbl, "SEQUENCE");
            if (tbl) {
                rc = TableReaderWGS_MakeTable(&self->reader, mgr->vmgr, tbl,
                                                 mgr->reader_options, mgr->cache);
                VTableRelease(tbl);
            }
        }
        else {
            rc = RC(rcAlign, rcTable, rcOpening, rcType, rcInvalid);
        }
        VDatabaseRelease(db);
    }
    return rc;
}
Exemplo n.º 2
0
static rc_t prepare_db_table( prepare_ctx *ctx,
                              const VDBManager *vdb_mgr,
                              VSchema *vdb_schema,
                              const char * path )
{
    rc_t rc;
    ctx->db = NULL;
    ctx->seq_tab = NULL;

    rc = VDBManagerOpenDBRead ( vdb_mgr, &ctx->db, vdb_schema, "%s", path );
    if ( rc != 0 )
    {
        rc = VDBManagerOpenTableRead ( vdb_mgr, &ctx->seq_tab, NULL, "%s", path );
        if ( rc != 0 )
        {
            PLOGERR( klogErr, ( klogErr, rc, "failed to open '$(path)'", "path=%s", path ) );
        }
        else {
            ReportResetTable(path, ctx->seq_tab);
        }
    }
    else
    {
        rc = VDatabaseOpenTableRead( ctx->db, &ctx->seq_tab, "SEQUENCE" );
        if ( rc != 0 )
        {
            LOGERR( klogInt, rc, "VDatabaseOpenTableRead( SEQUENCE ) failed" );
        }
        else
        {
            ReportResetDatabase( path, ctx->db );
        }
    }
    return rc;
}
Exemplo n.º 3
0
static rc_t get_prim_align_cursor( const VDatabase *db, const VCursor **curs )
{
    const VTable *tbl;
    rc_t rc = VDatabaseOpenTableRead ( db, &tbl, "PRIMARY_ALIGNMENT" );
    if ( rc != 0 )
        LOGERR( klogInt, rc, "VDatabaseOpenTableRead(PRIMARY_ALIGNMENT) failed" );
    else
    {
        rc = VTableCreateCursorRead ( tbl, curs );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "VTableCreateCursorRead(tab=PRIMARY_ALIGNMENT) failed" );
        else
        {
            uint32_t throw_away_idx;
            rc = VCursorAddColumn ( *curs, &throw_away_idx, "QUALITY" );
            if ( rc != 0 )
                LOGERR( klogInt, rc, "VTableCreateCursorRead(QUALITY) failed" );
            else
            {
                rc = VCursorAddColumn ( *curs, &throw_away_idx, "REF_ORIENTATION" );
                if ( rc != 0 )
                    LOGERR( klogInt, rc, "VTableCreateCursorRead(REF_ORIENTATION) failed" );
            }
        }
        VTableRelease ( tbl );
    }
    return rc;
}
Exemplo n.º 4
0
static rc_t report_ref_table( const VDBManager *vdb_mgr, const char * path, int64_t start, int64_t stop )
{
    const VDatabase* db;
    rc_t rc = VDBManagerOpenDBRead ( vdb_mgr, &db, NULL, "%s", path );
    if ( rc != 0 )
    {
        (void)LOGERR( klogErr, rc, "cannot open vdb-database" );
    }
    else
    {
        const VTable* tb;
        rc = VDatabaseOpenTableRead ( db, &tb, "REFERENCE" );
        if ( rc != 0 )
        {
            (void)LOGERR( klogErr, rc, "cannot open REFERENCE-table" );
        }
        else
        {
            const VCursor *cur;
            rc = VTableCreateCursorRead ( tb, &cur );
            if ( rc != 0 )
            {
                (void)LOGERR( klogErr, rc, "cannot open REFERENCE-cursor" );
            }
            else
            {
                rc = report_ref_cursor( cur, start, stop );
                VCursorRelease( cur );
            }
            VTableRelease ( tb );
        }
        VDatabaseRelease ( db );
    }
    return rc;
}
Exemplo n.º 5
0
static rc_t ref_walker_add_iterator( struct ref_walker * self, const char * ref_name,
                        uint64_t start, uint64_t end, const char * src_name, Vector * cur_id_vector,
                        const VDatabase *db, const ReferenceObj * ref_obj, ReferenceIterator * ref_iter,
                        const char * table_name, align_id_src id_selector )
{
    walker_col_ids * cursor_ids;
    rc_t rc = make_cursor_ids( cur_id_vector, &cursor_ids );
    if ( rc == 0 )
    {
        const VTable *tbl;
        rc_t rc = VDatabaseOpenTableRead ( db, &tbl, table_name );
        if ( rc == 0 )
        {
            const VCursor *cursor;
            rc = add_required_columns( self, tbl, &cursor, cursor_ids );
            if ( rc == 0 )
            {
                rc = ReferenceIteratorAddPlacements ( ref_iter,             /* the outer ref-iter */
                                                      ref_obj,              /* the ref-obj for this chromosome */
                                                      start - 1,            /* start ( zero-based ) */
                                                      ( end - start ) + 1,  /* length */
                                                      NULL,                 /* ref-cursor */
                                                      cursor,               /* align-cursor */
                                                      id_selector,          /* which id's */
                                                      self->spot_group,     /* what read-group */
                                                      cursor_ids            /* placement-context */
                                                     );
                VCursorRelease( cursor );
            }
            VTableRelease ( tbl );
        }
    }
    return rc;
}
Exemplo n.º 6
0
CVDBTable::CVDBTable(const CVDB& db,
                     const char* table_name,
                     EMissing missing)
    : m_Db(db),
      m_Name(table_name)
{
    DECLARE_SDK_GUARD();
    if ( rc_t rc = VDatabaseOpenTableRead(db, x_InitPtr(), table_name) ) {
        *x_InitPtr() = 0;
        RCState rc_state = GetRCState(rc);
        int rc_object = GetRCObject(rc);
        if ( rc_state == rcNotFound &&
             (rc_object == rcParam ||
              rc_object == rcPath) ) {
            // missing table in the DB
            if ( missing != eMissing_Throw ) {
                return;
            }
            NCBI_THROW2_FMT(CSraException, eNotFoundTable,
                            "Cannot open VDB table: "<<*this, rc);
        }
        else {
            // other errors
            NCBI_THROW2_FMT(CSraException, eOtherError,
                            "Cannot open VDB table: "<<*this, rc);
        }
    }
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
0
static uint64_t get_tab_row_count( const VDatabase * db, const char * table_name )
{
    uint64_t res = 0;
    const VTable * tab;
    rc_t rc = VDatabaseOpenTableRead( db, &tab, table_name );
    if ( rc == 0 )
    {
        res = get_rowcount( tab );
        VTableRelease( tab );
    }
    return res;
}
Exemplo n.º 9
0
static rc_t read_statistic_from_table( statistic * data,
                                       KDirectory *dir,
                                       context *ctx,
                                       const VDatabase *my_database,
                                       const char *table_name )
{
    const VTable *my_table;
    rc_t rc = VDatabaseOpenTableRead( my_database, &my_table, "%s", table_name );
    if ( rc != 0 )
    {
        LogErr( klogInt, rc, "VDatabaseOpenTableRead() failed\n" );
    }
    else
    {
        const VCursor *my_cursor;
        rc = VTableCreateCursorRead( my_table, &my_cursor );
        if ( rc != 0 )
            LogErr( klogInt, rc, "VTableCreateCursorRead() failed\n" );
        else
        {
/*
            spot_pos sequence;

            rc = make_spot_pos( &sequence, my_database );
            if ( rc == 0 )
            {
*/
                statistic_reader reader;

/*
                rc = make_statistic_reader( &reader, &sequence, dir, my_cursor,
                            ctx->exclude_file_path, ctx->info );
*/
                rc = make_statistic_reader( &reader, NULL, dir, my_cursor,
                            ctx->exclude_file_path, ctx->info );

                if ( rc == 0 )
                {
                    /* ******************************************************* */
                    rc = read_loop( data, ctx, &reader, my_cursor );
                    /* ******************************************************* */
                    whack_reader( &reader );
                }
/*
                whack_spot_pos( &sequence );
            }
*/
            VCursorRelease( my_cursor );
        }
        VTableRelease( my_table );
    }
    return rc;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
static rc_t extract_spotgroups( VNamelist * spotgroups, input_files * ifs, bool from_stats )
{
    rc_t rc = 0;
    uint32_t i;
    for ( i = 0; i < ifs->database_count && rc == 0; ++i )
    {
        input_database * id = VectorGet( &ifs->dbs, i );
        if ( id != NULL )
        {
            if ( from_stats )
            {
                const VTable * tab;
                rc = VDatabaseOpenTableRead( id->db, &tab, "SEQUENCE" );
                if ( rc != 0 )
                    (void)PLOGERR( klogErr, ( klogErr, rc, "cannot open table SEQUENCE in '$(t)'", "t=%s", id->path ) );
                else
                {
                    const KMetadata * meta;
                    rc = VTableOpenMetadataRead( tab, &meta );
                    if ( rc != 0 )
                        (void)PLOGERR( klogErr, ( klogErr, rc, "cannot open metadata from '$(t)'", "t=%s", id->path ) );
                    else
                    {
                        if ( from_stats )
                            rc = extract_spotgroups_from_stats( spotgroups, id, meta );
                        KMetadataRelease( meta );
                    }
                    VTableRelease( tab );
                }
            }
            else
            {
                const KMetadata * meta;
                rc = VDatabaseOpenMetadataRead( id->db, &meta );
                /* do not report if metadata cannot be found, because this would produce an error message when a database has
                   no metadata at all */
                if ( rc == 0 )
                {
                    rc = extract_spotgroups_from_bam_hdr( spotgroups, id, meta );
                    KMetadataRelease( meta );
                }

            }
        }
    }
    return rc;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
static
void GetReadGroupInfo( SRA_DB_ReadCollection * self, ctx_t ctx )
{
    if ( self -> group_info == NULL )
    {
        const VTable * table;
        rc_t rc = VDatabaseOpenTableRead ( self -> db, & table, "SEQUENCE" );
        if ( rc != 0 )
        {
            INTERNAL_ERROR ( xcUnexpected, "VDatabaseOpenTableRead(SEQUENCE) rc = %R", rc );
        }
        else
        {
            self -> group_info = SRA_ReadGroupInfoMake ( ctx, table );
            VTableRelease ( table );
        }
    }
}
Exemplo n.º 14
0
static rc_t vdb_info_db( vdb_info_data * data, VSchema * schema, const VDBManager *mgr )
{
    const VDatabase * db;
    rc_t rc = VDBManagerOpenDBRead( mgr, &db, schema, "%s", data->acc );
    if ( rc == 0 )
    {
        const VTable * tab;
        const KMetadata * meta = NULL;

        rc_t rc1 = VDatabaseOpenTableRead( db, &tab, "SEQUENCE" );
        if ( rc1 == 0 )
        {
            data->s_platform = get_platform( tab );
            data->seq_rows = get_rowcount( tab );
            VTableRelease( tab );
        }

        data->ref_rows          = get_tab_row_count( db, "REFERENCE" );
        data->prim_rows         = get_tab_row_count( db, "PRIMARY_ALIGNMENT" );
        data->sec_rows          = get_tab_row_count( db, "SECONDARY_ALIGNMENT" );
        data->ev_rows           = get_tab_row_count( db, "EVIDENCE_ALIGNMENT" );
        data->ev_int_rows       = get_tab_row_count( db, "EVIDENCE_INTERVAL" );
        data->consensus_rows    = get_tab_row_count( db, "CONSENSUS" );
        data->passes_rows       = get_tab_row_count( db, "PASSES" );
        data->metrics_rows      = get_tab_row_count( db, "ZMW_METRICS" );

        if ( data->ref_rows > 0 )
            get_species( data->species, sizeof data->species, db, mgr );
        
        rc = VDatabaseOpenMetadataRead ( db, &meta );
        if ( rc == 0 )
        {
            get_meta_info( data, meta );
            KMetadataRelease ( meta );
        }

        VDatabaseRelease( db );
    }
    return rc;

}
Exemplo n.º 15
0
static rc_t vdb_fastq_database( const p_dump_context ctx,
                                const VDBManager *mgr,
                                fastq_ctx * fctx )
{
    const VDatabase * db;
    VSchema *schema = NULL;
    rc_t rc;

    vdh_parse_schema( mgr, &schema, &(ctx->schema_list) );

    rc = VDBManagerOpenDBRead( mgr, &db, schema, ctx->path );
    DISP_RC( rc, "VDBManagerOpenDBRead() failed" );
    if ( rc == 0 )
    {
        bool table_defined = ( ctx->table != NULL );
        if ( !table_defined )
            table_defined = vdh_take_this_table_from_db( ctx, db, "SEQUENCE" );

        if ( table_defined )
        {
            const VTable * tbl;

            rc = VDatabaseOpenTableRead( db, &tbl, ctx->table );
            DISP_RC( rc, "VDatabaseOpenTableRead() failed" );
            if ( rc == 0 )
            {
                rc = vdb_fastq_tbl( ctx, tbl, fctx );
                VTableRelease( tbl );
            }
        }
        else
        {
            LOGMSG( klogInfo, "opened as vdb-database, but no table found/defined" );
            ctx->usage_requested = true;
        }
        VDatabaseRelease( db );
    }

    VSchemaRelease( schema );
    return rc;
}
Exemplo n.º 16
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;
}
Exemplo n.º 17
0
static void get_species( char * buffer, size_t buffer_size, const VDatabase * db, const VDBManager *mgr )
{
    const VTable * tab;
    rc_t rc = VDatabaseOpenTableRead( db, &tab, "REFERENCE" );
    if ( rc == 0 )
    {
        char seq_id[ 1024 ];
        
        seq_id[ 0 ] = 0;
        get_string_cell( seq_id, sizeof seq_id, tab, 1, "SEQ_ID" );
        VTableRelease( tab );
        if ( seq_id[ 0 ] != 0 )
        {
            rc = VDBManagerOpenTableRead( mgr, &tab, NULL, "%s", seq_id );
            if ( rc == 0 )
            {
                get_string_cell( buffer, buffer_size, tab, 1, "DEF_LINE" );
                VTableRelease( tab );    
            }
        }
    }
}
Exemplo n.º 18
0
rc_t init_vdb_objects (
    VDBManager const** mgr,
    VDatabase const** db,
    VTable const** table_ref,
    VTable const** table_pa,
    VCursor const** cursor_ref,
    VCursor const** cursor_pa,
    char const* db_path,
    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
    )
{
    rc_t rc = 0;

    rc = VDBManagerMakeRead ( mgr, NULL );
    if ( rc != 0 )
    {
        rc_t res = string_printf ( error_buf, error_buf_size, NULL,
            "ERROR: VDBManagerMakeRead failed with error: 0x%08x (%u) [%R]",
            rc, rc, rc);
        if (res == rcBuffer || res == rcInsufficient)
            error_buf [ error_buf_size - 1 ] = '\0';

        return rc;
    }

    rc = VDBManagerOpenDBRead ( *mgr, db, NULL, db_path );
    if ( rc != 0 )
    {
        rc_t res = string_printf ( error_buf, error_buf_size, NULL,
            "ERROR: VDBManagerOpenDBRead(%s) failed with error: 0x%08x (%u) [%R]",
            db_path, rc, rc, rc);
        if (res == rcBuffer || res == rcInsufficient)
            error_buf [ error_buf_size - 1 ] = '\0';

        return rc;
    }

    rc = VDatabaseOpenTableRead ( *db, table_ref, "REFERENCE" );
    if ( rc != 0 )
    {
        rc_t res = string_printf ( error_buf, error_buf_size, NULL,
            "ERROR: VDatabaseOpenTableRead(REFERENCE) failed with error: 0x%08x (%u) [%R]",
            rc, rc, rc);
        if (res == rcBuffer || res == rcInsufficient)
            error_buf [ error_buf_size - 1 ] = '\0';

        return rc;
    }

    rc = VDatabaseOpenTableRead ( *db, table_pa, "PRIMARY_ALIGNMENT" );
    if ( rc != 0 )
    {
        rc_t res = string_printf ( error_buf, error_buf_size, NULL,
            "ERROR: VDatabaseOpenTableRead(PRIMARY_ALIGNMENT) failed with error: 0x%08x (%u) [%R]",
            rc, rc, rc);
        if (res == rcBuffer || res == rcInsufficient)
            error_buf [ error_buf_size - 1 ] = '\0';

        return rc;
    }

    rc = VTableCreateCursorRead ( *table_ref, cursor_ref );
    /*rc = VTableCreateCachedCursorRead ( *table_ref, cursor_ref, (size_t)64 << 30 );*/
    if ( rc != 0 )
    {
        rc_t res = string_printf ( error_buf, error_buf_size, NULL,
            "ERROR: VTableCreateCursorRead(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;
    }

    rc = init_column_index ( *cursor_ref, column_names_ref, column_index_ref, column_count_ref, error_buf, error_buf_size );
    if ( rc != 0 )
        return rc;

    rc = VCursorOpen ( *cursor_ref );
    if ( rc != 0 )
    {
        rc_t res = string_printf ( error_buf, error_buf_size, NULL,
            "ERROR: VCursorOpen(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;
    }

    rc = VTableCreateCursorRead ( *table_pa, cursor_pa );
    /*rc = VTableCreateCachedCursorRead ( *table_pa, cursor_pa, (size_t)64 << 30 );*/
    if ( rc != 0 )
    {
        rc_t res = string_printf ( error_buf, error_buf_size, NULL,
            "ERROR: VTableCreateCursorRead(pa) failed with error: 0x%08x (%u) [%R]", rc, rc, rc);
        if (res == rcBuffer || res == rcInsufficient)
            error_buf [ error_buf_size - 1 ] = '\0';

        return rc;
    }

    rc = init_column_index ( *cursor_pa, column_names_pa, column_index_pa, column_count_pa, error_buf, error_buf_size );
    if ( rc != 0 )
        return rc;

    rc = VCursorOpen ( *cursor_pa );
    if ( rc != 0 )
    {
        rc_t res = string_printf ( error_buf, error_buf_size, NULL,
            "ERROR: VCursorOpen(pa) failed with error: 0x%08x (%u) [%R]", rc, rc, rc);
        if (res == rcBuffer || res == rcInsufficient)
            error_buf [ error_buf_size - 1 ] = '\0';

        return rc;
    }

    return rc;
}
Exemplo n.º 19
0
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;
}
Exemplo n.º 20
0
static rc_t qual_stats(const Params* prm, const VDatabase* db) {
    rc_t rc = 0;
    const char tblName[] = "SEQUENCE";
    const VTable* tbl = NULL;
    const KMetadata* meta = NULL;
    const KMDataNode* node = NULL;
    assert(prm && db);
    if (rc == 0) {
        rc = VDatabaseOpenTableRead(db, &tbl, tblName);
        DISP_RC2(rc, tblName, "while calling VDatabaseOpenTableRead");
    }
    if (rc == 0) {
        rc = VTableOpenMetadataRead(tbl, &meta);
        DISP_RC2(rc, tblName, "while calling VTableOpenMetadataRead");
    }
    if (rc == 0) {
        bool found = false;
        const char path[] = "STATS/QUALITY";
        rc = KMetadataOpenNodeRead(meta, &node, path);
        if (rc == 0)
        {   found = true; }
        else if (GetRCState(rc) == rcNotFound)
        {   rc = 0; }
        DISP_RC2(rc, path, "while calling KMetadataOpenNodeRead");
        if (found) {
            uint32_t i = 0;
            int nbr = 0;
            uint32_t count = 0;
            KNamelist* names = NULL;
            int* quals = NULL;
            if (rc == 0) {
                rc = KMDataNodeListChild(node, &names);
                DISP_RC2(rc, path, "while calling KMDataNodeListChild");
            }
            if (rc == 0) {
                rc = KNamelistCount(names, &count);
                DISP_RC2(rc, path, "while calling KNamelistCount");
                if (rc == 0 && count > 0) {
                    quals = calloc(count, sizeof *quals);
                    if (quals == NULL) {
                        rc = RC(rcExe,
                            rcStorage, rcAllocating, rcMemory, rcExhausted);
                    }
                }
            }
            for (i = 0; i < count && rc == 0; ++i) {
             /* uint64_t u = 0;
                const KMDataNode* n = NULL; */
                const char* nodeName = NULL;
                const char* name = NULL;
                rc = KNamelistGet(names, i, &nodeName);
                DISP_RC2(rc, path, "while calling KNamelistGet");
                if (rc)
                {   break; }
                name = nodeName;
             /* rc = KMDataNodeOpenNodeRead(node, &n, name);
                DISP_RC(rc, name);
                if (rc == 0) {
                    rc = KMDataNodeReadAsU64(n, &u);
                    DISP_RC(rc, name);
                } */
                if (rc == 0) {
                    char* c = strchr(name, '_');
                    if (c != NULL && *(c + 1) != '\0') {
                        name = c + 1;
                        if (sscanf(name, "%d", &quals[i]) != 1) {
                            rc = RC(rcExe,
                                rcNode, rcParsing, rcName, rcUnexpected);
                            PLOGERR(klogInt,
                                (klogInt, rc, "$(name)", "name=%s", nodeName));
                        }
                    }
                    /* OUTMSG(("QUALITY %s %lu\n", name, u)); */
                }
             /* DESTRUCT(KMDataNode, n); */
            }
            if (rc == 0 && count > 0)
            {   ksort(quals, count, sizeof *quals, sort_callback, NULL); }
            if (rc == 0) {
                OUTMSG(("%s", prm->dbPath));
            }
            for (i = 0, nbr = 0; i < count && rc == 0; ++i, ++nbr) {
                uint64_t u = 0;
                char name[64];
                const KMDataNode* n = NULL;
                sprintf(name, "PHRED_%d", quals[i]);
                rc = KMDataNodeOpenNodeRead(node, &n, name);
                DISP_RC(rc, name);
                if (rc == 0) {
                    rc = KMDataNodeReadAsU64(n, &u);
                    DISP_RC(rc, name);
                    if (rc == 0) {
                        while (nbr < quals[i]) {
                            OUTMSG(("\t0"));
                            ++nbr;
                        }
                        OUTMSG(("\t%lu", u));
                    /*  OUTMSG(("QUALITY %d %lu\n", quals[i], u)); */
                    }
                }
                DESTRUCT(KMDataNode, n);
            }
            while (rc == 0 && nbr <= 40) {
                OUTMSG(("\t0"));
                nbr++;
            }
            if (rc == 0) {
                OUTMSG(("\n"));
            }
            DESTRUCT(KNamelist, names);
        }
    }
    DESTRUCT(KMDataNode, node);
    DESTRUCT(KMetadata, meta);
    DESTRUCT(VTable, tbl);
    return rc;
}
Exemplo n.º 21
0
rc_t run(const TestCase& test_case)
{
    rc_t rc;
    KDirectory * cur_dir;
    const VDBManager * manager;
    const VDatabase * database;
    const VTable * table;
    const VCursor * cursor;
    uint32_t name_idx;
    uint32_t name_range_idx;
    
    rc = KDirectoryNativeDir( &cur_dir );
    if ( rc != 0 )
        LOGERR( klogInt, rc, "KDirectoryNativeDir() failed" );
    else
    {
        rc = VDBManagerMakeRead ( &manager, cur_dir );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "VDBManagerMakeRead() failed" );
        else
        {
            rc = VDBManagerOpenDBRead( manager, &database, NULL, "%s", test_case.path );
            if (rc != 0)
                LOGERR( klogInt, rc, "VDBManagerOpenDBRead() failed" );
            else
            {
                rc = VDatabaseOpenTableRead( database, &table, "%s", TABLE_NAME );
                if ( rc != 0 )
                    LOGERR( klogInt, rc, "VDatabaseOpenTableRead() failed" );
                else
                {
                    rc = VTableCreateCursorRead( table, &cursor );
                    if ( rc != 0 )
                        LOGERR( klogInt, rc, "VTableCreateCursorRead() failed" );
                    else
                    {
                        /* add columns to cursor */
                        rc = VCursorAddColumn( cursor, &name_idx, "(utf8)NAME" );
                        if ( rc != 0 )
                            LOGERR( klogInt, rc, "VCursorAddColumn() failed" );
                        else
                        {
                            rc = VCursorAddColumn( cursor, &name_range_idx, "NAME_RANGE" );
                            if ( rc != 0 )
                                LOGERR( klogInt, rc, "VCursorAddColumn() failed" );
                            else
                            {
                                rc = VCursorOpen( cursor );
                                if (rc != 0)
                                    LOGERR( klogInt, rc, "VCursorOpen() failed" );
                                else
                                    rc = runChecks( test_case, cursor, name_idx, name_range_idx );
                            }
                        }
                        VCursorRelease( cursor );
                    }
                    VTableRelease( table );
                }
                VDatabaseRelease( database );
            }
            
            VDBManagerRelease( manager );
        }
        KDirectoryRelease( cur_dir );
    }
    return rc;
}
Exemplo n.º 22
0
/* OpenRead
 *  open an existing table
 *
 *  "tbl" [ OUT ] - return parameter for table
 *
 *  "spec" [ IN ] - NUL terminated UTF-8 string giving path
 *  to table.
 */
static
rc_t CC SRAMgrVOpenAltTableRead ( const SRAMgr *self,
    const SRATable **rslt, const char *altname, const char *spec, va_list args )
{
    rc_t rc;

    if ( rslt == NULL )
        rc = RC ( rcSRA, rcTable, rcOpening, rcParam, rcNull );
    else
    {
        if ( self == NULL )
            rc = RC ( rcSRA, rcMgr, rcAccessing, rcSelf, rcNull );
        else if ( spec == NULL )
            rc = RC ( rcSRA, rcTable, rcOpening, rcName, rcNull );
        else if ( spec [ 0 ] == 0 )
            rc = RC ( rcSRA, rcTable, rcOpening, rcName, rcEmpty );
        else
        {
            char path [ 4096 ];
            rc = ResolveTablePath ( self, path, sizeof path, spec, args );
            if ( rc == 0 )
            {
                SRATable *tbl = calloc ( 1, sizeof *tbl );
                if ( tbl == NULL )
                    rc = RC ( rcSRA, rcTable, rcConstructing, rcMemory, rcExhausted );
                else
                {
                    VSchema *schema = NULL;

                    rc = VDBManagerMakeSRASchema(self -> vmgr, & schema);
                    if ( rc == 0 ) 
                    {
                        rc = VDBManagerOpenTableRead ( self -> vmgr, & tbl -> vtbl, schema, path );
                        if ( rc != 0 && GetRCObject ( rc ) == rcTable && GetRCState ( rc ) == rcIncorrect )
                        {
                            const VDatabase *db;
                            rc_t rc2 = VDBManagerOpenDBRead ( self -> vmgr, & db, schema, path );
                            if ( rc2 == 0 )
                            {
                                rc2 = VDatabaseOpenTableRead ( db, & tbl -> vtbl, altname );
                                if ( rc2 == 0 )
                                    rc = 0;

                                VDatabaseRelease ( db );
                            }
                        }

                        VSchemaRelease(schema);

                        if ( rc == 0 )
                        {
                            rc = VTableOpenMetadataRead ( tbl -> vtbl, & tbl -> meta );
                            if ( rc == 0 )
                            {
                                rc = KMetadataVersion ( tbl -> meta, & tbl -> metavers );
                                if ( rc == 0 )
                                {
                                    rc = VTableCreateCursorRead ( tbl -> vtbl, & tbl -> curs );
                                    if ( rc == 0 )
                                    {
                                        tbl -> mgr = SRAMgrAttach ( self );
                                        tbl -> mode = self -> mode;
                                        tbl -> read_only = true;
                                        KRefcountInit ( & tbl -> refcount, 1, "SRATable", "OpenTableRead", path );
                                        
                                        rc = SRATableFillOut ( tbl, false );
                                        if ( rc == 0 )
                                        {
                                            * rslt = tbl;
                                            return 0;
                                        }
                                    }
                                }
                            }
                        }
                        
                    }
                    SRATableWhack ( tbl );
                }
            }
        }

        * rslt = NULL;
    }
    return rc;
}
Exemplo n.º 23
0
/**
 * returns true if accession is good
 */
bool checkAccession ( const char * accession, const CheckCorruptConfig * config )
{
    rc_t rc;
    KDirectory * cur_dir;
    const VDBManager * manager;
    const VDatabase * database;
    const VTable * pa_table;
    const VTable * sa_table;
    const VTable * seq_table;

    const VCursor * pa_cursor;
    const VCursor * sa_cursor;
    const VCursor * seq_cursor;

    rc = KDirectoryNativeDir( &cur_dir );
    if ( rc != 0 )
        PLOGERR( klogInt, (klogInt, rc, "$(ACC) KDirectoryNativeDir() failed", "ACC=%s", accession));
    else
    {
        rc = VDBManagerMakeRead ( &manager, cur_dir );
        if ( rc != 0 )
            PLOGERR( klogInt, (klogInt, rc, "$(ACC) VDBManagerMakeRead() failed", "ACC=%s", accession));
        else
        {
            int type = VDBManagerPathType ( manager, "%s", accession );
            if ( ( type & ~ kptAlias ) != kptDatabase )
                PLOGMSG (klogInfo, (klogInfo, "$(ACC) SKIPPING - can't be opened as a database", "ACC=%s", accession));
            else
            {
                rc = VDBManagerOpenDBRead( manager, &database, NULL, "%s", accession );
                if (rc != 0)
                    PLOGERR( klogInt, (klogInt, rc, "$(ACC) VDBManagerOpenDBRead() failed", "ACC=%s", accession));
                else
                {
                    rc = VDatabaseOpenTableRead( database, &pa_table, "%s", "PRIMARY_ALIGNMENT" );
                    if ( rc != 0 )
                    {
                        PLOGMSG (klogInfo, (klogInfo, "$(ACC) SKIPPING - failed to open PRIMARY_ALIGNMENT table", "ACC=%s", accession));
                        rc = 0;
                    }
                    else
                    {
                        rc = VTableCreateCursorRead( pa_table, &pa_cursor );
                        if ( rc != 0 )
                            PLOGERR( klogInt, (klogInt, rc, "$(ACC) VTableCreateCursorRead() failed for PRIMARY_ALIGNMENT cursor", "ACC=%s", accession));
                        else
                        {
                            rc = VDatabaseOpenTableRead( database, &sa_table, "%s", "SECONDARY_ALIGNMENT" );
                            if ( rc != 0 )
                            {
                                PLOGMSG (klogInfo, (klogInfo, "$(ACC) SKIPPING - failed to open SECONDARY_ALIGNMENT table", "ACC=%s", accession));
                                rc = 0;
                            }
                            else
                            {
                                rc = VTableCreateCursorRead( sa_table, &sa_cursor );
                                if ( rc != 0 )
                                    PLOGERR( klogInt, (klogInt, rc, "$(ACC) VTableCreateCursorRead() failed for SECONDARY_ALIGNMENT cursor", "ACC=%s", accession));
                                else
                                {
                                    rc = VDatabaseOpenTableRead( database, &seq_table, "%s", "SEQUENCE" );
                                    if ( rc != 0 )
                                    {
                                        PLOGMSG (klogInfo, (klogInfo, "$(ACC) SKIPPING - failed to open SEQUENCE table", "ACC=%s", accession));
                                        rc = 0;
                                    }
                                    else
                                    {
                                        rc = VTableCreateCursorRead( seq_table, &seq_cursor );
                                        if ( rc != 0 )
                                            PLOGERR( klogInt, (klogInt, rc, "VTableCreateCursorRead() failed for SEQUENCE cursor", "ACC=%s", accession));
                                        else
                                        {
                                            try {
                                                runChecks( accession, config, pa_cursor, sa_cursor, seq_cursor );
                                            } catch ( VDB_ERROR & x ) {
                                                PLOGERR (klogErr, (klogInfo, x.rc, "$(ACC) VDB error: $(MSG)", "ACC=%s,MSG=%s", accession, x.msg));
                                                rc = 1;
                                            } catch ( VDB_ROW_ERROR & x ) {
                                                PLOGERR (klogErr, (klogInfo, x.rc, "$(ACC) VDB error: $(MSG) row_id: $(ROW_ID)", "ACC=%s,MSG=%s,ROW_ID=%ld", accession, x.msg, x.row_id));
                                                rc = 1;
                                            } catch ( DATA_ERROR & x ) {
                                                KOutMsg("%s\n", accession);
                                                PLOGMSG (klogInfo, (klogInfo, "$(ACC) Invalid data: $(MSG) ", "ACC=%s,MSG=%s", accession, x.msg.c_str()));
                                                rc = 1;
                                            }
                                            VCursorRelease( seq_cursor );
                                        }
                                        VTableRelease( seq_table );
                                    }
                                    VCursorRelease( sa_cursor );
                                }
                                VTableRelease( sa_table );
                            }
                            VCursorRelease( pa_cursor );
                        }
                        VTableRelease( pa_table );
                    }
                    VDatabaseRelease( database );
                }
            }
            VDBManagerRelease( manager );
        }
        KDirectoryRelease( cur_dir );
    }
    return rc == 0;
}
Exemplo n.º 24
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;
}
Exemplo n.º 25
0
static ref_node * make_ref_node( ref_exclude *exclude, const String * s )
{
    ref_node * res = calloc( 1, sizeof * res );
    if ( res != NULL )
    {
        if ( StringCopy ( &res->name, s ) != 0 )
        {
            free( res );
            res = NULL;
        }
    }
    if ( res != NULL && exclude->path != NULL )
    {
        char buf[ 1024 ];
        size_t num_writ;
        rc_t rc = string_printf ( buf, sizeof buf, &num_writ, 
                                  "%s/%S", exclude->path, s );
        if ( rc != 0 )
        {
            PLOGERR( klogInt, ( klogInt, rc, 
                 "error to assemble path to exclude-table $(tab_name)",
                 "tab_name=%S", s ) );
        }
        else
        {
            rc = VDBManagerOpenDBRead ( exclude->mgr, &res->db, NULL, "%s", buf );
            if ( rc != 0 )
            {
                PLOGERR( klogInt, ( klogInt, rc, 
                     "error to open exclude-table $(db_name)",
                     "db_name=%s", buf ) );
                /*
                it can be OK if the database/table cannot be found!
                */
                rc = 0;
            }
            else
            {
                rc = VDatabaseOpenTableRead ( res->db, &res->tab, "HITMAP" );
                if ( rc != 0 )
                {
                    PLOGERR( klogInt, ( klogInt, rc, 
                         "error to open exclude-table 'HITMAP' in $(db_name)",
                         "db_name=%s", buf ) );
                    /*
                    it can be OK if the database/table cannot be found!
                    */
                    rc = 0;
                }
                else
                {
                    rc = detect_read_len( res );
                    if ( rc == 0 )
                    {
                        rc = prepare_ref_node( res );
                    }
                }
            }
        }
    }
    return res;
}
Exemplo n.º 26
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;
}
Exemplo n.º 27
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;
}
Exemplo n.º 28
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;
}