utils.cpp

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

CPP
595
字号
void GetDeltaSeqSummary(const CBioseq_Handle& seq, SDeltaSeqSummary& summary){    if ( !seq.IsSetInst()                                ||         !seq.IsSetInst_Repr()                           ||         !(seq.GetInst_Repr() == CSeq_inst::eRepr_delta) ||         !seq.IsSetInst_Ext()                            ||         !seq.GetInst_Ext().IsDelta() ) {        return;    }    SDeltaSeqSummary temp;    CScope& scope = seq.GetScope();    const CDelta_ext::Tdata& segs = seq.GetInst_Ext().GetDelta().Get();    temp.num_segs = segs.size();        size_t len = 0;    CNcbiOstrstream text;    CDelta_ext::Tdata::const_iterator curr = segs.begin();    CDelta_ext::Tdata::const_iterator end = segs.end();    CDelta_ext::Tdata::const_iterator next;    for ( ; curr != end; curr = next ) {        {{            // set next to one after curr            next = curr; ++next;        }}        size_t from = len + 1;        switch ( (*curr)->Which() ) {        case CDelta_seq::e_Loc:            {{                const CDelta_seq::TLoc& loc = (*curr)->GetLoc();                if ( loc.IsNull() ) {  // gap                    ++temp.num_gaps;                    text << "* " << from << ' ' << len                          << " gap of unknown length~";                } else {                    size_t tlen = sequence::GetLength(loc, &scope);                    len += tlen;                    temp.residues += tlen;                    text << "* " << from << " " << len << ": contig of "                         << tlen << " bp in length~";                }            }}              break;        case CDelta_seq::e_Literal:            {{                const CDelta_seq::TLiteral& lit = (*curr)->GetLiteral();                size_t lit_len = lit.CanGetLength() ? lit.GetLength() : 0;                len += lit_len;                if ( lit.CanGetSeq_data() ) {                    temp.residues += lit_len;                    while ( next != end  &&  (*next)->IsLiteral()  &&                        (*next)->GetLiteral().CanGetSeq_data() ) {                        const CDelta_seq::TLiteral& next_lit = (*next)->GetLiteral();                        size_t next_len = next_lit.CanGetLength() ?                            next_lit.GetLength() : 0;                        lit_len += next_len;                        len += next_len;                        temp.residues += next_len;                        ++next;                    }                    text << "* " << from << " " << len << ": contig of "                          << lit_len << " bp in length~";                } else {                    bool unk = false;                    ++temp.num_gaps;                    if ( lit.CanGetFuzz() ) {                        const CSeq_literal::TFuzz& fuzz = lit.GetFuzz();                        if ( fuzz.IsLim()  &&                               fuzz.GetLim() == CInt_fuzz::eLim_unk ) {                            unk = true;                            ++temp.num_faked_gaps;                            if ( from > len ) {                                text << "*                    gap of unknown length~";                            } else {                                text << "* " << from << " " << len                                      << ": gap of unknown length~";                            }                        }                    }                    if ( !unk ) {                        text << "* " << from << " " << len << ": gap of "                             << lit_len << " bp~";                    }                }            }}            break;        default:            break;        }    }    summary = temp;    summary.text = CNcbiOstrstreamToString(text);}const string& GetTechString(int tech){    static const string concept_trans_str = "conceptual translation";    static const string seq_pept_str = "direct peptide sequencing";    static const string both_str = "conceptual translation with partial peptide sequencing";    static const string seq_pept_overlap_str = "sequenced peptide, ordered by overlap";    static const string seq_pept_homol_str = "sequenced peptide, ordered by homology";    static const string concept_trans_a_str = "conceptual translation supplied by author";        switch ( tech ) {    case CMolInfo::eTech_concept_trans:        return concept_trans_str;    case CMolInfo::eTech_seq_pept :        return seq_pept_str;    case CMolInfo::eTech_both:        return both_str;    case CMolInfo::eTech_seq_pept_overlap:        return seq_pept_overlap_str;    case CMolInfo::eTech_seq_pept_homol:        return seq_pept_homol_str;    case CMolInfo::eTech_concept_trans_a:        return concept_trans_a_str;    default:        return kEmptyStr;    }    return kEmptyStr;}bool s_IsModelEvidanceUop(const CUser_object& uo){    return (uo.CanGetType()  &&  uo.GetType().IsStr()  &&        uo.GetType().GetStr() == "ModelEvidence");}const CUser_object* s_FindModelEvidanceUop(const CUser_object& uo){    if ( s_IsModelEvidanceUop(uo) ) {        return &uo;    }    const CUser_object* temp = 0;    ITERATE (CUser_object::TData, ufi, uo.GetData()) {        const CUser_field& uf = **ufi;        if ( !uf.CanGetData() ) {            continue;        }        const CUser_field::TData& data = uf.GetData();        switch ( data.Which() ) {        case CUser_field::TData::e_Object:            temp = s_FindModelEvidanceUop(data.GetObject());            break;        case CUser_field::TData::e_Objects:            ITERATE (CUser_field::TData::TObjects, obj, data.GetObjects()) {                temp = s_FindModelEvidanceUop(**obj);                if ( temp != 0 ) {                    break;                }            }            break;        default:            break;        }        if ( temp != 0 ) {            break;        }    }    return temp;}bool s_GetModelEvidance(const CBioseq_Handle& bsh, SModelEvidance& me){    const CUser_object* moduop = 0;    bool result = false;    for (CSeqdesc_CI it(bsh, CSeqdesc::e_User);  it;  ++it) {        const CUser_object* modup = s_FindModelEvidanceUop(it->GetUser());        if ( modup != 0 ) {            result = true;            const CUser_field* ufp = 0;            if ( moduop->HasField("Contig Name") ) {                ufp = &(moduop->GetField("Contig Name"));                if ( ufp->CanGetData()  &&  ufp->GetData().IsStr() ) {                    me.name = ufp->GetData().GetStr();                }            }            if ( moduop->HasField("Method") ) {                ufp = &(moduop->GetField("Method"));                if ( ufp->CanGetData()  &&  ufp->GetData().IsStr() ) {                    me.method = ufp->GetData().GetStr();                }            }            if ( moduop->HasField("mRNA") ) {                me.mrnaEv = true;            }            if ( moduop->HasField("EST") ) {                me.estEv = true;            }        }    }    return result;}bool GetModelEvidance(const CBioseq_Handle& bsh, SModelEvidance& me){    if ( s_GetModelEvidance(bsh, me) ) {        return true;    }    if ( CSeq_inst::IsAa(bsh.GetInst_Mol()) ) {        CBioseq_Handle nuc = sequence::GetNucleotideParent(bsh);        if ( nuc  ) {            return s_GetModelEvidance(nuc, me);        }    }    return false;}// in Ncbistdaa orderstatic const char* kAANames[] = {    "---", "Ala", "Asx", "Cys", "Asp", "Glu", "Phe", "Gly", "His", "Ile",    "Lys", "Leu", "Met", "Asn", "Pro", "Glu", "Arg", "Ser", "Thr", "Val",    "Trp", "OTHER", "Tyr", "Glx", "Sec", "TERM"};const char* GetAAName(unsigned char aa, bool is_ascii){    if (is_ascii) {        aa = CSeqportUtil::GetMapToIndex            (CSeq_data::e_Ncbieaa, CSeq_data::e_Ncbistdaa, aa);    }    return (aa < sizeof(kAANames)/sizeof(*kAANames)) ? kAANames[aa] : "OTHER";}END_SCOPE(objects)END_NCBI_SCOPE/** ===========================================================================** $Log: utils.cpp,v $* Revision 1000.1  2004/06/01 19:45:35  gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10** Revision 1.10  2004/05/26 14:08:14  shomrat* ValidateAccession allow 2 letters + underscore + 9 digits** Revision 1.9  2004/05/21 21:42:54  gorelenk* Added PCH ncbi_pch.hpp** Revision 1.8  2004/05/07 15:23:14  shomrat* + RemovePeriodFromEnd** Revision 1.7  2004/04/22 15:54:47  shomrat* Use CBioseq_Handle instead of CBioseq** Revision 1.6  2004/04/07 14:29:16  shomrat* + GetAAName** Revision 1.5  2004/03/25 20:47:26  shomrat* Use handles** Revision 1.4  2004/03/18 15:35:17  shomrat* Fixes in JoinNoRedund** Revision 1.3  2004/03/08 20:55:32  shomrat* Use case sensetive search when looking for redundent content** Revision 1.2  2004/02/11 16:57:34  shomrat* added JoinNoRedund functions** Revision 1.1  2003/12/17 20:25:01  shomrat* Initial Revision (adapted from flat lib)*** ===========================================================================*/

⌨️ 快捷键说明

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