Answers.Body: <p>It's difficult to answer this without example data.</p>
  <p>Before we go deeper please try the following.</p>
  <ol>
  <li>Do not use '-' in the taxa name, in old phylogenetics algorithms this was banned because it represented an indel. Thus change &quot;-&quot; to &quot;_&quot;. I do this all the time automatically.</li>
  <li>You are running an ancestral reconstruction with nucleotide sequences.
  In this case the first thing to do is run:</li>
  </ol>
  <pre><code>     iqtree -s sequence.fa -m MFP -msub nuclear -o example.tre
  </code></pre>
  <ol start="3">
  <li>Find the tree model <strong>and the tree</strong> and then input that model <strong>and the tree</strong> into the <code>asr</code> analysis via the <code>-m</code> and then run the exact model via:</li>
  </ol>
  <pre><code>    iqtree -s sequence.phy -m GTR+G -asr -te example.tre
  </code></pre>
  <p><code>-m GTR+G</code> is an example but its whatever output MFP gives you.</p>
  <p>Do you see the output tree of the first step is being loaded into the second step to ensure perfect alignment between alignment and tree?</p>
  <p>Also why is sequence.phy used when it's fasta format? phy stands for phylip format and those are mix of two different formats.</p>
  <p>I personally think this might be about taxa getting confused, but I'd need to see example data with a tree <strong>and</strong> I'd like to be sure the alignment and the tree perfectly match before a second debugging.</p>
  <hr />
  <h4>comments</h4>
  <p>Using phy direct from mafft. I would output the alignment as a fasta and do the whole thing again, unless you dump stuff here for inspection. phylip is the worst for taxa label bugs, the old phylip is terrible - that would absolutely in errors everywhere. The &quot;relaxed phylip format&quot; is still restrictive.
  I'd just use fasta, IQ-TREE will take it and it removes one more possibility. Honestly if you dumped your output here this could be cleared up quickly. This approach of try this try that isn't efficient</p>
  <hr />
  <h3>Post update</h3>
  <p>Okay the issues are:</p>
  <ol>
  <li>The format you are presenting is fasta</li>
  <li>The labels on the fasta are radically different to the alignment
  e.g.</li>
  </ol>
  <pre><code>&quot;&gt; Lophius-piscatorius_GP-Orthoebolavirus-restonense&quot;
  
  &gt; Lophius_piscatorius
  </code></pre>
  <ul>
  <li>The labels must be identical.</li>
  <li>There is a complex issue about concatenation for <strong>asr</strong> but the problem is the alignment in the first instance must be identical to the tree labels.</li>
  <li>Once the labels are identical and we have a clear result then complex stuff can begin</li>
  <li>There is another problem with the alignment itself, those indels are huge, at a guess this is a 18S style gene, the only gene I know with such massive indels.</li>
  <li>The quotation marks <strong>MUST</strong> be removed. There can be no quotation marks in the alignment file at all.</li>
  <li>There is a huge concern that you are not supplying an alignment file to the <strong>asr</strong> calculation. In that case the calculation will fail.</li>
  </ul>
  <p>Its complicated. Have a go with the above, but my suggestion is to ask someone to help you follow the above instructions. This is because you appear to be trying to perform <strong>ASR</strong> on an unaligned file and that will violate the safety limits of the calculation, in addition the labels are differing between alignment and tree. There is a post-manipulation that might be needed but this is a some way from that stage.</p>
  <p>Again unless the above instructions &quot;suddenly click&quot;, I recommend you ask for help from someone. The reason is that this is a complex calculation and IQ-TREE is not the simplest way to perform this calculation.</p>
  <hr />
  <p>My personal suggestion here is to use Beast (this maybe in Beast2, it's definitely in Beast). I know this is not quite the answer you wanted but there is a point and click option for ASR. You just have to find where the checkbox is within Beauti GUI (I don't remember where it is). The advantage is it will do everything for you in one step, you just need to use a &quot;lognormal&quot; model, under something generic like GTR+Gamma. The alignment format of nexus (or Newick) can be obtained from MAFFT.</p>
  <p>With Beast there is no chance of getting a conflict between the alignment file and tree file, Beast does it all at once and the nexus/Newick (file format needed) doesn't have weird issues like &quot;_&quot; versus &quot;-&quot; and there's no alternative formats like Phylip.</p>
  <p>It is certainly worth looking and would simplify things.</p>
  <p>My concern is - if you get your tree wrong - everything goes wrong no matter how right you've done it.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-31T19:11:17.910Z
Answers.Text: Thank you. That partially solves it. To answer your question: I'm using an alignment (phy format from mafft), because the sequences are of different lengths. The approach you suggested does work for producing an asr but this one is then sorted by the tree of the sequences rather than grouped by the species tree.
Answers.UserDisplayName: Alice de Sampaio Kalkuhl
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-31T19:22:49.310Z
Answers.Text: I see @AlicedeSampaioKalkuhl update
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-31T19:36:44.587Z
Answers.Text: Using a fasta instead of a phylip format sadly still results in sequences from one species scattered across the tree in the iqtree -s sequence.fa -m MFP -msub nuclear -o example.tre step. A very clunky solution would be to rerun everything with one sequence per species per run but apart from that I'm not sure.
Answers.UserDisplayName: Alice de Sampaio Kalkuhl
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-31T16:57:07.267Z
Answers.LastActivityDate: 2025-01-01T23:31:02.933Z
Answers.LastEditDate: 2025-01-01T23:31:02.933Z
Answers.UserDisplayName: M__
Body: <p>I have an alignment file of DNA sequences with fasta headers in the format</p>
  <pre><code>&gt;species-name_protein-name
  </code></pre>
  <p>and a Newick-format (.nwk) tree of the species. The DNA sequences are aligned, because they differ in length.</p>
  <p>I am trying to run</p>
  <pre><code>iqtree -s sequence.phy -m MFP -msub nuclear -asr -te species.nwk
  </code></pre>
  <p>but run into two problems:</p>
  <ul>
  <li>If I just run this, I end up with the protein names not matching the
  guide tree.</li>
  <li>If I change the protein names to the species names, I
  have duplicates.</li>
  </ul>
  <p>How do I get IQ-TREE to link the guide tree and the alignment correctly?</p>
  <p>The main goal here is to obtain the -asr output.
  Any solutions including using a different software than IQ-TREE to find the asr are welcome.</p>
  <p>The species.nwk file contains a tree of (in this case anglerfish) with branch lengths and species names:</p>
  <pre><code>((Lophius_americanus:6.16014000,Lophius_piscatorius:6.16014000)'14':69.50036000,(Antennarius_maculatus:46.40414000,(Antennarius_striatus:42.06712000,Brachionichthys_hirsutus:42.06712000)'13':4.33702000)'25':29.25636000);
  </code></pre>
  <p>The first couple of sequences from the DNA sequences are</p>
  <pre><code>&gt;Lophius-piscatorius_GP-Orthoebolavirus-restonense
  AGAGTGGCTCACTCCCTACCCAAGAAGCCTCAGTTGAAGCGGGTACGGCGAGAAGATTCCGATATCTTCG
  GGACTCATCACCAATCCCCTTTCAAGAACGTACTAGGCCCCCTCCTTCCTTTTTACGGCGTCATGTCTGC
  CTTAGATCAAATTGCCGATCTGTCTCATGCAATCGAGGTCATAGCGAATGAAACCGGTAAGGCTCTCCTG
  ATCATCTCCAGTGAACTCGCCTCAGTCAGACTTCTGGCTTTACAGAACAGAGCCGCTTTGGATTTTCTCC
  TGGCAGCCCAAGGAGGAACGTGTGCCGTCATCGGTTCTGAATGTTGCACCTTTGTGCCTGAATATAATGC
  TACCATTGCTGATATAGTCAATCACCTC
  </code></pre>
  <p>in the original fasta and</p>
  <pre><code>&gt;Lophius-piscatorius_GP-Orthoebolavirus-restonense
  ------------------------------------agagtggctcactccct------------accca
  agaagcctcag-------------------ttgaagc-----gggtacggcgagaagattcc--------
  --------------gatatcttcgggactcatcaccaatcccctttcaagaacgtactaggccccctcct
  tcctttttacggcgtcatgtctgcctta------------------------------gatcaaattgcc
  gatctgtctcatgcaatcgaggtcatagcgaatgaaaccggtaaggctctcctgatcatctcc---agtg
  aactcgcctcagtcagacttctggctttacagaacagagccgctttggattttctcctggcagcccaagg
  aggaacgtgtgccgtcatcggttctgaatgttgcacctttgtgcctgaatataatgctaccattgctgat
  atagtcaatcacctc-------------------------------------------------------
  ----------------------------------------------------------------------
  -
  </code></pre>
  <p>in the alignment used here.</p>
  <p>I would like to use <code>IQ-TREE -asr</code> to infer the ancestral state of the sequences in the fasta grouped by the branches in the guide tree. If this is possible, how do I get IQ-TREE to match the sequences to the guide tree? If this isn't possible, what other software could I use?</p>
  <p><a href="https://drive.google.com/drive/folders/1uHs2J2RwzLtlTD71CU-BTH82gXd97oWL?usp=drive_link" rel="nofollow noreferrer">example files</a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-12-31T16:24:13.767Z
