NCBI C++ Toolkit Cross Reference

  C++/src/gui/widgets/phylo_tree/phylo_tree_ds.cpp


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
/* $Id: phylo_tree_ds.cpp 32814 2015-04-24 14:34:04Z falkrb $ * =========================================================================== * * 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: Bob Falk * * File Description: * */ #include <ncbi_pch.hpp> #include <gui/widgets/phylo_tree/phylo_tree_ds.hpp> #include <objects/general/User_object.hpp> #include <objects/general/User_field.hpp> #include <objects/general/Object_id.hpp> #include <objects/biotree/FeatureDictSet.hpp> #include <objects/biotree/FeatureDescr.hpp> #include <objects/biotree/NodeSet.hpp> #include <objects/biotree/Node.hpp> #include <objects/biotree/NodeFeatureSet.hpp> #include <objects/biotree/NodeFeature.hpp> #include <util/xregexp/regexp.hpp> BEGIN_NCBI_SCOPE void CTreeLabel::InitializeFromUserObject(const CBioTreeContainer_Base::TUser& uo) { if (uo.HasField("view-label") && uo.GetField("view-label").GetData().IsObject()) { const CUser_field::C_Data::TObject& label_obj = uo.GetField("view-label").GetData().GetObject(); if (label_obj.HasField("label") && label_obj.GetField("label").GetData().IsStr()) { m_Label = label_obj.GetField("label").GetData().GetStr(); } if (label_obj.HasField("font-name") && label_obj.GetField("font-name").GetData().IsStr()) { m_FontName = label_obj.GetField("font-name").GetData().GetStr(); } if (label_obj.HasField("font-size") && label_obj.GetField("font-size").GetData().IsInt()) { m_FontSize = label_obj.GetField("font-size").GetData().GetInt(); } if (label_obj.HasField("posx") && label_obj.GetField("posx").GetData().IsInt()) { m_XPos = label_obj.GetField("posx").GetData().GetInt(); } if (label_obj.HasField("posy") && label_obj.GetField("posy").GetData().IsInt()) { m_YPos = label_obj.GetField("posy").GetData().GetInt(); } if (label_obj.HasField("color") && label_obj.GetField("color").GetData().IsStr()) { m_Color.FromString(label_obj.GetField("color").GetData().GetStr()); } } } void CTreeLabel::SaveToUserObject(CBioTreeContainer_Base::TUser& uo) { CRef<CUser_field::C_Data::TObject> label_object; if (uo.HasField("view-label") && uo.GetField("view-label").GetData().IsObject()) { label_object.Reset(&(uo.SetField("view-label").SetData().SetObject())); } else { CUser_object* label_uo = new CUser_object(); CRef<CObject_id> uo_id; uo_id.Reset(new CObject_id()); uo_id->SetStr("label-parameters"); label_uo->SetType(*uo_id); label_object.Reset(label_uo); uo.AddField("view-label", *label_uo); } if (label_object->HasField("label") && label_object->GetField("label").GetData().IsStr()) { label_object->SetField("label").SetData().SetStr(m_Label); } else { label_object->AddField("label", m_Label); } if (label_object->HasField("font-name") && label_object->GetField("font-name").GetData().IsStr()) { label_object->SetField("font-name").SetData().SetStr(m_FontName); } else { label_object->AddField("font-name", m_FontName); } if (label_object->HasField("font-size") && label_object->GetField("font-size").GetData().IsInt()) { label_object->SetField("font-size").SetData().SetInt(m_FontSize); } else { label_object->AddField("font-size", m_FontSize); } if (label_object->HasField("posx") && label_object->GetField("posx").GetData().IsInt()) { label_object->SetField("posx").SetData().SetInt(m_XPos); } else { label_object->AddField("posx", m_XPos); } if (label_object->HasField("posy") && label_object->GetField("posy").GetData().IsInt()) { label_object->SetField("posy").SetData().SetInt(m_YPos); } else { label_object->AddField("posy", m_YPos); } if (label_object->HasField("color") && label_object->GetField("color").GetData().IsStr()) { label_object->SetField("color").SetData().SetStr(m_Color.ToString()); } else { label_object->AddField("color", m_Color.ToString()); } } void CPhyloSelectionSet::InitFromUserObject(CRef< CUser_object > sel_set) { if (sel_set->HasField("selection-name") && sel_set->GetField("selection-name").GetData().IsStr()) { m_SelectionName = sel_set->GetField("selection-name").GetData().GetStr(); } if (sel_set->HasField("color-red") && sel_set->HasField("color-green") && sel_set->HasField("color-blue") && sel_set->GetField("color-red").GetData().IsReal() && sel_set->GetField("color-green").GetData().IsReal() && sel_set->GetField("color-blue").GetData().IsReal()) { m_SelectionColor.Set(float(sel_set->GetField("color-red").GetData().GetReal()), float(sel_set->GetField("color-green").GetData().GetReal()), float(sel_set->GetField("color-blue").GetData().GetReal())); } if (sel_set->HasField("selected") && sel_set->GetField("selected").GetData().IsBool()) { m_Selected = sel_set->GetField("selected").GetData().GetBool(); } if (sel_set->HasField("cluster-id") && sel_set->GetField("cluster-id").GetData().IsInt()) { m_ClusterID = sel_set->GetField("cluster-id").GetData().GetInt(); } if (sel_set->HasField("selection-ids") && sel_set->GetField("selection-ids").GetData().IsInts()) { vector<int> node_ids = sel_set->GetField("selection-ids").GetData().GetInts(); m_SelectedIDs.clear(); for (size_t i=0; i<node_ids.size(); ++i) { m_SelectedIDs.push_back(node_ids[i]); } } } CRef< CUser_object > CPhyloSelectionSet::SaveToUserObject() const { CRef<CUser_object> uo_sel_set; uo_sel_set.Reset(new CUser_object()); CRef<CObject_id> uo_id; uo_id.Reset(new CObject_id()); uo_id->SetStr("selection-set"); uo_sel_set->SetType(*uo_id); uo_sel_set->AddField("selection-name", GetName()); uo_sel_set->AddField("color-red", GetColor().GetRed()); uo_sel_set->AddField("color-green", GetColor().GetGreen()); uo_sel_set->AddField("color-blue", GetColor().GetBlue()); uo_sel_set->AddField("selected", GetSelected()); uo_sel_set->AddField("cluster-id", GetClusterID()); // need ints, not size_t's: vector<int> selected; for (size_t j=0; j<GetSelectionSet().size(); ++j) selected.push_back(int(GetSelectionSet()[j])); uo_sel_set->AddField("selection-ids", selected); return uo_sel_set; } CPhyloTree CPhyloTreeDataSource::m_sTreeClipboard; ////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////// CPhyloTreeDataSource::CPhyloTreeDataSource(const objects::CBioTreeContainer& tree, objects::CScope& scope) : m_Calc(NULL) { Init(tree, scope); } CPhyloTreeDataSource::~CPhyloTreeDataSource() { delete m_Calc; m_Calc = NULL; } void CPhyloTreeDataSource::Init(const objects::CBioTreeContainer& tree, objects::CScope& scope) { // Make sure we have a valid container - it can't be empty. if (tree.GetNodeCount() == 0 ) { NCBI_THROW(CException, eUnknown, "Cannot initialize CPhyloTreeDataSource with an empty tree"); } if (!m_TreeModel.IsNull()) m_TreeModel->Clear(); else m_TreeModel.Reset(new CPhyloTree()); m_Scope.Reset(&scope); BioTreeConvertContainer2Tree(m_TreeModel.GetNCObject(), tree, &m_TreeModel->GetFeatureDict(), true); m_TreeModel->UpdateNodesMapping(); if (tree.IsSetUser()) { const CBioTreeContainer_Base::TUser& uo = tree.GetUser(); m_TreeLabel.InitializeFromUserObject(uo); m_SelectionSets.clear(); // Only copy label-format since that's all that should be there if (uo.HasField("selection-sets") && uo.GetField("selection-sets").GetData().IsObjects()) { vector< CRef< CUser_object > > sel_sets = uo.GetField("selection-sets").GetData().GetObjects(); m_SelectionSets.resize(sel_sets.size()); for (size_t i=0; i<sel_sets.size(); ++i) { m_SelectionSets[i].InitFromUserObject(sel_sets[i]); } // sync with current model immediately after loading x_SyncSelectionSets(); // set selection x_SetSelectionSetProperty(); } } #ifdef TEXTURED_COLORS TreeDepthFirst(m_TreeModel.GetNCObject(), visitor_read_properties(m_TreeModel->GetGraphicsModel().GetColorTable())); #else TreeDepthFirst(m_TreeModel.GetNCObject(), visitor_read_properties()); #endif MeasureTree(); m_Calc->DumpStats(); } void CPhyloTreeDataSource::Clear() { m_TreeModel->Clear(); m_SearchCurrentNode = CPhyloTree::Null(); m_SearchCache.clear(); } void CPhyloTreeDataSource::SetColorIndices(CPhyloTreeScheme* scheme) { if (scheme != NULL) scheme->UpdateColorTable(m_TreeModel->GetGraphicsModel().GetColorTable()); m_TreeModel->GetGraphicsModel().GetColorTable()->LoadTexture(); } void CPhyloTreeDataSource::MeasureTree(TTreeIdx node) { if (!m_Calc) m_Calc = new CPhyloTreeCalculator(m_TreeModel.GetPointer(), m_TreeModel->GetGraphicsModel().GetColorTable()); m_Calc->Init(m_TreeModel->GetGraphicsModel().GetColorTable()); *m_Calc = TreeDepthFirst(m_TreeModel.GetNCObject(), node, *m_Calc); } void CPhyloTreeDataSource::MeasureTree() { MeasureTree(m_TreeModel->GetRootIdx()); } string CPhyloTreeDataSource::GenerateTooltipFormat() { string ttf = ""; if (!m_TreeModel.IsNull()) { CBioTreeFeatureDictionary dict = m_TreeModel->GetFeatureDict(); ITERATE(CBioTreeFeatureDictionary::TFeatureDict, it, dict.GetFeatureDict()) { string sName = it->second; string sKey = "$(" + it->second + ")"; ttf += ttf.empty()?"" : "\n"; ttf += (sName + ": " + sKey); } } return ttf.empty()?"Tree Node":ttf; } void CPhyloTreeDataSource::ApplyAttributes(CBioTreeAttrReader::TAttrTable & attrs, CPhyloTreeScheme* scheme) { m_Calc->Init(m_TreeModel->GetGraphicsModel().GetColorTable()); m_Calc->SetAttrTable(attrs); *m_Calc = TreeDepthFirst(m_TreeModel.GetNCObject(), m_TreeModel->GetRootIdx(), *m_Calc); m_Calc->ClearAttrTable(); // Update all colors in the color table (scheme colors, colors attached to nodes // and cluster colors) m_TreeModel->GetGraphicsModel().GetColorTable()->ClearColors(); #ifdef TEXTURED_COLORS TreeDepthFirst(m_TreeModel.GetNCObject(), visitor_read_properties(m_TreeModel->GetGraphicsModel().GetColorTable())); #else TreeDepthFirst(m_TreeModel.GetNCObject(), visitor_read_properties()); #endif Clusterize(scheme); } // clusters check bool CPhyloTreeDataSource::HasClusters() { return (m_Calc != NULL && !m_Calc->GetClusters().empty()); } // clusterizing with colors void CPhyloTreeDataSource::Clusterize(CPhyloTreeScheme* scheme) { if (!m_Calc) return; // seed color CRgbaColor color(204, 153, 102); CRgbaColor white(255,255,255,255); #ifdef TEXTURED_COLORS size_t color_idx; if (!m_TreeModel->GetGraphicsModel().GetColorTable()->FindColor(color, color_idx)) { color_idx = m_TreeModel->GetGraphicsModel().GetColorTable()->AddColor(color); } #endif m_ClusterToColorMap.clear(); // COLOR 'STEP' int nmbClusters = m_Calc->GetClusters().size(); float colorStep = nmbClusters? (180.0 / nmbClusters): 0; //unsigned contrast = 1; // for narrow color angle we will try an alternative color assignment bool narrow_angle = colorStep < 5.0; // Get cluster ids from selection sets -these have threir own assigned colors so // we should not generate them. Only active (selected) selection sets need to // be considered here. map<int, size_t> cluster_id_to_selection_map; for (size_t i=0; i<m_SelectionSets.size(); ++i) { if (m_SelectionSets[i].GetSelected()) { int id = m_SelectionSets[i].GetClusterID(); cluster_id_to_selection_map[id] = i; } } // Find colors for each cluster ITERATE (CPhyloTreeCalculator::TClusterHash, cl, m_Calc->GetClusters()) { int cluster_id = cl->first; // Get color froms table of selected node sets OR generate it for the cluster. // We generate a new color each time though the loop even if not all are used // because we want to not change cluster colors when selection changes. (disconcerting // for user) CRgbaColor cluster_color = color; if (cluster_id_to_selection_map.find(cluster_id) != cluster_id_to_selection_map.end()) { size_t select_set_idx = cluster_id_to_selection_map[cluster_id]; cluster_color = m_SelectionSets[select_set_idx].GetColor(); } else { // This code is to protect us from colors too bright (almost white) float c_dist = CRgbaColor::ColorDistance(white, cluster_color); while (c_dist < 0.2f) { cluster_color.Darken(0.15f); c_dist = CRgbaColor::ColorDistance(white, cluster_color); } } if (!m_TreeModel->GetGraphicsModel().GetColorTable()->FindColor(cluster_color, color_idx)) { size_t closest_idx; float dist = m_TreeModel->GetGraphicsModel().GetColorTable()->FindClosestColor(cluster_color, closest_idx); if (dist > 0.01f) { // Add a new color to the color table color_idx = m_TreeModel->GetGraphicsModel().GetColorTable()->AddColor(cluster_color); } else { // Use an existing color (to avoid letting the table get large - since it's stored in a texture // max size may be 4096 or 8192. color_idx = closest_idx; } } m_ClusterToColorMap[cluster_id] = color_idx; float rotate_angle = colorStep + (narrow_angle ? 90.0 : 180.0); color = CRgbaColor::RotateColor(color, rotate_angle); } // ITERATE // propagate colors const CPhyloTreeCalculator::TClusterHash& cluster_map = m_Calc->GetClusters(); ITERATE(CPhyloTreeCalculator::TClusterHash, cl, cluster_map) { // getting min x of each cluster int minX = m_Calc->GetWidth(); ITERATE (vector<TTreeIdx>, node_iter, cl->second) { if ((*m_TreeModel)[*node_iter].HasParent()) { CPhyloTreeNode& parent = m_TreeModel->GetParent((*m_TreeModel)[*node_iter]); if ((*parent).IDX().first < minX) { minX = (*parent).IDX().first; } } } color_idx = m_ClusterToColorMap[cl->first]; bool selection_cluster = (cluster_id_to_selection_map.find(cl->first) != cluster_id_to_selection_map.end()); // Selection clusters propogate all the way to the root. Standard clusters // (cluster-id property) propogate to nearest common ancester. Also standard clusters // are only seen when coloration mode is 'cluster' if (selection_cluster) minX = 0; else if (scheme->GetColoration()!=CPhyloTreeScheme::eClusters) continue; ITERATE (vector<TTreeIdx>, node_iter, cl->second) { TTreeIdx parent_idx = *node_iter; bool propogate_to_parents = false; // if it is not lowest common node, mark parents for (; (*m_TreeModel)[parent_idx].HasParent(); parent_idx = (*m_TreeModel)[parent_idx].GetParent()) { CPhyloTreeNode& cursor = ((*m_TreeModel)[parent_idx]); if ((*cursor).IDX().first > minX) { // If its the primary cluster-id, update cluster colors. // If there are multiple cluster id's in the node add a marker // if were are visiting parents for > 1 time... ignore. Only multi-mark // the selected nodes themselves, and only visit parents of dominant // color. (first sel color or, if none, cluster-id). int primary_cluster_id = (*cursor).GetPrimaryCluster(); if (parent_idx == *node_iter) { if (primary_cluster_id == cl->first) { propogate_to_parents = true; (*cursor).SetClusterFgColorIdx(color_idx); (*cursor).SetClusterEdgeColorIdx(color_idx); } if (cursor.IsLeaf() && (*cursor).GetNumClusters() > 1) { // only include selection colors in the set of colors for // markers, and only apply markers to leaf nodes. if (selection_cluster) { int marker_size = (*cursor).GetNodeSize() + 3; (*cursor).SetMarkerSize(marker_size); (*cursor).GetMarkerColors().push_back( m_TreeModel->GetGraphicsModel().GetColorTable()->GetColor(color_idx)); } } } else { // only propogate the primary cluster //if (propogate_to_parents) { // If clusters are overlapping, have to pick the dominant cluster. // for selection clusters this is based on the order in the list of // selection clusters. (*cursor).SetClusterFgColorIdx(color_idx); (*cursor).SetClusterEdgeColorIdx(color_idx); //} } } else { break; } } } } SetColorIndices(scheme); } void CPhyloTreeDataSource::ReRoot(TTreeIdx root_idx) { m_TreeModel->ReRoot(root_idx); MeasureTree(); } void CPhyloTreeDataSource::Relabel(CPhyloTreeScheme* scheme, string labelFmt) { m_Calc->Init(m_TreeModel->GetGraphicsModel().GetColorTable()); m_Calc->SetLabelFormat(labelFmt); *m_Calc = TreeDepthFirst(m_TreeModel.GetNCObject(), m_TreeModel->GetRootIdx(), *m_Calc); Clusterize(scheme); } void CPhyloTreeDataSource::Sort(bool ascending) { TreeDepthFirst(m_TreeModel.GetNCObject(), m_TreeModel->GetRootIdx(), CPhyloTreeSorter(m_TreeModel.GetPointer(), ascending)); MeasureTree(); } void CPhyloTreeDataSource::SortDist(bool ascending) { if (!m_TreeModel->GetFeatureDict().HasFeature("dist")) return; CPhyloTreeMaxChildDist child_dist = TreeDepthFirst(m_TreeModel.GetNCObject(), m_TreeModel->GetRootIdx(), CPhyloTreeMaxChildDist(m_TreeModel.GetNCPointer(), ascending)); TreeDepthFirst(m_TreeModel.GetNCObject(), m_TreeModel->GetRootIdx(), CPhyloTreeSorterSubtreeDist(m_TreeModel.GetNCPointer(), child_dist.GetDistances(), ascending)); MeasureTree(); } void CPhyloTreeDataSource::SortLabel(bool ascending) { CPhyloTreeMaxChildDist child_dist = TreeDepthFirst(m_TreeModel.GetNCObject(), m_TreeModel->GetRootIdx(), CPhyloTreeMaxChildDist(m_TreeModel.GetNCPointer(), ascending)); TreeDepthFirst(m_TreeModel.GetNCObject(), m_TreeModel->GetRootIdx(), CPhyloTreeSorterLabel(m_TreeModel.GetNCPointer(), ascending)); MeasureTree(); } void CPhyloTreeDataSource::SortLabelRange(bool ascending) { CPhyloTreeLabelRange label_ranges = TreeDepthFirst(m_TreeModel.GetNCObject(), m_TreeModel->GetRootIdx(), CPhyloTreeLabelRange(m_TreeModel.GetNCPointer(), ascending)); TreeDepthFirst(m_TreeModel.GetNCObject(), m_TreeModel->GetRootIdx(), CPhyloTreeSorterLabelRange(m_TreeModel.GetNCPointer(), label_ranges.GetLabelRanges(), ascending)); MeasureTree(); } TModelRect CPhyloTreeDataSource::GetBoundRect(void) { // rectangle calculator CPhyloTreeRectCalculator rect_calc(m_TreeModel); rect_calc.Init(); rect_calc = TreeDepthFirst(m_TreeModel.GetNCObject(), m_TreeModel->GetRootIdx(), rect_calc); return rect_calc.GetRect(); } void CPhyloTreeDataSource::Clean() { // This removes single child nodes but seems to also do some sorting in the process... CPhyloTreeFilter_Export fexport(m_TreeModel); fexport = TreeDepthFirstInvarient(m_TreeModel.GetNCObject(), m_TreeModel->GetRootIdx(), fexport); MeasureTree(); } void CPhyloTreeDataSource::Filter() { // not currently hooked up to UI (and would have problems - needs to fix child pointers..) CPhyloTreeFilter_Selector selector(m_TreeModel.GetNCPointer()); selector = TreeDepthFirstInvarient(m_TreeModel.GetNCObject(), m_TreeModel->GetRootIdx(), selector); MeasureTree(); } void CPhyloTreeDataSource::FilterDistances(double x_dist) { // not currently hooked up to UI (and would have problems - needs to fix child pointers..) CPhyloTreeFilter_Distance dfilter(m_TreeModel.GetNCPointer(), x_dist); dfilter = TreeDepthFirstInvarient(m_TreeModel.GetNCObject(), m_TreeModel->GetRootIdx(), dfilter); MeasureTree(); } string CPhyloTreeDataSource::GetColumnLabel(size_t col) const { const CBioTreeFeatureDictionary:: TFeatureDict& fdict = m_TreeModel->GetFeatureDict().GetFeatureDict(); CBioTreeFeatureDictionary::TFeatureDict::const_iterator fiter; size_t count = 0; for (fiter=fdict.begin(); fiter != fdict.end(); ++fiter, ++count) { if (count == col) { return (*fiter).second; } } return ""; } size_t CPhyloTreeDataSource::GetColsCount() const { return m_TreeModel->GetFeatureDict().GetFeatureDict().size(); } CQueryExec* CPhyloTreeDataSource::GetQueryExec(bool casesensitive, CStringMatching::EStringMatching matching) { CTreeQueryExec* qexec = new CTreeQueryExec(&(this->GetDictionary())); qexec->SetTree(this->GetTree()); // Logical operators: qexec->AddFunc(CQueryParseNode::eAnd, new CQueryFuncPromoteLogic()); qexec->AddFunc(CQueryParseNode::eOr, new CQueryFuncPromoteLogic()); qexec->AddFunc(CQueryParseNode::eSub, new CQueryFuncPromoteLogic()); qexec->AddFunc(CQueryParseNode::eXor, new CQueryFuncPromoteLogic()); qexec->AddFunc(CQueryParseNode::eNot, new CQueryFuncPromoteLogic()); // Constants: qexec->AddFunc(CQueryParseNode::eIntConst, new CQueryFuncPromoteValue()); qexec->AddFunc(CQueryParseNode::eFloatConst, new CQueryFuncPromoteValue()); qexec->AddFunc(CQueryParseNode::eBoolConst, new CQueryFuncPromoteValue()); qexec->AddFunc(CQueryParseNode::eString, new CQueryFuncPromoteValue()); NStr::ECase cs = casesensitive ? NStr::eCase : NStr::eNocase; // Comparison operators: qexec->AddFunc(CQueryParseNode::eEQ, new CQueryFuncPromoteEq(cs, matching)); qexec->AddFunc(CQueryParseNode::eGT, new CQueryFuncPromoteGtLt(CQueryParseNode::eGT, cs)); qexec->AddFunc(CQueryParseNode::eGE, new CQueryFuncPromoteGtLt(CQueryParseNode::eGE, cs)); qexec->AddFunc(CQueryParseNode::eLT, new CQueryFuncPromoteGtLt(CQueryParseNode::eLT, cs)); qexec->AddFunc(CQueryParseNode::eLE, new CQueryFuncPromoteGtLt(CQueryParseNode::eLE, cs)); qexec->AddFunc(CQueryParseNode::eIn, new CQueryFuncPromoteIn(cs, matching)); qexec->AddFunc(CQueryParseNode::eBetween, new CQueryFuncPromoteBetween(cs)); qexec->AddFunc(CQueryParseNode::eLike, new CQueryFuncLike(cs)); return qexec; } void CPhyloTreeDataSource::SetQueryResults(CQueryExec* q) { CTreeQueryExec *e = dynamic_cast<CTreeQueryExec*>(q); m_SearchCache = e->GetTreeSelected(); m_SearchCurrentNode = CPhyloTree::Null(); } void CPhyloTreeDataSource::ExecuteStringQuery(const string &query, size_t& num_selected, size_t& num_queried, CStringMatching::EStringMatching string_matching, NStr::ECase use_case) { // Re-run the query if options that can change query results have changed m_SearchCache.clear(); m_SearchCurrentNode = CPhyloTree::Null(); num_queried = 0; // simple string queries are completed synchronously since // they can never get hung up in network access. if (query != "") { m_SearchCache = FindNodes(query, num_queried, string_matching, use_case); } num_selected = m_SearchCache.size(); LOG_POST(Info << "String Query: " << query); } class visitor_stringmatch_query { public: typedef CPhyloTree::TTreeIdx TTreeIdx; public: visitor_stringmatch_query(CStringMatching &stringMatching, vector<TTreeIdx> &selNodes, size_t &numQueried) : m_StringMatching(stringMatching), m_SelNodes(selNodes), m_NumQueried(numQueried) {} ETreeTraverseCode operator()(CPhyloTree& tree, TTreeIdx node, int delta) { if (delta==1 || delta==0){ ++m_NumQueried; CBioTreeFeatureList::TFeatureList f_list = tree[node]->GetBioTreeFeatureList().GetFeatureList(); ITERATE(CBioTreeFeatureList::TFeatureList, it, f_list) { if (m_StringMatching.MatchString(it->value)) { m_SelNodes.push_back(node); break; } } } return eTreeTraverse; } private: CStringMatching &m_StringMatching; vector<TTreeIdx> &m_SelNodes; size_t &m_NumQueried; }; vector<CPhyloTree::TTreeIdx> CPhyloTreeDataSource::FindNodes(const string &query, size_t& num_queried, CStringMatching::EStringMatching string_matching, NStr::ECase use_case) const { vector<TTreeIdx> selNodes; CStringMatching stringMatching(query, string_matching, use_case); visitor_stringmatch_query finder(stringMatching, selNodes, num_queried); TreeDepthFirst(m_TreeModel.GetNCObject(), finder); return selNodes; } CPhyloTree::TTreeIdx CPhyloTreeDataSource::IterateOverSelNodes(int direction, bool highlight) { // highlight if (m_TreeModel->GetRootIdx() == CPhyloTree::Null()) return CPhyloTree::Null(); m_TreeModel->ClearSelection(); if (m_SearchCache.empty()) return CPhyloTree::Null(); // cursor if (direction==0) { if (m_SearchCurrentNode == CPhyloTree::Null()) m_SearchCurrentNode = (*m_SearchCache.begin()); } else if (direction>0) { if (m_SearchCurrentNode == CPhyloTree::Null()) { m_SearchCurrentNode = (*m_SearchCache.begin()); } else { vector<TTreeIdx>::iterator itt = find(m_SearchCache.begin(), m_SearchCache.end(), m_SearchCurrentNode); // If not found (unexpected) set cursor to beginning. if (itt==m_SearchCache.end()) { m_SearchCurrentNode = (*m_SearchCache.begin()); } // else increment unless we are already at the end. else if (++itt!=m_SearchCache.end()) { m_SearchCurrentNode = *itt; } } } else { if (m_SearchCurrentNode == CPhyloTree::Null()) { m_SearchCurrentNode = *(m_SearchCache.begin() + (m_SearchCache.size()-1)); } else { vector<TTreeIdx>::iterator itt = find(m_SearchCache.begin(), m_SearchCache.end(), m_SearchCurrentNode); // If not found (unexpected) set cursor to the end if (itt==m_SearchCache.end()) { m_SearchCurrentNode = *(m_SearchCache.begin() + (m_SearchCache.size()-1)); } // else decrement cursor if not already at the beginning else if (itt!=m_SearchCache.begin()) { m_SearchCurrentNode = *(--itt); } } } // highlight if (highlight) { ITERATE(vector<TTreeIdx>, it, m_SearchCache) { m_TreeModel->SetSelection(*it, true, false, true); } } else { if (m_SearchCurrentNode) { m_TreeModel->SetSelection(m_SearchCurrentNode, true, false, true); } } // Make the node we have iterated to the current node -this will give it // a small visual marker (square) around the node so user knows where they are. if (m_SearchCurrentNode) m_TreeModel->SetCurrentNode(m_SearchCurrentNode); return m_SearchCurrentNode; } void CPhyloTreeDataSource::UpdateSelectionSets(CPhyloTreeScheme* scheme) { x_SetSelectionSetProperty(); MeasureTree(); Clusterize(scheme); } void CPhyloTreeDataSource::x_SetSelectionSetProperty() { // First clear any existing selection set cluster ids. size_t num_nodes = m_TreeModel->GetSize(); TBioTreeFeatureId cluster_id = m_TreeModel->GetFeatureDict().Register("cluster-id"); TBioTreeFeatureId sel_feat_id = m_TreeModel->GetFeatureDict().Register("$SEL_CLUSTERS"); TBioTreeFeatureId marker_feat_id = m_TreeModel->GetFeatureDict().Register("marker"); // Clearing should also restore node markers from node properties? and cluster IDs? //------------------------------------------------------------------------------------ if (sel_feat_id != (TBioTreeFeatureId)-1) { for (size_t i=0; i<num_nodes; ++i) { CPhyloTreeNode& n = m_TreeModel->GetNode(i); // clear all selection cluster info - that will be re-added below if there is any n.GetValue().GetSelClusters().clear(); n.GetValue().GetBioTreeFeatureList().RemoveFeature(sel_feat_id); // reset cluster id from feature list, if available string cid = n.GetValue().GetBioTreeFeatureList().GetFeatureValue(cluster_id); int cluster_id=-1; if (cid != "") { int sel_id = NStr::StringToInt(cid, NStr::fConvErr_NoThrow); if (sel_id || errno == 0) cluster_id = sel_id; } n.GetValue().SetClusterID(cluster_id); // Reset node marker from feature (if available) since it can also be overridden by // selection clusters n.GetValue().GetMarkerColors().clear(); const string& marker = n.GetValue().GetBioTreeFeatureList().GetFeatureValue(marker_feat_id); try { if (!marker.empty()) { n.GetValue().SetMarkerColors(marker); } } catch(std::exception&){} } } // Set selection-cluster property in feature list of all selected nodes // in active selection sets. for (size_t i=0; i<m_SelectionSets.size(); ++i) { if (m_SelectionSets[i].GetSelected()) { int cluster_id = m_SelectionSets[i].GetClusterID(); string cid; NStr::IntToString(cid, cluster_id); for (size_t j=0; j<m_SelectionSets[i].GetSelectionSet().size(); ++j) { CPhyloTree::TID node_id = m_SelectionSets[i].GetSelectionSet()[j]; CPhyloTree::TTreeIdx node_idx = m_TreeModel->FindNodeById(node_id); // Node could be NULL if user edited (removed nodes from) tree or if // this is a subtree which would have copied only some nodes but // inherits all user data - so some ids in selection-sets may not exist. // (cleaned up if missing_ids gets set to true) if (node_idx != CPhyloTree::Null()) { CPhyloTreeNode& node = m_TreeModel->GetNode(node_idx); node.GetValue().GetSelClusters().push_back(cluster_id); string sel_clusters = node.GetValue().GetBioTreeFeatureList().GetFeatureValue(sel_feat_id); if (sel_clusters.length() > 0) sel_clusters += " "; sel_clusters += cid; node.GetValue().GetBioTreeFeatureList().SetFeature(sel_feat_id, sel_clusters); } } } } } void CPhyloTreeDataSource::x_SyncSelectionSets() { // Selection sets may be out of sync with actual tree if the // tree was created as a subtree of another tree but inherited // the other trees full selections sets, or also if user // directly edits selection set. // First remove any ids that are not in the current tree for (size_t i=0; i<m_SelectionSets.size(); ++i) { vector<CPhyloTree::TID> selected = m_SelectionSets[i].GetSelectionSet(); m_SelectionSets[i].GetSelectionSet().clear(); for (size_t j=0; j<selected.size(); ++j) { CPhyloTree::TID node_id = selected[j]; CPhyloTree::TTreeIdx node_idx = m_TreeModel->FindNodeById(node_id); if (node_idx != CPhyloTree::Null()) m_SelectionSets[i].GetSelectionSet().push_back(node_id); } } // Now remove any empty selection sets vector<CPhyloSelectionSet> selection_sets = m_SelectionSets; m_SelectionSets.clear(); for (size_t i=0; i<selection_sets.size(); ++i) { if (selection_sets[i].GetSelectionSet().size() > 0) { m_SelectionSets.push_back(selection_sets[i]); } } } class visitor_detach_subtree { public: visitor_detach_subtree(){} ETreeTraverseCode operator()(CPhyloTree& tree, CPhyloTree::TTreeIdx node, int delta) { if (delta==1 || delta==0){ tree[node].GetValue().SetId(CPhyloNodeData::TID(-1)); } return eTreeTraverse; } }; class visitor_copy_subtree { public: typedef CPhyloTree TTreeType; typedef CPhyloTree::TTreeIdx TTreeIdx; typedef CPhyloTree::TNodeType TNodeType; public: visitor_copy_subtree(CPhyloTree& tree, CPhyloTree& target) : m_Target(target) { m_Target.GetFeatureDict() = tree.GetFeatureDict(); m_Target.SetRootIdx(0); } ETreeTraverseCode operator()(CPhyloTree& tree, CPhyloTree::TTreeIdx node_idx, int delta) { if (delta < 0) { return eTreeTraverse; } TNodeType& node = tree[node_idx]; CPhyloNodeData::TID id = node.GetValue().GetId(); // Make sure not already in tree (but traversal should guarantee) TTreeIdx idx = m_Target.FindNodeById(id); if (idx != CPhyloTreeNode::Null()) { return eTreeTraverse; } // Adds a copy of node. Need to update indices to match the target tree TTreeIdx new_node_idx = m_Target.AddNode(node); TNodeType& new_node = m_Target[new_node_idx]; new_node.ClearConnections(); // Look up the parent index of the new node using the // node id CPhyloNodeData::TID parent_id = tree[node.GetParent()]->GetId(); TTreeIdx parent_idx = m_Target.FindNodeById(parent_id); // This will only happen for the top (first) node of the // subtree being cut since its parent won't be in the subtree if (parent_idx == CPhyloTreeNode::Null()) { return eTreeTraverse; } m_Target.AddChild(parent_idx, new_node_idx); return eTreeTraverse; } CPhyloTree& m_Target; }; class visitor_paste_subtree { public: typedef CPhyloTree TTreeType; typedef CPhyloTree::TTreeIdx TTreeIdx; typedef CPhyloTree::TNodeType TNodeType; public: visitor_paste_subtree(CPhyloTree& source, CPhyloTree& target, TTreeIdx target_idx) : m_Target(target) , m_Source(source) , m_TargetIdx(target_idx) { CPhyloTreeMaxIdCalculator next_id(&m_Target); next_id = TreeDepthFirst(m_Target, next_id); m_TargetMaxId = next_id.GetMaxId(); } // This is iterating over the source tree adding each // element to the target tree (m_Target) ETreeTraverseCode operator()(CPhyloTree& tree, CPhyloTree::TTreeIdx node_idx, int delta) { if (delta < 0) { return eTreeTraverse; } // Node from source tree (the tree we are copying into the target tree) TNodeType& node = tree[node_idx]; CPhyloNodeData::TID source_id = node.GetValue().GetId(); // Adds a copy of node. Need to update indices to match the target tree TTreeIdx new_node_idx = m_Target.AddNode(node); TNodeType& new_node = m_Target[new_node_idx]; new_node.ClearConnections(); CPhyloNodeData::TID target_id = ++m_TargetMaxId; m_IdMap[source_id] = target_id; new_node->SetId(target_id); new_node.GetValue().GetBioTreeFeatureList() = CBioTreeFeatureList(); // Add any features in in dictionary of source but not target to target. // Get the id for the name each time too since ids between the two // trees may not match. ITERATE(CBioTreeFeatureList::TFeatureList, it, node->GetBioTreeFeatureList().GetFeatureList()) { // Use the id for the feature to get the feature name string feature_name = m_Source.GetFeatureDict().GetName(it->id); TBioTreeFeatureId id = m_Target.GetFeatureDict().Register(feature_name); new_node.GetValue().GetBioTreeFeatureList().SetFeature(id, it->value); } // If this is the root of the source tree, attach it to the node // m_TargetIdx in the target tree. Otherwise attach it to the // corresponding node copied from the source tree using the id-to-id map if (node.GetParent() == CPhyloTreeNode::Null()) { m_Target.AddChild(m_TargetIdx, new_node_idx); } else { CPhyloNodeData::TID parent_id = tree[node.GetParent()]->GetId(); CPhyloNodeData::TID target_tree_parent_id = m_IdMap[parent_id]; TTreeIdx parent_idx = m_Target.FindNodeById(target_tree_parent_id); if (parent_idx != CPhyloTreeNode::Null()) { m_Target.AddChild(parent_idx, new_node_idx); } else { LOG_POST(Info << "Error - did not find parent node as expected."); } } return eTreeTraverse; } CPhyloTree& m_Target; CPhyloTree& m_Source; TTreeIdx m_TargetIdx; /// mapping from Ids in source tree to target tree map<CPhyloNodeData::TID, CPhyloNodeData::TID> m_IdMap; CPhyloNodeData::TID m_TargetMaxId; }; void CPhyloTreeDataSource::Cut() { TTreeIdx node_idx = m_TreeModel->GetCurrentNodeIdx(); if (node_idx == CPhyloTree::Null()) { _TRACE("CPhyloTreeDataSource::Cut - Nothing is selected"); return; } if (node_idx == m_TreeModel->GetRootIdx()) { _TRACE("CPhyloTreeDataSource::Cut - Removing root item is illegal"); return; } m_sTreeClipboard.Clear(); CPhyloTree::TNodeType& n = m_TreeModel->GetCurrentNode(); m_TreeModel->SetSelection(n.GetParent(), true, true); TreeDepthFirst(m_TreeModel.GetNCObject(), node_idx, visitor_copy_subtree(m_TreeModel.GetNCObject(), m_sTreeClipboard)); m_TreeModel->ClearSelection(); m_TreeModel->RemoveChild(n.GetParent(), node_idx); MeasureTree(); } void CPhyloTreeDataSource::Paste(void) { TTreeIdx node_idx = m_TreeModel->GetCurrentNodeIdx(); if (node_idx == CPhyloTree::Null()) { _TRACE("CPhyloTreeDataSource::Paste - Nothing is selected"); return; } if (m_sTreeClipboard.GetRootIdx() == CPhyloTreeNode::Null()) { _TRACE("CPhyloTreeDataSource::Paste - Clipboard is empty"); return; } TreeDepthFirst( m_sTreeClipboard, visitor_paste_subtree(m_sTreeClipboard, m_TreeModel.GetNCObject(), node_idx)); MeasureTree(); } void CPhyloTreeDataSource::NewNode(bool after) { TTreeIdx current_node_idx = m_TreeModel->GetCurrentNodeIdx(); if (current_node_idx == CPhyloTree::Null()) { _TRACE("CPhyloTreeDataSource::NewNode - Nothing is selected"); return; } TTreeIdx parent_node_idx = m_TreeModel->GetNode(current_node_idx).GetParent(); if (!after && parent_node_idx == CPhyloTree::Null()) { _TRACE("CPhyloTreeDataSource::NewNode - New root cannot be added"); return; } TTreeIdx new_node_idx = m_TreeModel->AddNode(); TNodeType& new_node = m_TreeModel->GetNode(new_node_idx); // Set node id to current maximim node id value +1. IDs needed during export. CPhyloTreeMaxIdCalculator next_id(m_TreeModel); next_id = TreeDepthFirst(m_TreeModel.GetNCObject(), next_id); new_node->SetId(next_id.GetMaxId() + 1); if (after) { // insert as a child TNodeType& current_node = m_TreeModel->GetCurrentNode(); current_node.GetChildren().insert(current_node.SubNodeBegin(), new_node_idx); new_node.SetParent(m_TreeModel->GetCurrentNodeIdx()); } else { m_TreeModel->RemoveChild(parent_node_idx, current_node_idx); m_TreeModel->AddChild(parent_node_idx, new_node_idx); m_TreeModel->AddChild(new_node_idx, current_node_idx); } // Set dictionary and a blank feature table with all values from dictionary. //new_node.GetValue().SetDictionaryPtr(&(m_TreeModel->GetFeatureDict())); // Do we need this - I don't see why... maybe dist? ITERATE(CBioTreeFeatureDictionary::TFeatureDict, it, m_TreeModel->GetFeatureDict().GetFeatureDict()) { new_node.GetValue().SetFeature(m_TreeModel->GetFeatureDict(), it->second, ""); } #ifdef TEXTURED_COLORS new_node->Init(m_TreeModel->GetFeatureDict(), m_TreeModel->GetGraphicsModel().GetColorTable()); #else new_node->Init(m_TreeModel->GetFeatureDict()); #endif MeasureTree(); } void CPhyloTreeDataSource::Remove(bool subtree) { TTreeIdx current_node_idx = m_TreeModel->GetCurrentNodeIdx(); if (current_node_idx == CPhyloTree::Null()) { _TRACE("CPhyloTreeDataSource::MoveNode - Nothing is selected"); return; } TTreeIdx parent_node_idx = m_TreeModel->GetNode(current_node_idx).GetParent(); if (parent_node_idx == CPhyloTree::Null()) { _TRACE("CPhyloTreeDataSource::MoveNode - The root node can't be moved"); return; } m_TreeModel->ClearSelection(); if (subtree) { // Remove the node and all it's subnodes TreeDepthFirst(m_TreeModel.GetNCObject(), current_node_idx, visitor_detach_subtree()); m_TreeModel->RemoveChild(parent_node_idx, current_node_idx); } else { // Remove the node and add all its children to its parent TNodeType& current_node = m_TreeModel->GetNode(current_node_idx); for(TNodeType::TNodeList_I it = current_node.SubNodeBegin(); it != current_node.SubNodeEnd(); it++ ) { m_TreeModel->AddChild(parent_node_idx, *it); } current_node.ClearConnections(); m_TreeModel->RemoveChild(parent_node_idx, current_node_idx); current_node.GetValue().SetId(CPhyloNodeData::TID(-1)); } MeasureTree(); } void CPhyloTreeDataSource::MoveNode(bool up) { TTreeIdx current_node_idx = m_TreeModel->GetCurrentNodeIdx(); if (current_node_idx == CPhyloTree::Null()) { _TRACE("CPhyloTreeDataSource::MoveNode - Nothing is selected"); return; } TTreeIdx parent_node_idx = m_TreeModel->GetNode(current_node_idx).GetParent(); if (parent_node_idx == CPhyloTree::Null()) { _TRACE("CPhyloTreeDataSource::MoveNode - The root node can't be moved"); return; } TNodeType& parent = m_TreeModel->GetNode(parent_node_idx); for(TNodeType::TNodeList_I it = parent.SubNodeBegin(); it != parent.SubNodeEnd(); it++ ) { if (*it == current_node_idx) { if (up && (it!=parent.SubNodeBegin())) { TNodeType::TNodeList_I pre = it--; swap(*pre, *it); break; } else { TNodeType::TNodeList_I last = parent.SubNodeEnd(); last--; if (it != last) { TNodeType::TNodeList_I pst = it++; swap(*pst, *it); break; } } } } } END_NCBI_SCOPE

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.