# Neighbor Joining method in Phylip

To carry out phylogenetic analysis it is important to begin with an alignment in which all gap-containing positions have been removed.

```
CLUSTAL 2.0.12 multiple sequence alignment


zf_12a1_a       VADLVFLVDGSWSVGRENFRFIRSFIGA--
zf_12a1_b       KADLVFLIDGSWSIGDDSFAKVRQFVFS--
hs_22a1         HYDLVFLLDTSSSVGKEDFEKVRQWVAN--
hs_a11          YMDIVIVLDGSNSIYP--WVEVQHFLINIL
zf_a11          YMDIVIVLDGSNSIYP--WNEVQDFLINIL
                  *:*:::* * *:    :  :: ::    
```

* This can be accomplished using the [gap strip](http://www.hiv.lanl.gov/content/sequence/GAPSTREEZE/strip_ready.html) tool.
* There is a bug in the process but the gap-free alignment can be loaded into clustalX, the the save sequences as "Phylip" format function can be used.

```
        5  26
zf_12a1_a  VADLVFLVDGSWSVGRFRFIRSFIGA
zf_12a1_b  KADLVFLIDGSWSIGDFAKVRQFVFS
hs_22a1    HYDLVFLLDTSSSVGKFEKVRQWVAN
hs_a11     YMDIVIVLDGSNSIYPWVEVQHFLIN
zf_a11     YMDIVIVLDGSNSIYPWNEVQDFLIN
```

* The correct alignment can be created with a text editor. Another version of it is in your clustal/phylip folder called tiny\_nogap.phy
* enter the phylip folder:

```
cd /home/USERNAME/clustal/phylip/
```

* The first step to to create the bootstrap replicates. This is done with the phylip application seqboot.

```
seqboot
```

* when prompted, provide the name "tiny\_nogap.phy".
* At the interactive menu:
  * change option r to 10 for 10 replicates. NOTE: normally the number used is 1000 for neighbor
  * press Y to accept changes
  * enter 111 as random number seed.

```
cat outfile
```

* Move outfile to tiny\_nogap.seqboot

```
mv outfile tiny_nogap.seqboot
```

* The next step is to calculate the distances between the sequences in each replicate. This is done with protdist

```
protdist
```

* when prompted, provide the name "tiny\_nogap.seqboot".
* At the interactive menu:
  * change option m to d for datasets and 10 for number of replicates.
  * press Y to accept changes

```
cat outfile
```

* Rename the outfile

```
mv outfile tiny_nogap.protdist
```

* Build the neighbor-joining tree for each distance matrix wth neighbor:

```
neighbor
```

* when prompted, provide the name "tiny\_nogap.protdist".
* At the interactive menu:
  * change option m to 10 for number of replicates.
  * enter 111 for random number seed
  * press Y to accept changes

```
cat outfile
cat outtree
```

* Rename the output:

```
mv outtree tiny_nogap.neightree
mv outfile tiny_nogap.neighout
```

* Create a consensus version of the outtree file with consense:

```
consense
```

* when prompted, provide the name "tiny\_nogap.neightree".
* At the interactive menu, default settings are ok so type "Y"

```
cat outfile
cat outtree
```

* Rename the output:

```
mv outtree tiny_nogap.neigh.constree
mv outfile tiny_nogap.neigh.consout
```

* Draw the tree with drawtree:

```
drawtree
```

* when prompted for a file enter tiny\_nogap.neigh.constree
* when prompted for a fontfile, enter:

```
/net/n3/data/Teaching/IAP_2010_day3/clustal/font1
```

```
NOTE: a series of different fonts are available within the phylip installation directory
```

* At the interactive menu, select option V, then N to turn off preview. Then option Y
* This results in a postscript plot of the tree. rename it to:

```
mv plotfile tiny_nogap.tree.ps
```

* The contents of this file can be viewed with photo software like but it looks like this:

<figure><img src="/files/c8MWiOU3W7HMSkJjidLK" alt=""><figcaption></figcaption></figure>

* The bootstrap values can be viewed in the file tiny\_nogap.neigh.constree. Or graphicall by opening this file with [NJ-plot](http://pbil.univ-lyon1.fr/software/njplot.html). With branch lengths selected, the view looks like this:

<figure><img src="/files/TmvlaxDmpIZDmri8byWK" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://igb.mit.edu/bioinformatics-topics/tasks-bioinformatics-methods/phylogenetic-analysis/neighbor-joining-method-in-phylip.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
