| 1 |
#!/bin/bash |
| 2 |
minimum_cluster_size=3 |
| 3 |
similarity=0.98 |
| 4 |
threads=1 |
| 5 |
|
| 6 |
print_help() |
| 7 |
{ |
| 8 |
fold --spaces <<EOF |
| 9 |
Usage: find-large-clusters [OPTIONS...] |
| 10 |
Fast and approximate method for finding large clusters. It first clusters a small subset of sequences, then uses the centers of the clusters that are larger than the specified threshold to recruit from the rest of the sequences. Note that this method does not cluster all of the sequences. Hopefully, however, we will find most the of large clusters. |
| 11 |
|
| 12 |
-m SIZE The minimum size of the clusters whose centers are |
| 13 |
uesd in the second phase (default=3) |
| 14 |
-s SIZE The size of set of sample sequences for finding the |
| 15 |
centers of large clusters (default=n^0.8) |
| 16 |
-r SIMILARITY Set similarity between cluster center and cluster |
| 17 |
sequences (default=0.98) |
| 18 |
-t THREADS Set the number of threads to use |
| 19 |
-a Produce multiple sequence alignment for each cluster |
| 20 |
-v Print verbose messages to standard error |
| 21 |
-h Give this help list |
| 22 |
|
| 23 |
The sequences to be clustered are read from the STDIN. The cluster centers are written to STDOUT. Messages are written to STDERR. |
| 24 |
EOF |
| 25 |
} |
| 26 |
|
| 27 |
while getopts "m:s:r:t:avh" option |
| 28 |
do |
| 29 |
case $option in |
| 30 |
m) minimum_cluster_size="$OPTARG";; |
| 31 |
s) sample_count="$OPTARG";; |
| 32 |
r) similarity="$OPTARG";; |
| 33 |
t) threads="$OPTARG";; |
| 34 |
a) multiple_alignment="--multiple-alignment";; |
| 35 |
v) verbose=0;; |
| 36 |
h) print_help; exit 0;; |
| 37 |
[?]) print_help; exit 1;; |
| 38 |
esac |
| 39 |
done |
| 40 |
|
| 41 |
print_message() |
| 42 |
{ |
| 43 |
if [ $verbose ] |
| 44 |
then |
| 45 |
echo "`date +%T` $1" >&2 |
| 46 |
fi |
| 47 |
} |
| 48 |
|
| 49 |
dnaclust_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 50 |
|
| 51 |
tempdir=`mktemp -d -p .` |
| 52 |
#trap "rm -fr $tempdir" EXIT |
| 53 |
|
| 54 |
sequences_sorted=`mktemp -p $tempdir` |
| 55 |
# Reads the sequences from STDIN. |
| 56 |
print_message "Reading and sorting the input sequences." |
| •57 |
"/usr/lib/dnaclust/fastasort" --random-shuffle > $sequences_sorted |
| 58 |
|
| 59 |
input_count=`grep -c '^>' $sequences_sorted` |
| 60 |
if [ $input_count -le 1 ] |
| 61 |
then |
| 62 |
echo "ERROR: Input sequences must contain more than one sequence." >&2 |
| 63 |
exit 1 |
| 64 |
fi |
| 65 |
|
| 66 |
if [ -z $sample_count ] |
| 67 |
then |
| 68 |
sample_count_float=`echo "e(l($input_count)*0.8)" | bc -l` |
| 69 |
sample_count=`echo "($sample_count_float * 2 + 1) / 2" | bc` |
| 70 |
fi |
| 71 |
|
| 72 |
sample_lines=`awk --assign=count=$sample_count '/^>/{if (++n > count) {print FNR - 1; exit}}' $sequences_sorted` |
| 73 |
|
| 74 |
|
| 75 |
print_message "Splitting $input_count input sequences into a sample of size $sample_count, and the rest." |
| 76 |
sequences_sorted_head=`mktemp -p $tempdir` |
| 77 |
head -n $sample_lines $sequences_sorted > $sequences_sorted_head |
| 78 |
|
| 79 |
large_clusters=`mktemp -p $tempdir` |
| 80 |
print_message "Clustering the set of sample sequences, and extracting centers of large clusters." |
| 81 |
"$dnaclust_path/dnaclust" -s $similarity -t $threads -i $sequences_sorted_head \ |
| 82 |
| awk --assign=minimum=$minimum_cluster_size '{if (NF >= minimum) print $0}' > $large_clusters |
| 83 |
|
| 84 |
sequences_sorted_head_large_centers=`mktemp -p $tempdir` |
| •85 |
"/usr/lib/dnaclust/fastaselect" -c -f $sequences_sorted_head < $large_clusters > $sequences_sorted_head_large_centers |
| 86 |
|
| 87 |
sequences_minus_centers=`mktemp -p $tempdir` |
| •88 |
"/usr/lib/dnaclust/fastaselect" --everything-except -f $sequences_sorted < $large_clusters > $sequences_minus_centers |
| 89 |
|
| 90 |
centers_count=`grep -c '^>' $sequences_sorted_head_large_centers` |
| 91 |
print_message "Recruiting from the rest of the sequences, using $centers_count centers." |
| 92 |
"$dnaclust_path/dnaclust" -s $similarity -t $threads $multiple_alignment --no-k-mer-filter -i $sequences_minus_centers -p $sequences_sorted_head_large_centers -r |
| 93 |
|
| 94 |
print_message "Done." |