static rc_t report_references( const VDBManager *vdb_mgr, VFSManager * vfs_mgr, const char * spec, bool extended ) { const String * resolved = NULL; rc_t rc = resolve_accession( vfs_mgr, spec, &resolved ); if ( rc == 0 && resolved != NULL ) { rc = KOutMsg( "resolved into '%S'\n", resolved ); if ( rc == 0 ) { int path_type = ( VDBManagerPathType ( vdb_mgr, "%s", spec ) & ~ kptAlias ); switch( path_type ) { case kptDatabase : rc = report_ref_database( vdb_mgr, vfs_mgr, spec, extended ); break; case kptTable : KOutMsg( "cannot report references on a table-object\n" ); rc = RC ( rcApp, rcNoTarg, rcAccessing, rcParam, rcInvalid ); (void)LOGERR( klogErr, rc, "cannot report references on a table-object" ); break; default : KOutMsg( "the given object is not a vdb-database\n" ); rc = RC ( rcApp, rcNoTarg, rcAccessing, rcParam, rcInvalid ); (void)LOGERR( klogErr, rc, "the given object is not a vdb-database" ); break; } } StringWhack ( resolved ); } return rc; }
static rc_t vdb_fastq_by_pathtype( const p_dump_context ctx, const VDBManager *mgr, fastq_ctx * fctx ) { rc_t rc; int path_type = ( VDBManagerPathType ( mgr, ctx->path ) & ~ kptAlias ); /* types defined in <kdb/manager.h> */ switch ( path_type ) { case kptDatabase : rc = vdb_fastq_database( ctx, mgr, fctx ); DISP_RC( rc, "dump_database() failed" ); break; case kptPrereleaseTbl: case kptTable : rc = vdb_fastq_table( ctx, mgr, fctx ); DISP_RC( rc, "dump_table() failed" ); break; default : rc = RC( rcVDB, rcNoTarg, rcConstructing, rcItem, rcNotFound ); PLOGERR( klogInt, ( klogInt, rc, "the path '$(p)' cannot be opened as vdb-database or vdb-table", "p=%s", ctx->path ) ); if ( vdco_schema_count( ctx ) == 0 ) { LOGERR( klogInt, rc, "Maybe it is a legacy table. If so, specify a schema with the -S option" ); } break; } return rc; }
static rc_t ref_seq_load_main( const p_context ctx ) { KDirectory *dir; rc_t rc = KDirectoryNativeDir( &dir ); if ( rc != 0 ) { LOGERR( klogErr, rc, "ref_seq_load_main:KDirectoryNativeDir() failed" ); } else { VDBManager *mgr; rc = VDBManagerMakeUpdate ( &mgr, dir ); if ( rc != 0 ) { LOGERR( klogErr, rc, "ref_seq_load_main:VDBManagerMakeRead() failed" ); } else { rc = prepare_load( dir, ctx ); if ( rc != 0 ) { LOGERR( klogInt, rc, "ref_seq_load_main:prepare_load() failed" ); } else { char tblpath[ 4096 ]; rc = KDirectoryResolvePath( dir, true, tblpath, sizeof tblpath, ctx->dst_path ); if ( rc != 0 ) { LOGERR( klogErr, rc, "ref_seq_load_main:KDirectoryResolvePath() failed" ); } else { KPathType type = VDBManagerPathType( mgr, tblpath ); if ( type != kptNotFound ) { rc = RC( rcExe, rcDatabase, rcCreating, rcFile, rcExists ); PLOGERR( klogErr, ( klogErr, rc, "$(path)", "path=%s", tblpath ) ); } } } if ( rc == 0 ) { rc = perform_load( ctx, dir, mgr ); /* <====================== */ if ( rc != 0 ) { remove_path( dir, ctx->dst_path, ctx->quiet ); } } VDBManagerRelease( mgr ); } KDirectoryRelease( dir ); } return rc; }
static const char * get_path_type( const VDBManager *mgr, const char * acc_or_path ) { const char * res = PT_NONE; int path_type = ( VDBManagerPathType ( mgr, "%s", acc_or_path ) & ~ kptAlias ); switch ( path_type ) /* types defined in <kdb/manager.h> */ { case kptDatabase : res = PT_DATABASE; break; case kptPrereleaseTbl : case kptTable : res = PT_TABLE; break; } return res; }
static rc_t report_deletes_spec( const VDBManager *vdb_mgr, VFSManager * vfs_mgr, const char * spec, uint32_t min_len ) { rc_t rc = KOutMsg( "\nreporting deletes of '%s'\n", spec ); if ( rc == 0 ) { VPath * path = NULL; const VPath * local_cache = NULL; const KFile * remote_file = NULL; rc = VFSManagerResolveSpec ( vfs_mgr, spec, &path, &remote_file, &local_cache, true ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot resolve spec via VFSManager" ); } else { char buffer[ 4096 ]; size_t num_read; rc = VPathReadPath ( path, buffer, sizeof buffer, &num_read ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot read path from vpath" ); } else { int path_type = ( VDBManagerPathType ( vdb_mgr, "%s", buffer ) & ~ kptAlias ); switch( path_type ) { case kptDatabase : rc = report_deletes_db( vdb_mgr, buffer, min_len ); break; case kptTable : KOutMsg( "cannot report deletes on a table-object\n" ); rc = RC ( rcApp, rcNoTarg, rcAccessing, rcParam, rcInvalid ); (void)LOGERR( klogErr, rc, "cannot report references on a table-object" ); break; default : KOutMsg( "the given object is not a vdb-database\n" ); rc = RC ( rcApp, rcNoTarg, rcAccessing, rcParam, rcInvalid ); (void)LOGERR( klogErr, rc, "the given object is not a vdb-database" ); break; } } KFileRelease( remote_file ); VPathRelease ( local_cache ); VPathRelease ( path ); } } return rc; }
static rc_t report_references( const VDBManager *vdb_mgr, VFSManager * vfs_mgr, const char * spec, bool extended ) { rc_t rc = KOutMsg( "\nreporting references of '%s'\n", spec ); if ( rc == 0 ) { VPath * path = NULL; const VPath * local_cache = NULL; const KFile * remote_file = NULL; rc = VFSManagerResolveSpec ( vfs_mgr, spec, &path, &remote_file, &local_cache, true ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot resolve spec via VFSManager" ); } else { char buffer[ 4096 ]; size_t num_read; rc = VPathReadPath ( path, buffer, sizeof buffer, &num_read ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot read path from vpath" ); } else { rc = KOutMsg( "resolved into '%s'\n", buffer ); if ( rc == 0 ) { int path_type = ( VDBManagerPathType ( vdb_mgr, "%s", buffer ) & ~ kptAlias ); switch( path_type ) { case kptDatabase : rc = report_ref_database( vdb_mgr, vfs_mgr, buffer, extended ); break; case kptTable : rc = KOutMsg( "cannot report references on a table-object\n" ); break; default : rc = KOutMsg( "the given object is not a vdb-database\n" ); break; } } } KFileRelease( remote_file ); VPathRelease ( local_cache ); VPathRelease ( path ); } } return rc; }
static rc_t report_ref_loc( const VDBManager *vdb_mgr, VFSManager * vfs_mgr, const char * seq_id ) { const String * path; rc_t rc = resolve_accession( vfs_mgr, seq_id, &path ); if ( rc == 0 ) { rc = KOutMsg( "location:\t%S\n", path ); if ( rc == 0 ) { uint32_t pt = VDBManagerPathType ( vdb_mgr, "%S", path ); const char * spt = path_type_2_str( pt ); rc = KOutMsg( "pathtype:\t%s\n", spt ); } free ( (void*) path ); } return rc; }
static rc_t cg_dump_src_dst_rows( cg_dump_opts * opts, const char * src, cg_dump_ctx * cg_ctx ) { rc_t rc = KDirectoryNativeDir( &cg_ctx->dir ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot create internal directory object" ); } else { const VDBManager * mgr; rc = VDBManagerMakeRead ( &mgr, cg_ctx->dir ); if ( rc != 0 ) { (void)LOGERR( klogErr, rc, "cannot create vdb-manager" ); } else { int path_type = ( VDBManagerPathType ( mgr, "%s", src ) & ~ kptAlias ); if ( path_type != kptDatabase ) { rc = RC( rcExe, rcNoTarg, rcReading, rcParam, rcInvalid ); if ( path_type == kptNotFound ) { (void)LOGERR( klogErr, rc, "the source object cannot be found" ); } else { (void)LOGERR( klogErr, rc, "source cannot be used" ); KOutMsg( "it is instead: '%s'\n", pathtype_2_pchar( path_type ) ); } } else { rc = cg_dump_src_dst_rows_vdb( opts, mgr, src, cg_ctx ); /* <================== */ } VDBManagerRelease( mgr ); } KDirectoryRelease( cg_ctx->dir ); } return rc; }
static rc_t ref_walker_prepare_1_src( struct ref_walker * self, const char * name ) { VPath * path = NULL; const VPath * local_cache = NULL; const KFile * remote_file = NULL; rc_t rc = VFSManagerResolveSpec ( self->vfs_mgr, name, &path, &remote_file, &local_cache, true ); if ( rc != 0 ) { PLOGERR( klogErr, ( klogErr, rc, "cannot resolve '$(n)' via VFSManager", "n=%s", name ) ); } else { char buffer[ 4096 ]; size_t num_read; rc = VPathReadPath ( path, buffer, sizeof buffer, &num_read ); if ( rc != 0 ) { PLOGERR( klogErr, ( klogErr, rc, "cannot read path from vpath for '$(n)'", "n=%s", name ) ); } else { if ( rc == 0 ) { int path_type = ( VDBManagerPathType ( self->vmgr, "%s", buffer ) & ~ kptAlias ); if ( path_type == kptDatabase ) { const ReferenceList * reflist; uint32_t options = ( ereferencelist_usePrimaryIds | ereferencelist_useSecondaryIds | ereferencelist_useEvidenceIds ); rc = ReferenceList_MakePath( &reflist, self->vmgr, name, options, 0, NULL, 0 ); if ( rc != 0 ) { PLOGERR( klogErr, ( klogErr, rc, "cannot create ReferenceList for '$(n)'", "n=%s", name ) ); } else { uint32_t count; rc = ReferenceList_Count( reflist, &count ); if ( rc != 0 ) { PLOGERR( klogErr, ( klogErr, rc, "ReferenceList_Count() for '$(n)' failed", "n=%s", name ) ); } else { uint32_t idx; for ( idx = 0; idx < count && rc == 0; ++idx ) { const ReferenceObj * refobj; rc = ReferenceList_Get( reflist, &refobj, idx ); if ( rc != 0 ) { LOGERR( klogInt, rc, "ReferenceList_Get() failed" ); } else { const char * seqid; rc = ReferenceObj_SeqId( refobj, &seqid ); if ( rc == 0 ) { INSDC_coord_len seqlen; rc = ReferenceObj_SeqLength( refobj, &seqlen ); if ( rc == 0 ) { rc = add_region( &self->regions, seqid, 0, seqlen - 1 ); } } ReferenceObj_Release( refobj ); } } } ReferenceList_Release( reflist ); } } } } KFileRelease( remote_file ); VPathRelease ( local_cache ); VPathRelease ( path ); } return rc; }
/** * 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; }