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); } } }
void CVPath::x_Init(const CVFSManager& mgr, const string& path, EType type) { VPath* vpath = 0; if ( type == eSys ) { if ( rc_t rc = VFSManagerMakeSysPath(mgr, &vpath, path.c_str()) ) { *x_InitPtr() = 0; NCBI_THROW2_FMT(CSraException, eInitFailed, "Cannot create sys VPath: "<<path, rc); } } else if ( type == eAcc ) { if ( rc_t rc = VFSManagerMakeAccPath(mgr, &vpath, path.c_str()) ) { *x_InitPtr() = 0; NCBI_THROW2_FMT(CSraException, eInitFailed, "Cannot create acc VPath: "<<path, rc); } } else { if ( rc_t rc = VFSManagerMakePath(mgr, &vpath, path.c_str()) ) { *x_InitPtr() = 0; NCBI_THROW2_FMT(CSraException, eInitFailed, "Cannot create VPath: "<<path, rc); } } *x_InitPtr() = vpath; }
void CSraMgr::x_DoInit(void) { if ( rc_t rc = SRAMgrMakeRead(x_InitPtr()) ) { *x_InitPtr() = 0; NCBI_THROW2(CSraException, eInitFailed, "Cannot open SRAMgr", rc); } }
CKDBManager::CKDBManager(const CVDBMgr& mgr) { if ( rc_t rc = VDBManagerGetKDBManagerRead(mgr, x_InitPtr()) ) { *x_InitPtr() = 0; NCBI_THROW2(CSraException, eInitFailed, "Cannot get KDBManager", rc); } }
void CVFSManager::x_InitNew(void) { if ( rc_t rc = VFSManagerMake(x_InitPtr()) ) { *x_InitPtr() = 0; NCBI_THROW2(CSraException, eInitFailed, "Cannot create VFSManager", rc); } }
CKNSManager::CKNSManager(const CVFSManager& mgr) { if ( rc_t rc = VFSManagerGetKNSMgr(mgr, x_InitPtr()) ) { *x_InitPtr() = 0; NCBI_THROW2(CSraException, eInitFailed, "Cannot get KNSManager", rc); } }
CKConfig::CKConfig(const CVDBMgr& mgr) { *x_InitPtr() = VFSManagerGetConfig(CVFSManager(mgr)); if ( rc_t rc = KConfigAddRef(*this) ) { *x_InitPtr() = 0; NCBI_THROW2(CSraException, eInitFailed, "Cannot get reference to KConfig", rc); } }
CVResolver::CVResolver(const CVFSManager& mgr, const CKConfig& cfg) : m_Mgr(mgr) { if ( rc_t rc = VFSManagerMakeResolver(mgr, x_InitPtr(), cfg) ) { *x_InitPtr() = 0; NCBI_THROW2(CSraException, eInitFailed, "Cannot create VResolver", rc); } }
CKConfig::CKConfig(void) { KConfig* cfg; if ( rc_t rc = KConfigMake(&cfg, 0) ) { *x_InitPtr() = 0; NCBI_THROW2(CSraException, eInitFailed, "Cannot create KConfig", rc); } *x_InitPtr() = cfg; }
void CVDBMgr::x_Init(void) { if ( rc_t rc = VDBManagerMakeRead(x_InitPtr(), 0) ) { *x_InitPtr() = 0; NCBI_THROW2(CSraException, eInitFailed, "Cannot open VDBManager", rc); } uint32_t sdk_ver; if ( rc_t rc = VDBManagerVersion(*this, &sdk_ver) ) { NCBI_THROW2(CSraException, eInitFailed, "Cannot get VDBManager version", rc); } CKNSManager kns_mgr(CVFSManager(*this)); CNcbiOstrstream str; CNcbiApplication* app = CNcbiApplication::Instance(); if ( app ) { str << app->GetAppName() << ": " << app->GetVersion().Print() << "; "; } #if NCBI_PACKAGE str << "Package: " << NCBI_PACKAGE_NAME << ' ' << NCBI_PACKAGE_VERSION << "; "; #endif str << "C++ "; #ifdef NCBI_PRODUCTION_VER str << NCBI_PRODUCTION_VER << "/"; #endif #ifdef NCBI_DEVELOPMENT_VER str << NCBI_DEVELOPMENT_VER; #endif string prefix = CNcbiOstrstreamToString(str); KNSManagerSetUserAgent(kns_mgr, "%s; SRA Toolkit %V", prefix.c_str(), sdk_ver); // redirect VDB log to C++ Toolkit if ( s_GetDiagHandler() ) { KLogInit(); KLogLevelSet(klogDebug); KLogLibHandlerSet(VDBLogWriter, 0); } if ( app ) { string host = app->GetConfig().GetString("CONN", "HTTP_PROXY_HOST", kEmptyStr); int port = app->GetConfig().GetInt("CONN", "HTTP_PROXY_PORT", 0); if ( !host.empty() && port != 0 ) { if ( rc_t rc = KNSManagerSetHTTPProxyPath(kns_mgr, "%s:%d", host.c_str(), port) ) { NCBI_THROW2(CSraException, eInitFailed, "Cannot set KNSManager proxy parameters", rc); } KNSManagerSetHTTPProxyEnabled(kns_mgr, true); } } }
void CSraPath::x_Init(void) { CSraMgr::RegisterFunctions(); if ( rc_t rc = SRAPathMake(x_InitPtr(), 0) ) { *x_InitPtr() = 0; NCBI_THROW2(CSraException, eInitFailed, "Cannot make SRAPath", rc); } if ( rc_t rc = SRAPathClear(*this) ) { NCBI_THROW2(CSraException, eInitFailed, "Cannot clear SRAPath", rc); } }
void CSraRun::x_DoInit(CSraMgr& mgr, const string& acc) { if ( rc_t rc = SRAMgrOpenTableRead(mgr, x_InitPtr(), mgr.FindAccPath(acc).c_str()) ) { *x_InitPtr() = 0; NCBI_THROW3(CSraException, eNotFoundDb, "Cannot open run read", rc, acc); } m_Name.Init(*this, "NAME", vdb_ascii_t); m_Read.Init(*this, "READ", insdc_fasta_t); m_Qual.Init(*this, "QUALITY", ncbi_qual1_t); m_SDesc.Init(*this, "SPOT_DESC", sra_spot_desc_t); m_RDesc.Init(*this, "READ_DESC", sra_read_desc_t); m_TrimStart.TryInitRc(*this, "TRIM_START", "INSDC:coord:zero"); }
void CSraColumn::Init(const CSraRun& run, const char* name, const char* type) { if ( rc_t rc = TryInitRc(run, name, type) ) { *x_InitPtr() = 0; NCBI_THROW3(CSraException, eInitFailed, "Cannot get SRA column", rc, name); } }
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); } } }
CVDBTable::CVDBTable(const CVDBMgr& mgr, const string& acc_or_path, EMissing missing) : m_Name(acc_or_path) { *x_InitPtr() = 0; VSchema *schema; DECLARE_SDK_GUARD(); if ( rc_t rc = SRASchemaMake(&schema, mgr) ) { NCBI_THROW2(CSraException, eInitFailed, "Cannot make default SRA schema", rc); } string path = CVPath::ConvertAccOrSysPathToPOSIX(acc_or_path); if ( rc_t rc = VDBManagerOpenTableRead(mgr, x_InitPtr(), schema, "%.*s", int(path.size()), path.data()) ) { *x_InitPtr() = 0; VSchemaRelease(schema); if ( (GetRCObject(rc) == RCObject(rcDirectory) || GetRCObject(rc) == RCObject(rcPath)) && GetRCState(rc) == rcNotFound ) { // no SRA accession if ( missing != eMissing_Throw ) { return; } NCBI_THROW2_FMT(CSraException, eNotFoundTable, "Cannot open SRA table: "<<acc_or_path, rc); } else if ( GetRCObject(rc) == RCObject(rcDatabase) && GetRCState(rc) == rcIncorrect ) { // invalid SRA database NCBI_THROW2_FMT(CSraException, eDataError, "Cannot open SRA table: "<<acc_or_path, rc); } else { // other errors NCBI_THROW2_FMT(CSraException, eOtherError, "Cannot open SRA table: "<<acc_or_path, rc); } } VSchemaRelease(schema); }
void CVDBCursor::Init(const CVDBTable& table) { if ( *this ) { NCBI_THROW2(CSraException, eInvalidState, "Cannot init VDB cursor again", RC(rcApp, rcCursor, rcConstructing, rcSelf, rcOpen)); } if ( rc_t rc = VTableCreateCursorRead(table, x_InitPtr()) ) { *x_InitPtr() = 0; NCBI_THROW2(CSraException, eInitFailed, "Cannot create VDB cursor", rc); } if ( rc_t rc = VCursorPermitPostOpenAdd(*this) ) { NCBI_THROW2(CSraException, eInitFailed, "Cannot allow VDB cursor post open column add", rc); } if ( rc_t rc = VCursorOpen(*this) ) { NCBI_THROW2(CSraException, eInitFailed, "Cannot open VDB cursor", rc); } m_Table = table; }
CVDBTableIndex::CVDBTableIndex(const CVDBTable& table, const char* index_name, EMissing missing) : m_Table(table), m_Name(index_name) { if ( rc_t rc = VTableOpenIndexRead(table, x_InitPtr(), index_name) ) { *x_InitPtr() = 0; if ( GetRCObject(rc) == RCObject(rcIndex) && GetRCState(rc) == rcNotFound ) { // no such index if ( missing != eMissing_Throw ) { return; } NCBI_THROW2_FMT(CSraException, eNotFoundIndex, "Cannot open VDB table index: "<<*this, rc); } else { NCBI_THROW2_FMT(CSraException, eOtherError, "Cannot open VDB table index: "<<*this, rc); } } }
rc_t CSraColumn::TryInitRc(const CSraRun& run, const char* name, const char* type) { return SRATableOpenColumnRead(run, x_InitPtr(), name, type); }