vector<int> mark_leaves;
99 if(mark_query_node) {
100mark_leaves.push_back(0);
104label_type, mark_leaves,
116 constvector<int>& mark_leaves,
124label_type, mark_leaves,
136vector<string>& seq_ids,
140 stringmv_build_name)
143vector<int> mark_leaves;
151label_type, mark_leaves,
178 boolmark_query_node)
181vector<int> mark_leaves;
182 if(mark_query_node) {
183mark_leaves.push_back(0);
206vector<int> mark_leaves;
207mark_leaves.push_back(0);
211lbl_type, mark_leaves,
251vector<string> labels;
258 const string& tree_name)
261vector<string> labels;
273<<
" DIMENSIONS ntax="<< labels.size() <<
";"<<
NcbiEndl 275 ITERATE(vector<string>, it, labels) {
282<<
" TREE "<< tree_name <<
" = "<<
tree 307 if(!groupper.
GetError().empty()) {
334 if(!groupper.
GetError().empty()) {
353 "Invalid tree simplify mode");
361CBioTreeDynamic::CBioNode* node =
x_GetBioNode(node_id);
375 if(!
tracker.GetError().empty()) {
381 string label= it->first;
383 for(; it !=
tracker.End(); ++it) {
384 label+=
", "+ it->first;
387 if(
tracker.GetNumLabels() == 1) {
391 if(
tracker.FoundQueryNode()) {
394 else if(
tracker.FoundSeqFromType()) {
397 else if(
tracker.FoundSeqFromVerifiedMat()) {
400 else if(
tracker.FoundSeqReferenceDB()) {
403 else if(
tracker.FoundSeqKmerBlast()) {
406 intleafCount =
tracker.GetLeafCount();
407 if(leafCount != 0) {
429CBioTreeDynamic::CBioNode* parent
430= (CBioTreeDynamic::CBioNode*)node->GetParent();
438parent->GetValue().features.SetFeature(fid,
439node->GetValue().features.GetFeatureValue(fid));
441node = parent->DetachNode(node);
442node->AddNode(parent);
447CBioTreeDynamic::CBioNode* node =
x_GetBioNode(new_root_id);
451 if(node &&
x_IsLeafEx(*node) && node->GetParent()) {
452node = (CBioTreeDynamic::CBioNode*)node->GetParent();
456 if(!node->GetParent()) {
465vector<CBioTreeDynamic::CBioNode*> children;
466CBioTreeDynamic::CBioNode::TParent::TNodeList_I it
467= old_root->SubNodeBegin();
469 for(; it != old_root->SubNodeEnd();it++) {
470children.push_back((CBioTreeDynamic::CBioNode*)*it);
473old_root->DetachNode(*ch);
477CBioTreeDynamic::CBioNode* new_old_root
478=
newCBioTreeDynamic::CBioNode(*old_root);
479 ITERATE(vector<CBioTreeDynamic::CBioNode*>, ch, children) {
480new_old_root->AddNode(*ch);
484CBioTreeDynamic::CBioNode* parent
485= (CBioTreeDynamic::CBioNode*)node->GetParent();
486node = parent->DetachNode(node);
492node->AddNode(parent);
502CBioTreeDynamic::CBioNode* node =
x_GetBioNode(root_id);
507 boolcollapsed =
false;
515CBioTreeDynamic::CBioNode::TParent* parent = node->GetParent();
517parent->DetachNode(node);
554 if(!finder.
GetNode() && throw_if_null) {
590it != groupper.
End(); ++it) {
615 if(leafCount != 0) {
626 if(nodeMap.
size() <= 2) {
629leafCount = it->second.size();
630 if(nodeMap.
size() == 1) {
631nodeColor = it->second[0].nodeColor;
633 else if(nodeMap.
size() == 2) {
635 if(leafCount > it->second.size()) {
636title +=
" and "+ it->first;
640title = it->first +
" and "+ title;
642leafCount += it->second.size();
646title =
"Multiple organisms";
647 for(
autoit = nodeMap.
begin(); it != nodeMap.
end(); ++it) {
648vector <CPhyTreeNodeAnalyzer::TLeafNodeInfo> vecInf = it->second;
649leafCount += vecInf.size();
658it != groupper.
End(); ++it) {
661 if(leafInfoMap && !(*leafInfoMap).
empty()) {
662 string label,nodeColor;
667 if(!nodeColor.empty()) {
696 const string&
color)
704 constCBioTreeDynamic::CBioNode& node,
705vector<string>& labels,
712 if(!node.IsLeaf()) {
714 for(CBioTreeDynamic::CBioNode::TNodeList_CI it = node.SubNodeBegin(); it != node.SubNodeEnd(); ++it) {
715 if(it != node.SubNodeBegin())
718name_subtrees,
false);
723 if(!is_outer_node) {
725 if(node.IsLeaf() || !
label.empty()) {
726 for(
size_t i=0;
i<
label.length();
i++)
729 if(node.IsLeaf() || name_subtrees) {
731labels.push_back(
label);
745 if((*node)->CanGetFeatures()) {
746 stringblastName =
"",accNbr;
769(*node)->SetFeatures().Set()) {
774 if((*node_feature)->GetFeatureid() ==
eLabelId) {
775label_feature_node = *node_feature;
780blastName = (*node_feature)->GetValue();
784accNbr = (*node_feature)->GetValue();
786 if((*node_feature)->GetFeatureid() == featureSelectedID) {
790selected_feature_node = *node_feature;
795 string label= selected_feature_node->GetValue();
805label_feature_node->ResetValue();
806label_feature_node->SetValue() =
label;
845 boolget_best_id =
true;
850 if(seq_id_handle.
IsGi()) {
851get_best_id =
false;
864(*seq_id).GetLabel(&id_string);
872 #define MAX_NODES_TO_COLOR 24 875 stringblast_tax_name)
881= {
"0 0 255",
"0 255 0",
"191 159 0",
"30 144 255",
882 "255 0 255",
"223 11 95",
"95 79 95",
"143 143 47",
883 "0 100 0",
"128 0 0",
"175 127 255",
"119 136 153",
884 "255 69 0",
"205 102 0",
"0 250 154",
"173 255 47",
885 "139 0 0",
"255 131 250",
"155 48 255",
"205 133 0",
886 "127 255 212",
"255 222 173",
"221 160 221",
"200 100 0"};
890 for(;
i< blast_name_color_map.size();
i++) {
891pair<string, string>& map_item = blast_name_color_map[
i];
893 if(map_item.first == blast_tax_name) {
894 color= map_item.second;
904blast_name_color_map.push_back(make_pair(blast_tax_name,
color));
915 constvector<int>& mark_leaves,
924 boolsuccess = tax.
Init();
927 "Problem initializing taxonomy information.");
930sequence::CDeflineGenerator defgen;
933 intnum_rows = (
int)seqids.size();
934vector<string> labels(num_rows);
935vector<string> organisms(num_rows);
936vector<string> accession_nbrs(num_rows);
937vector<string> titles(num_rows);
938vector<string> blast_names(num_rows);
939vector<string> tax_node_colors(num_rows);
940vector<CBioseq_Handle> bio_seq_handles(num_rows);
941vector<string> common_names(num_rows);
943 for(
int i=0;
i< num_rows;
i++) {
951common_names[
i] = (common_names[
i].empty()) ? organisms[
i] : common_names[
i];
958 if(!success || blast_names[
i].
empty()) {
969titles[
i] = defgen.GenerateDefline(bio_seq_handles[
i]);
980 const CDbtag& dtg =
id->GetGeneral();
983 if(accession_nbrs[
i].
empty()) {
984accession_nbrs[
i] =
id->GetSeqIdString(
true);
990 switch(label_type) {
992labels[
i] = organisms[
i];
996labels[
i] = titles[
i];
1000labels[
i] = blast_names[
i];
1004labels[
i] = accession_nbrs[
i];
1008labels[
i] = accession_nbrs[
i] +
"("+ blast_names[
i] +
")";
1012labels[
i] = organisms[
i] +
"("+ accession_nbrs[
i] +
")";
1016labels[
i] = common_names[
i];
1020 if(labels[
i].
empty()) {
1025(*best_id).GetLabel(&labels[
i]);
1058 if((*node)->CanGetFeatures()) {
1060(*node)->SetFeatures().Set()) {
1061 if((*node_feature)->GetFeatureid() ==
eLabelId) {
1066 stringlabel_id = (*node_feature)->GetValue();
1067 unsigned intseq_number;
1068 if(!
isdigit((
unsigned char) label_id[0])) {
1069 const char* ptr = label_id.c_str();
1076(*node_feature)->GetValue());
1079 if((
int)seq_number >= num_rows) {
1081 "Number of Seq-ids is smaller than number " 1087(*node_feature)->SetValue(labels[seq_number]);
1096 if(!organisms[seq_number].
empty()) {
1101 if(!titles[seq_number].
empty()) {
1105 if(!accession_nbrs[seq_number].
empty()) {
1110 if(!blast_names[seq_number].
empty()) {
1115 if(!common_names[seq_number].
empty()) {
1121 if(seqTypeMap.
empty()) {
1123tax_node_colors[seq_number], node);
1127 if(!seqTypeMap.
empty()) {
1131 if(!mark_leaves.empty()
1132&& binary_search(mark_leaves.begin(),
1133mark_leaves.end(), seq_number)) {
1151 else if(linkoutDB) {
1152 intseqLinkout = linkoutDB->
GetLinkout(*seqids[seq_number],
"");
1168 else if(!seqTypeMap.
empty()) {
1189 else if(simpleTree) {
1196 else if(simpleTree) {
1201 if((
int)num_rows != num_leaves) {
1203 " then tree leaves");
1211 if( iter != seqTypeMap.
end() ){
1212seqType = iter->second;
1219vector<string>& ids,
1223vector< pair< CNode*, CSeq_id_Handle> > nodes;
1225 if((*node)->CanGetFeatures()) {
1227(*node)->SetFeatures().Set()) {
1229 if((*node_feature)->GetFeatureid() ==
eSeqIdId 1232pair<CNode*, CSeq_id_Handle> p;
1233p.first = node->GetNonNullPointer();
1242 ITERATE(vector<string>, sid, ids) {
1245pair<CNode*, CSeq_id_Handle> p(
nullptr, idhandle);
1246vector< pair<CNode*, CSeq_id_Handle> >::iterator node;
1248 for(node = nodes.begin();node != nodes.end();++node) {
1270feat_descr->SetId(
id);
1271feat_descr->SetName(desc);
1272btc.
SetFdict().Set().push_back(feat_descr);
1278CNodeSet::Tdata::iterator iter)
1281node_feature->SetFeatureid(
id);
1282node_feature->SetValue(
value);
1283(*iter)->SetFeatures().Set().push_back(node_feature);
1290node_feature->SetFeatureid(
id);
1291node_feature->SetValue(
value);
1292node->
SetFeatures().Set().push_back(node_feature);
Things for representing and manipulating bio trees.
static const char * bgColor
static string GetGnlID(const objects::CDbtag &dtg)
Return ID for GNL label.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Computaion of distance-based phylognetic tree.
CRef< CBioTreeContainer > GetSerialTree(void) const
Get serial tree.
const vector< CRef< CSeq_id > > & GetSeqIds(void) const
Get seq-ids of sequences used in tree construction.
CRef< CScope > GetScope(void)
Get scope.
Tree visitor, finds BioTreeDynamic node by id.
CBioTreeDynamic::CBioNode * GetNode(void)
Get pointer to found node.
Tree visitor class, expands all nodes and corrects node colors.
ETreeTraverseCode operator()(CBioTreeDynamic::CBioNode &node, int delta)
Expand subtree.
Tree visitor for checking whether a subtree contains a query node.
bool HasSeqReferenceDB(void) const
int GetLeafCount(void) const
bool HasSeqFromVerifiedMat(void) const
bool HasSeqKmerBlast(void) const
bool HasSeqFromType(void) const
Check if an examined subtree has a sequence from type.
bool HasQueryNode(void) const
Check if an examined subtree has a query node.
bool IsSingleBlastName(void) const
Check if all sequences in examined tree have the same Blast Name.
ETreeSimplifyMode m_SimplifyMode
Current tree simplification mode.
void x_InitTreeFeatures(CBioTreeContainer &btc, const vector< CRef< CSeq_id > > &seqids, CScope &scope, ELabelType label_type, const vector< int > &mark_leaves, TBlastNameColorMap &bcolormap, map< string, int > &seqTypeMap, bool simpleTree=false, ILinkoutDB *linkoutDB=NULL, int linkoutType=0)
Create and initialize tree features.
static void x_AddFeature(int id, const string &value, CNodeSet::Tdata::iterator iter)
Add feature to tree node.
void x_MarkNode(CBioTreeDynamic::CBioNode *node, const string &color)
Mark node.
void RerootTree(int new_root_id)
Reroot tree.
void x_Init(void)
Init class attributes to default values.
static string GetFeatureTag(EFeatureID feat)
Get tree feature tag.
int GetRootNodeID(void)
Get tree root node id.
CBioTreeDynamic m_Dyntree
Stores tree data.
string x_GetSeqIDString(CBioseq_Handle &handle, bool get_gi_first)
static void x_Expand(CBioTreeDynamic::CBioNode &node)
Expand node (show subtree)
bool WriteTreeAs(CNcbiOstream &out, ETreeFormat format)
Write tree structure to stream in selected format.
void FullyExpand(void)
Fully expand tree.
CPhyTreeFormatter(CPhyTreeCalc &guide_tree_calc, ELabelType lbl_type=eSeqId, bool mark_query_node=true, ILinkoutDB *linkoutDB=NULL, int linkoutType=0)
Constructor.
TBlastNameColorMap m_BlastNameColorMap
Blast Name to color map.
CBioTreeDynamic::CBioNode * GetNonNullNode(TBioTreeNodeId id)
Get pointer to the node with given id and throw exception if node not found.
bool ExpandCollapseSubtree(int node_id)
Expand or collapse subtree rooted in given node.
static const char * kNodeInfoSeqFromType
Node feature "node-info" value for sequences from type.
vector< TBlastNameToColor > TBlastNameColorMap
@ eLabelBgColorId
Color for backgroud of node label.
@ eNodeInfoId
Used for denoting query nodes.
@ eTitleId
Sequence title.
@ eTreeSimplificationTagId
Is subtree collapsed.
@ eLabelColorId
Node label color.
@ eNodeColorId
Node color.
@ eOrganismId
Taxonomic organism id (for sequence)
@ eBlastNameId
Sequence Blast Name.
@ eAccessionNbrId
Sequence accession.
@ eDistId
Edge length from parent to this node.
@ eAlignIndexId
Index of sequence in Seq_align.
static void x_Collapse(CBioTreeDynamic::CBioNode &node)
Collapse node (do not show subtree)
CBioTreeDynamic::CBioNode * x_GetBioNode(TBioTreeNodeId id, bool throw_if_null=true)
Find pointer to a BioTreeDynamic node with given numerical id.
void x_AddFeaturesForInnerNodes(CPhyTreeNodeAnalyzer &groupper)
bool PrintNewickTree(CNcbiOstream &ostr)
Write tree in Newick format to stream.
ELabelType
Information shown as labels in the guide tree.
bool WriteTree(CNcbiOstream &out)
Write tree structure to stream.
static const char * kNodeInfoSeqReferenceDB
map< string, int > m_SeqTypeMap
bool IsSingleBlastName(void)
Check whether tree is composed of sequences with the same Blast Name.
void x_CollapseSubtrees(CPhyTreeNodeGroupper &groupper)
Collapse given subtrees.
void CollapseToViewPort(void)
CBioTreeDynamic::CBioNode * GetNode(TBioTreeNodeId id)
Get pointer to the node with given id.
static int x_FindSeqType(map< string, int > &seqTypeMap, string idString)
ETreeSimplifyMode
Tree simplification modes.
@ eFullyExpanded
Tree fully expanded.
@ eNone
No simplification mode.
@ eCollapseToViewPort
collapse to viewport
@ eByBlastName
Subtrees that contain sequences with the the same Blast Name are collapsed.
void x_PrintNewickTree(CNcbiOstream &ostr, const CBioTreeDynamic::CBioNode &node, vector< string > &labels, bool name_subtrees=true, bool is_outer_node=true)
Generates tree in Newick format, recursive.
void x_InitTreeLabels(CBioTreeContainer &btc, ELabelType lbl_type)
Init tree leaf labels with selected labels type.
void x_MarkLeavesBySeqId(CBioTreeContainer &btc, vector< string > &ids, CScope &scope)
Mark leave nodes corresponding to sequences with given sequence ids.
bool ShowSubtree(int root_id)
Show subtree.
static const char * kNodeInfoQuery
Node feature "node-info" value for query nodes.
static bool x_IsLeafEx(const CBioTreeDynamic::CBioNode &node)
Check if node is a leaf or collapsed.
CRef< CBioTreeContainer > GetSerialTree(void)
Get serialized tree.
static void x_AddFeatureDesc(int id, const string &desc, CBioTreeContainer &btc)
Add feature descriptor to tree.
static const char * kNodeInfoSeqKmerBlast
static bool x_IsExpanded(const CBioTreeDynamic::CBioNode &node)
Check if node is expanded (subtree shown)
ETreeFormat
Output formats.
static const char * kNodeInfoSeqFromVerifiedMat
string m_MapViewerBuildName
vector< CConstRef< CSeq_id > > m_TreeSeqIDs
void SimplifyTree(ETreeSimplifyMode method)
Group nodes according to user-selected scheme and collapse subtrees composed of nodes that belong to ...
bool PrintNexusTree(CNcbiOstream &ostr, const string &tree_name="Blast_guide_tree")
Write tree in Nexus format to stream.
Tree visitor, finds all labels and node colors for leafes.
TLabelColorMap::iterator TLabelColorMap_I
CLabeledNodes::iterator CLabeledNodes_I
CLabeledNodes_I Begin(void)
const string & GetError(void) const
This file provides tree visitor classes and functions for node groupping and simplification of phylog...
CLabeledNodes::iterator CLabeledNodes_I
CLabeledNodes_I Begin(void)
const string & GetError(void) const
bool GetBlastName(TTaxId tax_id, string &blast_name_out)
virtual int GetLinkout(TGi gi, const string &mv_build_name)=0
Retrieve the Linkout for a given GI.
container_type::iterator iterator
const_iterator begin() const
const_iterator end() const
const_iterator find(const key_type &key) const
static const Colors colors
API (CDeflineGenerator) for computing sequences' titles ("definitions").
std::ofstream out("events_result.xml")
main entry point for tests
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
SStrictId_Tax::TId TTaxId
Taxon id type.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
#define MSerial_AsnText
I/O stream manipulators â.
CConstRef< CSeq_id > GetSeqId(void) const
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
@ fParse_Default
By default in ParseIDs and IsValid, allow raw parsable non-numeric accessions and plausible local acc...
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
const COrg_ref & GetOrg_ref(const CBioseq_Handle &handle)
Return the org-ref associated with a given sequence.
@ eGetId_Best
return the "best" gi (uses FindBestScore(), with CSeq_id::CalculateScore() as the score function
@ eGetId_ForceGi
return only a gi-based seq-id
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
bool IsSameBioseq(const CSeq_id_Handle &id1, const CSeq_id_Handle &id2, EGetBioseqFlag get_flag)
Check if two seq-ids are resolved to the same Bioseq.
@ eGetBioseq_All
Search bioseq, load if not loaded yet.
bool NotEmpty(void) const THROWS_NONE
Check if CRef is not empty â pointing to an object and has a non-null value.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Fun TreeDepthFirstTraverse(TTreeNode &tree_node, Fun func)
Depth-first tree traversal algorithm.
ETreeTraverseCode
Tree traverse code returned by the traverse predicate function.
unsigned int TBioTreeNodeId
Tree node id. Every node has its unique id in the tree.
unsigned int TBioTreeFeatureId
Feature Id.
TBioTreeNode * GetTreeNodeNonConst()
void BioTreeConvert2Container(TBioTreeContainer &tree_container, const TDynamicTree &dyn_tree)
Convert Dynamic tree to ASN.1 BioTree container.
void BioTreeConvertContainer2Dynamic(TDynamicTree &dyn_tree, const TBioTreeContainer &tree_container, bool preserve_node_ids=false)
Convert ASN.1 BioTree container to dynamic tree.
const TBioTreeNode * GetTreeNode() const
void SetTreeNode(TBioTreeNode *node)
Assign new top level tree node.
@ eTreeTraverse
Keep traversal.
static const char label[]
void SetNodes(TNodes &value)
Assign a value to Nodes data member.
void SetFdict(TFdict &value)
Assign a value to Fdict data member.
void SetFeatures(TFeatures &value)
Assign a value to Features data member.
list< CRef< CNodeFeature > > Tdata
list< CRef< CNode > > Tdata
const TTaxname & GetTaxname(void) const
Get the Taxname member data.
const TCommon & GetCommon(void) const
Get the Common member data.
E_Choice Which(void) const
Which variant is currently selected.
@ e_General
for other databases
unsigned int
A callback function used to compare two keys in a database.
The blob sat and sat key Both must be positive integers</td > n< td > Non empty string The interpretation of the blob id depends on a processor Cassandra n processor expects the following format
constexpr bool empty(list< Ts... >) noexcept
const GenericPointer< typename T::ValueType > T2 value
Static variables safety - create on demand, destroy on application termination.
NCBI C++ auxiliary debug macros.
Int4 delta(size_t dimension_, const Int4 *score_)
static const char * s_kQueryNodeColor
static const char * s_kSeqKmerBlastNodeBgColor
static const char * s_kSubtreeDisplayed
static CSafeStatic< map< int, string > > seqTypeToBGColor
static const char * s_kNodeSize
static void s_InitFeatures(CPhyTreeNodeAnalyzer::TLeafNodeInfoMap nodeMap, string &title, int &leafCount, string &nodeColor)
static const char * s_kSeqReferenceDBNodeBgColor
static const char * s_kSeqFromVerifiedMatNodeBgColor
static const char * s_kUnknown
static CSafeStatic< map< int, string > > linkotTypeToBGColor
static const char * s_kSeqOfTypeNodeBgColor
#define MAX_NODES_TO_COLOR
static const char * s_kBranchColor
static const char * s_kQueryNodeBgColor
static const char * s_kSeqQueryNodeBgColor
void s_RerootUpstream(CBioTreeDynamic::CBioNode *node, TBioTreeFeatureId fid)
static string s_GetBlastNameColor(CPhyTreeFormatter::TBlastNameColorMap &blast_name_color_map, string blast_tax_name)
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