⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 seq_loc.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
TSeqPos CSeq_loc::GetEnd(TSeqPos seq_len) const{    if (seq_len == kInvalidSeqPos) {        return GetTotalRange().GetTo();    }    switch ( Which() ) {    case CSeq_loc::e_not_set:    case CSeq_loc::e_Null:    case CSeq_loc::e_Empty:        {            return kInvalidSeqPos;        }    case CSeq_loc::e_Whole:        {            return TRange::GetWhole().GetTo();        }    case CSeq_loc::e_Int:        {            return GetInt().GetTo();        }    case CSeq_loc::e_Pnt:        {            return GetPnt().GetPoint();        }    case CSeq_loc::e_Packed_int:        {            return (*GetPacked_int().Get().rbegin())->GetTo();        }    case CSeq_loc::e_Packed_pnt:        {            return *GetPacked_pnt().GetPoints().rbegin();        }    case CSeq_loc::e_Mix:        {            return (*GetMix().Get().rbegin())->GetEnd(seq_len);        }    case CSeq_loc::e_Equiv:    case CSeq_loc::e_Bond:    case CSeq_loc::e_Feat:    default:        {            NCBI_THROW(CException, eUnknown,                       "CSeq_loc::GetEnd -- "                       "unsupported location type");        }    }}TSeqPos CSeq_loc::GetCircularLength(TSeqPos seq_len) const{    if (seq_len == kInvalidSeqPos) {        return GetTotalRange().GetLength();    }    TSeqPos start = GetStart(seq_len);    TSeqPos stop = GetEnd(seq_len);    return start > stop ? seq_len - start + stop + 1 : stop - start + 1;}// CSeq_loc_CI implementationCSeq_loc_CI::CSeq_loc_CI(void)    : m_Location(0),      m_EmptyFlag(eEmpty_Skip){    m_CurLoc = m_LocList.end();}CSeq_loc_CI::CSeq_loc_CI(const CSeq_loc& loc, EEmptyFlag empty_flag)    : m_Location(&loc),      m_EmptyFlag(empty_flag){    x_ProcessLocation(loc);    m_CurLoc = m_LocList.begin();}CSeq_loc_CI::CSeq_loc_CI(const CSeq_loc_CI& iter){    *this = iter;}CSeq_loc_CI::~CSeq_loc_CI(){}CSeq_loc_CI& CSeq_loc_CI::operator= (const CSeq_loc_CI& iter){    if (this == &iter)        return *this;    m_LocList.clear();    m_Location = iter.m_Location;    m_EmptyFlag = iter.m_EmptyFlag;    ITERATE(TLocList, li, iter.m_LocList) {        TLocList::iterator tmp = m_LocList.insert(m_LocList.end(), *li);        if (iter.m_CurLoc == li)            m_CurLoc = tmp;    }    return *this;}void CSeq_loc_CI::x_ThrowNotValid(const char* where) const{    string msg;    msg += "CSeq_loc_CI::";    msg += where;    msg += " -- iterator is not valid";    NCBI_THROW(CException, eUnknown,        msg);}void CSeq_loc_CI::x_ProcessLocation(const CSeq_loc& loc){    switch ( loc.Which() ) {    case CSeq_loc::e_not_set:    case CSeq_loc::e_Null:    case CSeq_loc::e_Empty:        {            if (m_EmptyFlag == eEmpty_Allow) {                SLoc_Info info;                info.m_Id.Reset(new CSeq_id);                info.m_Range = TRange::GetEmpty();                info.m_Loc = &loc;                m_LocList.push_back(info);            }            return;        }    case CSeq_loc::e_Whole:        {            SLoc_Info info;            info.m_Id = &loc.GetWhole();            info.m_Range = TRange::GetWhole();            info.m_Loc = &loc;            m_LocList.push_back(info);            return;        }    case CSeq_loc::e_Int:        {            SLoc_Info info;            info.m_Id = &loc.GetInt().GetId();            info.m_Range.Set(loc.GetInt().GetFrom(), loc.GetInt().GetTo());            if ( loc.GetInt().IsSetStrand() )                info.m_Strand = loc.GetInt().GetStrand();            info.m_Loc = &loc;            if (loc.GetInt().IsSetFuzz_from()) {                info.m_Fuzz[0] = &loc.GetInt().GetFuzz_from();            }            if (loc.GetInt().IsSetFuzz_to()) {                info.m_Fuzz[1] = &loc.GetInt().GetFuzz_to();            }            m_LocList.push_back(info);            return;        }    case CSeq_loc::e_Pnt:        {            SLoc_Info info;            info.m_Id = &loc.GetPnt().GetId();            info.m_Range.Set(loc.GetPnt().GetPoint(), loc.GetPnt().GetPoint());            if ( loc.GetPnt().IsSetStrand() )                info.m_Strand = loc.GetPnt().GetStrand();            info.m_Loc = &loc;            if (loc.GetPnt().IsSetFuzz()) {                info.m_Fuzz[0] = info.m_Fuzz[1] = &loc.GetPnt().GetFuzz();            }            m_LocList.push_back(info);            return;        }    case CSeq_loc::e_Packed_int:        {            ITERATE ( CPacked_seqint::Tdata, ii, loc.GetPacked_int().Get() ) {                SLoc_Info info;                info.m_Id = &(*ii)->GetId();                info.m_Range.Set((*ii)->GetFrom(), (*ii)->GetTo());                if ( (*ii)->IsSetStrand() )                    info.m_Strand = (*ii)->GetStrand();                info.m_Loc = &loc;                if ((*ii)->IsSetFuzz_from()) {                    info.m_Fuzz[0] = &(*ii)->GetFuzz_from();                }                if ((*ii)->IsSetFuzz_to()) {                    info.m_Fuzz[1] = &(*ii)->GetFuzz_to();                }                m_LocList.push_back(info);            }            return;        }    case CSeq_loc::e_Packed_pnt:        {            ITERATE ( CPacked_seqpnt::TPoints, pi, loc.GetPacked_pnt().GetPoints() ) {                SLoc_Info info;                info.m_Id = &loc.GetPacked_pnt().GetId();                info.m_Range.Set(*pi, *pi);                if ( loc.GetPacked_pnt().IsSetStrand() )                    info.m_Strand = loc.GetPacked_pnt().GetStrand();                info.m_Loc = &loc;                if (loc.GetPacked_pnt().IsSetFuzz()) {                    info.m_Fuzz[0] = info.m_Fuzz[1]                        = &loc.GetPacked_pnt().GetFuzz();                }                m_LocList.push_back(info);            }            return;        }    case CSeq_loc::e_Mix:        {            ITERATE(CSeq_loc_mix::Tdata, li, loc.GetMix().Get()) {                x_ProcessLocation(**li);            }            return;        }    case CSeq_loc::e_Equiv:        {            ITERATE(CSeq_loc_equiv::Tdata, li, loc.GetEquiv().Get()) {                x_ProcessLocation(**li);            }            return;        }    case CSeq_loc::e_Bond:        {            SLoc_Info infoA;            infoA.m_Id = &loc.GetBond().GetA().GetId();            infoA.m_Range.Set(loc.GetBond().GetA().GetPoint(),                              loc.GetBond().GetA().GetPoint());            if ( loc.GetBond().GetA().IsSetStrand() )                infoA.m_Strand = loc.GetBond().GetA().GetStrand();            infoA.m_Loc = &loc;            if (loc.GetBond().GetA().IsSetFuzz()) {                infoA.m_Fuzz[0] = infoA.m_Fuzz[1]                    = &loc.GetBond().GetA().GetFuzz();            }            m_LocList.push_back(infoA);            if ( loc.GetBond().IsSetB() ) {                SLoc_Info infoB;                infoB.m_Id = &loc.GetBond().GetB().GetId();                infoB.m_Range.Set(loc.GetBond().GetB().GetPoint(),                                  loc.GetBond().GetB().GetPoint());                if ( loc.GetBond().GetB().IsSetStrand() )                    infoB.m_Strand = loc.GetBond().GetB().GetStrand();                infoB.m_Loc = &loc;                if (loc.GetBond().GetB().IsSetFuzz()) {                    infoB.m_Fuzz[0] = infoB.m_Fuzz[1]                        = &loc.GetBond().GetB().GetFuzz();                }                m_LocList.push_back(infoB);            }            return;        }    case CSeq_loc::e_Feat:    default:        {            NCBI_THROW(CException, eUnknown,                       "CSeq_loc_CI -- unsupported location type");        }    }}// Append a string representation of a CSeq_id to labelinlinevoid s_GetLabel(const CSeq_id& id, string* label){    CNcbiOstrstream os;    id.WriteAsFasta(os);    *label += CNcbiOstrstreamToString(os);}// Append to label info for a CSeq_pointinlineconst CSeq_id* s_GetLabel(const CSeq_point& pnt, const CSeq_id*    last_id, string*           label){    // If CSeq_id does not match last_id, then append id to label    if ( !last_id  ||  !last_id->Match(pnt.GetId()) ) {        s_GetLabel(pnt.GetId(), label);        *label += ":";    }    // Add strand info to label    if (pnt.IsSetStrand()) {        *label += GetTypeInfo_enum_ENa_strand()            ->FindName(pnt.GetStrand(), true);    }    if (pnt.IsSetFuzz()) {        // Append Fuzz info to label        pnt.GetFuzz().GetLabel(label, pnt.GetPoint());    } else {        // Append 1 based point to label        *label += NStr::IntToString(pnt.GetPoint()+1);    }    // update last_id    last_id = &pnt.GetId();    return last_id;}// Append to label info for CSeq_intervalinlineconst CSeq_id* s_GetLabel(const CSeq_interval& itval, const CSeq_id*       last_id, string*              label){    if (!last_id || !last_id->Match(itval.GetId())) {        s_GetLabel(itval.GetId(), label);        *label += ":";    }    last_id = &itval.GetId();    if (itval.IsSetStrand()) {        *label += GetTypeInfo_enum_ENa_strand()            ->FindName(itval.GetStrand(), true);    }    if (itval.IsSetStrand() &&        (itval.GetStrand() == eNa_strand_minus ||         itval.GetStrand() == eNa_strand_both_rev)) {        if (itval.IsSetFuzz_to()) {            itval.GetFuzz_to().GetLabel(label, itval.GetTo(), false);        } else {            *label += NStr::IntToString(itval.GetTo()+1);        }        *label += "-";        if (itval.IsSetFuzz_from()) {            itval.GetFuzz_from().GetLabel(label, itval.GetFrom());        } else {            *label += NStr::IntToString(itval.GetFrom()+1);        }    } else {        if (itval.IsSetFuzz_from()) {            itval.GetFuzz_from().GetLabel                (label, itval.GetFrom(), false);        } else {            *label += NStr::IntToString(itval.GetFrom()+1);        }        *label += "-";        if (itval.IsSetFuzz_to()) {            itval.GetFuzz_to().GetLabel(label, itval.GetTo());        } else {            *label += NStr::IntToString(itval.GetTo()+1);        }    }    return last_id;}// Forward declarationconst CSeq_id* s_GetLabel(const CSeq_loc& loc, const CSeq_id*  last_id, string*         label, bool            first = false);// Appends to label info for each CSeq_loc in a list of CSeq_locsinlineconst CSeq_id* s_GetLabel(const list<CRef<CSeq_loc> >&  loc_list, const CSeq_id*                last_id, string*                       label){    bool first = true;    ITERATE (list<CRef<CSeq_loc> >, it, loc_list) {        // Append to label for each CSeq_loc in list        last_id = s_GetLabel(**it, last_id, label, first);        first = false;    }    return last_id;}// Builds a label based upon a CSeq_loc and all embedded CSeq_locsconst CSeq_id* s_GetLabel(const CSeq_loc& loc, const CSeq_id*  last_id, string*         label, bool            first){    // Ensure label is not null    if (!label) {        return last_id;    }    // Put a comma separator if necessary    if (!first) {        *label += ", ";    }    // Loop through embedded CSeq_locs and create a label, depending on    // type of CSeq_loc    switch (loc.Which()) {    case CSeq_loc::e_Null:        *label += "~";        break;    case CSeq_loc::e_Empty:        *label += "{";        s_GetLabel(loc.GetEmpty(), label);        last_id = &loc.GetEmpty();        *label += "}";        break;    case CSeq_loc::e_Whole:        s_GetLabel(loc.GetWhole(), label);        last_id = &loc.GetWhole();        break;    case CSeq_loc::e_Int:        last_id = s_GetLabel(loc.GetInt(), last_id, label);        break;    case CSeq_loc::e_Packed_int:    {        *label += "(";        bool first = true;        ITERATE(CPacked_seqint::Tdata, it, loc.GetPacked_int().Get()) {            if (!first) {                *label += ", ";            }            first = false;            last_id = s_GetLabel(**it, last_id, label);        }        *label += ")";        break;    }    case CSeq_loc::e_Pnt:        last_id = s_GetLabel(loc.GetPnt(), last_id, label);        break;    case CSeq_loc::e_Packed_pnt:        *label += "(" + loc.GetPacked_pnt().GetId().AsFastaString() + ":";        {{             string str;             ITERATE (CPacked_seqpnt::TPoints, iter,                      loc.GetPacked_pnt().GetPoints()) {                 if ( !str.empty() ) {                     str += ", ";                 }                 str += NStr::IntToString(*iter);             }             *label += str;         }}        *label += ")";        last_id = &loc.GetPacked_pnt().GetId();        break;    case CSeq_loc::e_Mix:        *label += "[";        last_id = s_GetLabel(loc.GetMix().Get(), last_id, label);        *label += "]";        break;    case CSeq_loc::e_Equiv:        *label += "[";        last_id = s_GetLabel(loc.GetEquiv().Get(), last_id, label);        *label += "]";        break;    case CSeq_loc::e_Bond:        last_id = s_GetLabel(loc.GetBond().GetA(), last_id, label);        *label += "=";        if (loc.GetBond().IsSetB()) {            last_id = s_GetLabel(loc.GetBond().GetB(), last_id, label);        } else {            *label += "?";        }        break;    case CSeq_loc::e_Feat:        *label += "(feat)";        break;    default:        *label += "(?\?)";        break;    }    return last_id;}bool CSeq_loc::IsPartialLeft (void) const{    switch (Which ()) {        case CSeq_loc::e_Null :            return true;        case CSeq_loc::e_Int :            return GetInt ().IsPartialLeft ();        case CSeq_loc::e_Pnt :            return GetPnt ().IsPartialLeft ();        case CSeq_loc::e_Mix :            return GetMix ().IsPartialLeft ();        default :            break;    }    return false;}bool CSeq_loc::IsPartialRight (void) const{    switch (Which ()) {        case CSeq_loc::e_Null :            return true;        case CSeq_loc::e_Int :            return GetInt ().IsPartialRight ();        case CSeq_loc::e_Pnt :            return GetPnt ().IsPartialRight ();        case CSeq_loc::e_Mix :            return GetMix ().IsPartialRight ();        default :            break;    }    return false;}void CSeq_loc::SetPartialLeft (bool val){    if ( val == IsPartialLeft() ) {        return;    }    switch ( Which() ) {        case CSeq_loc::e_Int:            SetInt().SetPartialLeft(val);        case CSeq_loc::e_Pnt:            SetPnt().SetPartialLeft(val);        case CSeq_loc::e_Mix :            SetMix().SetPartialLeft(val);        default :            break;    }}void CSeq_loc::SetPartialRight(bool val){    if ( val == IsPartialRight() ) {

⌨️ 快捷键说明

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