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

📄 alignment_manager.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* * =========================================================================== * PRODUCTION $Log: alignment_manager.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 18:27:33  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.94 * PRODUCTION * =========================================================================== *//*  $Id: alignment_manager.cpp,v 1000.2 2004/06/01 18:27:33 gouriano Exp $* ===========================================================================**                            PUBLIC DOMAIN NOTICE*               National Center for Biotechnology Information**  This software/database is a "United States Government Work" under the*  terms of the United States Copyright Act.  It was written as part of*  the author's official duties as a United States Government employee and*  thus cannot be copyrighted.  This software/database is freely available*  to the public for use. The National Library of Medicine and the U.S.*  Government have not placed any restriction on its use or reproduction.**  Although all reasonable efforts have been taken to ensure the accuracy*  and reliability of the software and data, the NLM and the U.S.*  Government do not and cannot warrant the performance or results that*  may be obtained by using this software or data. The NLM and the U.S.*  Government disclaim all warranties, express or implied, including*  warranties of performance, merchantability or fitness for any particular*  purpose.**  Please cite the author in any work or product based on this material.** ===========================================================================** Authors:  Paul Thiessen** File Description:*      Classes to manipulate alignments** ===========================================================================*/#ifdef _MSC_VER#pragma warning(disable:4018)   // disable signed/unsigned mismatch warning in MSVC#endif#include <ncbi_pch.hpp>#include <corelib/ncbistd.hpp>#include <objects/seqalign/Dense_diag.hpp>#include <objects/seqalign/Dense_seg.hpp>#include "alignment_manager.hpp"#include "sequence_set.hpp"#include "alignment_set.hpp"#include "block_multiple_alignment.hpp"#include "messenger.hpp"#include "structure_set.hpp"#include "sequence_viewer.hpp"#include "molecule.hpp"#include "show_hide_manager.hpp"#include "cn3d_threader.hpp"#include "update_viewer.hpp"#include "sequence_display.hpp"#include "cn3d_tools.hpp"#include "molecule_identifier.hpp"#include "cn3d_blast.hpp"#include "style_manager.hpp"#include "cn3d_ba_interface.hpp"USING_NCBI_SCOPE;USING_SCOPE(objects);BEGIN_SCOPE(Cn3D)///// AlignmentManager methods /////void AlignmentManager::Init(void){    sequenceViewer = new SequenceViewer(this);    GlobalMessenger()->AddSequenceViewer(sequenceViewer);    updateViewer = new UpdateViewer(this);    GlobalMessenger()->AddSequenceViewer(updateViewer);    threader = new Threader();    blaster = new BLASTer();    blockAligner = new BlockAligner();    originalMultiple = NULL;}AlignmentManager::AlignmentManager(const SequenceSet *sSet, const AlignmentSet *aSet){    Init();    NewAlignments(sSet, aSet);}AlignmentManager::AlignmentManager(const SequenceSet *sSet,    const AlignmentSet *aSet, const UpdateAlignList& updates){    Init();    NewAlignments(sSet, aSet);    // create BlockMultipleAlignments from updates; add to update viewer    PairwiseAlignmentList pairwise(1);    UpdateViewer::AlignmentList updateAlignments;    UpdateAlignList::const_iterator u, ue = updates.end();    for (u=updates.begin(); u!=ue; ++u) {        if (u->GetObject().IsSetSeqannot() && u->GetObject().GetSeqannot().GetData().IsAlign()) {            CSeq_annot::C_Data::TAlign::const_iterator                s, se = u->GetObject().GetSeqannot().GetData().GetAlign().end();            for (s=u->GetObject().GetSeqannot().GetData().GetAlign().begin(); s!=se; ++s) {                // determine master sequence                const Sequence *master = NULL;                if (aSet) {                    master = aSet->master;                } else if (updateAlignments.size() > 0) {                    master = updateAlignments.front()->GetMaster();                } else {                    SequenceSet::SequenceList::const_iterator q, qe = sSet->sequences.end();                    for (q=sSet->sequences.begin(); q!=qe; ++q) {                        if ((*q)->identifier->MatchesSeqId(                                (*s)->GetSegs().IsDendiag() ?                                    (*s)->GetSegs().GetDendiag().front()->GetIds().front().GetObject() :                                    (*s)->GetSegs().GetDenseg().GetIds().front().GetObject()                            )) {                            master = *q;                            break;                        }                    }                }                if (!master) {                    ERRORMSG("AlignmentManager::AlignmentManager() - "                        << "can't determine master sequence for updates");                    return;                }                const MasterSlaveAlignment *alignment =                    new MasterSlaveAlignment(NULL, master, s->GetObject());                pairwise.front() = alignment;                BlockMultipleAlignment *multiple = CreateMultipleFromPairwiseWithIBM(pairwise);                multiple->updateOrigin = *u;    // to keep track of which Update-align this came from                updateAlignments.push_back(multiple);                delete alignment;            }        }    }    updateViewer->AddAlignments(updateAlignments);    // set this set of updates as the initial state of the editor's undo stack    updateViewer->SetInitialState();}AlignmentManager::~AlignmentManager(void){    GlobalMessenger()->RemoveSequenceViewer(sequenceViewer);    GlobalMessenger()->RemoveSequenceViewer(updateViewer);    delete sequenceViewer;    delete updateViewer;    delete threader;    delete blaster;    delete blockAligner;    if (originalMultiple) delete originalMultiple;}void AlignmentManager::NewAlignments(const SequenceSet *sSet, const AlignmentSet *aSet){    sequenceSet = sSet;    alignmentSet = aSet;    if (!alignmentSet) {        sequenceViewer->DisplaySequences(&(sequenceSet->sequences));        return;    }    // all slaves start out visible    slavesVisible.resize(alignmentSet->alignments.size());    for (int i=0; i<slavesVisible.size(); ++i)        slavesVisible[i] = true;    NewMultipleWithRows(slavesVisible);    originalMultiple = GetCurrentMultipleAlignment()->Clone();    originalRowOrder.resize(originalMultiple->NRows());    for (int r=0; r<originalMultiple->NRows(); ++r)        originalRowOrder[r] = r;}void AlignmentManager::SavePairwiseFromMultiple(const BlockMultipleAlignment *multiple,    const vector < int >& rowOrder){    // create new AlignmentSet based on this multiple alignment, feed back into StructureSet    AlignmentSet *newAlignmentSet =        AlignmentSet::CreateFromMultiple(multiple->GetMaster()->parentSet, multiple, rowOrder);    if (newAlignmentSet) {        multiple->GetMaster()->parentSet->ReplaceAlignmentSet(newAlignmentSet);        alignmentSet = newAlignmentSet;    } else {        ERRORMSG("Couldn't create pairwise alignments from the current multiple!\n"            << "Alignment data in output file will be left unchanged.");        return;    }    // see whether PSSM and/or row order have changed    if (!originalMultiple) {        originalMultiple = multiple->Clone();        originalRowOrder = rowOrder;        alignmentSet->parentSet->SetDataChanged(StructureSet::ePSSMData);        alignmentSet->parentSet->SetDataChanged(StructureSet::eRowOrderData);    } else {        // check for row order change        TRACEMSG("checking for row order changes..." << originalMultiple << ' ' << multiple);        if (originalMultiple->NRows() != multiple->NRows()) {            TRACEMSG("row order changed");            alignmentSet->parentSet->SetDataChanged(StructureSet::eRowOrderData);        } else {            for (int row=0; row<originalMultiple->NRows(); ++row) {                if (originalMultiple->GetSequenceOfRow(originalRowOrder[row]) !=                        multiple->GetSequenceOfRow(rowOrder[row]) ||                    originalRowOrder[row] != rowOrder[row])                {                    TRACEMSG("row order changed");                    alignmentSet->parentSet->SetDataChanged(StructureSet::eRowOrderData);                    break;                }            }        }        // check for PSSM change        const BLAST_Matrix *originalPSSM = originalMultiple->GetPSSM(), *currentPSSM = multiple->GetPSSM();        TRACEMSG("checking for PSSM changes... " << originalPSSM << ' ' << currentPSSM);        if (originalPSSM->rows != currentPSSM->rows ||            originalPSSM->columns != currentPSSM->columns ||            originalPSSM->karlinK != currentPSSM->karlinK)        {            TRACEMSG("PSSM changed");            alignmentSet->parentSet->SetDataChanged(StructureSet::ePSSMData);        } else {            int i, j;            for (i=0; i<originalPSSM->rows; ++i) {                for (j=0; j<originalPSSM->columns; ++j) {                    if (originalPSSM->matrix[i][j] != currentPSSM->matrix[i][j]) {                        TRACEMSG("PSSM changed");                        alignmentSet->parentSet->SetDataChanged(StructureSet::ePSSMData);                        i = originalPSSM->rows;                        break;                    }                }            }        }        // keep for comparison on next save        delete originalMultiple;        originalMultiple = multiple->Clone();        originalMultiple->RemovePSSM();        originalRowOrder = rowOrder;    }}const BlockMultipleAlignment * AlignmentManager::GetCurrentMultipleAlignment(void) const{    const ViewerBase::AlignmentList& currentAlignments = sequenceViewer->GetCurrentAlignments();    return ((currentAlignments.size() > 0) ? currentAlignments.front() : NULL);}static bool AlignedToAllSlaves(int masterResidue,    const AlignmentManager::PairwiseAlignmentList& alignments){    AlignmentManager::PairwiseAlignmentList::const_iterator a, ae = alignments.end();    for (a=alignments.begin(); a!=ae; ++a) {        if ((*a)->masterToSlave[masterResidue] == -1) return false;    }    return true;}static bool NoSlaveInsertionsBetween(int masterFrom, int masterTo,    const AlignmentManager::PairwiseAlignmentList& alignments){    AlignmentManager::PairwiseAlignmentList::const_iterator a, ae = alignments.end();    for (a=alignments.begin(); a!=ae; ++a) {        if (((*a)->masterToSlave[masterTo] - (*a)->masterToSlave[masterFrom]) !=            (masterTo - masterFrom)) return false;    }    return true;}static bool NoBlockBoundariesBetween(int masterFrom, int masterTo,    const AlignmentManager::PairwiseAlignmentList& alignments){    AlignmentManager::PairwiseAlignmentList::const_iterator a, ae = alignments.end();    for (a=alignments.begin(); a!=ae; ++a) {        if ((*a)->blockStructure[masterTo] != (*a)->blockStructure[masterFrom])            return false;    }    return true;}BlockMultipleAlignment *AlignmentManager::CreateMultipleFromPairwiseWithIBM(const PairwiseAlignmentList& alignments){    PairwiseAlignmentList::const_iterator a, ae = alignments.end();    // create sequence list; fill with sequences of master + slaves    BlockMultipleAlignment::SequenceList        *sequenceList = new BlockMultipleAlignment::SequenceList(alignments.size() + 1);    BlockMultipleAlignment::SequenceList::iterator s = sequenceList->begin();    *(s++) = alignments.front()->master;    for (a=alignments.begin(); a!=ae; ++a) {        *(s++) = (*a)->slave;        if ((*a)->master != sequenceList->front()) {            ERRORMSG("AlignmentManager::CreateMultipleFromPairwiseWithIBM() -\n"                << "all pairwise alignments must have the same master sequence");

⌨️ 快捷键说明

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