<p>Specific questions</p>

<ol>
<li>When there are multiple hsps in one alignment then which one do I include in the tree?</li>
</ol>

<p>You can included them all because NJ is not computer intensive, so running loads is fine. You can remove identical sequences if you want either programmatically (these days I use pandas Python) or something like RAxML. Its honestly not critical for an NJ tree (and in fact the more the better) providing you can read the labels. A tree viewing program such as FigTree allows you to collapse clades to make the tree more readable to users.</p>

<ol start="2">
<li>If two sequences map to two different parts of the query sequence and do not overlap, then what should I do?</li>
</ol>

<p>Hmmmm.... good question. Do 3 alignments one with one e.g. 5' fragment, the other with the 3' fragment and attempt a joint alignment. Under other non-pairwise tree buidling algorithms this would be disasterous, NJ gets around the problem because it is pairwise. HOWEVER, ask yourself whether your feel the resulting tree is meaningful, I would argue not because there are no homologous sites between the 5' and 3' partial sequences and phylogeny models point mutations. NJ will give you a tree however and will even bootstrap it. </p>

<p>Generic questions, you can actually do this as one of the new features of NCBI's Blast</p>

<ul>
<li>Go to Blast here, <a href="https://blast.ncbi.nlm.nih.gov/Blast.cgi" rel="nofollow noreferrer">https://blast.ncbi.nlm.nih.gov/Blast.cgi</a></li>
<li>Enter your sequence into the box (it doesn't accept PDB codes alone)</li>
<li>Enter the protein database - when I first did this calculation I used SwissProt, thinking there would be alot of sequences - I then used "nr"</li>
<li>Under the algorithm parameters enter "50" (default is too many)</li>
<li>Hit "Blast"</li>
<li>Once the search is complete at the top of the page are the hyperlinks: "Other reports:       </li>
<li>Search Summary [Taxonomy reports] [Distance tree of results]"</li>
<li>Click on "Distance tree of results"</li>
<li>The tree page will load automatically, automatically aligning your sequences and producing, in this case a parsimony based tree, but there is also the option of a nj tree (recommended) ....</li>
<li>Click "Tool", "Download", "PDF" ...</li>
</ul>

<p>You can generate a distance and matrix and/or perform a neighbor-joining phylogeny in <a href="https://www.megasoftware.net" rel="nofollow noreferrer">MEGA10</a> and using Timura 3-parameter model is a good model. The bootstrap option is important. Its very easy to use, the format is a bit weird</p>

<pre><code># MEGA
Title: Stuff
# Sequence1
ACTAGACGT
# Sequence2
ACCTTAGGA

etc ...
</code></pre>

CC BY-SA 4.0
2019-09-12T13:04:33.280Z
2019-09-12T13:18:30.180Z
2019-09-12T13:18:30.180Z
M__
<p>I'm trying to plot a simple distance tree of my blastn output with nj (like the tree view on NCBI). From what I understood, what I think I should do is </p>

<ol>
<li>extract all the hsps from each alignment</li>
<li>re-align them using MUSCLE </li>
<li>generate a distance matrix from the msa file</li>
<li>plot the tree using nj</li>
</ol>

<p>However, there is a couple problems I am not sure about:</p>

<p>1) When there are multiple hsps in one alignment then which one do I include in the tree?</p>

<p>2) If two sequences map to two different parts of the query sequence and do not overlap, then what should I do?</p>

CC BY-SA 4.0
2019-09-09T11:47:33.703Z
You can do this directly in blast
M__
CC BY-SA 4.0
2019-09-09T12:17:25.693Z
Anyway you have the gist but load the MSA into Mega as an easy way to build a distance tree. I'll forward details later
M__
CC BY-SA 4.0
2019-09-09T12:43:49.197Z
@MichaelG. Right, that would be very helpful thanks. I'll take a look myself meanwhile.
David Young
CC BY-SA 4.0
2019-09-09T21:50:26.963Z
Hi @DavidYoung I've not managed to answer this today. Promise a comprehensive answer late tomorrow.
M__
CC BY-SA 4.0
2019-09-10T11:14:59.230Z
@MichaelG. Sure, thanks.
David Young
CC BY-SA 4.0
2019-09-11T09:03:07.580Z
@MichaelG. I should add that, the NCBI tree view is what I'm trying to get. But as I am using the NcbiblastnCommandline wrapper with my own custom nr database, I am trying to reproduce the tree view myself.
David Young
<ngs><blast><blastn>
Plotting distance tree from blastn output
# Plotting distance tree from blastn output

