Answers.Body: <p>the fact is that the present upgma tree as a midpoint rooting here, corresponding to node 46.</p>
  
  <pre><code>getRoot(upgma.a)
  </code></pre>
  
  <p>so for this kind of tree, I recommend you to use the midpoint() rooting function.</p>
  
  <pre><code>pars.a &lt;- optim.parsimony(upgma.a, a.phydat)
  pars.a&lt;-acctran(pars.a, a.phydat)
  plot(midpoint(pars.a))
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-15T08:33:22.153Z
Answers.Text: let me try it out and how do we decide which rooting to use? based on observation after plotting
Answers.UserDisplayName: kcm
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-15T08:39:08.570Z
Answers.Text: yes visual inspection seems relevant. It totally depends of your input data, whether your sequences are strongly conserved (without evident outgroup) or more divergent. I think you may write a control loop after constructing the upgma tree, by checking if the ouptput of `getRoot(upgma.a)` returns a node or a tip. If it is a node, then it might proceed with the `midpoint()` version.
Answers.UserDisplayName: thomas duge de bernonville
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-15T08:45:26.850Z
Answers.Text: I haven't tried with ML but this mid point should work with ML as well?
Answers.UserDisplayName: kcm
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-15T08:52:01.183Z
Answers.Text: yes, probably! it is probably a more universal solution, but not the necessarily the best one!
Answers.UserDisplayName: thomas duge de bernonville
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-15T09:13:13.440Z
Answers.Text: last time i was looking to compare tress which you had suggested turn them into dedrogram and then for comparison you suggested something this '
  pars.a.rooted<-root(pars.a, outgroup="ABN10911", resolve.root=T)
  pars.a.rooted.dd<-as.dendrogram(force.ultrametric(pars.a.rooted))' how to do the same  here shall i put node 46 as the outgroup?
Answers.UserDisplayName: kcm
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-15T09:15:05.607Z
Answers.Text: It won't work because you have only 45 tip labels, if I remember well. I think you may run: `pars.a.rooted.dd<-as.dendrogram(force.ultrametric(midpoint(pars.a)))`
Answers.UserDisplayName: thomas duge de bernonville
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-15T09:22:51.953Z
Answers.Text: works perfectly fine for parsimony and...for pars for ML i m doing this rectify me if im wrong "ml.a.rooted.dd<-as.dendrogram(force.ultrametric(midpoint(fit$tree)))
  "
Answers.UserDisplayName: kcm
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-15T09:26:52.343Z
Answers.Text: seems ok. It is true that in the previous code, we used  `root(midpoint(fit$tree), outgroup="AAA64460", resolve.root=T)` to force using a given tip as root. Using `force.ultrametric(midpoint(pars.a))` should work too indeed.
Answers.UserDisplayName: thomas duge de bernonville
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-15T10:53:50.837Z
Answers.Text: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/109380/discussion-between-krushnach-chandra-and-thomas-duge-de-bernonville).
Answers.UserDisplayName: kcm
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-15T08:22:06.550Z
Answers.LastActivityDate: 2020-06-15T08:22:06.550Z
Answers.UserDisplayName: thomas duge de bernonville
Body: <p>Im trying to find the out-group in the alignment my data files <a href="https://drive.google.com/file/d/1N60Va-smHbsmCePOnkVL_jjAaxCagZWf/view?usp=sharing" rel="nofollow noreferrer">file a</a> and  <a href="https://drive.google.com/file/d/1_E0Ozgv_7Wtxr9AKPrvW606IWH99hIPb/view?usp=sharing" rel="nofollow noreferrer">file b</a> both the case i'm getting NA when i run this     <code>pars.a$tip.label[pars.a$edge[which.max(pars.a$edge.length),2]]</code></p>
  
  <p>I tried NJ instead of upgma i do still get NA not sure what is the issue ,but at the same time when i used other alignment file <a href="https://drive.google.com/file/d/10P6qF3nrXlnm-tUONK5bTAPqR4wapX-q/view?usp=sharing" rel="nofollow noreferrer">with 50 sequence </a> works fine.</p>
  
  <pre><code>a&lt;-read.alignment("abhi_seq/final_abhi_tempa1.fas", format="fasta")
  a.phydat&lt;-as.phyDat(a)
  dist.a.phydat&lt;-dist.dna(as.DNAbin(a.phydat))
  upgma.a&lt;-upgma(dist.a.phydat)
  parsimony(upgma.a,a.phydat)
  pars.a &lt;- optim.parsimony(upgma.a, a.phydat)
  pars.a&lt;-acctran(pars.a, a.phydat)
  pars.a<span class="math-container">$tip.label[pars.a$</span>edge[which.max(pars.a$edge.length),2]]
  </code></pre>
  
