-
Notifications
You must be signed in to change notification settings - Fork 3
/
Plasmer
executable file
·228 lines (175 loc) · 11.7 KB
/
Plasmer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#/bin/bash
help()
{
cat <<- EOF
Plasmer - an accurate and sensitive bacterial plasmid identification tool based on machine-learning of shared k-mers and genomic features
Usage: Plasmer -g input_fasta -p out_prefix -d db -t threads -m minimum_length -l length -o outpath
Author: Qianhui Zhu
The parameters:
-h --help Print the help info and exit.
-v --version Print the version info.
-g --genome The input fasta. [required]
-p --prefix The prefix of output. [Default: output]
-d --db The path of databases. [required]
-t --threads Number of threads. [Default: 8]
-m --minimum_length The minimum length(bp) of sequences, the sequences shorter than the length will be dropped. [Default: 500]
-l --length The length(bp) threshold of sequences as chromosome to filtered. If set 0, no sequence are filtered, all sequences will be predicted. [Default: 500000]
-o --outpath The outpath. [required]
GitHub: https://github.com/nekokoe/Plasmer
License: CC-BY 4.0
EOF
exit 0
}
version_info()
{
cat <<- EOF
Plasmer v0.1 20220816
EOF
exit 0
}
while true;do
case "$1" in
-g|--genome)
genome=$2;shift 2;;
-p|--prefix)
prefix=$2;shift 2;;
-d|--db)
db=$2;shift 2;;
-t|--threads)
threads=$2;shift 2;;
-m|--minimum_length)
minimum_length=$2;shift 2;;
-l|--length)
length=$2;shift 2;;
-o|--outpath)
outpath=$2;shift 2;;
-h|--help)
help;; # Print the help info.
-v|--version)
version_info;; # Print the version info.
*)
echo "Usage: `basename $0` -h|--help -g|--genome -v|--version -p|--prefix -d|--db -t|--threads -m|minimum_length -l|--length -o|--outpath"
break;;
esac
done
threads=${threads:-8}
length=${length:-500000}
minimum_length=${minimum_length:-500}
prefix=${prefix:-output}
#check software
for sw in seqkit python3 perl kmer-db prodigal hmmsearch blastn cmscan diamond parallel kraken2 Rscript
do
if [ -z $(which ${sw}) ];then
echo "ERROR: required software ${sw} not properly installed"
exit 1
fi
done
script_Dir=$(dirname $(readlink -f $0))
if [ ! -s ${genome} ];then
echo "ERROR: Genome is not found or empty!"
exit 1
fi
if [ ! -d ${db} ];then
exit 1
echo "ERROR: ${db} is not found or empty!"
else
if [ ! -s ${db}/plasmerMainDB.list ];then
echo "ERROR: ${db}/plasmerMainDB.list is not found or empty!"
exit 1
else
bash ${script_Dir}/plasmerMainDB_check.sh ${db}/plasmerMainDB.list
fi
fi
if [ ! -d ${outpath} ];then
mkdir ${outpath}
mkdir ${outpath}/intermediate
mkdir ${outpath}/results
else
mkdir ${outpath}/intermediate
mkdir ${outpath}/results
fi
seqkit fx2tab --gc --gc-skew --length --only-id --name ${genome} > ${outpath}/intermediate/${prefix}.seqkit
if [ ! -s ${outpath}/intermediate/${prefix}.seqkit ];then
echo "ERROR: seqkit didn't find any sequences! Please check your input file."
exit 1
fi
echo "Checking sequence length..."
python3 ${script_Dir}/check_length_by_input.py ${genome} ${outpath}/intermediate/${prefix}.seqkit $length $minimum_length ${outpath}/intermediate/${prefix}.plasmer.length.class ${outpath}/intermediate/${prefix}.plasmer.length.unclass.fasta ${outpath}/intermediate/${prefix}.plasmer.shorterM.class ${outpath}/results/${prefix}.plasmer.shorterM.fasta
echo ${outpath}/intermediate/${prefix}.plasmer.length.unclass.fasta > ${outpath}/intermediate/${prefix}.sample.list
echo "Generating k-mer features..."
kmer-db new2all -t ${threads} -multisample-fasta ${db}/plsdb_minus_ncbi_representative.k25.kmer-db ${outpath}/intermediate/${prefix}.sample.list ${outpath}/intermediate/${prefix}.pmr.common_table
kmer-db new2all -t ${threads} -multisample-fasta ${db}/plsdb.k25.kmer-db ${outpath}/intermediate/${prefix}.sample.list ${outpath}/intermediate/${prefix}.p.common_table
kmer-db new2all -t ${threads} -multisample-fasta ${db}/ncbi_representative_minus_plsdb.k18.f0.1.kmer-db ${outpath}/intermediate/${prefix}.sample.list ${outpath}/intermediate/${prefix}.rmp.common_table
kmer-db new2all -t ${threads} -multisample-fasta ${db}/ncbi_representative.k18.f0.1.kmer-db ${outpath}/intermediate/${prefix}.sample.list ${outpath}/intermediate/${prefix}.r.common_table
perl -ne 'chomp; next if ($.<3); @F=split/,/; @ID=split/\s/,$F[0]; ($id,$class)=split/-/,$ID[0]; print join("\t",($ID[0],$F[-1]/$F[-2]))."\n";' ${outpath}/intermediate/${prefix}.pmr.common_table > ${outpath}/intermediate/${prefix}.pmr.common_table.features
perl -ne 'chomp; next if ($.<3); @F=split/,/; @ID=split/\s/,$F[0]; ($id,$class)=split/-/,$ID[0]; print join("\t",($ID[0],$F[-1]/$F[-2]))."\n";' ${outpath}/intermediate/${prefix}.p.common_table > ${outpath}/intermediate/${prefix}.p.common_table.features
perl -ne 'chomp; next if ($.<3); @F=split/,/; @ID=split/\s/,$F[0]; ($id,$class)=split/-/,$ID[0]; print join("\t",($ID[0],$F[-1]/$F[-2]))."\n";' ${outpath}/intermediate/${prefix}.rmp.common_table > ${outpath}/intermediate/${prefix}.rmp.common_table.features
perl -ne 'chomp; next if ($.<3); @F=split/,/; @ID=split/\s/,$F[0]; ($id,$class)=split/-/,$ID[0]; print join("\t",($ID[0],$F[-1]/$F[-2]))."\n";' ${outpath}/intermediate/${prefix}.r.common_table > ${outpath}/intermediate/${prefix}.r.common_table.features
#prodigal
echo "Predicting gene with Prodigal..."
prodigal -p meta -a ${outpath}/intermediate/${prefix}.aa -f gff -i ${outpath}/intermediate/${prefix}.plasmer.length.unclass.fasta -o ${outpath}/intermediate/${prefix}.gff
echo "hmmsearch --cpu 2 -E 1E-10 -o ${outpath}/intermediate/${prefix}.conjugation.hmmerout --domtblout ${outpath}/intermediate/${prefix}.conjugation.domtblout --noali ${db}/platon_db/conjugation ${outpath}/intermediate/${prefix}.aa" > ${outpath}/intermediate/${prefix}_hmmscan.sh
echo "hmmsearch --cpu 2 -E 1E-10 -o ${outpath}/intermediate/${prefix}.mobilization.hmmerout --domtblout ${outpath}/intermediate/${prefix}.mobilization.domtblout --noali ${db}/platon_db/mobilization ${outpath}/intermediate/${prefix}.aa" >> ${outpath}/intermediate/${prefix}_hmmscan.sh
echo "hmmsearch --cpu 2 --cut_tc -o ${outpath}/intermediate/${prefix}.ncbifam-amr.hmmerout --domtblout ${outpath}/intermediate/${prefix}.ncbifam-amr.domtblout --noali ${db}/platon_db/ncbifam-amr ${outpath}/intermediate/${prefix}.aa" >> ${outpath}/intermediate/${prefix}_hmmscan.sh
echo "hmmsearch --cpu 2 -E 1E-10 -o ${outpath}/intermediate/${prefix}.replication.hmmerout --domtblout ${outpath}/intermediate/${prefix}.replication.domtblout --noali ${db}/platon_db/replication ${outpath}/intermediate/${prefix}.aa" >> ${outpath}/intermediate/${prefix}_hmmscan.sh
echo "blastn -db ${db}/platon_db/orit -query ${outpath}/intermediate/${prefix}.plasmer.length.unclass.fasta -out ${outpath}/intermediate/${prefix}.orit.blastn.out -outfmt 6 -max_target_seqs 1 -num_threads ${threads}" > ${outpath}/intermediate/${prefix}_blastn.sh
echo "cmscan --cpu 2 --noali --nohmmonly --rfam --cut_tc --fmt 2 --oskip -o ${outpath}/intermediate/${prefix}.rRNA.cmscan.out --tblout ${outpath}/intermediate/${prefix}.rRNA.cmscan.tblout ${db}/platon_db/rRNA ${outpath}/intermediate/${prefix}.plasmer.length.unclass.fasta" >> ${outpath}/intermediate/${prefix}_hmmscan.sh
echo "diamond blastp --threads ${threads} --db ${db}/platon_db/mps.dmnd --out ${outpath}/intermediate/${prefix}.mps.dmnd.out --outfmt 6 --query ${outpath}/intermediate/${prefix}.aa --subject-cover 80 --max-target-seqs 1" > ${outpath}/intermediate/${prefix}_diamond.sh
echo "Searching with BLASTN..."
parallel --will-cite -j 1 :::: ${outpath}/intermediate/${prefix}_blastn.sh
echo "Searching with DIAMOND..."
parallel --will-cite -j 1 :::: ${outpath}/intermediate/${prefix}_diamond.sh
echo "Searching with hmmsearch..."
parallel --will-cite -j ${threads} :::: ${outpath}/intermediate/${prefix}_hmmscan.sh
echo "Generating genomic features..."
#find conjugation
perl ${script_Dir}/getFeatDomTbl.pl ${outpath}/intermediate/${prefix}.plasmer.length.unclass.fasta ${outpath}/intermediate/${prefix}.conjugation.domtblout > ${outpath}/intermediate/${prefix}.conjugation.domtblout.feature
#find mobilization
perl ${script_Dir}/getFeatDomTbl.pl ${outpath}/intermediate/${prefix}.plasmer.length.unclass.fasta ${outpath}/intermediate/${prefix}.mobilization.domtblout > ${outpath}/intermediate/${prefix}.mobilization.domtblout.feature
#ncbifam-amr
perl ${script_Dir}/getFeatDomTbl.pl ${outpath}/intermediate/${prefix}.plasmer.length.unclass.fasta ${outpath}/intermediate/${prefix}.ncbifam-amr.domtblout > ${outpath}/intermediate/${prefix}.ncbifam-amr.domtblout.feature
#replication
perl ${script_Dir}/getFeatDomTbl.pl ${outpath}/intermediate/${prefix}.plasmer.length.unclass.fasta ${outpath}/intermediate/${prefix}.replication.domtblout > ${outpath}/intermediate/${prefix}.replication.domtblout.feature
#MPS - RDS score
perl ${script_Dir}/getFeatMDS.pl ${outpath}/intermediate/${prefix}.plasmer.length.unclass.fasta ${outpath}/intermediate/${prefix}.mps.dmnd.out ${db}/platon_db/mps.tsv > ${outpath}/intermediate/${prefix}.mps.rds.feature
perl ${script_Dir}/getFeatBlastn.pl ${outpath}/intermediate/${prefix}.plasmer.length.unclass.fasta ${outpath}/intermediate/${prefix}.orit.blastn.out > ${outpath}/intermediate/${prefix}.orit.feature
#rRNA
perl ${script_Dir}/getFeatRiboRNA.pl ${outpath}/intermediate/${prefix}.plasmer.length.unclass.fasta ${outpath}/intermediate/${prefix}.rRNA.cmscan.tblout > ${outpath}/intermediate/${prefix}.rRNA.feature
echo "Merging features..."
#merge features
Rscript ${script_Dir}/mergeFeatsPredict.R \
${outpath}/intermediate/${prefix}.seqkit \
${outpath}/intermediate/${prefix}.r.common_table.features \
${outpath}/intermediate/${prefix}.rmp.common_table.features \
${outpath}/intermediate/${prefix}.p.common_table.features \
${outpath}/intermediate/${prefix}.pmr.common_table.features \
${outpath}/intermediate/${prefix}.conjugation.domtblout.feature \
${outpath}/intermediate/${prefix}.mobilization.domtblout.feature \
${outpath}/intermediate/${prefix}.mps.rds.feature \
${outpath}/intermediate/${prefix}.ncbifam-amr.domtblout.feature \
${outpath}/intermediate/${prefix}.orit.feature \
${outpath}/intermediate/${prefix}.replication.domtblout.feature \
${outpath}/intermediate/${prefix}.rRNA.feature \
${outpath}/intermediate/${prefix}.allFeatures
echo "Predicting..."
#Model predict
Rscript ${script_Dir}/predict_by_rpmodel.R ${db}/All.rk18pk25.rp.all2class.per0.8OR10w.traindata.rfmodel.RData ${outpath}/intermediate/${prefix}.allFeatures
#Rscript ${script_Dir}/predict_by_rpmodel.R ${db}/All.sample6w.filter.features.rmGC.2class.rfmodel.RData ${outpath}/intermediate/${prefix}.allFeatures
cat ${outpath}/intermediate/${prefix}.allFeatures.plasmer.predClass.tsv ${outpath}/intermediate/${prefix}.plasmer.length.class ${outpath}/intermediate/${prefix}.plasmer.shorterM.class > ${outpath}/results/${prefix}.plasmer.predClass.tsv
#extract plasmids sequences
python3 ${script_Dir}/extract_predPlasmids_seqs.py ${genome} ${outpath}/results/${prefix}.plasmer.predClass.tsv ${outpath}/results/${prefix}.plasmer.predPlasmids.fa
mv ${outpath}/intermediate/${prefix}.allFeatures.plasmer.predProb.tsv ${outpath}/results/${prefix}.plasmer.predProb.tsv
echo "Predicting finished!"
echo "See your result in ${outpath}/results/"
echo "Classifying taxonomy..."
#annotate plasmids
if [ ! -s ${db}/customizedKraken2DB.list ];then
echo "${db}/customizedKraken2DB.list is not found or empty, skipping this step!"
exit 1
else
bash ${script_Dir}/customizedKraken2DB_check.sh ${db}/customizedKraken2DB.list
kraken2 --use-names --threads ${threads} --db ${db}/ncbiPlasmids --report ${outpath}/intermediate/${prefix}.plasmer.predPlasmids.k2.report --output ${outpath}/intermediate/${prefix}.plasmer.predPlasmids.k2.out ${outpath}/results/${prefix}.plasmer.predPlasmids.fa
cut -f2,3 ${outpath}/intermediate/${prefix}.plasmer.predPlasmids.k2.out > ${outpath}/results/${prefix}.plasmer.predPlasmids.taxon
echo "Plasmid taxonomy finished!"
echo "See your result in ${outpath}/results/"
fi