We will be offering mothur and R workshops throughout 2019. Learn more.
Once a distance matrix gets read into mothur, the cluster command can be used to assign sequences to OTUs. Presently, mothur implements three clustering methods:
- Nearest neighbor: Each of the sequences within an OTU are at most X% distant from the most similar sequence in the OTU.
- Furthest neighbor: All of the sequences within an OTU are at most X% distant from all of the other sequences within the OTU.
- Average neighbor: This method is a middle ground between the other two algorithms.
If there is an algorithm that you would like to see implemented, please consider either contributing to the mothur project or contacting the developers and we'll see what we can do. The average neighbor algorithm is the default option. For this tutorial you should download the AmazonData.zip file and decompress it.
Either a phylip-formatted distance matrix or a column-formatted distance matrix must be inputted for cluster to be successful, the default output of the dist.seqs command is the column-format. If you have a favorite format, please let us know and we can work with you to incorporate that feature into mothur. Because the phylip format is so popular most software can generate this format for you.
To read in a phylip-formatted distance matrix you need to use the phylip option:
mothur > cluster(phylip=98_sq_phylip_amazon.dist)
mothur > cluster(phylip=98_lt_phylip_amazon.dist)
Whereas dotur required you to indicate whether the matrix was square or lower-triangular, mothur is able to figure this out for you.
Once you execute the command, mothur reads in the matrix and generates a progress bar:
mothur > cluster(phylip=98_lt_phylip_amazon.dist) *******************#****#****#****#****#****#****#****#****#****#****# Reading matrix: ||||||||||||||||||||||||||||||||||||||||||||||||||| **********************************************************************
column & name
mothur > cluster(column=96_sq_column_amazon.dist, name=amazon.names)
mothur > cluster(column=96_lt_column_amazon.dist, name=amazon.names)
Again, the column-formatted distance matrix can be square or lower-triangle and mothur will figure it out.
A names file contains two columns. The first column contains the name of a reference sequence that is in a distance matrix and the second column contains the names of the sequences (separated by commas) that the reference sequence represents. The list of names in the second column should always contain at least the reference sequence name.
There are several reasons to be interested in providing a name file with your distance matrix. First, as sequencing collections increase in size, the number of duplicate sequences is increasing. This is especially the case with sequences generated via pyrosequencing. Sogin and colleagues  found that less than 50% of their sequences were unique. Because the alignments and distances for the duplicate sequences are the same, re-processing each duplicate sequence takes a considerable amount of computing time and memory.
Example from amazon.names:
... U68616 U68616 U68617 U68617 U68618 U68618,U68620 U68619 U68619 U68621 U68621 ...
Second, if you pre-screen a clone library using ARDRA then you may only have a sequence for a handful of clones, but you know the number of times that you have seen a sequence like it. In such a case the second column of the names file would contain the sequence name as well as dummy sequence names
... AA1234 AA1234,AA1234.1,AA1234.2 AA1235 AA1235 AA1236 AA1236,AA1236.1 AA1237 AA1237,AA1237.1,AA1237.2,AA1237.3 AA1238 AA1238,AA1238.1 ...
A names file is not required (unless you are using the column= option), but depending on the data set to be analyzed, could significantly accelerate the processing time of downstream calculations. Although this is a simple example, the 98 sequence amazon data set has two pairs of duplicate sequences (U68618 and U68620) and (U68667 and U68641). The distance matrix in the file 96_lt_phylip_amazon.dist is a lower triangle matrix for the 96 unique sequences. While you could just read the matrix in and analyze the set of 96 unqiue sequences, this would give a considerably different analysis than if you used the entire 98 sequence data set. Considering the frequency of sequences is critical for pretty much every analysis in mothur, we want to use the name file to artificially inflate the matrix to its full size. In this case we use the namefile option:
mothur > cluster(phylip=96_lt_phylip_amazon.dist, name=amazon.names)
mothur remembers that the distances for the reference sequence also apply to all of the sequences listed in the second column. Using a name file can considerably accelerate the amount of processing time required to analyze some data sets.
By default cluster() executes the average neighbor clustering algorithm. For a detailed description of this and the other algorithms check out the example clustering calculations page. Next lets run the cluster() command:
mothur > cluster(phylip=98_sq_phylip_amazon.dist)
This command will generate the following output:
unique 2 94 2 0.00 2 92 3 0.01 3 87 4 1 0.02 4 83 2 1 2 0.03 4 75 6 1 2 0.04 4 69 9 1 2 0.05 4 55 13 3 2 0.06 4 48 14 2 4 0.07 7 42 15 2 2 1 0 1 ...
Outputted to the screen is a label describing the distance cutoff used to form OTUs, the number of sequences in the largest OTU, the number of OTUs with only one sequence, with two, etc. Running the cluster() command generates three output files whose names end in sabund, rabund, and list. The data outputted to the screen is the same as that in the sabund file. You will notice that the sample rabund, sabund, and list files each have a ".an." tag inserted after the name of the distance matrix. an corresponds to the algorithm that was used to perform the clustering. In this case average neighbor (an) was used. Other possibilities include "fn" for furthest neighbor and "nn" for nearest neighbor.
The count file is similar to the name file in that it is used to represent the number of duplicate sequences for a given representative sequence. Mothur will use this information to form the correct OTU's. Unlike, when you use a names file the list file generated will contain only the unique names, so be sure to include the count file in downstream analysis with the list file.
mothur > make.table(name=amazon.names) Example from amazon.count_table: ... U68616 1 U68617 1 U68618 2 U68619 1 U68621 1 ... mothur > cluster(phylip=96_lt_phylip_amazon.dist, count=amazon.count_table)
By default cluster() uses the average neighbor algorithm; this can be changed with the method option. By running the following command you will get the same output as just running cluster():
mothur > cluster(phylip=98_sq_phylip_amazon.dist, method=average)
To obtain a nearest neighbor clustering of the data use the method option to produce the subsequent output:
mothur > cluster(phylip=98_sq_phylip_amazon.dist, method=nearest) unique 2 94 2 0.00 2 92 3 0.01 4 86 4 0 1 0.02 4 83 2 1 2 0.03 4 75 6 1 2 0.04 4 68 8 2 2 0.05 5 53 13 2 2 1 0.06 13 47 12 2 2 0 0 0 0 0 0 0 0 1 0.07 16 41 10 2 2 0 0 1 0 0 0 0 0 0 0 0 1 ...
To obtain an furthest neighbor clustering of the data again use the method option to produce the subsequent output:
mothur > cluster(phylip=98_sq_phylip_amazon.dist, method=furthest)
unique 2 94 2 0.01 2 88 5 0.02 4 85 3 1 1 0.03 4 83 2 1 2 0.04 4 73 7 1 2 0.05 4 64 10 2 2 0.06 4 50 13 2 4 0.07 7 45 14 2 3 0 0 1
Similar to reading in the distance matrix, you can set a cutoff value for performing the clustering operation. This will provide a similar boost in speed if you didn't set the cutoff for reading in the matrix. If you already set the cutoff value when reading in the matrix, then don't worry about it for clustering unless you want an even smaller distance. The cutoff can be set for the cluster command as follows:
mothur > cluster(phylip=98_sq_phylip_amazon.dist, cutoff=0.05) unique 2 94 2 0.00 2 92 3 0.01 2 88 5 0.02 4 84 2 2 1 0.03 4 75 6 1 2 0.04 4 69 9 1 2 0.05 4 55 13 3 2
Perhaps the most commonly asked question is why the cluster command produces data for both the "unique" and "0.00" lines. Aren't they the same? No. The "unique" line represents data for the situation where all of the sequences in an OTU are identical; the "0.00" line represents data for the situation where all of the sequences in an OTU have pairwise distances less than 0.0049. We made the decision that because there is error in everything, we should round these distances as well and not apply a hard cutoff at 0.01, 0.02, etc. If you want greater precision, there is a precision option in the read.dist() and cluster() commands:
mothur > cluster(phylip=98_sq_phylip_amazon.dist, cutoff=0.02, precision=1000) unique 2 94 2 0.003 2 92 3 0.006 2 90 4 0.008 2 88 5 0.017 3 87 4 1 0.018 3 86 3 2 0.020 4 84 2 2 1
Remember that the 16S rRNA gene is roughly 1,500 bp long. So it would seem silly to have a precision greater than 1,000. Just because you can calculate a number to 20 digits, doesn't mean they're all significant.
The sim parameter is used to indicate that your input file contains similarity values instead of distance values. The default is false, if sim=true then mothur will convert the similarity values to distances.
mothur > cluster(column=96_lt_column_11_amazon.dist, name=amazon.names, sim=t)
Clustering with vsearch
The vsearch program is written by the vsearch team. You can now use vsearch clustering methods through mothur. NOTE: vsearch is not available for Windows.
Vsearch requires a fasta file to cluster.
mothur > cluster(fasta=amazon.fasta, method=agc)
The name parameter allows you to enter the name file associated with your fasta file.
mothur > cluster(fasta=amazon.fasta, name=amazon.names, method=agc)
The count parameter allows you to enter the count file associated with your fasta file.
mothur > cluster(fasta=amazon.fasta, count=amazon.count_table, method=agc)
The available clustering methods are agc and dgc.
mothur > cluster(fasta=amazon.fasta, method=dgc)
Perhaps the second most commonly asked question is why there isn't a line for distance 0.XX. If you notice the previous example the distances jump from 0.003 to 0.006. Where are 0.004 and 0.005? mothur only outputs data if the clustering has been updated for a distance. So if you don't have data at your favorite distance, that means that nothing changed between the previous distance and the next one. Therefore if you want OTU data for a distance of 0.005 in this case, you would use the data from 0.003.
You may notice that if you run the same command multiple times for the same dataset you might get slightly different out for some distances:
mothur > cluster(phylip=98_sq_phylip_amazon.dist, method=furthest) unique 2 94 2 0.00 2 92 3 0.01 2 88 5 0.02 4 84 2 2 1 0.03 4 75 6 1 2 0.04 4 69 9 1 2 0.05 4 55 13 3 2 0.06 4 48 14 2 4 0.07 4 44 16 2 4 0.08 7 35 17 3 2 1 0 1 ...
mothur > cluster(phylip=98_sq_phylip_amazon.dist, method=furthest) unique 2 94 2 0.00 2 92 3 0.01 2 88 5 0.02 4 84 2 2 1 0.03 4 75 6 1 2 0.04 4 69 9 1 2 0.05 4 55 13 3 2 0.06 4 48 14 2 4 0.07 4 44 16 2 4 0.08 7 36 15 4 2 1 0 1 ...
At a distance of 0.08 these two executions diverge from one another. This is because there was a tie. A sequence could have joined more than one pre-existing OTU. mothur is programmed to randomly select the OTU that it should join. Because of this, it is possible to get differences between runs. This is just a byproduct of using an algorithm-based approach to clustering.
- 1.27.0 - reduced memory by 50% and increased speed by 55%.
- 1.28.0 - added count parameter
- 1.34.0 - Bug Fix: nearest method caused crash.
- 1.35.0 - Clustering commands did not include the count file info. when printing list file OTU order. Only effects clustering commands. *.pick commands must preserve otuLabels order. - http://www.mothur.org/forum/viewtopic.php?f=3&t=3460&p=10483#p10483.
- 1.37.0 - Adds vsearch clustering methods: agc and dgc. #169
- 1.38.0 - Fixes bug with age method.
- 1.38.1 - Removes hard parameter.