seqdbalias.cpp

来自「ncbi源码」· C++ 代码 · 共 589 行 · 第 1/2 页

CPP
589
字号
                       eFileErr,                       "Illegal configuration: DB alias files are mutually recursive.");        }                if ( CFile(new_db_loc).Exists() ) {            if (parens == false && seqdb_debug_class & debug_alias) {                parens = true;                cout << " {" << endl;            }                        string newpath = SeqDB_GetDirName(new_db_loc);            string newfile = SeqDB_GetBaseName(new_db_loc);                        CRef<CSeqDBAliasNode>                subnode( new CSeqDBAliasNode(newpath,                                             newfile,                                             prot_nucl,                                             use_mmap,                                             recurse) );                        m_SubNodes.push_back(subnode);        } else {            // If the name is not found as an alias file, it is            // considered to be a volume.                        m_VolNames.push_back( SeqDB_GetBasePath(new_db_loc) );        }    }        if (seqdb_debug_class & debug_alias) {        if (parens) {            cout << "}" << endl;        } else {            cout << ";" << endl;        }    }}void CSeqDBAliasNode::GetVolumeNames(vector<string> & vols) const{    set<string> volset;    x_GetVolumeNames(volset);        vols.clear();    for(set<string>::iterator i = volset.begin(); i != volset.end(); i++) {        vols.push_back(*i);    }        // Sort to insure deterministic order.    sort(vols.begin(), vols.end());}void CSeqDBAliasNode::x_GetVolumeNames(set<string> & vols) const{    Uint4 i = 0;        for(i = 0; i < m_VolNames.size(); i++) {        vols.insert(m_VolNames[i]);    }        for(i = 0; i < m_SubNodes.size(); i++) {        m_SubNodes[i]->x_GetVolumeNames(vols);    }}class CSeqDB_TitleWalker : public CSeqDB_AliasWalker {public:    virtual const char * GetFileKey(void) const    {        return "TITLE";    }        virtual void Accumulate(const CSeqDBVol & vol)    {        AddString( vol.GetTitle() );    }        virtual void AddString(const string & value)    {        if (! value.empty()) {            if (! m_Value.empty()) {                m_Value += "; ";            }            m_Value += value;        }    }        string GetTitle(void)    {        return m_Value;    }    private:    string m_Value;};// A slightly more clever approach (might) track the contributions// from each volume or alias file and trim the final total by the// amount of provable overcounting detected.// // Since this is probably impossible in most cases, it is not done.// The working assumption then is that the specified databases are// disjoint.  This design should prevent undercounting but allows// overcounting in some cases.class CSeqDB_MaxLengthWalker : public CSeqDB_AliasWalker {public:    CSeqDB_MaxLengthWalker(void)    {        m_Value = 0;    }        virtual const char * GetFileKey(void) const    {        // This field is not overrideable.                return "MAX_SEQ_LENGTH";    }        virtual void Accumulate(const CSeqDBVol & vol)    {        Uint4 new_max = vol.GetMaxLength();                if (new_max > m_Value)            m_Value = new_max;    }        virtual void AddString(const string & value)    {        m_Value = NStr::StringToUInt(value);    }        Uint4 GetMaxLength(void)    {        return m_Value;    }    private:    Uint4 m_Value;};class CSeqDB_NSeqsWalker : public CSeqDB_AliasWalker {public:    CSeqDB_NSeqsWalker(void)    {        m_Value = 0;    }        virtual const char * GetFileKey(void) const    {        return "NSEQ";    }        virtual void Accumulate(const CSeqDBVol & vol)    {        m_Value += vol.GetNumSeqs();    }        virtual void AddString(const string & value)    {        m_Value += NStr::StringToUInt(value);    }        Uint4 GetNumSeqs(void) const    {        return m_Value;    }    private:    Uint4 m_Value;};class CSeqDB_TotalLengthWalker : public CSeqDB_AliasWalker {public:    CSeqDB_TotalLengthWalker(void)    {        m_Value = 0;    }        virtual const char * GetFileKey(void) const    {        return "LENGTH";    }        virtual void Accumulate(const CSeqDBVol & vol)    {        m_Value += vol.GetTotalLength();    }        virtual void AddString(const string & value)    {        m_Value += NStr::StringToUInt8(value);    }        Uint8 GetTotalLength(void) const    {        return m_Value;    }    private:    Uint8 m_Value;};voidCSeqDBAliasNode::WalkNodes(CSeqDB_AliasWalker * walker,                           const CSeqDBVolSet & volset) const{    TVarList::const_iterator iter =        m_Values.find(walker->GetFileKey());        if (iter != m_Values.end()) {        walker->AddString( (*iter).second );        return;    }        Uint4 i;        for(i = 0; i < m_SubNodes.size(); i++) {        m_SubNodes[i]->WalkNodes( walker, volset );    }        // For each volume name, try to find the corresponding volume and    // call Accumulate.        for(i = 0; i < m_VolNames.size(); i++) {        if (const CSeqDBVol * vptr = volset.GetVol(m_VolNames[i])) {            walker->Accumulate( *vptr );        }    }}void CSeqDBAliasNode::SetMasks(CSeqDBVolSet & volset){    TVarList::iterator oid_iter = m_Values.find(string("OIDLIST"));    TVarList::iterator db_iter  = m_Values.find(string("DBLIST"));        if ((oid_iter != m_Values.end()) &&        (db_iter  != m_Values.end())) {                string vol_path (SeqDB_CombinePath(m_DBPath, (*db_iter).second));        string mask_path(SeqDB_CombinePath(m_DBPath, (*oid_iter).second));                volset.AddMaskedVolume(vol_path, mask_path);                return;    }        Uint4 i;        for(i = 0; i < m_SubNodes.size(); i++) {        m_SubNodes[i]->SetMasks( volset );    }        for(i = 0; i < m_VolNames.size(); i++) {        if (CSeqDBVol * vptr = volset.GetVol(m_VolNames[i])) {            // We did NOT find an OIDLIST entry; therefore, any db            // volumes mentioned here are included unfiltered.                        volset.AddFullVolume(vptr->GetVolName());        }    }}string CSeqDBAliasNode::GetTitle(const CSeqDBVolSet & volset) const{    CSeqDB_TitleWalker walk;    WalkNodes(& walk, volset);        return walk.GetTitle();}Uint4 CSeqDBAliasNode::GetNumSeqs(const CSeqDBVolSet & vols) const{    CSeqDB_NSeqsWalker walk;    WalkNodes(& walk, vols);        return walk.GetNumSeqs();}Uint8 CSeqDBAliasNode::GetTotalLength(const CSeqDBVolSet & volset) const{    CSeqDB_TotalLengthWalker walk;    WalkNodes(& walk, volset);        return walk.GetTotalLength();}END_NCBI_SCOPE

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?