Tags: <r><phylogenetics>
Title: Finding out-group in unrooted tree
ThreadText: # Finding out-group in unrooted tree
  
  (Asked by: username_0 on 2020-06-15)
  
  Im trying to find the out-group in the alignment my data files [file a](https://drive.google.com/file/d/1N60Va-smHbsmCePOnkVL_jjAaxCagZWf/view?usp=sharing) and [file b](https://drive.google.com/file/d/1_E0Ozgv_7Wtxr9AKPrvW606IWH99hIPb/view?usp=sharing) both the case i'm getting NA when i run this `pars.a$tip.label[pars.a$edge[which.max(pars.a$edge.length),2]]`
  
  I tried NJ instead of upgma i do still get NA not sure what is the issue ,but at the same time when i used other alignment file [with 50 sequence](https://drive.google.com/file/d/10P6qF3nrXlnm-tUONK5bTAPqR4wapX-q/view?usp=sharing)  works fine.
  
  ```
  a<-read.alignment("abhi_seq/final_abhi_tempa1.fas", format="fasta")
  a.phydat<-as.phyDat(a)
  dist.a.phydat<-dist.dna(as.DNAbin(a.phydat))
  upgma.a<-upgma(dist.a.phydat)
  parsimony(upgma.a,a.phydat)
  pars.a <- optim.parsimony(upgma.a, a.phydat)
  pars.a<-acctran(pars.a, a.phydat)
  pars.a$tip.label[pars.a$edge[which.max(pars.a$edge.length),2]]
  
  ```
  
  **Tags:** r, phylogenetics
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-06-15. Score: 1 | Accepted answer
  
  the fact is that the present upgma tree as a midpoint rooting here, corresponding to node 46.
  
  ```
  getRoot(upgma.a)
  
  ```
  
  so for this kind of tree, I recommend you to use the midpoint() rooting function.
  
  ```
  pars.a <- optim.parsimony(upgma.a, a.phydat)
  pars.a<-acctran(pars.a, a.phydat)
  plot(midpoint(pars.a))
  
  ```
  
  > **Comments:**
  > **username_0**: let me try it out and how do we decide which rooting to use? based on observation after plotting  
  > **username_1**: yes visual inspection seems relevant. It totally depends of your input data, whether your sequences are strongly conserved (without evident outgroup) or more divergent. I think you may write a control loop after constructing the upgma tree, by checking if the ouptput of `getRoot(upgma.a)` returns a node or a tip. If it is a node, then it might proceed with the `midpoint()` version.  
  > **username_0**: I haven't tried with ML but this mid point should work with ML as well?  
  > **username_1**: yes, probably! it is probably a more universal solution, but not the necessarily the best one!  
  > **username_0**: last time i was looking to compare tress which you had suggested turn them into dedrogram and then for comparison you suggested something this ' pars.a.rooted<-root(pars.a, outgroup="ABN10911", resolve.root=T) pars.a.rooted.dd<-as.dendrogram(force.ultrametric(pars.a.rooted))' how to do the same  here shall i put node 46 as the outgroup?  
  > **username_1**: It won't work because you have only 45 tip labels, if I remember well. I think you may run: `pars.a.rooted.dd<-as.dendrogram(force.ultrametric(midpoint(pars.a)))`  
  > **username_0**: works perfectly fine for parsimony and...for pars for ML i m doing this rectify me if im wrong "ml.a.rooted.dd<-as.dendrogram(force.ultrametric(midpoint(fit$tree))) "  
  > **username_1**: seems ok. It is true that in the previous code, we used  `root(midpoint(fit$tree), outgroup="AAA64460", resolve.root=T)` to force using a given tip as root. Using `force.ultrametric(midpoint(pars.a))` should work too indeed.  
  > **username_0**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/109380/discussion-between-krushnach-chandra-and-username_1).  
  
  ---
  
  