📄 alignment_manager.cpp
字号:
Threader::AlignmentList newAlignments; int nRowsAddedToMultiple; bool foundSingle = false; // sanity check singleList.push_back(single); if (threader->Realign( options, currentAlignments.front(), &singleList, &nRowsAddedToMultiple, &newAlignments)) { // replace threaded alignment with new one(s) (or leftover where threader/merge failed) UpdateViewer::AlignmentList::const_iterator a, ae = updateViewer->GetCurrentAlignments().end(); for (a=updateViewer->GetCurrentAlignments().begin(); a!=ae; ++a) { if (*a == single) { Threader::AlignmentList::const_iterator n, ne = newAlignments.end(); for (n=newAlignments.begin(); n!=ne; ++n) replacedList.push_back(*n); foundSingle = true; } else replacedList.push_back((*a)->Clone()); } if (!foundSingle) ERRORMSG( "AlignmentManager::ThreadUpdate() - threaded alignment not found in update viewer!"); updateViewer->ReplaceAlignments(replacedList); // tell the sequenceViewer that rows have been merged into the multiple if (nRowsAddedToMultiple > 0) sequenceViewer->GetCurrentDisplay()-> RowsAdded(nRowsAddedToMultiple, currentAlignments.front()); }}void AlignmentManager::ThreadAllUpdates(const ThreaderOptions& options){ const ViewerBase::AlignmentList& currentAlignments = sequenceViewer->GetCurrentAlignments(); if (currentAlignments.size() == 0) return; // make sure the editor is on in the sequenceViewer if (!sequenceViewer->EditorIsOn() && options.mergeAfterEachSequence) { ERRORMSG("Can only merge updates when editing is enabled in the sequence window"); return; } // run the threader on update pairwise alignments Threader::AlignmentList newAlignments; int nRowsAddedToMultiple; if (threader->Realign( options, currentAlignments.front(), &(updateViewer->GetCurrentAlignments()), &nRowsAddedToMultiple, &newAlignments)) { // replace update alignments with new ones (or leftovers where threader/merge failed) updateViewer->ReplaceAlignments(newAlignments); // tell the sequenceViewer that rows have been merged into the multiple if (nRowsAddedToMultiple > 0) sequenceViewer->GetCurrentDisplay()-> RowsAdded(nRowsAddedToMultiple, currentAlignments.front()); }}void AlignmentManager::MergeUpdates(const AlignmentManager::UpdateMap& updatesToMerge, bool mergeToNeighbor){ if (updatesToMerge.size() == 0) return; const ViewerBase::AlignmentList& currentUpdates = updateViewer->GetCurrentAlignments(); if (currentUpdates.size() == 0) return; // transform this structure view into an alignment view, and turn on the editor. ViewerBase::AlignmentList::const_iterator u, ue = currentUpdates.end(); const BlockMultipleAlignment *newMultiple = NULL; if (sequenceViewer->GetCurrentAlignments().size() == 0) { for (u=currentUpdates.begin(); u!=ue; ++u) { // find first update alignment if (updatesToMerge.find(*u) != updatesToMerge.end()) { newMultiple = *u; // create new alignment, then call SavePairwiseFromMultiple to create // an AlignmentSet and the initial ASN data sequenceViewer->DisplayAlignment(newMultiple->Clone()); vector < int > rowOrder(newMultiple->NRows()); for (int i=0; i<newMultiple->NRows(); ++i) rowOrder[i] = i; SavePairwiseFromMultiple(newMultiple, rowOrder); // editor needs to be on if >1 update is to be merged in sequenceViewer->TurnOnEditor(); // set default alignment-type style newMultiple->GetMaster()->parentSet->styleManager-> SetGlobalRenderingStyle(StyleSettings::eTubeShortcut); newMultiple->GetMaster()->parentSet->styleManager-> SetGlobalColorScheme(StyleSettings::eAlignedShortcut); GlobalMessenger()->PostRedrawAllStructures(); break; } } } BlockMultipleAlignment *multiple = (sequenceViewer->GetCurrentAlignments().size() > 0) ? sequenceViewer->GetCurrentAlignments().front() : NULL; if (!multiple) { ERRORMSG("Must have an alignment in the sequence viewer to merge with"); return; } // make sure the editor is on in the sequenceViewer if (!sequenceViewer->EditorIsOn()) { ERRORMSG("Can only merge updates when editing is enabled in the sequence window"); return; } int nSuccessfulMerges = 0; ViewerBase::AlignmentList updatesToKeep; for (u=currentUpdates.begin(); u!=ue; ++u) { if (*u == newMultiple) continue; bool merged = false; if (updatesToMerge.find(*u) != updatesToMerge.end()) { merged = multiple->MergeAlignment(*u); if (merged) { nSuccessfulMerges += (*u)->NRows() - 1; } else { for (int i=0; i<(*u)->NRows(); ++i) { string status = (*u)->GetRowStatusLine(i); if (status.size() > 0) status += "; merge failed!"; else status = "Merge failed!"; (*u)->SetRowStatusLine(i, status); } } } if (!merged) { BlockMultipleAlignment *keep = (*u)->Clone(); updatesToKeep.push_back(keep); } } updateViewer->ReplaceAlignments(updatesToKeep); if (nSuccessfulMerges > 0) { int where = -1; // if necessary, find nearest neighbor to merged sequence, and add new row after it if (mergeToNeighbor && nSuccessfulMerges == 1) { BlockMultipleAlignment::UngappedAlignedBlockList blocks; multiple->GetUngappedAlignedBlocks(&blocks); BlockMultipleAlignment::UngappedAlignedBlockList::const_iterator b, be = blocks.end(); int col, row, rowScore, bestScore, lastRow = multiple->NRows() - 1; const Sequence *mergeSeq = multiple->GetSequenceOfRow(lastRow); for (row=0; row<lastRow; ++row) { const Sequence *otherSeq = multiple->GetSequenceOfRow(row); rowScore = 0; for (b=blocks.begin(); b!=be; ++b) { for (col=0; col<(*b)->width; ++col) { rowScore += GetBLOSUM62Score( mergeSeq->sequenceString[(*b)->GetRangeOfRow(lastRow)->from + col], otherSeq->sequenceString[(*b)->GetRangeOfRow(row)->from + col]); } } if (row == 0 || rowScore > bestScore) { where = row; bestScore = rowScore; } } INFOMSG("Closest row is #" << (where+1) << ", " << multiple->GetSequenceOfRow(where)->identifier->ToString()); } sequenceViewer->GetCurrentDisplay()->RowsAdded(nSuccessfulMerges, multiple, where); } // add pending imported structures to asn data updateViewer->SavePendingStructures();}void AlignmentManager::CalculateRowScoresWithThreader(double weightPSSM){ threader->CalculateScores(GetCurrentMultipleAlignment(), weightPSSM);}int AlignmentManager::NUpdates(void) const{ return updateViewer->GetCurrentAlignments().size();}void AlignmentManager::GetUpdateSequences(list < const Sequence * > *updateSequences) const{ updateSequences->clear(); const ViewerBase::AlignmentList& currentUpdates = updateViewer->GetCurrentAlignments(); if (currentUpdates.size() == 0) return; ViewerBase::AlignmentList::const_iterator u, ue = currentUpdates.end(); for (u=currentUpdates.begin(); u!=ue; ++u) updateSequences->push_back((*u)->GetSequenceOfRow(1)); // assume update aln has just one slave...}bool AlignmentManager::GetStructureProteins(vector < const Sequence * > *chains) const{ if (!chains || GetCurrentMultipleAlignment() != NULL || !sequenceViewer || !sequenceViewer->GetCurrentDisplay()) return false; sequenceViewer->GetCurrentDisplay()->GetProteinSequences(chains); return (chains->size() > 0);}void AlignmentManager::ReplaceUpdatesInASN(ncbi::objects::CCdd::TPending& newUpdates) const{ if (sequenceSet) sequenceSet->parentSet->ReplaceUpdates(newUpdates); else ERRORMSG("AlignmentManager::ReplaceUpdatesInASN() - can't get StructureSet");}void AlignmentManager::PurgeSequence(const MoleculeIdentifier *identifier){ BlockMultipleAlignment *multiple = (sequenceViewer->GetCurrentAlignments().size() > 0) ? sequenceViewer->GetCurrentAlignments().front() : NULL; if (!multiple) return; // remove matching rows from multiple alignment vector < int > rowsToRemove; int i; for (i=1; i<multiple->NRows(); ++i) if (multiple->GetSequenceOfRow(i)->identifier == identifier) rowsToRemove.push_back(i); if (rowsToRemove.size() > 0) { // turn on editor, and update multiple pointer if (!sequenceViewer->EditorIsOn()) { sequenceViewer->TurnOnEditor(); multiple = sequenceViewer->GetCurrentAlignments().front(); } if (!multiple->ExtractRows(rowsToRemove, NULL)) { ERRORMSG("AlignmentManager::PurgeSequence() - ExtractRows failed!"); return; } // remove rows from SequenceDisplay SequenceDisplay *display = sequenceViewer->GetCurrentDisplay(); if (!display) { ERRORMSG("AlignmentManager::PurgeSequence() - can't get SequenceDisplay!"); return; } display->RowsRemoved(rowsToRemove, multiple); } // remove matching alignments from Update window const ViewerBase::AlignmentList& currentUpdates = updateViewer->GetCurrentAlignments(); if (currentUpdates.size() == 0) return; ViewerBase::AlignmentList::const_iterator u, ue = currentUpdates.end(); for (u=currentUpdates.begin(); u!=ue; ++u) // quick check if any match found if ((*u)->GetSequenceOfRow(1)->identifier == identifier) break; if (u != ue) { ViewerBase::AlignmentList updatesToKeep; for (u=currentUpdates.begin(); u!=ue; ++u) { if ((*u)->GetSequenceOfRow(1)->identifier != identifier) { BlockMultipleAlignment *keep = (*u)->Clone(); updatesToKeep.push_back(keep); } } updateViewer->ReplaceAlignments(updatesToKeep); }}void AlignmentManager::BlockAlignAllUpdates(void){ BlockMultipleAlignment *currentMultiple = (sequenceViewer->GetCurrentAlignments().size() > 0) ? sequenceViewer->GetCurrentAlignments().front() : NULL; if (!currentMultiple) return; const UpdateViewer::AlignmentList& currentUpdates = updateViewer->GetCurrentAlignments(); if (currentUpdates.size() == 0) return; // run the block aligner on update pairwise alignments BlockAligner::AlignmentList newAlignmentsList; int nRowsAddedToMultiple; if (blockAligner->CreateNewPairwiseAlignmentsByBlockAlignment(currentMultiple, currentUpdates, &newAlignmentsList, &nRowsAddedToMultiple, sequenceViewer->EditorIsOn())) { // replace update alignments with new ones (or leftovers where threader/merge failed) updateViewer->ReplaceAlignments(newAlignmentsList); // tell the sequenceViewer that rows have been merged into the multiple if (nRowsAddedToMultiple > 0) sequenceViewer->GetCurrentDisplay()->RowsAdded(nRowsAddedToMultiple, currentMultiple); }}void AlignmentManager::BlockAlignUpdate(BlockMultipleAlignment *single){ BlockMultipleAlignment *currentMultiple = (sequenceViewer->GetCurrentAlignments().size() > 0) ? sequenceViewer->GetCurrentAlignments().front() : NULL; if (!currentMultiple) return; // run the threader on the given alignment UpdateViewer::AlignmentList singleList, replacedList; BlockAligner::AlignmentList newAlignments; int nRowsAddedToMultiple; bool foundSingle = false; // sanity check singleList.push_back(single); if (blockAligner->CreateNewPairwiseAlignmentsByBlockAlignment( currentMultiple, singleList, &newAlignments, &nRowsAddedToMultiple, sequenceViewer->EditorIsOn())) { // replace threaded alignment with new one(s) (or leftover where threader/merge failed) UpdateViewer::AlignmentList::const_iterator a, ae = updateViewer->GetCurrentAlignments().end(); for (a=updateViewer->GetCurrentAlignments().begin(); a!=ae; ++a) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -