1 // 2 // phylosupertreeunlinked.h 3 // tree 4 // 5 // Created by Minh Bui on 2/5/18. 6 // 7 8 #ifndef phylosupertreeunlinked_h 9 #define phylosupertreeunlinked_h 10 11 #include "phylosupertree.h" 12 13 /** 14 Super-tree with separate partition tree topologies 15 */ 16 class PhyloSuperTreeUnlinked : public PhyloSuperTree { 17 public: 18 /** 19 constructors 20 */ 21 PhyloSuperTreeUnlinked(SuperAlignment *alignment); 22 isSuperTreeUnlinked()23 virtual bool isSuperTreeUnlinked() { 24 return true; 25 } 26 27 /** 28 read the tree from the ifstream in newick format 29 @param in the input stream. 30 @param is_rooted (IN/OUT) true if tree is rooted 31 */ 32 virtual void readTree(istream &in, bool &is_rooted); 33 34 35 /** 36 Set the alignment, important to compute parsimony or likelihood score 37 Assing taxa ids according to their position in the alignment 38 @param alignment associated alignment 39 */ 40 virtual void setAlignment(Alignment *alignment); 41 42 /** 43 * setup all necessary parameters (declared as virtual needed for phylosupertree) 44 */ 45 virtual void initSettings(Params& params); 46 47 /** 48 create sub-trees T|Y_1,...,T|Y_k of the current super-tree T 49 and map F={f_1,...,f_k} the edges of supertree T to edges of subtrees T|Y_i 50 */ 51 virtual void mapTrees(); 52 53 /** 54 * FAST VERSION: compute parsimony tree by step-wise addition 55 * @param out_prefix prefix for .parstree file 56 * @param alignment input alignment 57 * @param rand_stream random stream 58 * @return parsimony score 59 */ 60 virtual int computeParsimonyTree(const char *out_prefix, Alignment *alignment, int *rand_stream); 61 62 /** 63 * Assign branch lengths for branch that has no or negative length 64 * With single model branch lengths are assigned using parsimony. With partition model 65 * branch lengths are assigned randomly 66 * @param force_change if true then force fixing also positive branch lengths 67 * @return number of branches fixed 68 */ 69 virtual int wrapperFixNegativeBranch(bool force_change); 70 71 /** @return true if tree is bifurcating, false otherwise */ 72 virtual bool isBifurcating(Node *node = NULL, Node *dad = NULL); 73 74 /** 75 Read the tree saved with Taxon IDs and branch lengths. 76 @param tree_string tree string to read from 77 @param updatePLL if true, tree is read into PLL 78 */ 79 virtual void readTreeString(const string &tree_string); 80 81 /* 82 * Return the tree string contining taxon IDs and branch lengths 83 * @return 84 * @param format (WT_TAXON_ID, WT_BR_LEN, ...) 85 * @return the tree string with the specified format 86 */ 87 virtual string getTreeString(); 88 89 /** 90 save object into the checkpoint 91 */ 92 virtual void saveCheckpoint(); 93 94 /** 95 restore object from the checkpoint 96 */ 97 virtual void restoreCheckpoint(); 98 99 /** 100 * save branch lengths into a vector 101 */ 102 virtual void saveBranchLengths(DoubleVector &lenvec, int startid = 0, PhyloNode *node = NULL, PhyloNode *dad = NULL); 103 /** 104 * restore branch lengths from a vector previously called with saveBranchLengths 105 */ 106 virtual void restoreBranchLengths(DoubleVector &lenvec, int startid = 0, PhyloNode *node = NULL, PhyloNode *dad = NULL); 107 108 /** set the root by name 109 @param my_root root node name 110 @param multi_taxa TRUE if my_root is a comma-separated list of nodes 111 */ 112 virtual void setRootNode(const char *my_root, bool multi_taxa = false); 113 114 /** 115 compute the weighted average of branch lengths over partitions 116 */ 117 virtual void computeBranchLengths(); 118 119 /** 120 print the tree to the output file in newick format 121 @param out the output stream. 122 @param brtype type of branch to print 123 */ 124 virtual void printTree(ostream & out, int brtype = WT_BR_LEN); 125 126 /** 127 print tree to .treefile 128 @param params program parameters, field root is taken 129 */ 130 virtual void printResultTree(string suffix = ""); 131 132 /** 133 @return sum of all branch lengths 134 @param node the starting node, NULL to start from the root 135 @param dad dad of the node, used to direct the search 136 */ 137 virtual double treeLength(Node *node = NULL, Node *dad = NULL); 138 139 140 /** 141 @return sum length of all internal branches 142 @param node the starting node, NULL to start from the root 143 @param dad dad of the node, used to direct the search 144 */ 145 virtual double treeLengthInternal(double epsilon, Node *node = NULL, Node *dad = NULL); 146 147 /** 148 * @brief Perform NNI search on the current tree topology 149 * @return <number_of_NNIs, number_of_NNI_steps> 150 * This function will automatically use the selected kernel (either PLL or IQ-TREE) 151 */ 152 virtual pair<int, int> doNNISearch(bool write_info = false); 153 154 /** 155 perform tree search 156 @return best likelihood found 157 */ 158 virtual double doTreeSearch(); 159 160 /** summarize bootstrap trees */ 161 virtual void summarizeBootstrap(Params ¶ms); 162 163 /** 164 write .ufboot trees file 165 */ 166 virtual void writeUFBootTrees(Params ¶ms); 167 168 /** 169 Test all branches of the tree with aLRT SH-like interpretation 170 */ 171 virtual int testAllBranches(int threshold, double best_score, double *pattern_lh, 172 int reps, int lbp_reps, bool aLRT_test, bool aBayes_test, 173 PhyloNode *node = NULL, PhyloNode *dad = NULL); 174 175 /** 176 test the best number of threads 177 */ 178 virtual int testNumThreads(); 179 180 }; 181 182 #endif /* phylosupertreeunlinked_h */ 183