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

📄 sequence_display.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    }    if (masterOK) {        rows = newRows;        (*viewerWindow)->UpdateDisplay(this);        (*viewerWindow)->viewer->Save();   // make this an undoable operation        GlobalMessenger()->PostRedrawAllSequenceViewers();    }}void SequenceDisplay::RedrawAlignedMolecules(void) const{    for (int i=0; i<rows.size(); ++i) {        const Sequence *sequence = rows[i]->GetSequence();        if (sequence && sequence->molecule)            GlobalMessenger()->PostRedrawMolecule(sequence->molecule);    }}DisplayRowFromString * SequenceDisplay::FindBlockBoundaryRow(const BlockMultipleAlignment *forAlignment) const{    DisplayRowFromString *blockBoundaryRow = NULL;    for (int row=0; row<rows.size(); ++row) {        if ((blockBoundaryRow = dynamic_cast<DisplayRowFromString*>(rows[row])) != NULL) {            if (blockBoundaryRow->alignment == forAlignment &&                blockBoundaryRow->title == blockBoundaryStringTitle)                break;            else                blockBoundaryRow = NULL;        }    }    return blockBoundaryRow;}static inline DisplayRowFromString * CreateBlockBoundaryRow(BlockMultipleAlignment *forAlignment){    return new DisplayRowFromString("", Vector(0,0,0),        blockBoundaryStringTitle, true, Vector(0.8,0.8,1), forAlignment);}void SequenceDisplay::AddBlockBoundaryRows(void){    if (!IsEditable()) return;    // find alignment master rows    int i = 0;    map < const BlockMultipleAlignment * , bool > doneForAlignment;    do {        RowVector::iterator r;        for (r=rows.begin(), i=0; i<rows.size(); ++r, ++i) {            DisplayRowFromAlignment *alnRow = dynamic_cast<DisplayRowFromAlignment*>(*r);            if (!alnRow || alnRow->row != 0 || !alnRow->alignment ||                doneForAlignment.find(alnRow->alignment) != doneForAlignment.end()) continue;            // insert block row before each master row            DisplayRowFromString *blockBoundaryRow = CreateBlockBoundaryRow(alnRow->alignment);            UpdateBlockBoundaryRow(blockBoundaryRow);            rows.insert(r, blockBoundaryRow);            doneForAlignment[alnRow->alignment] = true;            break;  // insert on vector can cause invalidation of iterators, so start over        }    } while (i < rows.size());    if (*viewerWindow) (*viewerWindow)->UpdateDisplay(this);}void SequenceDisplay::AddBlockBoundaryRow(BlockMultipleAlignment *forAlignment){    DisplayRowFromString *blockBoundaryRow = CreateBlockBoundaryRow(forAlignment);    AddRow(blockBoundaryRow);    UpdateBlockBoundaryRow(blockBoundaryRow);}void SequenceDisplay::UpdateBlockBoundaryRow(const BlockMultipleAlignment *forAlignment) const{    DisplayRowFromString *blockBoundaryRow;    if (!IsEditable() || (blockBoundaryRow = FindBlockBoundaryRow(forAlignment)) == NULL ||        !blockBoundaryRow->alignment) return;    UpdateBlockBoundaryRow(blockBoundaryRow);}void SequenceDisplay::UpdateBlockBoundaryRow(DisplayRowFromString *blockBoundaryRow) const{    if (!IsEditable() || !blockBoundaryRow || !blockBoundaryRow->alignment) return;    int alignmentWidth = blockBoundaryRow->alignment->AlignmentWidth();    blockBoundaryRow->theString.resize(alignmentWidth);    // fill out block boundary marker string    int blockColumn, blockWidth;    for (int i=0; i<alignmentWidth; ++i) {        blockBoundaryRow->alignment->GetAlignedBlockPosition(i, &blockColumn, &blockWidth);        if (blockColumn >= 0 && blockWidth > 0) {            if (blockWidth == 1)                blockBoundaryRow->theString[i] = blockOneColumnChar;            else if (blockColumn == 0)                blockBoundaryRow->theString[i] = blockLeftEdgeChar;            else if (blockColumn == blockWidth - 1)                blockBoundaryRow->theString[i] = blockRightEdgeChar;            else                blockBoundaryRow->theString[i] = blockInsideChar;        } else            blockBoundaryRow->theString[i] = ' ';    }    if (*viewerWindow) GlobalMessenger()->PostRedrawSequenceViewer((*viewerWindow)->viewer);}void SequenceDisplay::RemoveBlockBoundaryRows(void){    vector < bool > toRemove(rows.size(), false);    int nToRemove = 0;    for (int row=0; row<rows.size(); ++row) {        DisplayRowFromString *blockBoundaryRow = dynamic_cast<DisplayRowFromString*>(rows[row]);        if (blockBoundaryRow && blockBoundaryRow->title == blockBoundaryStringTitle) {            delete blockBoundaryRow;            toRemove[row] = true;            ++nToRemove;        }    }    VectorRemoveElements(rows, toRemove, nToRemove);    UpdateMaxRowWidth();    if (*viewerWindow) (*viewerWindow)->UpdateDisplay(this);}void SequenceDisplay::GetProteinSequences(SequenceList *seqs) const{    seqs->clear();    for (int row=0; row<rows.size(); ++row) {        const Sequence *seq = rows[row]->GetSequence();        if (seq && seq->isProtein)            seqs->push_back(seq);    }}void SequenceDisplay::GetSequences(const BlockMultipleAlignment *forAlignment, SequenceList *seqs) const{    seqs->clear();    for (int row=0; row<rows.size(); ++row) {        DisplayRowFromAlignment *alnRow = dynamic_cast<DisplayRowFromAlignment*>(rows[row]);        if (alnRow && alnRow->alignment == forAlignment)            seqs->push_back(alnRow->alignment->GetSequenceOfRow(alnRow->row));    }}void SequenceDisplay::GetRowOrder(    const BlockMultipleAlignment *forAlignment, vector < int > *slaveRowOrder) const{    slaveRowOrder->clear();    for (int row=0; row<rows.size(); ++row) {        DisplayRowFromAlignment *alnRow = dynamic_cast<DisplayRowFromAlignment*>(rows[row]);        if (alnRow && alnRow->alignment == forAlignment)            slaveRowOrder->push_back(alnRow->row);    }}// comparison function: if CompareRows(a, b) == true, then row a moves uptypedef bool (*CompareRows)(const DisplayRowFromAlignment *a, const DisplayRowFromAlignment *b);static bool CompareRowsByIdentifier(const DisplayRowFromAlignment *a, const DisplayRowFromAlignment *b){    return MoleculeIdentifier::CompareIdentifiers(        a->alignment->GetSequenceOfRow(a->row)->identifier,        b->alignment->GetSequenceOfRow(b->row)->identifier);}static bool CompareRowsByScore(const DisplayRowFromAlignment *a, const DisplayRowFromAlignment *b){    return (a->alignment->GetRowDouble(a->row) > b->alignment->GetRowDouble(b->row));}static bool CompareRowsByEValue(const DisplayRowFromAlignment *a, const DisplayRowFromAlignment *b){    return ((a->alignment->GetRowDouble(a->row) >= 0.0 &&             a->alignment->GetRowDouble(a->row) < b->alignment->GetRowDouble(b->row)) ||            b->alignment->GetRowDouble(b->row) < 0.0);}static bool CompareRowsFloatPDB(const DisplayRowFromAlignment *a, const DisplayRowFromAlignment *b){    return (a->alignment->GetSequenceOfRow(a->row)->identifier->pdbID.size() > 0 &&            b->alignment->GetSequenceOfRow(b->row)->identifier->pdbID.size() == 0);}static bool CompareRowsFloatHighlights(const DisplayRowFromAlignment *a, const DisplayRowFromAlignment *b){    return (GlobalMessenger()->IsHighlightedAnywhere(a->alignment->GetSequenceOfRow(a->row)->identifier) &&            !GlobalMessenger()->IsHighlightedAnywhere(b->alignment->GetSequenceOfRow(b->row)->identifier));}static Threader::GeometryViolationsForRow violations;static bool CompareRowsFloatGV(const DisplayRowFromAlignment *a, const DisplayRowFromAlignment *b){    return (violations[a->row].size() > 0 && violations[b->row].size() == 0);}static CompareRows rowComparisonFunction = NULL;void SequenceDisplay::SortRowsByIdentifier(void){    rowComparisonFunction = CompareRowsByIdentifier;    SortRows();    (*viewerWindow)->viewer->Save();   // make this an undoable operation	(*viewerWindow)->UpdateDisplay(this);}void SequenceDisplay::SortRowsByThreadingScore(double weightPSSM){    if (!CalculateRowScoresWithThreader(weightPSSM)) return;    rowComparisonFunction = CompareRowsByScore;    SortRows();    TRACEMSG("sorted rows");    (*viewerWindow)->viewer->Save();   // make this an undoable operation	(*viewerWindow)->UpdateDisplay(this);}void SequenceDisplay::FloatPDBRowsToTop(void){    rowComparisonFunction = CompareRowsFloatPDB;    SortRows();    (*viewerWindow)->viewer->Save();   // make this an undoable operation	(*viewerWindow)->UpdateDisplay(this);}void SequenceDisplay::FloatHighlightsToTop(void){    rowComparisonFunction = CompareRowsFloatHighlights;    SortRows();    (*viewerWindow)->viewer->Save();   // make this an undoable operation	(*viewerWindow)->UpdateDisplay(this);}void SequenceDisplay::FloatGVToTop(void){    DisplayRowFromAlignment *alnRow = NULL;    for (int row=0; row<rows.size(); ++row) {        alnRow = dynamic_cast<DisplayRowFromAlignment*>(rows[row]);        if (alnRow)            break;    }    if (!alnRow) {        ERRORMSG("SequenceDisplay::FloatGVToTop() - can't get alignment");        return;    }    if ((*viewerWindow)->viewer->alignmentManager->threader->            GetGeometryViolations(alnRow->alignment, &violations) == 0)        return;    if (!(*viewerWindow)->menuBar->IsChecked(ViewerWindowBase::MID_SHOW_GEOM_VLTNS))        (*viewerWindow)->Command(ViewerWindowBase::MID_SHOW_GEOM_VLTNS);    rowComparisonFunction = CompareRowsFloatGV;    SortRows();    (*viewerWindow)->viewer->Save();   // make this an undoable operation    (*viewerWindow)->UpdateDisplay(this);}void SequenceDisplay::SortRowsBySelfHit(void){    // get alignment    for (int row=0; row<rows.size(); ++row) {        DisplayRowFromAlignment *alnRow = dynamic_cast<DisplayRowFromAlignment*>(rows[row]);        if (alnRow) {            // do self-hit calculation            (*viewerWindow)->viewer->CalculateSelfHitScores(alnRow->alignment);            // then sort by score            rowComparisonFunction = CompareRowsByEValue;            SortRows();			(*viewerWindow)->viewer->Save();   // make this an undoable operation			(*viewerWindow)->UpdateDisplay(this);            break;        }    }}void SequenceDisplay::SortRows(void){    if (!rowComparisonFunction) {        ERRORMSG("SequenceDisplay::SortRows() - must first set comparison function");        return;    }    // to simplify sorting, construct list of slave rows only    vector < DisplayRowFromAlignment * > slaves;    int row;    for (row=0; row<rows.size(); ++row) {        DisplayRowFromAlignment *alnRow = dynamic_cast<DisplayRowFromAlignment*>(rows[row]);        if (alnRow && alnRow->row > 0)            slaves.push_back(alnRow);    }    // do the sort    stable_sort(slaves.begin(), slaves.end(), rowComparisonFunction);    rowComparisonFunction = NULL;    // recreate the row list with new order    RowVector newRows(rows.size());    int nSlaves = 0;    for (row=0; row<rows.size(); ++row) {        DisplayRowFromAlignment *alnRow = dynamic_cast<DisplayRowFromAlignment*>(rows[row]);        if (alnRow && alnRow->row > 0)            newRows[row] = slaves[nSlaves++];   // put sorted slaves in place        else            newRows[row] = rows[row];           // leave other rows in original order    }    if (nSlaves == slaves.size())   // sanity check        rows = newRows;    else        ERRORMSG("SequenceDisplay::SortRows() - internal inconsistency");}bool SequenceDisplay::ProximitySort(int displayRow){    DisplayRowFromAlignment *keyRow = dynamic_cast<DisplayRowFromAlignment*>(rows[displayRow]);    if (!keyRow || keyRow->row == 0) return false;    if (keyRow->alignment->NRows() < 3) return true;    TRACEMSG("doing Proximity Sort on alignment row " << keyRow->row);    int row;    BlockMultipleAlignment::UngappedAlignedBlockList blocks;    keyRow->alignment->GetUngappedAlignedBlocks(&blocks);    BlockMultipleAlignment::UngappedAlignedBlockList::const_iterator b, be = blocks.end();    const Sequence *seq1 = keyRow->alignment->GetSequenceOfRow(keyRow->row);    vector < DisplayRowFromAlignment * > sortedByScore;    // calculate scores for each row based on simple Blosum62 sum of all aligned pairs    for (row=0; row<rows.size(); ++row) {        DisplayRowFromAlignment *alnRow = dynamic_cast<DisplayRowFromAlignment*>(rows[row]);        if (!alnRow) continue;        sortedByScore.push_back(alnRow);        if (alnRow == keyRow) {            keyRow->alignment->SetRowDouble(keyRow->row, kMax_Double);            keyRow->alignment->SetRowStatusLine(keyRow->row, "(key row)");        } else {            const Sequence *seq2 = alnRow->alignment->GetSequenceOfRow(alnRow->row);            double score = 0.0;            for (b=blocks.begin(); b!=be; ++b) {                const Block::Range                    *r1 = (*b)->GetRangeOfRow(keyRow->row),                    *r2 = (*b)->GetRangeOfRow(alnRow->row);                for (int i=0; i<(*b)->width; ++i)                    score += GetBLOSUM62Score(                        seq1->sequenceString[r1->from + i], seq2->sequenceString[r2->from + i]);            }            alnRow->alignment->SetRowDouble(alnRow->row, score);            wxString str;            str.Printf("Score vs. key row: %i", (int) score);            alnRow->alignment->SetRowStatusLine(alnRow->row, str.c_str());        }    }    if (sortedByScore.size() != keyRow->alignment->NRows()) {        ERRORMSG("SequenceDisplay::ProximitySort() - wrong # rows in sort list");        return false;    }    // sort by these scores    stable_sort(sortedByScore.begin(), sortedByScore.end(), CompareRowsByScore);    // find where the master row is in sorted list    int M;    for (M=0; M<sortedByScore.size(); ++M) if (sortedByScore[M]->row == 0) break;    // arrange by proximity to key row    vector < DisplayRowFromAlignment * > arrangedByProximity(sortedByScore.size(), NULL);    // add master and key row    arrangedByProximity[0] = sortedByScore[M];  // move master back to top    arrangedByProximity[M] = sortedByScore[0];  // move key row to M    // remove these from sorted list    vector < bool > toRemove(sortedByScore.size(), false);    toRemove[M] = toRemove[0] = true;    VectorRemoveElements(sortedByScore, toRemove, 2);    // add the rest of the sequences in the sorted list to the arranged list    int i = 1, j = 1, N, R = 0;    while (R < sortedByScore.size()) {        N = M + i*j;    // iterate N = M+1, M-1, M+2, M-2, ...        j = -j;

⌨️ 快捷键说明

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