NCBI C++ ToolKit
cuSeqtree.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: cuSeqtree.hpp 33815 2007-05-04 17:18:18Z kazimird $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Charlie Liu
27  *
28  * File Description:
29  * Define SeqTree and how to read and write it.
30  */
31 
32 #if !defined(CU_SEQTREE_HPP)
33 #define CU_SEQTREE_HPP
37 
38 #include <string>
39 #include <iostream>
40 #include <fstream>
41 #include <map>
42 #include <vector>
43 #include <queue>
44 
47 BEGIN_SCOPE(cd_utils)
48 
49 typedef map<CCdCore*, bool> SelectionByCd;
50 
52 {
53  friend ostream &operator<<(ostream& os, const SeqItem&);
54 public:
55  SeqItem();
56  SeqItem(const SeqItem& rhs);
57  SeqItem(int rowid, double dist=0.0);
58  explicit SeqItem(const std::string nameDist);
59  SeqItem(const std::string nameDist, int rowid, double dist=0.0);
60  void select(bool on=true); //select all instances of this row
61  void select(CCdCore* cd, bool on=true); //select the instance in this CD
62  int getAllInstances();
63  int getAllSelectedInstances();
64  ~SeqItem(){};
65 
66  bool operator==(const SeqItem& rhs) const;
67 
69  int id;
70  double distance;
72  int x;
73  int y;
74  int rowID;
76  bool selected;
77  bool collapsed;
79  long taxid;
80  string membership; //child cd accession to color the tree
82 private:
83  void init();
84 };
85 
88 
91 
93 {
94 public:
95  SeqTree();
96  virtual ~SeqTree();
97 
98 // SeqTree(const SeqTree& rhs);
99 // SeqTree& operator=(const SeqTree& rhs);
100 
101  //prepare deriative attributes for drawing
102  void prepare();
103  void forcePrepare();
104  bool isPrepared();
105  int getNumLeaf();
106  double getMaxDistanceToRoot();
107  std::string getLongestName();
108  //get the order of aligntment rows in the tree.
109  //master row (row=0) is not in the vector positions because it is not a real ealignment row.
110  void getOrdersInTree(vector<int>& positions);
111  void getDiversityRankToRow(int colRow, list<int>& rankList);
112  SeqTreeIterator getLeafById(int id);
113  //set child cd membership
114  void setMembershipColor(const RowMembershipColor* rowColorMap);
115 
116  //node selection
117  void getSelectedSequenceRowid(const iterator& node, vector<int>& selections);
118  void getSequenceRowid(const iterator& node, vector<int>& selections);
119  void clearInternalNodeSelection();
120  void selectByRowID(const set<int>& receivedSelection, bool select=true, CCdCore* cd=0);
121  void selectByTax(const vector<int>& rows, long taxid);
122  void selectByGI(const AlignmentCollection& aligns,const vector< CRef <CSeq_id> >& gis);
123  void selectNode(const iterator& node, bool select=true, CCdCore* cd=0);
124  //void deselectNode(const iterator& node, bool all=false);
125  void getDistantNodes(double dist, vector<SeqTreeIterator>& nodes);
126  //void getPeerLeafNodes(const iterator& node, vector<SeqTreeIterator>& nodes);
127  void uncollapseAll();
128 
129  //seq name
131  {
132  eGI,
136  eGI_SEQLOC_SPECIES
137  };
138  void fixRowName(AlignmentCollection& aligns, SeqNameMode mode);
139  void fixRowNumber(AlignmentCollection& aligns);
140  void addSelectionFields(AlignmentCollection& aligns);
141  void updateSeqCounts(const AlignmentCollection& aligns);
142  bool isSequenceCompositionSame(AlignmentCollection& aligns);
143  bool compareSequenceCompositions(IntToStringMap& com1, IntToStringMap& com2);
144  void getSequenceComposition(IntToStringMap& seqComposition);
145  void getSequenceComposition(AlignmentCollection& aligns,
146  IntToStringMap& seqComposition);
147 private:
150  double m_maxDist;
154  typedef queue<iterator> IteQueue;
155  IteQueue m_collapsedNodes; //used in prepare() only
156 
157  void prepare(int& numLeaf, double& maxDist, const iterator& cursor);
158  void prepareCollapsedNodes(int& numLeaf);
159  void clearTaxSelection();
160  void getDistantNodes(const iterator& start, double dist, vector<SeqTreeIterator>& nodes);
161  void getDiversityRankUnderNode(SeqTreeIterator node, list<int>& rankList);
162  //void selectByInternalRowID(const vector<int>& selection);
163 };
164 
165 END_SCOPE(cd_utils)
167 #endif
double distance
Definition: cuSeqtree.hpp:70
string membership
Definition: cuSeqtree.hpp:80
SelectionByCd selections
Definition: cuSeqtree.hpp:75
bool selected
Definition: cuSeqtree.hpp:76
double distanceToRoot
Definition: cuSeqtree.hpp:71
int rowID
Definition: cuSeqtree.hpp:74
~SeqItem()
Definition: cuSeqtree.hpp:64
std::string name
Definition: cuSeqtree.hpp:68
int id
Definition: cuSeqtree.hpp:69
bool interesting
Definition: cuSeqtree.hpp:78
CConstRef< CSeq_id > seqId
Definition: cuSeqtree.hpp:81
long taxid
Definition: cuSeqtree.hpp:79
bool collapsed
Definition: cuSeqtree.hpp:77
double m_maxDist
Definition: cuSeqtree.hpp:150
@ eGI_SEQLOC
Definition: cuSeqtree.hpp:135
@ eGI_SPECIES
Definition: cuSeqtree.hpp:134
bool m_prepared
Definition: cuSeqtree.hpp:148
queue< iterator > IteQueue
Definition: cuSeqtree.hpp:154
IteQueue m_collapsedNodes
Definition: cuSeqtree.hpp:155
int m_numLeaf
Definition: cuSeqtree.hpp:149
map< int, iterator > RowLeafMap
Definition: cuSeqtree.hpp:152
RowLeafMap m_leafNodes
Definition: cuSeqtree.hpp:153
std::string m_longestName
Definition: cuSeqtree.hpp:151
Definition: map.hpp:338
USING_SCOPE(objects)
SeqTreeBase::iterator SeqTreeIterator
Definition: cuSeqtree.hpp:90
tree< SeqItem > SeqTreeBase
Definition: cuSeqtree.hpp:89
map< int, string > RowMembershipColor
Definition: cuSeqtree.hpp:87
map< int, std::string > IntToStringMap
Definition: cuSeqtree.hpp:86
bool operator==(const CEquivRange &A, const CEquivRange &B)
CNcbiOstream & operator<<(CNcbiOstream &out, const CEquivRange &range)
Definition: equiv_range.cpp:96
static void DLIST_NAME() init(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:40
string
Definition: cgiapp.hpp:687
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NCBI_CDUTILS_EXPORT
Definition: ncbi_export.h:376
mdb_mode_t mode
Definition: lmdb++.h:38
Modified on Wed Sep 04 15:05:38 2024 by modify_doxy.py rev. 669887