Hi Sean,

  It's possible to add brackets but not with using ape. It's a case of
string manipulation. Regular expressions are your friend here:

a <- '((Host a:4,Host b:4):2,(Host c:4, (Host d:4, Host e:4):4):3):1;'
b <-  gsub("([0-9])", "[\\1]", a)
cat(b, file="JaneInput.tre", sep="\n")

  The regular expression I used here assume that all numbers in your tree
string are branch lengths (no bootstrap values, or no numbers in your
species names). If it's not the case you'll need to build a more elaborate
expression.

  Cheers,
  -- François




On Wed, Feb 19, 2014 at 12:51 PM, Sean Downey <s...@codexdata.com> wrote:

> I am trying to write an input file for a cophylogeny analysis with Jane.
> Jane deviates from the Newick standard and required brackets around edge
> length. E.g.,
>
> t<-((Host a:[4],Host b:[4]):[2],(Host c:[4], (Host d:[4], Host
> e:[4]):[4]):[3]):[1];
>
> Is there a simple way to add those brackets.The following does not work
> because write.tree expected numeric edge.lengths:
>
>
> a<-'((Host a:4,Host b:4):2,(Host c:4, (Host d:4, Host e:4):4):3):1;'
> b<-read.tree(text=t)
> c<-paste('[',b$edge.length,']',sep='')
> class(b$edge.length) #numeric
> b$edge.length<-c
> class(b$edge.length) #character
> write.tree(b)
> #Error in sprintf(f.d, phy$edge.length[i]) :
> # invalid format '%.10g'; use format %s for character objects
>
> Thanks much,
> Sean
>
> --
> Dr. Sean S. Downey
> Assistant Professor
> Anthropology Department
> University of Maryland
> 1106 Woods Hall
> College Park, MD 20742
> s...@codexdata.com <mailto:s...@codexdata.com>
> http://www.anth.umd.edu/facultyprofile/Downey/Sean
> Office: 301-405-1427
>
> Students wanted: Applications due annually on Dec 15.
> http://terpconnect.umd.edu/~sdowney2/Sean_Downey/Opportunities.html <
> http://terpconnect.umd.edu/%7Esdowney2/Sean_Downey/Opportunities.html>
> http://www.anth.umd.edu/content/graduate-admissions
>
> _______________________________________________
> R-sig-phylo mailing list - R-sig-phylo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
> Searchable archive at http://www.mail-archive.com/r-
> sig-ph...@r-project.org/
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/

Reply via email to