1 /* $Id: cuSeqTreeAPI.hpp 195025 2010-06-18 14:23:18Z lanczyck $
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  *
30  *       A simple API layer to access Seqtree and its layout
31  *
32  * ===========================================================================
33  */
34 
35 #ifndef CU_SEQTREE_API_HPP
36 #define CU_SEQTREE_API_HPP
37 
38 #include <algo/structure/cd_utils/cuCdCore.hpp>
39 #include <algo/structure/cd_utils/cuTaxTree.hpp>
40 #include <algo/structure/cd_utils/cuSeqtree.hpp>
41 #include <algo/structure/cd_utils/cuCdFamily.hpp>
42 #include <algo/structure/cd_utils/cuSeqTreeFactory.hpp>
43 
44 BEGIN_NCBI_SCOPE
45 BEGIN_SCOPE(cd_utils) // namespace ncbi::objects::
46 
47 
48 struct SeqTreeNode
49 {
50 	string name; //gi or PDB for a leaf node; empty for internal node
51 	int x;
52 	int y;
53 	bool isLeaf;
54 	string annotation;
55 	string displayAnnotation;  //  empty by default; use if 'annotation' does not determine the node's display properties
56 };
57 typedef pair<SeqTreeNode, SeqTreeNode> SeqTreeEdge;
58 
59 class NCBI_CDUTILS_EXPORT SeqTreeAPI
60 {
61 public:
62 	SeqTreeAPI(vector<CCdCore*>& cds, bool loadExistingTreeOnly=true);
63 	SeqTreeAPI(CCdCore* cd);
64 	SeqTreeAPI(CDFamily& cdfam, TreeOptions& option);
65 	~SeqTreeAPI();
66 
67 	void annotateTreeByMembership();
68 
69 	enum TaxonomyLevel
70 	{
71 		BySuperkingdom,
72 		/*ByKingdom,
73 		ByBlink*/
74 	};
75 	void annotateTreeByTaxonomy(TaxonomyLevel tax);
76 
77 	int getNumOfLeaves();
78 	//return a string of tree method names
79 	//lay out the tree to the specified area, .i.e. with the "fit to screen" style
80     //'displayAnnotation' on the nodes of edges is empty; user is to populate it manually
81     string layoutSeqTree(int maxX, int maxY, vector<SeqTreeEdge>& edges);
82 	//lay out the tree with a fixed spacing between sequences
83     //'displayAnnotation' on the nodes of edges is empty; user is to populate it manually
84     string layoutSeqTree(int maxX, vector<SeqTreeEdge>& edges, int yInt = 3);
getRootCD()85 	CCdCore* getRootCD(){return m_cd ? m_cd : m_ma.getFirstCD();}
86 	bool makeOrLoadTree();
87 	bool loadAndValidateExistingTree();
88 	bool makeTree();
getAlignment()89 	MultipleAlignment& getAlignment() {return m_ma;};
getTree()90 	SeqTree* getTree() {return m_seqTree;};
getOptions()91 	TreeOptions& getOptions() {return m_treeOptions;}
92 
93 private:
94 	//diffferent source of cd data
95 	MultipleAlignment m_ma; //slow but validates the tree
96 	CCdCore* m_cd; //fast, trust the tree without validating
97 	CDFamily* m_family; //for changing scope
98 
99 	SeqTree* m_seqTree;
100 	TaxTreeData* m_taxTree;
101 	TaxClient* m_taxClient;
102 	bool m_useMembership;
103 	TaxonomyLevel m_taxLevel;
104 	TreeOptions m_treeOptions;
105 	bool m_triedTreeMaking;
106 	bool m_loadOnly;
107 
108 	string layoutSeqTree(int maxX, int maxY, int yInt, vector<SeqTreeEdge>& edges);
109 	int getAllEdges(vector<SeqTreeEdge>& edges);
110 	void getEdgesFromSubTree(const SeqTree::iterator& cursor, vector<SeqTreeEdge>& edges);
111 	void annotateLeafNode(const SeqItem& nodeData, SeqTreeNode& node);
112 	bool loadExistingTree(CCdCore* cd, TreeOptions* treeOptions, SeqTree* seqTree);
113 };
114 
115 END_SCOPE(cd_utils)
116 END_NCBI_SCOPE
117 
118 
119 #endif
120