alngraphic.cpp
来自「ncbi源码」· C++ 代码 · 共 696 行 · 第 1/2 页
CPP
696 行
delete *iter2; } (*iter)->clear(); } m_AlninfoListList.clear();}void CAlnGraphic::AlnGraphicDisplay(CNcbiOstream& out){ /*Note we can't just show each alnment as we go because we will need to put all hsp's with the same id on one line*/ TAlnInfoList* alninfo_list = NULL; bool is_first_aln = true; int num_align = 0; int master_len = 0; CNodeRef center; CRef<CHTML_table> tbl_box; CHTML_tc* tbl_box_tc; tbl_box = new CHTML_table; //draw a box around the graphics center = new CHTML_center; //align all graphic in center tbl_box->SetCellSpacing(0)->SetCellPadding(10)->SetAttribute("border", "1"); tbl_box->SetAttribute("bordercolorlight", "#0000FF"); tbl_box->SetAttribute("bordercolordark", "#0000FF"); CConstRef<CSeq_id> previous_id, subid, master_id; for (CSeq_align_set::Tdata::const_iterator iter = m_AlnSet->Get().begin(); iter != m_AlnSet->Get().end() && num_align < m_NumAlignToShow; iter++, num_align++){ if(!alninfo_list){ alninfo_list = new TAlnInfoList; } //get start and end seq position for master sequence CRange<TSeqPos>* seq_range = new CRange<TSeqPos>((*iter)->GetSeqRange(0)); //for minus strand if(seq_range->GetFrom() > seq_range->GetTo()){ seq_range->Set(seq_range->GetTo(), seq_range->GetFrom()); } subid = &((*iter)->GetSeq_id(1)); if(is_first_aln) { master_id = &((*iter)->GetSeq_id(0)); const CBioseq_Handle& handle = m_Scope->GetBioseqHandle(*master_id); if(!handle){ NCBI_THROW(CException, eUnknown, "Master sequence is not found!"); } master_len = handle.GetBioseqCore()->GetInst().GetLength(); x_DisplayMaster(master_len, &(*center), &(*tbl_box), tbl_box_tc); } if(!is_first_aln && !subid->Match(*previous_id)) { //this aln is a new id, show result for previous id //save ranges for the same seqid m_AlninfoListList.push_back(alninfo_list); alninfo_list = new TAlnInfoList; } SAlignInfo* alninfo = new SAlignInfo; alninfo->range = seq_range; //get aln info x_GetAlnInfo(**iter, *subid, alninfo); alninfo_list->push_back(alninfo); is_first_aln = false; previous_id = subid; } //save last set of seqs with the same id if(alninfo_list){ m_AlninfoListList.push_back(alninfo_list); } //merge range for seq with the same id ITERATE(TAlnInfoListList, iter, m_AlninfoListList) { (*iter)->sort(FromRangeAscendingSort); x_MergeSameSeq(**iter); } //merge non-overlapping range list so that they can be put on //the same line to compress the results if(m_View & eCompactView){ double pixel_factor = ((double)kMasterPixel)/master_len; x_MergeDifferentSeq(pixel_factor); } //display the graphic x_BuildHtmlTable(master_len, &(*tbl_box), tbl_box_tc); center->AppendChild(&(*tbl_box)); center->Print(out); CHTML_hr hr; hr.Print(out);}//print score legend, master labelvoid CAlnGraphic::x_PrintTop (CNCBINode* center, CHTML_table* tbl_box, CHTML_tc*& tbl_box_tc){ if(m_View & eMouseOverInfo){ CRef<CHTML_input> textbox(new CHTML_input("text", "defline")); CNodeRef centered_text; textbox->SetAttribute("size", 85); textbox->SetAttribute("value", "Mouse over to see the defline, click to show alignments"); center->AppendChild(&(*textbox)); } //score legend graph CRef<CHTML_table> tbl(new CHTML_table); CHTML_tc* tc; tbl->SetCellSpacing(1)->SetCellPadding(0)->SetAttribute("border", "0"); CRef<CHTML_img> score_margin_img(new CHTML_img(m_ImagePath + kGifWhite, kScoreMargin, m_BarHeight)); tc = tbl->InsertAt(0, 0, score_margin_img); tc->SetAttribute("align", "LEFT"); tc->SetAttribute("valign", "CENTER"); CRef<CHTML_img> score(new CHTML_img(m_ImagePath + kGifScore, kScoreLength, kScoreHeight)); tc = tbl->InsertAt(0, 1, score); tc->SetAttribute("align", "LEFT"); tc->SetAttribute("valign", "CENTER"); tbl_box_tc = tbl_box->InsertAt(0, 0, tbl); tbl_box_tc->SetAttribute("align", "LEFT"); tbl_box_tc->SetAttribute("valign", "CENTER"); //master graph tbl = new CHTML_table; tbl->SetCellSpacing(1)->SetCellPadding(0)->SetAttribute("border", "0"); CRef<CHTML_img> master(new CHTML_img(m_ImagePath + kGifMaster, kMasterBarLength, kMasterHeight)); tc = tbl->InsertAt(0, 0, master); tc->SetAttribute("align", "LEFT"); tc->SetAttribute("valign", "CENTER"); tbl_box_tc->AppendChild(&(*tbl)); }void CAlnGraphic::x_DisplayMaster(int master_len, CNCBINode* center, CHTML_table* tbl_box, CHTML_tc*& tbl_box_tc){ x_PrintTop(&(*center), &(*tbl_box), tbl_box_tc); //scale CRef<CHTML_table> tbl(new CHTML_table); CHTML_tc* tc; CRef<CHTML_img> image; int column = 0; tbl->SetCellSpacing(0)->SetCellPadding(0)->SetAttribute("border", "0"); image = new CHTML_img(m_ImagePath + kGifWhite, kScoreMargin + kScaleMarginAdj, m_BarHeight); tc = tbl->InsertAt(0, column, image); tc->SetAttribute("align", "LEFT"); tc->SetAttribute("valign", "CENTER"); column ++; //first scale image = new CHTML_img(m_ImagePath + kGifScale, kScaleWidth, kScaleHeight); tc = tbl->InsertAt(0, column, image); tc->SetAttribute("align", "LEFT"); tc->SetAttribute("valign", "CENTER"); column ++; //second scale mark and on float scale_unit = ((float)(master_len))/(kNumMark - 1); int round_number = s_GetRoundNumber(scale_unit); int spacer_length; double pixel_factor = ((double)kMasterPixel)/master_len; for (int i = 1; i*round_number <= master_len; i++) { spacer_length = pixel_factor*round_number - kScaleWidth; image = new CHTML_img(m_ImagePath + kGifWhite, spacer_length, m_BarHeight); tc = tbl->InsertAt(0, column, image); tc->SetAttribute("align", "LEFT"); tc->SetAttribute("valign", "CENTER"); column ++; image = new CHTML_img(m_ImagePath + kGifScale, kScaleWidth, kScaleHeight); tc = tbl->InsertAt(0, column, image); tc->SetAttribute("align", "LEFT"); tc->SetAttribute("valign", "CENTER"); column ++; } tbl_box_tc->AppendChild(&(*tbl)); //digits //first scale digit string digit_str, previous_digitstr; int previous_digit; column = 0; image = new CHTML_img(m_ImagePath + kGifWhite, kScoreMargin, m_BarHeight); tbl = new CHTML_table; tbl->SetCellSpacing(0)->SetCellPadding(0)->SetAttribute("border", "0"); tc = tbl->InsertAt(0, column, image); tc->SetAttribute("align", "LEFT"); tc->SetAttribute("valign", "CENTER"); column ++; image = new CHTML_img(m_ImagePath + kDigitGif[0], kDigitWidth, kDigitHeight); tc = tbl->InsertAt(0, column, image); column ++; previous_digit = 0; previous_digitstr = NStr::IntToString(0); //print scale digits from second mark and on for (TSeqPos i = 1; i*round_number <= master_len; i++) { digit_str = NStr::IntToString(i*round_number); spacer_length = pixel_factor*round_number - kDigitWidth*(previous_digitstr.size() - previous_digitstr.size()/2) - kDigitWidth*(digit_str.size()/2); previous_digitstr = digit_str; image = new CHTML_img(m_ImagePath + kGifWhite, spacer_length, m_BarHeight); tc = tbl->InsertAt(0, column, image); tc->SetAttribute("align", "LEFT"); tc->SetAttribute("valign", "CENTER"); column ++; //digits for(size_t j = 0; j < digit_str.size(); j ++){ string one_digit(1, digit_str[j]); int digit = NStr::StringToInt(one_digit); image = new CHTML_img(m_ImagePath + kDigitGif[digit], kDigitWidth, kDigitHeight); tc = tbl->InsertAt(0, column, image); tc->SetAttribute("align", "LEFT"); tc->SetAttribute("valign", "CENTER"); column ++; } } tbl_box_tc->AppendChild(&(*tbl)); CRef<CHTML_br> br(new CHTML_br); tbl_box_tc->AppendChild(br);}//alignment bar graphvoid CAlnGraphic::x_BuildHtmlTable(int master_len, CHTML_table* tbl_box, CHTML_tc*& tbl_box_tc) { CHTML_tc* tc; double pixel_factor = ((double)kMasterPixel)/master_len; int count = 0; //print out each alignment ITERATE(TAlnInfoListList, iter, m_AlninfoListList){ //iter = each line if(count > m_NumLine){ break; } CRef<CHTML_table> tbl; //each table represents one line CRef<CHTML_img> image; CConstRef<CSeq_id> previous_id, current_id; CRef<CHTML_a> ad; double temp_value ; int previous_end = -1; int front_margin = 0; int bar_length = 0; int column = 0; if(!(*iter)->empty()){ //table for starting white spacer count ++; tbl = new CHTML_table; tbl->SetCellSpacing(0)->SetCellPadding(0)->SetAttribute("border", "0"); image = new CHTML_img(m_ImagePath + kGifWhite, kScoreMargin, m_BarHeight); tc = tbl->InsertAt(0, column, image); column ++; tc->SetAttribute("align", "LEFT"); tc->SetAttribute("valign", "CENTER"); } ITERATE(TAlnInfoList, iter2, **iter){ //iter2 = each alignments on one line current_id = (*iter2)->id; //white space in front of this alignment temp_value = ((*iter2)->range->GetFrom() - (previous_end + 1))*pixel_factor; //rounding to int this way as round() is not portable front_margin = temp_value + (temp_value < 0.0 ? -0.5 : 0.5); //Need to add white space if(temp_value > 0) { //Need to show at least one gap if(front_margin < 1){ front_margin = 1; } //connecting the alignments with the same id if(m_View & eCompactView && !previous_id.Empty() && previous_id->Match(*current_id)){ image = new CHTML_img(m_ImagePath + kGifGrey, front_margin, kGapHeight); } else { image = new CHTML_img(m_ImagePath + kGifWhite, front_margin, m_BarHeight); } tc = tbl->InsertAt(0, column, image); column ++; tc->SetAttribute("align", "LEFT"); tc->SetAttribute("valign", "CENTER"); } previous_end = (*iter2)->range->GetTo(); previous_id = current_id; temp_value = (*iter2)->range->GetLength()*pixel_factor; bar_length = temp_value + (temp_value < 0.0 ? -0.5 : 0.5); image = new CHTML_img(m_ImagePath + s_GetGif((*iter2)->bits), bar_length, m_BarHeight); image->SetAttribute("border", 0); if(m_View & eMouseOverInfo){ image->SetAttribute("ONMouseOver", m_MouseOverFormName + ".defline.value=" + "'" + (*iter2)->info + "'"); image->SetAttribute("ONMOUSEOUT", m_MouseOverFormName + ".defline.value='Mouse-over to show defline and scores, click to show alignments'"); } if(m_View & eAnchorLink){ string acc; (*iter2)->id->GetLabel(&acc, CSeq_id::eContent, 0); string seqid = (*iter2)->gi == 0 ? acc : NStr::IntToString((*iter2)->gi); ad = new CHTML_a("#" + seqid, image); tc = tbl->InsertAt(0, column, ad); } else { tc = tbl->InsertAt(0, column, image); } column ++; tc->SetAttribute("valign", "CENTER"); tc->SetAttribute("align", "LEFT"); } if(!tbl.Empty()){ tbl_box_tc->AppendChild(&(*tbl)); //table for space between bars tbl = new CHTML_table; image = new CHTML_img(m_ImagePath + kGifWhite, kScoreMargin + kScoreLength, kBlankBarHeight); tbl->SetCellSpacing(0)->SetCellPadding(0)->SetAttribute("border", "0"); tbl->InsertAt(0, 0, image); tbl_box_tc->AppendChild(&(*tbl)); } }}END_SCOPE(objects)END_NCBI_SCOPE/* *============================================================*$Log: alngraphic.cpp,v $*Revision 1000.0 2004/06/01 19:48:35 gouriano*PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.2**Revision 1.2 2004/05/21 21:42:51 gorelenk*Added PCH ncbi_pch.hpp**Revision 1.1 2004/04/30 15:40:41 jianye*Initial checkin**===========================================================*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?