Closed Jigyasa3 closed 4 years ago
Dear @Jigyasa3
you need to use multi2di
instead of di2multi
to remove polytomies.
You can use is.binary
to check that your tree is really binary afterwards.
Regards,
Klaus
Dear Klaus
Thank you for replying! I tried what you suggested. After using mutli2di on my tree, is.binary shows TRUE. But still the contMap command gives an error.
Code used- termite_tree<-read.tree("termite-mt-paper2014.contree") #read the tree file termite_treerooted<-root(termite_tree, "229-08CryptocercidaePaleo-arctic") #root the tree termite_tree2<-multi2di(termite_treerooted,random=TRUE) #remove polytomies is.binary(termite_tree2) #check if polytomies removed
nitro<-read.csv("nitrogen_matrix2") rownames(nitro)<-nitro$X nitro$X<-NULL nitro2<-as.matrix(nitro) #convert to matrix
obj<-contMap(termite_tree2,nitro2,res=200, lwd=1, outline=T, fsize= 0.3) plot(obj,lwd=7,xlim=c(-0.2,3.6))
my files Error- Error in if (x <= trans[1]) state <- names(trans)[1] else if (x >= trans[length(trans)]) state <- names(trans)[length(trans)] else { : missing value where TRUE/FALSE needed
What version of phytools are you running?
Hey @liamrevell
I am using phytools_0.6-60 on R studio version 3.3.0 running under Windows.
Dear @KlausVigo @liamrevell
I figured out the polytomy problem.
Now when I run is.binary() -its TRUE is.ultrametric() -its TRUE
Using version 0.6.60 of Phytools, I am getting the error- "Error in if (x <= trans[1]) state <- names(trans)[1] else if (x >= trans[length(trans)]) state <- names(trans)[length(trans)] else { : missing value where TRUE/FALSE needed"
I followed your blog post http://blog.phytools.org/2015/06/update-to-rerootingmethod-for-ancestral.html to remove zero length internal branches. But I still get the same error.
your 2014 blogpost says that this problem has been solved- [http://blog.phytools.org/2014/05/some-useful-updates-to-contmap.html]
Can you suggest what might be going wrong?
my data - [https://drive.google.com/drive/folders/1KNJlh1zAgrb61NFPYjv7phTlovK8Qp6G?usp=sharing]
my code- `termite_tree<-read.tree(file="coding_first_consensus_treepaper.nwk") #dated tree plotTree(termite_tree,ftype="i") is.ultrametric(termite_tree) #check if polytomies present is.rooted(termite_tree) #check if rooted is.binary(termite_tree)
ko_nitrogen<-read.csv("nitrogen_metabolism_logtransformed.csv") ko_nitrogen_matrix<-as.matrix(ko_nitrogen) #convert to matrix
d<-data.frame(label=termite_tree$tip.label) d$label<-as.character(d$label) rownames(d)<-d$label colnames(ko_nitrogen_matrix)<-rownames(d) #order the sample names
dst<-termite_tree dst$edge.length[dst$edge.length==0]<-max(nodeHeights(termite_tree))*1e-6
fit<-fastAnc(dst,ko_nitrogen_matrix,vars=TRUE,CI=TRUE) fit fit$CI[1,] range(ko_nitrogen_matrix)
obj<-contMap(dst,ko_nitrogen_matrix_t,plot=FALSE) `
This script doesn't work at all. Your data file also doesn't contain data for a character with species names. What am I missing?
@liamrevell I have a similar issue, I've been running phytools 0.6-99 and trying to use contMap on a fairly simple dataset and phylo, but I get the exact same error when running it:
> contMap(tree,AC$CW.BW)
Error in if (x <= trans[1]) state <- names(trans)[1] else if (x >= trans[length(trans)]) state <- names(trans)[length(trans)] else { :
missing value where TRUE/FALSE needed
The tree is binary but not ultrametric, but same happens if I use force.ultrametric():
> contMap(force.ultrametric(tree),AC$CW.BW)
Error in if (x <= trans[1]) state <- names(trans)[1] else if (x >= trans[length(trans)]) state <- names(trans)[length(trans)] else { :
missing value where TRUE/FALSE needed
Here's the complete code I'm using:
tree<-read.nexus("UphamPruned.nex")
tree<-drop.tip(tree,"Erinaceus_amurensis")
AllomCoef<-read.csv("AllomCoef.csv")
AllomCoef<-na.omit(AllomCoef)
AllomCoef$species<-gsub(" ", "_", AllomCoef$species, fixed=TRUE)
rownames(AllomCoef)<-AllomCoef$species
AllomCoef<-AllomCoef[match(tree$tip.label,rownames(AllomCoef)),]
AC<-AllomCoef[,4:10]
contMap(tree,AC$CW.BW)
Error in if (x <= trans[1]) state <- names(trans)[1] else if (x >= trans[length(trans)]) state <- names(trans)[length(trans)] else { :
missing value where TRUE/FALSE needed
I've had the same issue with different phylogenies and datasets for other projects recently, so I'd appreciate it if someone can explain to me what I'm doing wrong.
Thanks!
Hi @clopeza & @Jigyasa3 ,
you need to supply contMap
with a named vector. Subsetting like this AC$CW.BW
will loose the names. This should work for the example of @clopeza
CW.BW <- AC$CW.BW
names(CW.BW) <- rownames(AC)
contMap(tree, CW.BW)
Cheers, Klaus
Hey
I am working through the contMap function and I tried all the different versions of di2multi command on my tree to remove polytomies. [https://www.r-phylo.org/wiki/HowTo/DataTreeManipulation and http://blog.phytools.org/2012/11/mapping-reconstructed-value-of.html]. But its still not resolved, and I keep getting the following error-
Error in if (x <= trans[1]) state <- names(trans)[1] else if (x >= trans[length(trans)]) state <- names(trans)[length(trans)] else { : missing value where TRUE/FALSE needed
My codes-
termite_treerooted<-root(termite_tree,
212) termite_tree2<-di2multi(termite_treerooted,0.03) #remove polytomies plotTree(termite_tree2,fsize=0.6)obj<-contMap(termite_tree2,ko_level3_nitrogen_matrix,res=200, lwd=1, outline=T, fsize=
0.3)
Any suggestions?