default_layoutpolicy.cpp
来自「ncbi源码」· C++ 代码 · 共 567 行 · 第 1/2 页
CPP
567 行
/* * =========================================================================== * PRODUCTION $Log: default_layoutpolicy.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 21:12:29 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13 * PRODUCTION * =========================================================================== *//* $Id: default_layoutpolicy.cpp,v 1000.3 2004/06/01 21:12:29 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: Vlad Lebedev * * File Description: * */#include <ncbi_pch.hpp>#include <gui/widgets/seq_graphic/default_layoutpolicy.hpp>#include <gui/config/feat_config_list.hpp>#include <gui/objutils/feature.hpp>#include <gui/objutils/alignment.hpp>#include <gui/objutils/graph.hpp>#include <gui/objutils/prot_product.hpp>#include <gui/objutils/histogram.hpp>#include <gui/objutils/utils.hpp>#include <gui/objutils/seq_map.hpp>#include <gui/objutils/comment.hpp>#include <gui/objutils/sequence.hpp>#include <objmgr/seq_vector.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);const int kLabelsColWidth = 100; // width of a column smallCDefaultLayoutPolicy::CDefaultLayoutPolicy(){}void CDefaultLayoutPolicy::SetHandle(const CBioseq_Handle& handle){ m_Handle = handle;}void CDefaultLayoutPolicy::SetConfig(CSeqGraphicConfig* config){ m_ConfigSettings = config;}void CDefaultLayoutPolicy::PrepareData(CGlPane& pane, CLayout& lay_objects){ pane.OpenOrtho(); if (x_IsOverviewMode(pane)) { x_PrepareGenesOverview(pane, lay_objects); } else { x_PrepareDetailedView(pane, lay_objects); } pane.Close();}bool CDefaultLayoutPolicy::x_IsOverviewMode(CGlPane& pane) const{ TModelRect rcV = pane.GetVisibleRect(); TSeqRange range( TSeqPos(rcV.Left()), TSeqPos(rcV.Right()) ); TModelUnit scale = pane.GetScaleX(); TSeqPos over_cut_off = m_ConfigSettings->GetOverviewCutoff(); TSeqPos gene_cut_off = m_ConfigSettings->GetGenesCutoff(); SAnnotSelector sel = CSeqUtils::GetAnnotSelector(CSeqFeatData::e_Gene); CFeat_CI iter(m_Handle, range.GetFrom(), range.GetTo(), sel); return scale > over_cut_off && iter.GetSize() > gene_cut_off;}void CDefaultLayoutPolicy::x_PrepareGenesOverview(CGlPane& pane, CLayout& lay_objects){ TModelRect rcV = pane.GetVisibleRect(); TSeqRange range( TSeqPos(rcV.Left()), TSeqPos(rcV.Right()) ); C2DLayoutEngine engine; engine.SetMinDist( x_GetMinSpacing(pane) ); CLayout temporary; CLayoutEngine::TObjects objs, obj_tmp; CLayoutFeatLabel::TFeatLabelList marks_labels; lay_objects.Clear(); engine.Layout(objs, lay_objects); // Add segment map if (m_ConfigSettings->GetShowSegmentMap()) { // add Segment map x_AddSeqSegmentMap(pane, lay_objects, range); } x_AddHistograms(pane, lay_objects, range); // retrieve landmark features first CLayoutFeat::TFeatList land_marks; CSeqUtils::GetLandmarkFeatures(m_Handle, range, 200, land_marks); // Comments for All Genes string str2 = "Only Landmark Genes Shown: " + NStr::UIntToString(land_marks.size()); CRef<CLayoutObject> comment(new CLayoutComment(str2)); objs.push_back(comment); engine.Layout(objs, temporary); lay_objects.Append(temporary); // we need to assemble a slightly different structure first objs.clear(); NON_CONST_ITERATE (CLayoutFeat::TFeatList, iter, land_marks) { CLayoutFeat& feat = **iter; CRef<CLayoutFeatLabel> lbl (new CLayoutFeatLabel(feat.GetMappedFeature())); CRef<CLayoutObject> obj(*iter); marks_labels.push_back(lbl); // store for sorting objs.push_back(obj); } engine.Layout(objs, temporary); lay_objects.Append(temporary); x_AddFeatureLabelsOverview(marks_labels, pane, lay_objects);}void CDefaultLayoutPolicy::x_AddHistograms(CGlPane& pane, CLayout& lay_objects, TSeqRange range){ CLayoutEngine::TObjects objs; CLayout temp; C2DLayoutEngine engine; // Show histograms first ITERATE(CFeatConfigList, iter, *GetFeatConfigList()) { bool hist = m_ConfigSettings->GetHistogram(iter->GetType(), iter->GetSubtype()); if(!hist) continue; SAnnotSelector selector = CSeqUtils::GetAnnotSelector (CSeqFeatData::ESubtype(iter->GetSubtype()) ); selector.SetSortOrder(SAnnotSelector::eSortOrder_None); CDensityMap<int> densityMap(range.GetFrom(), range.GetTo(), TSeqPos(pane.GetScaleX())); densityMap.AddFeatures(m_Handle, selector); if (densityMap.GetBins() == 0) { // skip empty maps continue; } CRef<CLayoutObject> dmap(new CLayoutHistogram(densityMap, CSeqFeatData::E_Choice(iter->GetType()), CSeqFeatData::ESubtype(iter->GetSubtype())) ); objs.push_back(dmap); } engine.Layout(objs, temp); lay_objects.Append(temp);}void CDefaultLayoutPolicy::x_AddFeatureLabelsOverview( CLayoutFeatLabel::TFeatLabelList& labels, CGlPane& pane, CLayout& lay_objects){ // sort feature labels alphabetically sort(labels.begin(), labels.end(), SFeatureByName()); // a number of columns that will fit int cols_count = pane.GetViewport().Width() / kLabelsColWidth; if (cols_count == 0) { cols_count = 1; // always at least 1 column } // assign columns and repack int cur_col = 0; CLayoutEngine::TObjects labels_obj; NON_CONST_ITERATE (CLayoutFeatLabel::TFeatLabelList, iter, labels) { (*iter)->SetColumn(cur_col); // set the column index CRef<CLayoutObject> obj(*iter); labels_obj.push_back(obj); if (++cur_col >= cols_count) { cur_col = 0; } } CLayout labels_layout; x_LayoutLabels(labels_obj, labels_layout, cols_count); lay_objects.Append(labels_layout); }void CDefaultLayoutPolicy::x_AddSequenceBar(CGlPane& pane, CLayout& lay_objects, TSeqRange range){ if (pane.GetScaleX() > 1.0f / 8.0f ) { // sequence would not fit return; } CLayout temp; C2DLayoutEngine engine; CLayoutEngine::TObjects obj_tmp; string seq_str; CSeqVector s_vec = m_Handle.GetSeqVector(CBioseq_Handle::eCoding_Iupac); s_vec.GetSeqData(range.GetFrom(), range.GetTo(), seq_str); CRef<CLayoutObject> sequence(new CLayoutSequence(seq_str)); // Add to layout obj_tmp.push_back(sequence); engine.Layout(obj_tmp, temp); lay_objects.Append(temp);}void CDefaultLayoutPolicy::x_AddSeqSegmentMap(CGlPane& pane, CLayout& lay_objects, TSeqRange range){ CLayoutEngine::TObjects objs, obj_tmp; // Segment maps first GetSeqMaps(objs, range); // Do not do anything if no segments if (objs.size() == 0) { return; } string str = "Segment Map: " + NStr::UIntToString(objs.size()); CRef<CLayoutObject> comment(new CLayoutComment(str)); C2DLayoutEngine engine; engine.SetMinDist(x_GetMinSpacing(pane) ); CLayout temp, temp2; obj_tmp.push_back(comment); engine.Layout(obj_tmp, temp); lay_objects.Append(temp); engine.Layout(objs, temp2); unsigned int kMaxSegMapRows = 4; // no more than 4 rows for (size_t idx = 0; idx != temp2.GetLayout().size() && idx < kMaxSegMapRows; idx++) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?