FIXTURE_TEST_CASE(TestNoDeps, RefseqFixture) {
    if (siteless) {
        TEST_MESSAGE("Test skipped because site repository does not exist");
        return;
    }

    rc_t rc = 0;

    const VDatabase *db = NULL;
    const char SRR600096[] = "SRR600096";
    REQUIRE_RC(VDBManagerOpenDBRead(mgr, &db, NULL, SRR600096));
    RELEASE(VDatabase, db);

    VPath* acc = NULL;
    REQUIRE_RC(VFSManagerMakePath(vmgr, &acc, SRR600096));
    const VPath *local = NULL;
    REQUIRE_RC(VResolverLocal(resolver, acc, &local));
    RELEASE(VPath, acc);
    const String *s = NULL;
    REQUIRE_RC(VPathMakeString(local, &s));
    REQUIRE(s && s->addr);

    REQUIRE_RC(VDBManagerOpenDBRead(mgr, &db, NULL, s->addr));

    const VDBDependencies *dep = NULL;

    REQUIRE_RC(VDatabaseListDependencies(db, &dep, true));
    uint32_t count = 1;
    REQUIRE_RC(VDBDependenciesCount(dep, &count));
    CHECK_EQUAL(count, (uint32_t)0);
    RELEASE(VDBDependencies, dep);

    REQUIRE_RC(VDatabaseListDependencies(db, &dep, false));
    REQUIRE_RC(VDBDependenciesCount(dep, &count));
    CHECK_EQUAL(count, (uint32_t)0);
    RELEASE(VDBDependencies, dep);

    RELEASE(VDatabase, db);
    free(const_cast<String*>(s));
    RELEASE(VPath, local);
}
Exemple #2
0
static rc_t report_ref_database( const VDBManager *vdb_mgr, VFSManager * vfs_mgr, const char * path, bool extended )
{
    const VDatabase *db;
    rc_t rc = VDBManagerOpenDBRead ( vdb_mgr, &db, NULL, "%s", path );
    if ( rc != 0 )
    {
        (void)LOGERR( klogErr, rc, "VDBManagerOpenDBRead() failed" );
    }
    else
    {
        const ReferenceList * reflist;
        uint32_t options = ( ereferencelist_usePrimaryIds | ereferencelist_useSecondaryIds | ereferencelist_useEvidenceIds );
        rc = ReferenceList_MakeDatabase( &reflist, db, options, 0, NULL, 0 );
        if ( rc != 0 )
        {
            (void)LOGERR( klogErr, rc, "ReferenceList_MakeDatabase() failed" );
        }
        else
        {
            uint32_t count;
            rc = ReferenceList_Count( reflist, &count );
            if ( rc != 0 )
            {
                (void)LOGERR( klogErr, rc, "ReferenceList_Count() failed" );
            }
            else
            {
                rc = KOutMsg( "this object uses %u references\n", count );
                if ( rc == 0 )
                {
                    uint32_t idx;
                    for ( idx = 0; idx < count && rc == 0; ++idx )
                    {
                        const ReferenceObj* ref_obj;
                        rc = ReferenceList_Get( reflist, &ref_obj, idx );
                        if ( rc != 0 )
                        {
                            (void)LOGERR( klogErr, rc, "ReferenceList_Get() failed" );
                        }
                        else
                        {
                            rc = report_ref_obj( vdb_mgr, vfs_mgr, path, idx, ref_obj, extended );
                            ReferenceObj_Release( ref_obj );
                        }
                    }
                }
            }
            ReferenceList_Release( reflist );
        }
        VDatabaseRelease( db );
    }
    return rc;
}
Exemple #3
0
rc_t make_trans_ctx( trans_ctx * ctx, trans_opt * opt, bool open_reference )
{
    rc_t rc = AlignMgrMakeRead ( &ctx->almgr );
    if ( rc != 0 )
        LOGERR( klogInt, rc, "AlignMgrMake() failed" );

    if ( rc == 0 )
    {
        rc = KDirectoryNativeDir( &ctx->dir );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "KDirectoryNativeDir() failed" );
    }

    if ( rc == 0 )
    {
        rc = VDBManagerMakeRead ( &ctx->vdb_mgr, ctx->dir );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "VDBManagerMakeRead() failed" );
    }

    if ( rc == 0 )
    {
        if ( opt->fname != NULL )
        {
            rc = VDBManagerOpenDBRead ( ctx->vdb_mgr, &ctx->db, NULL, "%s", opt->fname );
            if ( rc != 0 )
                LOGERR( klogInt, rc, "VDBManagerOpenDBRead() failed" );
        }
        else
            rc = RC ( rcApp, rcArgv, rcAccessing, rcParam, rcNull );
    }

    if ( rc == 0 )
    {
        rc = ReferenceList_MakeDatabase( &ctx->ref_list, ctx->db,
                                         ereferencelist_4na |
                                         ereferencelist_usePrimaryIds,
                                         0, NULL, 0 );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "ReferenceList_MakeDatabase() failed" );
    }

    if ( rc == 0 && open_reference )
    {
        OUTMSG(( "looking for reference '%s'\n", opt->ref_name ));
        rc = ReferenceList_Find( ctx->ref_list, &ctx->ref_obj, opt->ref_name, string_size( opt->ref_name ) );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "ReferenceList_Find() failed" );
    }

    return rc;
}
Exemple #4
0
CVDB::CVDB(const CVDBMgr& mgr, const string& acc_or_path)
    : m_Name(acc_or_path)
{
    DECLARE_SDK_GUARD();
    string path = CVPath::ConvertAccOrSysPathToPOSIX(acc_or_path);
    if ( rc_t rc = VDBManagerOpenDBRead(mgr, x_InitPtr(), 0, "%.*s",
                                        int(path.size()), path.data()) ) {
        *x_InitPtr() = 0;
        if ( (GetRCObject(rc) == RCObject(rcDirectory) ||
              GetRCObject(rc) == RCObject(rcPath) ||
              GetRCObject(rc) == RCObject(rcFile)) &&
             GetRCState(rc) == rcNotFound ) {
            // no SRA accession
            NCBI_THROW2_FMT(CSraException, eNotFoundDb,
                            "Cannot open VDB: "<<acc_or_path, rc);
        }
        else if ( GetRCObject(rc) == rcName &&
                  GetRCState(rc) == rcNotFound &&
                  GetRCContext(rc) == rcResolving ) {
            // invalid SRA database
            NCBI_THROW2_FMT(CSraException, eNotFoundDb,
                            "Cannot open VDB: "<<acc_or_path, rc);
        }
        else if ( GetRCObject(rc) == RCObject(rcFile) &&
                  GetRCState(rc) == rcUnauthorized ) {
            // invalid SRA database
            NCBI_THROW2_FMT(CSraException, eProtectedDb,
                            "Cannot open VDB: "<<acc_or_path, rc);
        }
        else if ( GetRCObject(rc) == RCObject(rcDatabase) &&
                  GetRCState(rc) == rcIncorrect ) {
            // invalid SRA database
            NCBI_THROW2_FMT(CSraException, eDataError,
                            "Cannot open VDB: "<<acc_or_path, rc);
        }
        else {
            // other errors
            NCBI_THROW2_FMT(CSraException, eOtherError,
                            "Cannot open VDB: "<<acc_or_path, rc);
        }
    }
}
Exemple #5
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;
}
Exemple #6
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;

}
Exemple #7
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;
}
Exemple #8
0
static int AccessionType(VDBManager const *const mgr,
                         unsigned const N, char const accession[],
                         rc_t *const rc)
{
    char scheme[1024];
    bool isOdd = false;

    scheme[0] = '\0';
    {
        KMetadata const *meta = NULL;
        {
            VDatabase const *db = NULL;

            *rc = VDBManagerOpenDBRead(mgr, &db, NULL, "%.*s", (int)N, accession);
            if (db) {
                *rc = VDatabaseOpenMetadataRead(db, &meta);
                VDatabaseRelease(db);
            }
            else {
                VTable const *tbl = NULL;

                *rc = VDBManagerOpenTableRead(mgr, &tbl, NULL, "%.*s", (int)N, accession);
                if (tbl) {
                    *rc = VTableOpenMetadataRead(tbl, &meta);
                    VTableRelease(tbl);
                }
                else {
                    isOdd = true;
                    *rc = VDBManagerOpenTableRead(mgr, &tbl, NULL, "ncbi-acc:%.*s?vdb-ctx=refseq", (int)N, accession);
                    if (tbl) {
                        *rc = VTableOpenMetadataRead(tbl, &meta);
                        VTableRelease(tbl);
                    }
                }
            }
        }
        if (meta) {
            KMDataNode const *node = NULL;

            *rc = KMetadataOpenNodeRead(meta, &node, "schema");
            KMetadataRelease(meta);
            if (node) {
                size_t sz = 0;

                *rc = KMDataNodeReadAttr(node, "name", scheme, sizeof(scheme) - 1, &sz);
                KMDataNodeRelease(node);
                scheme[sz] = '\0';
                while (sz) {
                    --sz;
                    if (scheme[sz] == '#') {
                        scheme[sz] = '\0';
                        break;
                    }
                }
            }
        }
    }
    if (strcmp(scheme, "NCBI:WGS:db:contig") == 0)
        return refSeqType_WGS;
    if (strcmp(scheme, "NCBI:refseq:tbl:reference") == 0)
        return isOdd ? refSeqType_RefSeq_odd : refSeqType_RefSeq;
    return 0;
}
Exemple #9
0
static rc_t ref_walker_walk_ref_range( struct ref_walker * self, ref_walker_data * rwd )
{
    ReferenceIterator * ref_iter;
    rc_t rc = AlignMgrMakeReferenceIterator ( self->amgr, &ref_iter, &self->cb_block, self->min_mapq ); /* align/iterator.h */
    if ( rc == 0 )
    {
        /* construct the reference iterator */

        uint32_t idx, count;
        uint32_t reflist_options = ref_walker_make_reflist_options( self ); /* above */
        Vector cur_id_vector;
        VectorInit ( &cur_id_vector, 0, 12 );

        rc = VNameListCount ( self->sources, &count );
        for ( idx = 0; idx < count && rc == 0; ++idx )
        {
            const char * src_name = NULL;
            rc = VNameListGet ( self->sources, idx, &src_name );
            if ( rc == 0 && src_name != NULL )
            {
                const VDatabase *db;
                rc = VDBManagerOpenDBRead ( self->vmgr, &db, self->vschema, "%s", src_name );
                if ( rc == 0 )
                {
                    const ReferenceList * ref_list;
                    rc = ReferenceList_MakeDatabase( &ref_list, db, reflist_options, 0, NULL, 0 );
                    if ( rc == 0 )
                    {
                        const ReferenceObj * ref_obj;
                        rc = ReferenceList_Find( ref_list, &ref_obj, rwd->ref_name, string_size( rwd->ref_name ) );
                        if ( rc == 0 )
                        {
                            INSDC_coord_len len;
                            rc = ReferenceObj_SeqLength( ref_obj, &len );
                            if ( rc == 0 )
                            {
                                if ( rwd->ref_start == 0 )
                                    rwd->ref_start = 1;
                                if ( ( rwd->ref_end == 0 )||( rwd->ref_end > len + 1 ) )
                                    rwd->ref_end = ( len - rwd->ref_start ) + 1;

                                if ( self->primary_alignments )
                                    rc = ref_walker_add_iterator( self, rwd->ref_name, rwd->ref_start, rwd->ref_end, src_name, 
                                            &cur_id_vector, db, ref_obj, ref_iter, TBL_PRIM, primary_align_ids );

                                if ( rc == 0 && self->secondary_alignments )
                                    rc = ref_walker_add_iterator( self, rwd->ref_name, rwd->ref_start, rwd->ref_end, src_name, 
                                            &cur_id_vector, db, ref_obj, ref_iter, TBL_SEC, secondary_align_ids );

                                if ( rc == 0 && self->evidence_alignments )
                                    rc = ref_walker_add_iterator( self, rwd->ref_name, rwd->ref_start, rwd->ref_end, src_name, 
                                            &cur_id_vector, db, ref_obj, ref_iter, TBL_EV, evidence_align_ids );

                            }
                            ReferenceObj_Release( ref_obj );
                        }
                        ReferenceList_Release( ref_list );
                    }
                    VDatabaseRelease( db );
                }
            }
        }

        if ( rc == 0 )
        {
            /* walk the reference iterator */
            struct ReferenceObj const * ref_obj;
            rc = ReferenceIteratorNextReference( ref_iter, NULL, NULL, &ref_obj );
            if ( rc == 0 && ref_obj != NULL )
            {
                if ( self->use_seq_name )
                    rc = ReferenceObj_Name( ref_obj, &rwd->ref_name );
                else
                    rc = ReferenceObj_SeqId( ref_obj, &rwd->ref_name );
                if ( rc == 0 )
                {
                    INSDC_coord_zero first_pos;
                    INSDC_coord_len len;
                    rc_t rc_w = ReferenceIteratorNextWindow ( ref_iter, &first_pos, &len );
                    while ( rc == 0 && rc_w == 0 )
                    {
                        rc_t rc_p = ReferenceIteratorNextPos ( ref_iter, !self->no_skip );
                        if ( rc_p == 0 )
                        {
                            rc = ReferenceIteratorPosition ( ref_iter, &rwd->pos, &rwd->depth, &rwd->bin_ref_base );
                            if ( rwd->depth > 0 && rc == 0 )
                            {
                                rc_t rc_sg = 0;
                                rwd->ascii_ref_base = _4na_to_ascii( rwd->bin_ref_base, false );
                                if ( self->on_enter_ref_pos != NULL )
                                    rc = self->on_enter_ref_pos( rwd );

                                while ( rc_sg == 0 && rc == 0 )
                                {
                                    rc_sg = ReferenceIteratorNextSpotGroup ( ref_iter, &rwd->spot_group, &rwd->spot_group_len );
                                    if ( rc_sg == 0 )
                                    {
                                        rc_t rc_pr = 0;
                                        if ( self->on_enter_spot_group != NULL )
                                            rc = self->on_enter_spot_group( rwd );

                                        while ( rc == 0 && rc_pr == 0 )
                                        {
                                            const PlacementRecord * rec;
                                            rc_pr = ReferenceIteratorNextPlacement ( ref_iter, &rec );
                                            if ( rc_pr == 0 && self->on_alignment != NULL )
                                                rc = ref_walker_walk_alignment( self, ref_iter, rec, rwd );
                                        }

                                        if ( self->on_exit_spot_group != NULL )
                                            rc = self->on_exit_spot_group( rwd );
                                    }
                                }
                                if ( self->on_exit_ref_pos != NULL )
                                    rc = self->on_exit_ref_pos( rwd );
                            }
                            rc = Quitting();
                        }
                    }
                }
            }
        }

        /* free cur_id_vector */

        ReferenceIteratorRelease ( ref_iter );
    }
    return rc;
}
Exemple #10
0
static rc_t align_info(const Params* prm) {
    rc_t rc = 0;

    const VDatabase* db = NULL;
    const VDBManager* mgr = NULL;
    const KDBManager *kmgr = NULL;
    VSchema* schema = NULL;
    bool is_db = false;

    if (prm == NULL)
    {   return RC(rcExe, rcQuery, rcExecuting, rcParam, rcNull); }

    if (rc == 0) {
        rc = VDBManagerMakeRead(&mgr, NULL);
        DISP_RC(rc, "while calling VDBManagerMakeRead");
    }

    if (rc == 0) {
        rc = VDBManagerOpenKDBManagerRead(mgr, &kmgr);
        DISP_RC(rc, "while calling VDBManagerOpenKDBManagerRead");
    }

    if (rc == 0) {
        rc = VDBManagerMakeSRASchema(mgr, &schema);
        DISP_RC(rc, "while calling VDBManagerMakeSRASchema");
    }

    if (rc == 0) {
/*      const char path[] = "/panfs/pan1/trace_work/scratch/XXX000013"; */
        rc = VDBManagerOpenDBRead(mgr, &db, schema, prm->dbPath);
        if (rc == 0) {
            is_db = true;
        }
        else if (rc == SILENT_RC(rcDB, rcMgr, rcOpening, rcDatabase, rcIncorrect)) {
            PLOGMSG(klogWarn, (klogWarn,
                "'$(path)' is not a database", "path=%s", prm->dbPath));
            rc = 0;
        }
        else {
            PLOGERR(klogErr,
                (klogErr, rc, "$(path)", "path=%s", prm->dbPath));
        }
    }

    if (is_db) {
        if (rc == 0) {
            if (prm->paramRef) {
                const VDBDependencies* dep = NULL;
                uint32_t count = 0;
                int i = 0;
                rc = VDatabaseListDependencies(db, &dep, false);
                DISP_RC2(rc, prm->dbPath,
                    "while calling VDatabaseListDependencies");
                if (rc == 0) {
                    rc = VDBDependenciesCount(dep, &count);
                    DISP_RC2(rc, prm->dbPath,
                        "while calling VDBDependenciesCount");
                }
                for (i = 0; i < count && rc == 0; ++i) {
                    bool circular = false;
                    const char* name = NULL;
                    const char* path = NULL;
                    const char* remote = NULL;
                    bool local = false;
                    const char* seqId = NULL;
                    rc = VDBDependenciesCircular(dep, &circular, i);
                    if (rc != 0) {
                        DISP_RC2(rc, prm->dbPath,
                            "while calling VDBDependenciesCircular");
                        break;
                    }
                    rc = VDBDependenciesName(dep, &name, i);
                    if (rc != 0) {
                        DISP_RC2(rc, prm->dbPath,
                            "while calling VDBDependenciesName");
                        break;
                    }
                    rc = VDBDependenciesPath(dep, &path, i);
                    if (rc != 0) {
                        DISP_RC2(rc, prm->dbPath,
                            "while calling VDBDependenciesPath");
                        break;
                    }
                    rc = VDBDependenciesLocal(dep, &local, i);
                    if (rc != 0) {
                        DISP_RC2(rc, prm->dbPath,
                            "while calling VDBDependenciesLocal");
                        break;
                    }
                    rc = VDBDependenciesSeqId(dep, &seqId, i);
                    if (rc != 0) {
                        DISP_RC2(rc, prm->dbPath,
                            "while calling VDBDependenciesSeqId");
                        break;
                    }
                    rc = VDBDependenciesPathRemote(dep, &remote, i);
                    if (rc != 0) {
                        DISP_RC2(rc, prm->dbPath,
                            "while calling VDBDependenciesRemote");
                        break;
                    }
                    OUTMSG(("%s,%s,%s,%s", seqId, name,
                        (circular ? "true" : "false"),
                        (local ? "local" : "remote")));
                    if (path && path[0]) {
                        OUTMSG((":%s", path));
                    }
                    else if (remote && remote[0]) {
                        OUTMSG(("::%s", remote));
                    }
                    OUTMSG(("\n"));
                }
                DESTRUCT(VDBDependencies, dep);
            }

            if (prm->paramBamHeader) {
                rc_t rc3 = bam_header(db);
                if (rc3 != 0 && rc == 0)
                {   rc = rc3; }
            }

            if (prm->paramQuality) {
                rc_t rc3 = qual_stats(prm, db);
                if (rc3 != 0 && rc == 0)
                {   rc = rc3; }
            }
        }

    }

    DESTRUCT(VSchema, schema);
    DESTRUCT(KDBManager, kmgr);
    DESTRUCT(VDBManager, mgr);
    DESTRUCT(VDatabase, db);

    return rc;
}
Exemple #11
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;
}
Exemple #12
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;
}
Exemple #13
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;
}
Exemple #14
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;
}
Exemple #15
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;
}
Exemple #16
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;
}