(Asked by: username_0 on 2019-09-09)

I'm trying to plot a simple distance tree of my blastn output with nj (like the tree view on NCBI). From what I understood, what I think I should do is

1. extract all the hsps from each alignment
2. re-align them using MUSCLE
3. generate a distance matrix from the msa file
4. plot the tree using nj

However, there is a couple problems I am not sure about:

1) When there are multiple hsps in one alignment then which one do I include in the tree?

2) If two sequences map to two different parts of the query sequence and do not overlap, then what should I do?

**Tags:** ngs, blast, blastn
> **Comments:**
> **username_1**: You can do this directly in blast  
> **username_1**: Anyway you have the gist but load the MSA into Mega as an easy way to build a distance tree. I'll forward details later  
> **username_0**: @MichaelG. Right, that would be very helpful thanks. I'll take a look myself meanwhile.  
> **username_1**: Hi @DavidYoung I've not managed to answer this today. Promise a comprehensive answer late tomorrow.  
> **username_0**: @MichaelG. Sure, thanks.  
> **username_0**: @MichaelG. I should add that, the NCBI tree view is what I'm trying to get. But as I am using the NcbiblastnCommandline wrapper with my own custom nr database, I am trying to reproduce the tree view myself.  

---

## 1 answers

### Answer by username_1 on 2019-09-12. Score: 1

Specific questions

When there are multiple hsps in one alignment then which one do I include in the tree?

You can included them all because NJ is not computer intensive, so running loads is fine. You can remove identical sequences if you want either programmatically (these days I use pandas Python) or something like RAxML. Its honestly not critical for an NJ tree (and in fact the more the better) providing you can read the labels. A tree viewing program such as FigTree allows you to collapse clades to make the tree more readable to users.

If two sequences map to two different parts of the query sequence and do not overlap, then what should I do?

Hmmmm.... good question. Do 3 alignments one with one e.g. 5' fragment, the other with the 3' fragment and attempt a joint alignment. Under other non-pairwise tree buidling algorithms this would be disasterous, NJ gets around the problem because it is pairwise. HOWEVER, ask yourself whether your feel the resulting tree is meaningful, I would argue not because there are no homologous sites between the 5' and 3' partial sequences and phylogeny models point mutations. NJ will give you a tree however and will even bootstrap it. 
Generic questions, you can actually do this as one of the new features of NCBI's Blast

Go to Blast here, https://blast.ncbi.nlm.nih.gov/Blast.cgi
Enter your sequence into the box (it doesn't accept PDB codes alone)
Enter the protein database - when I first did this calculation I used SwissProt, thinking there would be alot of sequences - I then used "nr"
Under the algorithm parameters enter "50" (default is too many)
Hit "Blast"
Once the search is complete at the top of the page are the hyperlinks: "Other reports:       
Search Summary [Taxonomy reports] [Distance tree of results]"
Click on "Distance tree of results"
The tree page will load automatically, automatically aligning your sequences and producing, in this case a parsimony based tree, but there is also the option of a nj tree (recommended) ....
Click "Tool", "Download", "PDF" ...

You can generate a distance and matrix and/or perform a neighbor-joining phylogeny in MEGA10 and using Timura 3-parameter model is a good model. The bootstrap option is important. Its very easy to use, the format is a bit weird
# MEGA
Title: Stuff
# Sequence1
ACTAGACGT
# Sequence2
ACCTTAGGA

etc ...


---

