# 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="https://498238201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWuHhstIreJ3jFvE4gQ3y%2Fuploads%2FTFrblw8FSmIeH2lHaJNh%2Fimage.png?alt=media&#x26;token=926aa6aa-cde4-4987-8834-6475408c03bc" 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="https://498238201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWuHhstIreJ3jFvE4gQ3y%2Fuploads%2FDPW9JXA53QXrjilEpMfu%2Fimage.png?alt=media&#x26;token=7867e0e2-c081-4500-93a1-f4c9b1a84182" alt=""><figcaption></figcaption></figure>
