68 #define DEFAULT_DB_SERVER "PUBSEQ_OS_PUBLIC_GI64"
69 #define DEFAULT_DB_USER "anyone"
70 #define DEFAULT_DB_PASSWORD "allowed"
71 #define DEFAULT_DB_DRIVER "ftds;ctlib"
72 #define DEFAULT_NUM_CONN 2
74 #define DEFAULT_ALLOW_GZIP true
75 #define DEFAULT_EXCL_WGS_MASTER true
77 #define NCBI_USE_ERRCODE_X Objtools_Rd_Pubseq
92 #define RPC_GET_ASN "id_get_asn"
93 #define RPC_GET_BLOB_INFO "id_get_blob_prop"
103 if (
Int4(
id) !=
id ) {
106 cmd.SetParam(param, &idIn);
111 cmd.SetParam(param, &idIn);
123 dbr.
ItemName(pos) <<
" value overflow: " <<
id);
146 const string& server,
149 const string& dbapi_driver)
150 : m_Server(server) , m_User(user), m_Password(pswd),
151 m_DbapiDriver(dbapi_driver),
155 m_SetCubbyUser(
false)
157 LOG_POST_X_ONCE(1,
"This app is using OM++ PubSeqOS reader which is being phased out. Please switch to using ID2 or PSG.");
176 const string& driver_name)
180 m_SetCubbyUser(
false)
182 LOG_POST_X_ONCE(1,
"This app is using OM++ PubSeqOS reader which is being phased out. Please switch to using ID2 or PSG.");
236 #if defined(NCBI_THREADS)
272 if ( stream.
get() ) {
284 CPubseqValidator(
bool allow_gzip,
bool excl_wgs_master)
285 : m_AllowGzip(allow_gzip),
286 m_ExclWGSMaster(excl_wgs_master)
293 (
conn.LangCmd(
"set accept gzip"));
297 if ( m_ExclWGSMaster ) {
299 (
conn.LangCmd(
"set exclude_wgs_master on"));
306 virtual string GetName(
void)
const {
307 return "CPubseqValidator";
311 bool m_AllowGzip, m_ExclWGSMaster;
336 return cmd.release();
342 while (
result.Fetch() ) {
343 for (
unsigned pos = 0; pos <
result.NofItems(); ++pos ) {
344 if (
result.ItemName(pos) == name ) {
395 auto context =
m_Context.load(memory_order_acquire);
399 context =
m_Context.load(memory_order_acquire);
404 args[
"packet"]=
"3584";
405 args[
"version"]=
"125";
406 vector<string> driver_list;
408 size_t driver_count = driver_list.size();
409 vector<string> errmsg(driver_count);
410 for (
size_t i = 0;
i < driver_count; ++
i ) {
418 catch ( exception& exc ) {
419 errmsg[
i] = exc.what();
423 for (
size_t i = 0;
i < driver_count; ++
i ) {
424 ERR_POST_X(2,
"Failed to create dbapi context with driver '"
425 <<driver_list[
i]<<
"': "<<errmsg[
i]);
428 "Cannot create dbapi context with driver '"+
432 m_Context.store(context, memory_order_release);
456 s <<
"Connected to " <<
conn->ServerName();
484 if ( lock.IsLoaded() ) {
495 if ( lock.IsLoaded() ) {
513 if ( !gi_ids.IsLoaded() ) {
528 if ( blob_ids.IsLoaded() ) {
559 _ASSERT(all_blob_ids.IsLoaded());
574 if ( seq_id.
IsGi() ) {
578 _TRACE(
"ResolveGi to Acc: " << gi);
589 while (
cmd->HasMoreResults() ) {
599 int status = v.
Value();
600 if ( status == 100 ) {
608 sx_FetchNextItem(*dbr,
"accver") ) {
617 while ( dbr->
Fetch() )
622 catch ( exception& ) {
631 while ( dbr->
Fetch() )
657 if ( seq_id.
IsGi() ) {
667 int result_count = 0;
674 cmd->SetParam(
"@asnin", &asnIn);
679 while(
cmd->HasMoreResults()) {
686 while ( dbr->
Fetch() )
691 while ( dbr->
Fetch() ) {
700 for (
unsigned pos = 0; pos < dbr->
NofItems(); ++pos ) {
701 const string& name = dbr->
ItemName(pos);
702 _TRACE(
"next item: " << name);
708 else if (name ==
"sat" ) {
712 else if(name ==
"sat_key") {
716 else if(name ==
"extra_feat" || name ==
"ext_feat") {
719 if ( extFeatGot.
IsNULL() ) {
720 _TRACE(
"ext_feat = NULL");
727 else if (name ==
"named_annots" ) {
730 if ( namedAnnotsGot.
Value() ) {
739 int sat = satGot.
Value();
740 int sat_key = sat_keyGot.
Value();
748 " satkey=" << sat_key <<
750 if ( extFeatGot.
IsNULL() ) {
754 s << extFeatGot.
Value();
758 if ( gi ==
ZERO_GI && !sat && !sat_key ) {
773 blob_id->SetSat(sat);
774 blob_id->SetSatKey(sat_key);
776 if ( !extFeatGot.
IsNULL() ) {
783 blob_id->SetSat(sat);
784 blob_id->SetSatKey(sat_key);
785 if ( !extFeatGot.
IsNULL() ) {
786 blob_id->SetSubSat(extFeatGot.
Value());
795 if ( with_named_accs && named_gi !=
ZERO_GI ) {
797 _TRACE(
"id_get_annot_types "<<named_gi);
801 while(
cmd->HasMoreResults()) {
808 while ( dbr->
Fetch() )
813 while ( dbr->
Fetch() ) {
819 for (
unsigned pos = 0; pos < dbr->
NofItems(); ++pos ) {
820 const string& name = dbr->
ItemName(pos);
821 _TRACE(
"next item: " << name);
827 else if (name ==
"sat" ) {
831 else if(name ==
"sat_key") {
835 else if(name ==
"type") {
839 else if(name ==
"name") {
848 blob_id->SetSat(satGot.
Value());
849 blob_id->SetSatKey(satKeyGot.
Value());
852 annot_info->AddNamedAnnotName(nameGot.
Value());
853 info.SetAnnotInfo(annot_info);
854 blob_ids.push_back(
info);
859 if ( result_count == 0 ) {
871 return result_count > 0;
879 if ( load_lock.IsLoaded() ) {
889 _TRACE(
"ResolveGi to Seq-ids: " << gi);
899 cmd->SetParam(
"@bin", &binIn);
904 while (
cmd->HasMoreResults() ) {
911 while ( dbr->
Fetch() ) {
914 int status = v.
Value();
915 if ( status == 100 ) {
927 sx_FetchNextItem(*dbr,
"seqid") ) {
932 while (
in.HaveMoreData() ) {
937 if (
in.HaveMoreData() ) {
938 ERR_POST_X(4,
"CPubseqReader: extra seqid data");
940 while ( dbr->
Fetch() )
945 while ( dbr->
Fetch() )
950 ids.push_back(seq_id);
964 if ( lock.IsLoaded() ) {
975 if ( lock.IsLoaded() ) {
991 hash.sequence_found =
true;
1013 if ( load_lock.IsLoaded() ) {
1023 _TRACE(
"ResolveGi to Hash: " << gi);
1033 cmd->SetParam(
"@ver", &hashIn);
1037 while (
cmd->HasMoreResults() ) {
1044 sx_FetchNextItem(*dbr,
"hash") ) {
1048 hash.sequence_found =
true;
1049 hash.hash_known =
true;
1051 while ( dbr->
Fetch() )
1072 ERR_POST_X(3,
"CPubseqReader: unexpected blob data");
1077 result.SetAndSaveBlobState(blob_id, 0);
1094 ERR_POST_X(5,
"CPubseqReader: unexpected blob data");
1099 result.SetAndSaveBlobVersion(blob_id, 0);
1102 catch ( exception& ) {
1104 result.SetAndSaveBlobVersion(blob_id, 0);
1148 if ( stream.read(
buf, 1) && stream.gcount() ) {
1149 ERR_POST_X(6,
"CPubseqReader: extra blob data: "<<blob_id);
1170 cmd->SetParam(
"@gi", &idIn);
1172 cmd->SetParam(
"@sat", &satIn);
1174 cmd->SetParam(
"@ext_feat", &ext_feat);
1178 cmd->SetParam(
"@sat", &satIn);
1180 cmd->SetParam(
"@sat_key", &satKeyIn);
1182 cmd->SetParam(
"@ext_feat", &ext_feat);
1185 return cmd.release();
1200 while( !ret.
dbr &&
cmd.HasMoreResults() ) {
1202 if (
cmd.HasFailed() ) {
1212 while ( dbr->
Fetch() )
1217 while ( !ret.
dbr && dbr->
Fetch() ) {
1219 for (
unsigned pos = 0; pos < dbr->
NofItems(); ++pos ) {
1220 const string& name = dbr->
ItemName(pos);
1221 _TRACE(
"next item: " << name);
1222 if ( name ==
"confidential" ) {
1230 else if ( name ==
"suppress" ) {
1234 if ( v.
Value() & 5 ) {
1240 else if ( name ==
"override" ) {
1248 else if ( name ==
"last_touched_m" ) {
1254 else if ( name ==
"state" ) {
1258 if ( v.
Value() == kState_dead ) {
1262 else if ( name ==
"zip_type" ) {
1268 else if ( name ==
"asn1" ) {
1275 _TRACE(
"item type: " << item->GetType());
1276 switch ( item->GetType() ) {
1303 if ( !ret.
dbr && force_blob ) {
1305 _TRACE(
"actually no data");
1317 if ( !web_cookie.empty() ) {
1338 objects::CPubseqReader>
1355 objects::CReader* drv = 0;
1361 drv =
new objects::CPubseqReader(params, driver);
User-defined methods of the data storage class.
User-defined methods of the data storage class.
bool IsMainBlob(void) const
TSatKey GetSatKey() const
TSubSat GetSubSat() const
string ToString(void) const
Get string representation of blob id.
ERW_Result PendingCount(size_t *)
Via parameter "count" (which is guaranteed to be supplied non-NULL) return the number of bytes that a...
ERW_Result Read(void *buf, size_t count, size_t *bytes_read)
Read as many as "count" bytes into a buffer pointed to by the "buf" argument.
CDB_Result_Reader(CDB_Result *db_result)
static TIntId GetExtAnnotGi(const CBlob_id &blob_id)
static void CreateExtAnnotBlob_ids(TBlobIds &blob_ids, TIntId gi, int ext_feat)
static bool IsAnnotSat(int sat)
static int GetExtAnnotSubSat(const CBlob_id &blob_id)
bool IsLoadedAccVer(void) const
bool IsLoadedChunk(void) const
bool IsLoadedGi(void) const
static bool IsFound(const TData &data)
static TGi GetGi(const TData &data)
bool IsLoadedHash(void) const
static int GetHash(const TData &data)
TData::TState GetState(void) const
Data loader exceptions, used by GenBank loader.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
CObjectIStreamAsnBinary –.
static TGi ConvertGiFromOM(TGi gi)
virtual void ProcessStream(CReaderRequestResult &result, const TBlobId &blob_id, TChunkId chunk_id, CNcbiIstream &stream) const
static void OffsetGiToOM(TGi &gi)
static bool TrySNPSplit(void)
static void OffsetIdToOM(CSeq_id &id)
static CSeq_id_Handle ConvertIdFromOM(CSeq_id_Handle id)
Class factory for Pubseq reader.
objects::CReader * CreateInstance(const string &driver=kEmptyStr, CVersionInfo version=NCBI_INTERFACE_VERSION(objects::CReader), const TPluginManagerParamTree *params=0) const
Create instance of TDriver.
CSimpleClassFactoryImpl< objects::CReader, objects::CPubseqReader > TParent
atomic< I_DriverContext * > m_Context
bool LoadGiHash(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
virtual void GetBlobState(CReaderRequestResult &result, const CBlob_id &blob_id) override
virtual ~CPubseqReader() override
virtual void GetBlob(CReaderRequestResult &result, const TBlobId &blob_id, TChunkId chunk_id) override
virtual int GetMaximumConnectionsLimit(void) const override
virtual void x_ConnectAtSlot(TConn conn) override
I_BaseCmd * x_SendRequest(const CBlob_id &blob_id, CDB_Connection *db_conn, const char *rpc)
virtual void x_DisconnectAtSlot(TConn conn, bool failed) override
bool LoadSeq_idInfo(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const SAnnotSelector *with_named_accs)
virtual void x_RemoveConnectionSlot(TConn conn) override
bool LoadGiSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
CDB_Connection * x_GetConnection(TConn conn)
virtual bool LoadSeq_idAccVer(CReaderRequestResult &result, const CSeq_id_Handle &seq_id) override
virtual void x_AddConnectionSlot(TConn conn) override
virtual bool LoadSeq_idSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id) override
void x_ReceiveData(CReaderRequestResult &result, SPubseqReaderReceiveData &data, const TBlobId &blob_id, I_BaseCmd &cmd, bool force_blob)
virtual void SetIncludeHUP(bool include_hup=true, const string &web_cookie=NcbiEmptyString) override
virtual bool LoadSequenceHash(CReaderRequestResult &result, const CSeq_id_Handle &seq_id) override
TConnections m_Connections
virtual void GetBlobVersion(CReaderRequestResult &result, const CBlob_id &blob_id) override
virtual bool LoadSeq_idBlob_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const SAnnotSelector *sel) override
All LoadXxx() methods should return false if there is no requested data in the reader.
CPubseqReader(int max_connections=0, const string &server=kEmptyStr, const string &user=kEmptyStr, const string &pswd=kEmptyStr, const string &dbapi_driver=kEmptyStr)
virtual bool LoadSeq_idGi(CReaderRequestResult &result, const CSeq_id_Handle &seq_id) override
Note about the "buf_size" parameter for streams in this API.
const CProcessor & GetProcessor(CProcessor::EType type) const
void LoadSeq_idGi(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
void LoadSequenceHash(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
void LoadSeq_idSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
vector< CSeq_id_Handle > TSeqIds
CReadDispatcher * m_Dispatcher
void SetAndSaveSeq_idAccVer(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const TSequenceAcc &acc_id) const
void SetAndSaveNoSeq_idBlob_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const SAnnotSelector *sel, const CLoadLockGi &gi_lock) const
void SetAndSaveSeq_idGi(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const TSequenceGi &gi) const
vector< CBlob_Info > TBlobIds
void SetAndSaveNoBlob(CReaderRequestResult &result, const TBlobId &blob_id, TChunkId chunk_id, TBlobState blob_state)
void x_SetIncludeHUP(bool include_hup)
void SetAndSaveSeq_idSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const CFixedSeq_ids &seq_ids) const
void x_ReportDisconnect(const char *reader, const char *server, TConn conn, bool failed) const
virtual bool LoadSeq_idAccVer(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
virtual void OpenConnection(TConn conn)
CDataLoader::SHashFound TSequenceHash
void SetAndSaveSeq_idBlob_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const SAnnotSelector *sel, CLoadLockBlobIds &lock, const CLoadLockBlobIds &blob_ids) const
void SetAndSaveSequenceHash(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const TSequenceHash &hash) const
void InitParams(CConfig &conf, const string &driver_name, int default_max_conn)
int SetMaximumConnections(int max)
void SetAndSaveNoSeq_idSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, TState state) const
CDataLoader::SGiFound TSequenceGi
Template class helps to implement one driver class factory.
static string GetUserName(void)
Get actual user name for the current process.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
definition of a Culling tree
CZipStreamDecompressor – zlib based decompression stream processor.
A very basic data-read interface.
static CS_CONNECTION * conn
#define DBLB_INSTALL_DEFAULT_EX(if_set)
Easy-to-use macro to install the default DBAPI service mapper, with control over what to do if a conn...
void reset(element_type *p=0, EOwnership ownership=eTakeOwnership)
Reset will delete the old pointer (if owned), set content to the new value, and assume the ownership ...
#define GI_FROM(T, value)
element_type * get(void) const
Get pointer.
element_type * release(void)
Release will release ownership of pointer to caller.
@ eTakeOwnership
An object can take ownership of another.
I_DriverContext * GetDriverContext(const string &driver_name, string *err_msg=0, const map< string, string > *attr=0)
virtual EDB_ResType ResultType() const
Get type of the result.
virtual bool SkipItem()
Skip result item.
virtual CDB_LangCmd * LangCmd(const string &lang_query)
Make language command.
virtual size_t ReadItem(void *buffer, size_t buffer_size, bool *is_null=0)
Read a result item body (for BLOB columns, mostly).
virtual CDB_Object * GetItem(CDB_Object *item_buf=0, EGetItem policy=eAppendLOB)
Get a result item (you can use either GetItem or ReadItem).
virtual const char * ItemName(unsigned int item_num) const
Get name of a result item.
virtual unsigned int NofItems() const
Get # of items (columns) in the result.
virtual CDB_RPCCmd * RPC(const string &rpc_name)
Make remote procedure call command.
virtual bool Fetch()
Fetch next row.
virtual void AssignValue(const CDB_Object &v)
const char * Value(void) const
virtual void AssignValue(const CDB_Object &v)
#define LOG_POST_X_ONCE(err_subcode, message)
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
#define NCBI_THROW_FMT(exception_class, err_code, message)
The same as NCBI_THROW but with message processed as output to ostream.
string GetString(const string &driver_name, const string ¶m_name, EErrAction on_error, const string &default_value, const list< string > *synonyms=NULL)
Utility function to get an element of parameter tree Throws an exception when mandatory parameter is ...
bool GetBool(const string &driver_name, const string ¶m_name, EErrAction on_error, bool default_value, const list< string > *synonyms=NULL)
Utility function to get an integer element of parameter tree Throws an exception when mandatory param...
@ eErr_NoThrow
Return default value on error.
CConstRef< CSeq_id > GetSeqId(void) const
static CSeq_id_Handle GetGiHandle(TGi gi)
Faster way to create a handle for a gi.
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
string AsString(void) const
CSeq_id::E_Choice Which(void) const
bool IsIncludedAnyNamedAnnotAccession(void) const
check if any named annot accession is included in the search
bool IsIncludedNamedAnnotAccession(const string &acc) const
check if named annot accession is included in the search
SAnnotSelector & IncludeNamedAnnotAccession(const string &acc, int zoom_level=0)
#define NCBI_PARAM_TYPE(section, name)
Generate typename for a parameter from its {section, name} attributes.
@ eParam_NoThread
Do not use per-thread values.
static void NCBI_EntryPointImpl(TDriverInfoList &info_list, EEntryPointRequest method)
Entry point implementation.
#define NCBI_INTERFACE_VERSION(iface)
Macro to construct CVersionInfo class using interface name (relies on CInterfaceVersion class)
list< SDriverInfo > TDriverInfoList
List of driver information.
EEntryPointRequest
Actions performed by the entry point.
int32_t Int4
4-byte (32-bit) signed integer
int64_t Int8
8-byte (64-bit) signed integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define END_SCOPE(ns)
End the previously defined scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define BEGIN_SCOPE(ns)
Define a new scope.
ERW_Result
Result codes for I/O operations.
@ eRW_NotImplemented
Action / information is not available.
@ eRW_Eof
End of data, should be considered permanent.
@ eRW_Success
Everything is okay, I/O completed.
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
static CStringUTF8 SQLEncode(const CStringUTF8 &str, ESqlEncode flag)
SQL-encode string.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
@ eSqlEnc_TagNonASCII
Produce N'...' when input's not pure ASCII.
#define DEFINE_STATIC_FAST_MUTEX(id)
Define static fast mutex and initialize it.
@ eNonCompatible
major, minor does not match
@ e_Gi
GenInfo Integrated Database.
string s_Value(TValue value)
std::istream & in(std::istream &in_, double &x_)
Helper classes and templates to implement plugins.
#define DEFAULT_DB_PASSWORD
#define DEFAULT_DB_DRIVER
static TIntId sx_GetIntId(CDB_Result &dbr, int pos)
#define DEFAULT_EXCL_WGS_MASTER
static void sx_SetIntId(CDB_RPCCmd &cmd, const char *param, TIntId id)
void NCBI_EntryPoint_ReaderPubseqos(CPluginManager< objects::CReader >::TDriverInfoList &info_list, CPluginManager< objects::CReader >::EEntryPointRequest method)
#define DEFAULT_DB_SERVER
NCBI_PARAM_DECL(int, GENBANK, PUBSEQOS_DEBUG)
NCBI_PARAM_DEF_EX(int, GENBANK, PUBSEQOS_DEBUG, 0, eParam_NoThread, GENBANK_PUBSEQOS_DEBUG)
static int GetDebugLevel(void)
void GenBankReaders_Register_Pubseq(void)
void NCBI_EntryPoint_xreader_pubseqos(CPluginManager< objects::CReader >::TDriverInfoList &info_list, CPluginManager< objects::CReader >::EEntryPointRequest method)
#define RPC_GET_BLOB_INFO
#define DEFAULT_ALLOW_GZIP
#define NCBI_GBLOADER_READER_PUBSEQ_PARAM_SERVER
#define NCBI_GBLOADER_READER_PUBSEQ_PARAM_USER
#define NCBI_GBLOADER_READER_PUBSEQ_PARAM_EXCL_WGS_MASTER
#define NCBI_GBLOADER_READER_PUBSEQ_DRIVER_NAME
#define NCBI_GBLOADER_READER_PUBSEQ_PARAM_GZIP
#define NCBI_GBLOADER_READER_PUBSEQ_PARAM_PASSWORD
#define NCBI_GBLOADER_READER_PUBSEQ_PARAM_DRIVER
Reader-writer based streams.
static const char * str(char *buf, int n)
Better replacement of GetAccVer(), this method should be defined in data loaders, GetAccVer() is left...
Better replacement of GetGi(), this method should be defined in data loaders, GetGi() is left for com...
Better replacement of GetSequenceHash(), this method should be defined in data loaders,...
AutoPtr< CDB_Result > dbr
CReader::TBlobState blob_state
CReader::TBlobVersion blob_version
SPubseqReaderReceiveData()