Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit dff6879

Browse files
committed
New option --cf-quartet to print sCF of all resampled quartets (requested by Benjamin Rosenzweig and Matt Hahn)
1 parent 219e884 commit dff6879

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

main/phyloanalysis.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4095,6 +4095,42 @@ void assignBranchSupportNew(Params &params) {
40954095
}
40964096
out.close();
40974097
cout << "Concordance factors per branch printed to " << filename << endl;
4098+
4099+
if (params.print_cf_quartets) {
4100+
filename = prefix + ".cf.quartet";
4101+
out.open(filename);
4102+
out << "# Site concordance factor for all resampled quartets (with replacement)" << endl
4103+
<< "# This file can be read in MS Excel or in R with command:" << endl
4104+
<< "# tab=read.table('" << filename << "',header=TRUE)" << endl
4105+
<< "# Columns are tab-separated with following meaning:" << endl
4106+
<< "# ID: Branch ID" << endl
4107+
<< "# QuartID: Quartet ID" << endl
4108+
<< "# Seq1: ID of sequence 1 on 'left' side of the branch" << endl
4109+
<< "# Seq2: ID of sequence 2 on 'left' side of the branch" << endl
4110+
<< "# Seq3: ID of sequence 3 on 'right' side of the branch" << endl
4111+
<< "# Seq4: ID of sequence 4 on 'right' side of the branch" << endl
4112+
<< "# qCF: Fraction of concordant sites supporting quartet Seq1,Seq2|Seq3,Seq4 (=qCF_N/qN)" << endl
4113+
<< "# qCF_N: Number of concordant sites supporting quartet Seq1,Seq2|Seq3,Seq4" << endl
4114+
<< "# qDF1: Fraction of discordant sites supporting quartet Seq1,Seq3|Seq2,Seq4 (=qDF1_N/qN)" << endl
4115+
<< "# qDF1_N: Number of discordant sites supporting quartet Seq1,Seq3|Seq2,Seq4" << endl
4116+
<< "# qDF2: Fraction of discordant sites supporting quartet Seq1,Seq4|Seq2,Seq3 (=qDF2_N/qN)" << endl
4117+
<< "# qDF2_N: Number of discordant sites supporting quartet Seq1,Seq4|Seq2,Seq3" << endl
4118+
<< "# qN: Number of decisive sites with four taxa Seq1,Seq2,Seq3,Seq4 (=qCF_N+qDF1_N+qDF2_N)" << endl
4119+
<< "ID\tQuartID\tSeq1\tSeq2\tSeq3\tSeq4\tqCF\tqCF_N\tqDF1\tqDF1_N\tqDF2\tqDF2_N\tqN" << endl;
4120+
for (brit = branches.begin(); brit != branches.end(); brit++) {
4121+
Neighbor *branch = brit->second->findNeighbor(brit->first);
4122+
int ID = brit->second->id;
4123+
for (int qid = 0; ; qid++) {
4124+
string qstr;
4125+
if (branch->attributes.find("q" + convertIntToString(qid)) == branch->attributes.end())
4126+
break;
4127+
out << ID << '\t' << qid+1 << '\t' << branch->attributes["q" + convertIntToString(qid)] << endl;
4128+
}
4129+
}
4130+
out.close();
4131+
cout << "Site concordance factors for quartets printed to " << filename << endl;
4132+
}
4133+
40984134
if (!params.site_concordance_partition)
40994135
return;
41004136

tree/discordance.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ void PhyloTree::computeSiteConcordance(Branch &branch, int nquartets, int *rstre
189189
}
190190
}
191191
}
192+
Neighbor *nei = branch.second->findNeighbor(branch.first);
192193
for (i = 0; i < nquartets; i++) {
193194
int j;
194195
// get a random quartet
@@ -209,6 +210,16 @@ void PhyloTree::computeSiteConcordance(Branch &branch, int nquartets, int *rstre
209210
sDF1_N += support[1];
210211
sDF2_N += support[2];
211212
}
213+
if (params->print_cf_quartets) {
214+
// print sCF for each quartet
215+
stringstream ss;
216+
ss << quartet[0]+1 << '\t' << quartet[1]+1 << '\t' << quartet[2]+1 << '\t' << quartet[3]+1
217+
<< '\t' << (((double)support[0]) / sum) << '\t' << support[0]
218+
<< '\t' << (((double)support[1]) / sum) << '\t' << support[1]
219+
<< '\t' << (((double)support[2]) / sum) << '\t' << support[2]
220+
<< '\t' << sum;
221+
nei->putAttr("q" + convertIntToString(i), ss.str());
222+
}
212223
}
213224
sN = (double)sum_sites / nquartets;
214225
// rounding
@@ -218,7 +229,6 @@ void PhyloTree::computeSiteConcordance(Branch &branch, int nquartets, int *rstre
218229
sCF_N = round(sCF_N / nquartets * 100)/100;
219230
sDF1_N = round(sDF1_N / nquartets * 100)/100;
220231
sDF2_N = round(sDF2_N / nquartets * 100)/100;
221-
Neighbor *nei = branch.second->findNeighbor(branch.first);
222232
PUT_ATTR(nei, sCF);
223233
PUT_ATTR(nei, sN);
224234
PUT_ATTR(nei, sDF1);

utils/tools.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,7 @@ void parseArg(int argc, char *argv[], Params &params) {
811811
params.support_tag = NULL;
812812
params.site_concordance = 0;
813813
params.site_concordance_partition = false;
814+
params.print_cf_quartets = false;
814815
params.print_df1_trees = false;
815816
params.internode_certainty = 0;
816817
params.tree_weight_file = NULL;
@@ -1586,6 +1587,10 @@ void parseArg(int argc, char *argv[], Params &params) {
15861587
params.site_concordance_partition = true;
15871588
continue;
15881589
}
1590+
if (strcmp(argv[cnt], "--cf-quartet") == 0) {
1591+
params.print_cf_quartets = true;
1592+
continue;
1593+
}
15891594
if (strcmp(argv[cnt], "--df-tree") == 0) {
15901595
params.print_df1_trees = true;
15911596
continue;
@@ -4584,6 +4589,7 @@ void usage_iqtree(char* argv[], bool full_command) {
45844589
<< " -s FILE Sequence alignment for --scf" << endl
45854590
<< " -p FILE|DIR Partition file or directory for --scf" << endl
45864591
<< " --cf-verbose Write CF per tree/locus to cf.stat_tree/_loci" << endl
4592+
<< " --cf-quartet Write sCF for all resampled quartets to .cf.quartet" << endl
45874593

45884594
#ifdef USE_LSD2
45894595
<< endl << "TIME TREE RECONSTRUCTION:" << endl

utils/tools.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,9 @@ class Params {
12681268
TRUE to print concordant sites per partition
12691269
*/
12701270
bool site_concordance_partition;
1271+
1272+
/** TRUE to print sCF for all sampled quartet */
1273+
bool print_cf_quartets;
12711274

12721275
/** TRUE to print trees associated with discordance factor 1 (NNI-1 tree) */
12731276
bool print_df1_trees;

0 commit comments

Comments
 (0)