Debian Codegraph @

dnaclust-ref

raw ◀ ▶
1 Debian patch touch this file
1 #!/bin/bash
2 similarity=0.98
3 threads=1
4
5 print_help()
6 {
7 fold -w 120 <<EOF
8 Usage: dnaclust-ref [OPTIONS...]
9 DNACLUST helper script to cluster sequences using a reference database.
10
11 -c CENTERS Fasta file of cluster centers/references.
12 -d After clustering with reference database, perform de novo clustering.
13 -r SIMILARITY Set similarity between cluster center and cluster
14 sequences (default=0.98)
15 -t THREADS Set the number of threads to use
16 -i INPUT_FILE Fasta file of sequences to be clustered.
17 -v Print verbose messages to standard error
18 -h Give this help list
19
20 The sequences to be clustered are read from the STDIN. The cluster centers are written to STDOUT. Messages are written to STDERR.
21 EOF
22 }
23
24 while getopts "c:i:dr:t:vhln" option
25 do
26 case $option in
27 c) cluster_centers="$OPTARG";;
28 i) input="$OPTARG";;
29 d) de_novo_cluster=0;;
30 r) similarity="$OPTARG";;
31 t) threads="$OPTARG";;
32 v) verbose=0;;
33 l) left_gaps_allowed=0;;
34 n) no_overlap=0;;
35 h) print_help; exit 0;;
36 [?]) print_help; exit 1;;
37 esac
38 done
39
40 print_message()
41 {
42 if [ $verbose ]
43 then
44 echo "`date +%T` $1" >&2
45 fi
46 }
47
48 parameters=""
49 if [ $left_gaps_allowed ]
50 then
51 parameters+=" --left-gaps-allowed "
52 fi
53
54 if [ $no_overlap ]
55 then
56 parameters+=" --no-overlap "
57 fi
58
59 dnaclust_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
60 print_message "$dnaclust_path"
61 #exit 1
62 UNAME=$( uname )
63 tempdir=""
64 if [ $UNAME = "Darwin" ];
65 then
66 tempdir=`mktemp -d -t .`
67 else
68 tempdir=`mktemp -d -p .`
69 fi
70 #tempdir="tmpref/"
71 trap "rm -fr $tempdir" EXIT
72
73 #sequences_sorted=`mktemp -p $tempdir`
74 db_sorted=`basename ${cluster_centers} .fasta`.sorted.fasta
75 # Reads the sequences from STDIN.
76 print_message "Reading and sorting the database sequences: $tempdir/${db_sorted}"
•77 #"/usr/lib/dnaclust/fastasort" --random-shuffle > $sequences_sorted
78 cat $cluster_centers | "/usr/lib/dnaclust/fastasort" > $tempdir/${db_sorted}
79
80 print_message "Recruiting from the sequences, using database."
81 "$dnaclust_path/dnaclust" $parameters -s $similarity -t $threads --no-k-mer-filter -i $input -p $tempdir/${db_sorted} -r | awk '{if (NF > 1) print $0}' > $input.db.clusters
82 print_message "DB recruited sequences: $input.db.clusters"
83
84 if [ $de_novo_cluster ]
85 then
86 print_message "Run DNACLUST on remaining sequences."
87 unclustered_seq=`basename $input .fasta`.unclustered.fasta
88 awk '{ for (i = 1; i <= NF; i++) print $i}' $input.db.clusters > $tempdir/clustered_seqs
89
•90 "/usr/lib/dnaclust/fastaselect" --everything-except -f ${input} < $tempdir/clustered_seqs > $tempdir/${unclustered_seq}
91 if [[ -s $tempdir/${unclustered_seq} ]] ; then
92 "$dnaclust_path/dnaclust" $parameters -s $similarity -t $threads --no-k-mer-filter -i $tempdir/${unclustered_seq} > $input.denovo.clusters
93 print_message "Writing de novo clusters to: $input.denovo.clusters"
94 else
95 touch $input.denovo.clusters
96 fi
97 fi
98 exit 1