Comments.Text: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Comments.UserDisplayName: Community
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-12-31T20:46:14.007Z
Comments.Text: Thanks updated post below.
Comments.UserDisplayName: M__
Tags: <phylogenetics><phylogeny><sequence-alignment>
Title: How do I group sequences by species with a guide tree in IQ-TREE for -asr?
ThreadText: # How do I group sequences by species with a guide tree in IQ-TREE for -asr?
  
  (Asked by: username_0 on 2024-12-31)
  
  I have an alignment file of DNA sequences with fasta headers in the format
  
  ```
  >species-name_protein-name
  
  ```
  
  and a Newick-format (.nwk) tree of the species. The DNA sequences are aligned, because they differ in length.
  
  I am trying to run
  
  ```
  iqtree -s sequence.phy -m MFP -msub nuclear -asr -te species.nwk
  
  ```
  
  but run into two problems:
  
  * If I just run this, I end up with the protein names not matching the
    guide tree.
  * If I change the protein names to the species names, I
    have duplicates.
  
  How do I get IQ-TREE to link the guide tree and the alignment correctly?
  
  The main goal here is to obtain the -asr output.
  Any solutions including using a different software than IQ-TREE to find the asr are welcome.
  
  The species.nwk file contains a tree of (in this case anglerfish) with branch lengths and species names:
  
  ```
  ((Lophius_americanus:6.16014000,Lophius_piscatorius:6.16014000)'14':69.50036000,(Antennarius_maculatus:46.40414000,(Antennarius_striatus:42.06712000,Brachionichthys_hirsutus:42.06712000)'13':4.33702000)'25':29.25636000);
  
  ```
  
  The first couple of sequences from the DNA sequences are
  
  ```
  >Lophius-piscatorius_GP-Orthoebolavirus-restonense
  AGAGTGGCTCACTCCCTACCCAAGAAGCCTCAGTTGAAGCGGGTACGGCGAGAAGATTCCGATATCTTCG
  GGACTCATCACCAATCCCCTTTCAAGAACGTACTAGGCCCCCTCCTTCCTTTTTACGGCGTCATGTCTGC
  CTTAGATCAAATTGCCGATCTGTCTCATGCAATCGAGGTCATAGCGAATGAAACCGGTAAGGCTCTCCTG
  ATCATCTCCAGTGAACTCGCCTCAGTCAGACTTCTGGCTTTACAGAACAGAGCCGCTTTGGATTTTCTCC
  TGGCAGCCCAAGGAGGAACGTGTGCCGTCATCGGTTCTGAATGTTGCACCTTTGTGCCTGAATATAATGC
  TACCATTGCTGATATAGTCAATCACCTC
  
  ```
  
  in the original fasta and
  
  ```
  >Lophius-piscatorius_GP-Orthoebolavirus-restonense
  ------------------------------------agagtggctcactccct------------accca
  agaagcctcag-------------------ttgaagc-----gggtacggcgagaagattcc--------
  --------------gatatcttcgggactcatcaccaatcccctttcaagaacgtactaggccccctcct
  tcctttttacggcgtcatgtctgcctta------------------------------gatcaaattgcc
  gatctgtctcatgcaatcgaggtcatagcgaatgaaaccggtaaggctctcctgatcatctcc---agtg
  aactcgcctcagtcagacttctggctttacagaacagagccgctttggattttctcctggcagcccaagg
  aggaacgtgtgccgtcatcggttctgaatgttgcacctttgtgcctgaatataatgctaccattgctgat
  atagtcaatcacctc-------------------------------------------------------
  ----------------------------------------------------------------------
  -
  
  ```
  
  in the alignment used here.
  
  I would like to use `IQ-TREE -asr` to infer the ancestral state of the sequences in the fasta grouped by the branches in the guide tree. If this is possible, how do I get IQ-TREE to match the sequences to the guide tree? If this isn't possible, what other software could I use?
  
  [example files](https://drive.google.com/drive/folders/1uHs2J2RwzLtlTD71CU-BTH82gXd97oWL?usp=drive_link)
  
  **Tags:** phylogenetics, phylogeny, sequence-alignment
  
  > **Comments:**
  > **username_1**: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.  
  > **username_2**: Thanks updated post below.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2024-12-31. Score: 0
  
  It's difficult to answer this without example data.
  
  Before we go deeper please try the following.
  
  1. Do not use '-' in the taxa name, in old phylogenetics algorithms this was banned because it represented an indel. Thus change "-" to "\_". I do this all the time automatically.
  2. You are running an ancestral reconstruction with nucleotide sequences.
     In this case the first thing to do is run:
  
  ```
       iqtree -s sequence.fa -m MFP -msub nuclear -o example.tre
  
  ```
  
  3. Find the tree model **and the tree** and then input that model **and the tree** into the `asr` analysis via the `-m` and then run the exact model via:
  
  ```
      iqtree -s sequence.phy -m GTR+G -asr -te example.tre
  
  ```
  
  `-m GTR+G` is an example but its whatever output MFP gives you.
  
  Do you see the output tree of the first step is being loaded into the second step to ensure perfect alignment between alignment and tree?
  
  Also why is sequence.phy used when it's fasta format? phy stands for phylip format and those are mix of two different formats.
  
  I personally think this might be about taxa getting confused, but I'd need to see example data with a tree **and** I'd like to be sure the alignment and the tree perfectly match before a second debugging.
  
  ---
  
  #### comments
  
  Using phy direct from mafft. I would output the alignment as a fasta and do the whole thing again, unless you dump stuff here for inspection. phylip is the worst for taxa label bugs, the old phylip is terrible - that would absolutely in errors everywhere. The "relaxed phylip format" is still restrictive.
  I'd just use fasta, IQ-TREE will take it and it removes one more possibility. Honestly if you dumped your output here this could be cleared up quickly. This approach of try this try that isn't efficient
  
  ---
  
  ### Post update
  
  Okay the issues are:
  
  1. The format you are presenting is fasta
  2. The labels on the fasta are radically different to the alignment
     e.g.
  
  ```
  "> Lophius-piscatorius_GP-Orthoebolavirus-restonense"
  
  > Lophius_piscatorius
  
  ```
  
  * The labels must be identical.
  * There is a complex issue about concatenation for **asr** but the problem is the alignment in the first instance must be identical to the tree labels.
  * Once the labels are identical and we have a clear result then complex stuff can begin
  * There is another problem with the alignment itself, those indels are huge, at a guess this is a 18S style gene, the only gene I know with such massive indels.
  * The quotation marks **MUST** be removed. There can be no quotation marks in the alignment file at all.
  * There is a huge concern that you are not supplying an alignment file to the **asr** calculation. In that case the calculation will fail.
  
  Its complicated. Have a go with the above, but my suggestion is to ask someone to help you follow the above instructions. This is because you appear to be trying to perform **ASR** on an unaligned file and that will violate the safety limits of the calculation, in addition the labels are differing between alignment and tree. There is a post-manipulation that might be needed but this is a some way from that stage.
  
  Again unless the above instructions "suddenly click", I recommend you ask for help from someone. The reason is that this is a complex calculation and IQ-TREE is not the simplest way to perform this calculation.
  
  ---
  
  My personal suggestion here is to use Beast (this maybe in Beast2, it's definitely in Beast). I know this is not quite the answer you wanted but there is a point and click option for ASR. You just have to find where the checkbox is within Beauti GUI (I don't remember where it is). The advantage is it will do everything for you in one step, you just need to use a "lognormal" model, under something generic like GTR+Gamma. The alignment format of nexus (or Newick) can be obtained from MAFFT.
  
  With Beast there is no chance of getting a conflict between the alignment file and tree file, Beast does it all at once and the nexus/Newick (file format needed) doesn't have weird issues like "\_" versus "-" and there's no alternative formats like Phylip.
  
  It is certainly worth looking and would simplify things.
  
  My concern is - if you get your tree wrong - everything goes wrong no matter how right you've done it.
  
  > **Comments:**
  > **username_0**: Thank you. That partially solves it. To answer your question: I'm using an alignment (phy format from mafft), because the sequences are of different lengths. The approach you suggested does work for producing an asr but this one is then sorted by the tree of the sequences rather than grouped by the species tree.  
  > **username_2**: I see @username_0 update  
  > **username_0**: Using a fasta instead of a phylip format sadly still results in sequences from one species scattered across the tree in the iqtree -s sequence.fa -m MFP -msub nuclear -o example.tre step. A very clunky solution would be to rerun everything with one sequence per species per run but apart from that I'm not sure.  
  
  ---
  
  