sequenceWindow(
NULL)
107vector < unsigned int > rowOrder;
109 for(
unsigned int i=0;
i<display->
rows.size(); ++
i) {
111 if(alnRow) rowOrder.push_back(alnRow->
row);
126alignments.push_back(alignment);
141 ERRORMSG(
"SequenceViewer::ReplaceAlignment() - bad parameters");
147alignments.push_back(newAln);
167SequenceList::const_iterator s, se = sequenceList->end();
168 for(s=sequenceList->begin(); s!=se; ++s) {
171 if(!(*s)->parentSet->IsMultiStructure() &&
172(*s)->parentSet->objects.front()->mmdbID != (*s)->identifier->mmdbID)
continue;
194 constvector < int >& rowOrder,
198 unsigned intfirstCol = 0, lastCol = alignment->
AlignmentWidth() - 1, nColumns = 70;
199 if(lastCol >= alignment->
AlignmentWidth() || firstCol > lastCol || nColumns < 1) {
200 ERRORMSG(
"DumpFASTA() - nonsensical display region parameters");
208 boolanyRepeat =
false;
212list < string >& titleList = idMap[seq->
identifier];
216 if (titleList.size() == 0) { 218 // create full title line for first instance of this sequence 219 CBioseq::TId::const_iterator i, ie = seq->bioseqASN->GetId().end(); 220 for (i=seq->bioseqASN->GetId().begin(); i!=ie; ++i) { 221 if (i != seq->bioseqASN->GetId().begin()) 223 oss << (*i)->AsFastaString(); 225 string descr = seq->GetDescription(); 226 if (descr.size() > 0) 231 oss << "lcl|instance #" << (titleList.size() + 1) << " of " << seq->identifier->ToString(); 236 titleList.resize(titleList.size() + 1); 237 titleList.back() = (string) CNcbiOstrstreamToString(oss); 240 static const int eAllRepeats=0, eFakeRepeatIDs=1, eNoRepeats=2; 241 int choice = eAllRepeats; 244 wxArrayString choices; 245 choices.Add("Include all repeats with normal IDs"); 246 choices.Add("Include all repeats, but use unique IDs"); 247 choices.Add("Include no repeated sequences"); 248 choice = wxGetSingleChoiceIndex("How do you want to handle repeated sequences?", 249 "Choose repeat type", choices); 250 if (choice < 0) return; // cancelled 253 // output each alignment row (in order of the display) 254 unsigned int paragraphStart, nParags = 0, i; 256 Vector color, bgColor; 257 bool highlighted, drawBG; 258 for (row=0; row<alignment->NRows(); ++row) { 259 const Sequence *seq = alignment->GetSequenceOfRow(rowOrder[row]); 262 list < string >& titleList = idMap[seq->identifier]; 263 if (choice == eAllRepeats) { 264 os << titleList.front(); // use full id 265 } else if (choice == eFakeRepeatIDs) { 266 os << titleList.front(); 267 titleList.pop_front(); // move to next (fake) id 268 } else if (choice == eNoRepeats) { 269 if (titleList.size() > 0) { 270 os << titleList.front(); 271 titleList.clear(); // remove all ids after first instance 277 // split alignment up into "paragraphs", each with nColumns 278 for (paragraphStart=0; (firstCol+paragraphStart)<=lastCol; paragraphStart+=nColumns, ++nParags) { 279 for (i=0; i<nColumns && (firstCol+paragraphStart+i)<=lastCol; ++i) { 280 if (alignment->GetCharacterTraitsAt(firstCol+paragraphStart+i, rowOrder[row], justification, 281 &ch, &color, &highlighted, &drawBG, &bgColor)) { 283 os << (isA2M ? '.
' : '-
'); 285 os << (isA2M ? ch : (char) toupper((unsigned char) ch)); 287 ERRORMSG("GetCharacterTraitsAt failed!"); 294 static string ShortAndEscapedString(const string& s) 297 for (unsigned int i=0; i<s.size(); ++i) { 308 constvector < int >& rowOrder,
312 #define LEFT_JUSTIFY resetiosflags(IOS_BASE::right) << setiosflags(IOS_BASE::left) 313 #define RIGHT_JUSTIFY resetiosflags(IOS_BASE::left) << setiosflags(IOS_BASE::right) 316 unsigned intfirstCol = 0, lastCol = alignment->
AlignmentWidth() - 1, nColumns = 60;
318 if(lastCol >= alignment->
AlignmentWidth() || firstCol > lastCol || nColumns < 1) {
319 ERRORMSG(
"DumpText() - nonsensical display region parameters");
328vector < string > titles(alignment->
NRows()), uids(doHTML ? alignment->
NRows() : 0);
329 unsigned intalnRow,
row, maxTitleLength = 0, maxSeqLocStrLength = 0, leftMargin, decimalLength;
330 for(alnRow=0; alnRow<alignment->
NRows(); ++alnRow) {
331 row= rowOrder[alnRow];
335 if(titles[
row].
size() > maxTitleLength) maxTitleLength = titles[
row].size();
336decimalLength = ((
int)
log10((
double) sequence->
Length())) + 1;
337 if(decimalLength > maxSeqLocStrLength) maxSeqLocStrLength = decimalLength;
356leftMargin = maxTitleLength + maxSeqLocStrLength + 2;
360vector < int > lastShownSeqLocs(alignment->
NRows());
361 unsigned intalnLoc,
i;
364 boolhighlighted, drawBG;
365 for(alnRow=0; alnRow<alignment->
NRows(); ++alnRow) {
366 row= rowOrder[alnRow];
367lastShownSeqLocs[
row] = -1;
368 for(alnLoc=0; alnLoc<firstCol; ++alnLoc) {
370&ch, &
color, &highlighted, &drawBG, &bgCol))
372 if(ch !=
'~') lastShownSeqLocs[
row]++;
378os <<
"<HTML><TITLE>Alignment Exported From Cn3D</TITLE>\n"<<
379 "<BODY BGCOLOR="<<
bgColor<<
">\n";
382 if(doHTML) os <<
"<TABLE>\n";
383 intparagraphStart, nParags = 0;
384 for(paragraphStart=0; (firstCol+paragraphStart)<=lastCol; paragraphStart+=nColumns, ++nParags) {
388os <<
"<tr><td><pre>\n";
390 if(paragraphStart > 0) os <<
'\n';
393 unsigned intnMarkers = 0, width;
394 if(doHTML) os <<
"<font color="<< rulerColor << '>
'; 395 for (i=0; i<nColumns && (firstCol+paragraphStart+i)<=lastCol; ++i) { 396 if ((paragraphStart+i+1)%10 == 0) { 398 width = leftMargin + i + 1; 401 os << RIGHT_JUSTIFY << setw(width) << (paragraphStart+i+1); 405 if (doHTML) os << "</font>"; 407 if (doHTML) os << "<font color=" << rulerColor << '>
'; 408 for (i=0; i<leftMargin; ++i) os << ' '; 409 for (i=0; i<nColumns && (firstCol+paragraphStart+i)<=lastCol; ++i) { 410 if ((paragraphStart+i+1)%10 == 0) 412 else if ((paragraphStart+i+1)%5 == 0) 417 if (doHTML) os << "</font>"; 420 int nDisplayedResidues; 422 // output each alignment row 423 for (alnRow=0; alnRow<alignment->NRows(); ++alnRow) { 424 row = rowOrder[alnRow]; // translate display row -> data row 425 const Sequence *sequence = alignment->GetSequenceOfRow(row); 427 // actual sequence characters and colors; count how many non-gaps in each row 428 nDisplayedResidues = 0; 430 vector < string > rowColors; 431 for (i=0; i<nColumns && (firstCol+paragraphStart+i)<=lastCol; ++i) { 432 if (!alignment->GetCharacterTraitsAt(firstCol+paragraphStart+i, row, justification, 433 &ch, &color, &highlighted, &drawBG, &bgCol)) 437 colorStr.Printf("#%02x%02x%02x", 438 (int) (color[0]*255), (int) (color[1]*255), (int) (color[2]*255)); 439 rowColors.push_back(WX_TO_STD(colorStr)); 440 if (ch != '~
') ++nDisplayedResidues; 444 if (doHTML && uids[row].size() > 0) { 445 string descr = sequence->GetDescription(); 446 os << "<a href=\"https://www.ncbi.nlm.nih.gov/protein/" 447 << uids[row] << "\" onMouseOut=\"window.status=''\"\n" 448 << "onMouseOver=\"window.status='" 449 << ShortAndEscapedString((descr.size() > 0) ? descr : titles[row]) 450 << "';return true\">" 451 << setw(0) << titles[row] << "</a>"; 453 os << setw(0) << titles[row]; 455 os << setw(maxTitleLength+1-titles[row].size()) << ' '; 457 // left start pos (output 1-numbered for humans...) 458 if (doHTML) os << "<font color=" << numColor << '>
'; 459 if (nDisplayedResidues > 0) 460 os << RIGHT_JUSTIFY << setw(maxSeqLocStrLength) << (lastShownSeqLocs[row]+2) << ' '; 462 os << RIGHT_JUSTIFY << setw(maxSeqLocStrLength) << ' ' << ' '; 464 // dump sequence, applying color changes only when necessary 467 for (i=0; i<rowChars.size(); ++i) { 468 if (rowColors[i] != prevColor) { 469 os << "</font><font color=" << rowColors[i] << '>
'; 470 prevColor = rowColors[i]; 479 if (nDisplayedResidues > 0) { 481 if (doHTML) os << "<font color=" << numColor << '>
'; 482 os << LEFT_JUSTIFY << setw(0) << (lastShownSeqLocs[row]+nDisplayedResidues+1); 483 if (doHTML) os << "</font>"; 487 // setup to begin next parag 488 lastShownSeqLocs[row] += nDisplayedResidues; 492 if (doHTML) os << "</pre></td></tr>\n"; 497 << "</BODY></HTML>\n"; 499 // additional sanity check on seqloc markers 500 if (firstCol == 0 && lastCol == alignment->AlignmentWidth()-1) { 501 for (alnRow=0; alnRow<alignment->NRows(); ++alnRow) { 502 row = rowOrder[alnRow]; // translate display row -> data row 503 if (lastShownSeqLocs[row] != (int)alignment->GetSequenceOfRow(row)->Length() - 1) { 504 ERRORMSG("DumpText: full display - seqloc markers don'tadd up
for row " << row); 508 if (alnRow != alignment->NRows()) 509 ERRORMSG("DumpText: full display - seqloc markers don
't add up correctly"); 513 void SequenceViewer::ExportAlignment(eExportType type) 516 wxString extension, wildcard; 517 if (type == asFASTA) { extension = ".fsa"; wildcard = "FASTA Files (*.fsa)|*.fsa"; } 518 else if (type == asFASTAa2m) { extension = ".a2m"; wildcard = "A2M FASTA (*.a2m)|*.a2m"; } 519 else if (type == asText) { extension = ".txt"; wildcard = "Text Files (*.txt)|*.txt"; } 520 else if (type == asHTML) { extension = ".html"; wildcard = "HTML Files (*.html)|*.html"; } 521 else if (type == asPSSM) { extension = ".pssm"; wildcard = "PSSM Files (*.pssm)|*.pssm"; } 523 wxString outputFolder = wxString(GetUserDir().c_str(), GetUserDir().size() - 1); // remove trailing / 524 wxString baseName, outputFile; 525 wxFileName::SplitPath(GetWorkingFilename().c_str(), NULL, &baseName, NULL); 526 wxFileDialog dialog(sequenceWindow, "Choose a file for alignment export:", outputFolder, 528 baseName + extension, 532 wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); 533 dialog.SetFilterIndex(0); 534 if (dialog.ShowModal() == wxID_OK) 535 outputFile = dialog.GetPath(); 537 if (outputFile.size() > 0) { 539 // create output stream 540 unique_ptr<CNcbiOfstream> ofs(new CNcbiOfstream(WX_TO_STD(outputFile).c_str(), IOS_BASE::out)); 542 ERRORMSG("Unable to open output file " << outputFile.c_str()); 546 // map display row order to rows in BlockMultipleAlignment 547 vector < int > rowOrder; 548 const SequenceDisplay *display = GetCurrentDisplay(); 549 for (unsigned int i=0; i<display->rows.size(); ++i) { 550 DisplayRowFromAlignment *alnRow = dynamic_cast<DisplayRowFromAlignment*>(display->rows[i]); 551 if (alnRow) rowOrder.push_back(alnRow->row); 554 // actually write the alignment 555 if (type == asFASTA || type == asFASTAa2m) { 556 INFOMSG("exporting" << (type == asFASTAa2m ? " A2M " : " ") << "FASTA to " << outputFile.c_str()); 557 DumpFASTA((type == asFASTAa2m), alignmentManager->GetCurrentMultipleAlignment(), 558 rowOrder, sequenceWindow->GetCurrentJustification(), *ofs); 559 } else if (type == asText || type == asHTML) { 560 INFOMSG("exporting " << (type == asText ? "text" : "HTML") << " to " << outputFile.c_str()); 561 DumpText((type == asHTML), alignmentManager->GetCurrentMultipleAlignment(), 562 rowOrder, sequenceWindow->GetCurrentJustification(), *ofs); 563 } else if (type == asPSSM) { 564 static string prevTitle; 565 if (prevTitle.size() == 0) 566 prevTitle = GetWorkingTitle(); 567 string title = WX_TO_STD(wxGetTextFromUser( 568 "Enter a name for this PSSM (to be used by other applications like PSI-BLAST or RPS-BLAST):", 569 "PSSM Title?", prevTitle.c_str(), *viewerWindow).Strip(wxString::both)); 570 if (title.size() > 0) { 571 INFOMSG("exporting PSSM (" << title << ") to " << outputFile.c_str()); 572 alignmentManager->GetCurrentMultipleAlignment()->GetPSSM().OutputPSSM(*ofs, title);static const char * numColor
static const char * bgColor
static const char * rulerColor
void SavePairwiseFromMultiple(const BlockMultipleAlignment *multiple, const std::vector< unsigned int > &rowOrder)
unsigned int AlignmentWidth(void) const
bool GetCharacterTraitsAt(unsigned int alignmentColumn, unsigned int row, eUnalignedJustification justification, char *character, Vector *color, bool *isHighlighted, bool *drawBackground, Vector *cellBackgroundColor) const
unsigned int GetFirstAlignedBlockPosition(void) const
const Sequence * GetSequenceOfRow(unsigned int row) const
unsigned int NRows(void) const
void PostRedrawSequenceViewer(ViewerBase *viewer)
void UnPostRedrawSequenceViewer(ViewerBase *viewer)
std::string GetLabel(void) const
std::string ToString(void) const
static const TGi GI_NOT_SET
void AddRowFromAlignment(unsigned int row, BlockMultipleAlignment *fromAlignment)
unsigned int NRows(void) const
void AddRowFromString(const std::string &anyString)
unsigned int GetStartingColumn(void) const
void AddRowFromSequence(const Sequence *sequence, unsigned int from, unsigned int to)
void AddBlockBoundaryRow(BlockMultipleAlignment *forAlignment)
void SetStartingColumn(unsigned int column)
SequenceViewerWindow * sequenceWindow
void CreateSequenceWindow(bool showNow)
friend class SequenceViewerWindow
std::list< const Sequence * > SequenceList
bool ReplaceAlignment(const BlockMultipleAlignment *origAln, BlockMultipleAlignment *newAln)
friend class SequenceDisplay
void DisplayAlignment(BlockMultipleAlignment *multipleAlignment)
void DisplaySequences(const SequenceList *sequenceList)
const MoleculeIdentifier * identifier
unsigned int Length(void) const
std::list< BlockMultipleAlignment * > AlignmentList
AlignmentManager * alignmentManager
SequenceDisplay * GetCurrentDisplay(void)
void InitData(const AlignmentList *alignments, SequenceDisplay *display)
ViewerWindowBase **const viewerWindow
const AlignmentList & GetCurrentAlignments(void) const
void NewDisplay(SequenceDisplay *display, bool enableSelectByColumn)
void ScrollToColumn(int column)
bool EditorIsOn(void) const
void UpdateDisplay(SequenceDisplay *display)
bool IsWindowedMode(void)
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define BEGIN_SCOPE(ns)
Define a new scope.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
unsigned int
A callback function used to compare two keys in a database.
Messenger * GlobalMessenger(void)
const struct ncbi::grid::netcache::search::fields::SIZE size
static void DumpText(bool doHTML, const BlockMultipleAlignment *alignment, const vector< int > &rowOrder, BlockMultipleAlignment::eUnalignedJustification justification, CNcbiOstream &os)
static void DumpFASTA(bool isA2M, const BlockMultipleAlignment *alignment, const vector< int > &rowOrder, BlockMultipleAlignment::eUnalignedJustification justification, CNcbiOstream &os)
#define row(bind, expected)
#define DELETE_ALL_AND_CLEAR(container, ContainerType)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4