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

📄 sequtil_convert_imp.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// convert a single NCBI8na byte into a single IUPACna byte.SIZE_TYPE CSeqConvert_imp::x_Convert8naToIupacna(const char* src, TSeqPos pos, TSeqPos length, char *dst){    return convert_1_to_1(src, pos, length, dst, C8naToIupacna::GetTable());}// NCBI8na -> NCBI2na// convert 4 NCBI8na bytes into a single NCBI2na byte.SIZE_TYPE CSeqConvert_imp::x_Convert8naTo2na(const char* src, TSeqPos pos, TSeqPos length, char *dst){    const Uint1* table = C8naTo2na::GetTable();        const char* iter = src + pos;        for ( size_t i = length / 4; i; --i, ++dst ) {        *dst = table[static_cast<Uint1>(*iter) * 4] |            table[static_cast<Uint1>(*(iter + 1)) * 4 + 1] |            table[static_cast<Uint1>(*(iter + 2)) * 4 + 2] |            table[static_cast<Uint1>(*(iter + 3)) * 4 + 3];        iter += 4;    }        // Handle overhang    if ( (length % 4) != 0 ) {        *dst = 0;        for( size_t i = 0; i < (length % 4); ++i, ++iter ) {            *dst |= table[static_cast<Uint1>(*iter) * 4 + i];        }    }        return length;}// NCBI8na -> NCBI2na_expand// convert a single NCBI8na byte into a single NCBI2na_expand byte.SIZE_TYPE CSeqConvert_imp::x_Convert8naTo2naExpand(const char* src, TSeqPos pos, TSeqPos length, char *dst){    // simple conversion table    static const Uint1 table[16] = {        0x03,    // gap -> T        0x00,    // A -> A        0x01,    // C -> C        0x01,    // M -> C        0x02,    // G -> G        0x02,    // R -> G        0x01,    // S -> C        0x00,    // V -> A        0x03,    // T -> T        0x03,    // W -> T        0x03,    // Y -> T        0x00,    // H -> A        0x02,    // K -> G        0x02,    // D -> G        0x01,    // B -> C        0x00     // N -> A    };        return convert_1_to_1(src, pos, length, dst, table);}// NCBI8na -> NCBI4na// convert 2 NCBI8na bytes into  a single NCBI4na byte.SIZE_TYPE CSeqConvert_imp::x_Convert8naTo4na(const char* src, TSeqPos pos, TSeqPos length, char *dst){    const char* iter = src + pos;    for ( size_t i = length / 2; i; --i, ++dst ) {        *dst = (*iter << 4) | (*(iter + 1));        iter += 2;    }    if ( (length % 2) != 0 ) {        *dst = (*iter << 4) & 0xf0;    }        return length;}// AA conversions:// All AA conversions ara a 1 to 1 conversion// from IUPACaa to ...//===========================================================================// IUPACaa -> NCBIeaaSIZE_TYPE CSeqConvert_imp::x_ConvertIupacaaToEaa(const char* src, TSeqPos pos, TSeqPos length, char *dst){    // they map directly    return Subseq(src, CSeqUtil::e_Iupacaa, pos, length, dst);}// IUPACaa -> NCBIstdaa (NCBI8aa)SIZE_TYPE CSeqConvert_imp::x_ConvertIupacaaToStdaa(const char* src, TSeqPos pos, TSeqPos length, char *dst){    return convert_1_to_1(src, pos, length, dst, CIupacaaToStdaa::GetTable());}// from NCBIeaa to ...//===========================================================================// NCBIeaa -> IUPACaaSIZE_TYPE CSeqConvert_imp::x_ConvertEaaToIupacaa(const char* src, TSeqPos pos, TSeqPos length, char *dst){    return convert_1_to_1(src, pos, length, dst, CEaaToIupacaa::GetTable());}// NCBIeaa -> NCBIstdaa (NCBI8aa)SIZE_TYPE CSeqConvert_imp::x_ConvertEaaToStdaa(const char* src, TSeqPos pos, TSeqPos length, char *dst){    return convert_1_to_1(src, pos, length, dst, CEaaToStdaa::GetTable());}// from NCBIstdaa (NCBI8aa) to ...//===========================================================================// NCBIstdaa (NCBI8aa) -> IUPACaaSIZE_TYPE CSeqConvert_imp::x_ConvertStdaaToIupacaa(const char* src, TSeqPos pos, TSeqPos length, char *dst){    return convert_1_to_1(src, pos, length, dst, CStdaaToIupacaa::GetTable());}// NCBIstdaa (NCBI8aa) -> NCBIeaaSIZE_TYPE CSeqConvert_imp::x_ConvertStdaaToEaa(const char* src, TSeqPos pos, TSeqPos length, char *dst){    return convert_1_to_1(src, pos, length, dst, CStdaaToEaa::GetTable());}///////////////////////////////////////////////////////////////////////////////// Subseq - partial sequenceSIZE_TYPE CSeqConvert_imp::Subseq(const char* src, TCoding coding, TSeqPos pos, TSeqPos length, char* dst){    SIZE_TYPE converted = 0;    char *buf = 0;    try {        switch ( coding ) {                    // for packed coding (2na and 4na) first expand, then re-pack        case CSeqUtil::e_Ncbi2na:            {{                buf = new char[length];                x_Convert2naTo2naExpand(src, pos, length, buf);                converted = x_Convert2naExpandTo2na(buf, 0, length, dst);                delete[] buf;                buf = 0;            }}            break;                    case CSeqUtil::e_Ncbi4na:            {{                buf = new char[length];                x_Convert4naTo8na(src, pos, length, buf);                converted = x_Convert8naTo4na(buf, 0, length, dst);                delete[] buf;                buf = 0;            }}            break;                    // iupacna may contain 'U' that needs to be converted to 'T'        case CSeqUtil::e_Iupacna:            {{                converted = convert_1_to_1(src, pos, length, dst,                     CIupacnaToIupacna::GetTable());            }}            break;                    // for other ascii codings make sure the output is upper case        case CSeqUtil::e_Iupacaa:        case CSeqUtil::e_Ncbieaa:            {{                const char* iter = src + pos;                const char* end  = iter + length;                                for ( ; iter != end; ++iter, ++dst ) {                    *dst++ = toupper(*iter);                }                converted = length;            }}            break;                    // for the rest of the codings (e.g. 8na, stdaa) copy        // the desired range.        default:            {{                copy(src + pos, src + pos + length, dst);                converted = length;            }}            break;        } // end of switch statement    } catch ( ... ) {        if ( buf != 0 ) {            delete[] buf;        }        throw;    }    return converted;}///////////////////////////////////////////////////////////////////////////////// PackingSIZE_TYPE CSeqConvert_imp::Pack(const char* src, TSeqPos length, TCoding src_coding, char* dst, TCoding& dst_coding){    dst_coding = x_HasAmbig(src, src_coding, length) ?        CSeqUtil::e_Ncbi4na : CSeqUtil::e_Ncbi2na;        return Convert(src, src_coding, 0, length, dst, dst_coding);}bool CSeqConvert_imp::x_HasAmbig(const char* src, TCoding src_coding, size_t length){    if ( length == 0 ) {        return false;    }        switch ( src_coding ) {    case CSeqUtil::e_Iupacna:        return x_HasAmbigIupacna(src, length);            case CSeqUtil::e_Ncbi4na:        return x_HasAmbigNcbi4na(src, length);            case CSeqUtil::e_Ncbi4na_expand:    case CSeqUtil::e_Ncbi8na:        return x_HasAmbigNcbi8na(src, length);            case CSeqUtil::e_Ncbi2na:    case CSeqUtil::e_Ncbi2na_expand:        return false;    }        return false;}bool CSeqConvert_imp::x_HasAmbigIupacna(const char* src, size_t length){    const bool *not_ambig = CIupacnaAmbig::GetTable();        const char* end = src + length;        const char* iter = src;    while ( (iter != end)  &&  (not_ambig[static_cast<Uint1>(*iter)]) ) {           ++iter;    }    return iter != end;}bool CSeqConvert_imp::x_HasAmbigNcbi4na(const char* src, size_t length){    const bool* not_ambig = CNcbi4naAmbig::GetTable();        const char* end = src + (length / 2);        const char* iter = src;    while ( (iter != end)  &&  (not_ambig[static_cast<Uint1>(*iter)]) ) {          ++iter;    }        if ( (iter == end)  &&  (length % 2) != 0 ) {        return not_ambig[static_cast<Uint1>(*iter) & 0xF1];    }    return iter != end;}bool CSeqConvert_imp::x_HasAmbigNcbi8na(const char* src, size_t length){    const bool *not_ambig = CNcbi8naAmbig::GetTable();        const char* end = src + length;        const char* iter = src;    while ( (iter != end)  &&  (not_ambig[static_cast<Uint1>(*iter)]) ) {          ++iter;    }        return iter != end;}END_NCBI_SCOPE/** ===========================================================================** $Log: sequtil_convert_imp.cpp,v $* Revision 1000.1  2004/06/01 19:42:17  gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.2** Revision 1.2  2004/05/17 21:08:53  gorelenk* Added include of PCH ncbi_pch.hpp** Revision 1.1  2003/10/08 13:34:59  shomrat* Initial version*** ===========================================================================*/

⌨️ 快捷键说明

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