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

📄 block_multiple_alignment.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        if (newUnalignedBlock) blocks.insert(a, newUnalignedBlock);        prevAlignedBlock = alignedBlock;    }    // right tail    newUnalignedBlock = CreateNewUnalignedBlockBetween(alignedBlock, NULL);    if (newUnalignedBlock) {        blocks.insert(a, newUnalignedBlock);    }    return true;}bool BlockMultipleAlignment::UpdateBlockMapAndColors(bool clearRowInfo){    int i = 0, j, n = 0;    BlockList::iterator b, be = blocks.end();    // reset old stuff, recalculate width    totalWidth = 0;    for (b=blocks.begin(); b!=be; ++b) totalWidth += (*b)->width;//    TESTMSG("alignment display size: " << totalWidth << " x " << NRows());    // fill out the block map    conservationColorer->Clear();    blockMap.resize(totalWidth);    UngappedAlignedBlock *aBlock;    for (b=blocks.begin(); b!=be; ++b) {        aBlock = dynamic_cast<UngappedAlignedBlock*>(*b);        if (aBlock) {            conservationColorer->AddBlock(aBlock);            ++n;        }        for (j=0; j<(*b)->width; ++j, ++i) {            blockMap[i].block = *b;            blockMap[i].blockColumn = j;            blockMap[i].alignedBlockNum = aBlock ? n : -1;        }    }    // if alignment changes, any pssm/scores/status/special colors become invalid    RemovePSSM();    if (clearRowInfo) ClearRowInfo();    ShowGeometryViolations(showGeometryViolations); // recalculate GV's    return true;}bool BlockMultipleAlignment::GetCharacterTraitsAt(    int alignmentColumn, int row, eUnalignedJustification justification,    char *character, Vector *color, bool *isHighlighted,    bool *drawBackground, Vector *cellBackgroundColor) const{    const Sequence *sequence;    int seqIndex;    bool isAligned;    if (!GetSequenceAndIndexAt(alignmentColumn, row, justification, &sequence, &seqIndex, &isAligned))        return false;    *character = (seqIndex >= 0) ? sequence->sequenceString[seqIndex] : '~';    if (isAligned)        *character = toupper(*character);    else        *character = tolower(*character);    // try to color by molecule first    if (sequence->molecule) {        *color = (seqIndex >= 0) ?            sequence->molecule->GetResidueColor(seqIndex) :            GlobalColors()->Get(Colors::eNoCoordinates);;    }    // otherwise (for unstructured sequence):    else {        StyleSettings::eColorScheme colorScheme =            sequence->parentSet->styleManager->GetGlobalStyle().proteinBackbone.colorScheme;        // color by hydrophobicity        if (sequence->isProtein && colorScheme == StyleSettings::eHydrophobicity) {            double hydrophobicity = GetHydrophobicity(toupper(*character));            *color = (hydrophobicity != UNKNOWN_HYDROPHOBICITY) ?                GlobalColors()->Get(Colors::eHydrophobicityMap, hydrophobicity) :                GlobalColors()->Get(Colors::eNoHydrophobicity);        }        // or color by charge        else if (sequence->isProtein && colorScheme == StyleSettings::eCharge) {            int charge = GetCharge(toupper(*character));            *color = GlobalColors()->Get(                (charge > 0) ? Colors::ePositive : ((charge < 0) ? Colors::eNegative : Colors::eNeutral));;        }        // else, color by alignment color        else {            const Vector *aColor;            if (isAligned && (aColor = GetAlignmentColor(row, seqIndex, colorScheme)) != NULL) {                *color = *aColor;            } else {                *color = GlobalColors()->Get(Colors::eUnaligned);            }        }    }    if (seqIndex >= 0)        *isHighlighted = GlobalMessenger()->IsHighlighted(sequence, seqIndex);    else        *isHighlighted = false;    // add special alignment coloring (but don't override highlight)    *drawBackground = false;    if (!(*isHighlighted)) {        // check for block flagged for realignment        if (markBlocks.find(blockMap[alignmentColumn].block) != markBlocks.end()) {            *drawBackground = true;            *cellBackgroundColor = GlobalColors()->Get(Colors::eMarkBlock);        }        // optionally show geometry violations        if (showGeometryViolations && seqIndex >= 0 && geometryViolations[row][seqIndex]) {            *drawBackground = true;            *cellBackgroundColor = GlobalColors()->Get(Colors::eGeometryViolation);        }        // check for unmergeable alignment        const BlockMultipleAlignment *referenceAlignment = alignmentManager->GetCurrentMultipleAlignment();        if (referenceAlignment && referenceAlignment != this &&			seqIndex >= 0 && GetMaster() == referenceAlignment->GetMaster()) {            bool unmergeable = false;            const Block *block = blockMap[alignmentColumn].block;            // case where master residues are aligned in multiple but not in this one            if (row == 0 && !isAligned && referenceAlignment->IsAligned(row, seqIndex))                unmergeable = true;            // block boundaries in this inside aligned block of multiple            else if (row > 0 && isAligned) {                const Block::Range *range = block->GetRangeOfRow(row);                bool                    isLeftEdge = (seqIndex == range->from),                    isRightEdge = (seqIndex == range->to);                if (isLeftEdge || isRightEdge) {                    // get corresponding block of multiple                    const Block::Range *masterRange = block->GetRangeOfRow(0);                    int masterIndex = masterRange->from + seqIndex - range->from;                    const Block *multipleBlock = referenceAlignment->GetBlock(0, masterIndex);                    masterRange = multipleBlock->GetRangeOfRow(0);                    if (multipleBlock->IsAligned() &&                        ((isLeftEdge && masterIndex > masterRange->from) ||                         (isRightEdge && masterIndex < masterRange->to)))                        unmergeable = true;                }            }            // check for inserts relative to the multiple            else if (row > 0 && !isAligned) {                const Block                    *blockBefore = GetBlockBefore(block),                    *blockAfter = GetBlockAfter(block),                    *refBlock;                if (blockBefore && blockBefore->IsAligned() && blockAfter && blockAfter->IsAligned() &&                        referenceAlignment->GetBlock(0, blockBefore->GetRangeOfRow(0)->to) ==                        (refBlock=referenceAlignment->GetBlock(0, blockAfter->GetRangeOfRow(0)->from)) &&                        refBlock->IsAligned()                    )                    unmergeable = true;            }            if (unmergeable) {                *drawBackground = true;                *cellBackgroundColor = GlobalColors()->Get(Colors::eMergeFail);            }        }    }    return true;}bool BlockMultipleAlignment::GetSequenceAndIndexAt(    int alignmentColumn, int row, eUnalignedJustification requestedJustification,    const Sequence **sequence, int *index, bool *isAligned) const{    if (sequence) *sequence = (*sequences)[row];    const BlockInfo& blockInfo = blockMap[alignmentColumn];    if (!blockInfo.block->IsAligned()) {        if (isAligned) *isAligned = false;        // override requested justification for end blocks        if (blockInfo.block == blocks.back()) // also true if there's a single aligned block            requestedJustification = eLeft;        else if (blockInfo.block == blocks.front())            requestedJustification = eRight;    } else        if (isAligned) *isAligned = true;    if (index)        *index = blockInfo.block->GetIndexAt(blockInfo.blockColumn, row, requestedJustification);    return true;}int BlockMultipleAlignment::GetRowForSequence(const Sequence *sequence) const{    // this only works for structured sequences, since non-structure sequences can    // be repeated any number of times in the alignment; assumes repeated structures    // will each have a unique Sequence object    if (!sequence || !sequence->molecule) {        ERRORMSG("BlockMultipleAlignment::GetRowForSequence() - Sequence must have associated structure");        return -1;    }    if (cachePrevRow < 0 || cachePrevRow >= NRows() || sequence != (*sequences)[cachePrevRow]) {        int row;        for (row=0; row<NRows(); ++row) if ((*sequences)[row] == sequence) break;        if (row == NRows()) {//            ERRORMSG("BlockMultipleAlignment::GetRowForSequence() - can't find given Sequence");            return -1;        }        cachePrevRow = row;    }    return cachePrevRow;}const Vector * BlockMultipleAlignment::GetAlignmentColor(    int row, int seqIndex, StyleSettings::eColorScheme colorScheme) const{     const UngappedAlignedBlock *block = dynamic_cast<const UngappedAlignedBlock*>(GetBlock(row, seqIndex));     if (!block || !block->IsAligned()) {        WARNINGMSG("BlockMultipleAlignment::GetAlignmentColor() called on unaligned residue");        return NULL;    }    const Vector *alignedColor;    switch (colorScheme) {        case StyleSettings::eAligned:            alignedColor = GlobalColors()->Get(Colors::eConservationMap, Colors::nConservationMap - 1);            break;        case StyleSettings::eIdentity:            alignedColor = conservationColorer->                GetIdentityColor(block, seqIndex - block->GetRangeOfRow(row)->from);            break;        case StyleSettings::eVariety:            alignedColor = conservationColorer->                GetVarietyColor(block, seqIndex - block->GetRangeOfRow(row)->from);            break;        case StyleSettings::eWeightedVariety:            alignedColor = conservationColorer->                GetWeightedVarietyColor(block, seqIndex - block->GetRangeOfRow(row)->from);            break;        case StyleSettings::eInformationContent:            alignedColor = conservationColorer->                GetInformationContentColor(block, seqIndex - block->GetRangeOfRow(row)->from);            break;        case StyleSettings::eFit:            alignedColor = conservationColorer->                GetFitColor(block, seqIndex - block->GetRangeOfRow(row)->from, row);            break;        case StyleSettings::eBlockFit:            alignedColor = conservationColorer->GetBlockFitColor(block, row);            break;        case StyleSettings::eBlockZFit:            alignedColor = conservationColorer->GetBlockZFitColor(block, row);            break;        case StyleSettings::eBlockRowFit:            alignedColor = conservationColorer->GetBlockRowFitColor(block, row);            break;        default:            alignedColor = NULL;    }    return alignedColor;}const Vector * BlockMultipleAlignment::GetAlignmentColor(    const Sequence *sequence, int seqIndex, StyleSettings::eColorScheme colorScheme) const{    int row = GetRowForSequence(sequence);    if (row < 0) return NULL;    return GetAlignmentColor(row, seqIndex, colorScheme);}bool BlockMultipleAlignment::IsAligned(int row, int seqIndex) const{    const Block *block = GetBlock(row, seqIndex);    return (block && block->IsAligned());}const Block * BlockMultipleAlignment::GetBlock(int row, int seqIndex) const{    // make sure we're in range for this sequence    if (row < 0 || seqIndex < 0 || row >= NRows() || seqIndex >= (*sequences)[row]->Length()) {        ERRORMSG("BlockMultipleAlignment::GetBlock() - coordinate out of range");        return NULL;    }    const Block::Range *range;    // first check to see if it's in the same block as last time.    if (cachePrevBlock) {        range = cachePrevBlock->GetRangeOfRow(row);        if (seqIndex >= range->from && seqIndex <= range->to) return cachePrevBlock;        ++cacheBlockIterator; // start search at next block    } else {        cacheBlockIterator = blocks.begin();    }    // otherwise, perform block search. This search is most efficient when queries    // happen in order from left to right along a given row.    do {        if (cacheBlockIterator == blocks.end()) cacheBlockIterator = blocks.begin();        range = (*cacheBlockIterator)->GetRangeOfRow(row);        if (seqIndex >= range->from && seqIndex <= range->to) {            cachePrevBlock = *cacheBlockIterator; // cache this block            return cachePrevBlock;        }        ++cacheBlockIterator;    } while (1);}int BlockMultipleAlignment::GetFirstAlignedBlockPosition(void) const{    BlockList::const_iterator b = blocks.begin();    if (blocks.size() > 0 && (*b)->IsAligned()) // first block is aligned        return 0;    else if (blocks.size() >= 2 && (*(++b))->IsAligned()) // second block is aligned        return blocks.front()->width;    else        return -1;}int BlockMultipleAlignment::GetAlignedSlaveIndex(int masterSeqIndex, int slaveRow) const{    const UngappedAlignedBlock        *aBlock = dynamic_cast<const UngappedAlignedBlock*>(GetBlock(0, masterSeqIndex));    if (!aBlock) return -1;    const Block::Range        *masterRange = aBlock->GetRangeOfRow(0),        *slaveRange = aBlock->GetRangeOfRow(slaveRow);    return (slaveRange->from + masterSeqIndex - masterRange->from);}void BlockMultipleAlignment::SelectedRange(int row, int from, int to,    eUnalignedJustification justification, bool toggle) const{    // translate from,to (alignment columns) into sequence indexes    const Sequence *sequence;    int fromIndex, toIndex;    bool ignored;    // trim selection area to size of this alignment

⌨️ 快捷键说明

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