-
Notifications
You must be signed in to change notification settings - Fork 0
/
pneumo-typer.pl
336 lines (243 loc) · 14.8 KB
/
pneumo-typer.pl
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#!/usr/bin/perl -w
use strict;
use warnings;
use threads;
use FindBin;
use lib "$FindBin::Bin/lib";
use Getopt::Long;
use File::Spec;
use PTyper;
#use vars qw(%options);
my $usage = <<USAGE;
=NAME
Pneumo-Typer
=DESCRIPTION
A comprehensive prediction and visualization of serotype and sequence type for streptococcus pneumoniae using assembled genomes.
=USAGE
pneumo-typer.pl -d genbank_file_directory [options]
FOR EXAMPLE:
perl pneumo-typer.pl -d Test_data -t 10 -p T
#######################################################################################################################################
=ARGUMENTS
=======================
REQUIRED ARGUMENTS:
~~~~~~~~~~~~~~~~~~~
-d, --genbank_file_directory
A directory containing files in GenBank format, FASTA format, or a combination of both.
OPTIONAL ARGUMENTS:
~~~~~~~~~~~~~~~~~~~
-o, --output_directory
An output directory holding all the generated files by pneumo-typer.pl. if this option is not set, a directory named "pneumo-typer_workplace" will be created in the bin directory from where pneumo-typer.pl was invoked.
-t, --multiple_threads
Set thread number (Default: 1)
-Ss, --skip_sequence_processing
Skip the process of sequence processing (STEP-1) (Default: F).
-hgc, --homologous_gene_cutoff
Set E-value, Identify, Coverage (Query and Subject), Match_length (alignment length) cutoff in Blastn analysis (default: E-value=1e-5, Identify=70, Coverage=95, Match_length=100).
-Sb, --skip_blastn
Skip the process of doing blastn during serotype analysis.
-p, --prodigal_annotation
Annotate all genomes using prodigal (Default: T).
-m, --mlst
Perform mlst analysis (Default: T).
-c, --cgmlst
Perform cgmlst analysis. It needs about 3 mins for one genome (Default: F).
-Rh, --recreate_heatmap
Re-create the heatmap of cps gene distribution in genomes (Default: F). At this step, users can add a parameter "phylogenetic_tree" or "strain_reorder_file".
-Rf, --recreate_figure
Re-create the figure of the genetic organization of cps gene cluster for genomes (Default: F). At this step, users can add a parameter "phylogenetic_tree" or "strain_reorder_file".
-tree, --phylogenetic_tree
A Newick format tree file is used by Pneumo-Typer to automatically associate the genomes with their phylogeny. Meanwhile, Pneumo-Typer will output a file named "temp_strain_reorder_file-svg.txt", which contains the order information of genomes in the tree from up to down. It should be noted that all node names in the provided tree must completely match the input file names of all genomes.
-srf, --strain_reorder_file
A two-column tab-delimited text file is used to sort genomes from up to down according to users' requirements. Each row must consist of a strain name followed by the numerical order that is used for sorting genomes. It should be noted that all strain names must completely match the input file names of all genomes.
-Ts, --test
Run pneumo-typer using Test_data as input to check whether Pneumo-Typer is installed successfully (Default: F).
-V, --version
The version of Pneumo-Typer.
-h, --help
Show this message.
=AUTHOR
Dr. Xiangyang Li (E-mail: lixiangyang\@fudan.edu.cn), Kaili University; Bacterial Genome Data mining & Bioinformatic Analysis (www.microbialgenomic.cn/).
=COPYRIGHT
Copyright 2024, Xiangyang Li. All Rights Reserved.
USAGE
my %options = (
'genbank_file_directory' => undef,
'workplace_directory' => undef,
'multiple_threads' => "3",
'skip_sequence_processing' => "F",
'homologous_gene_cutoff' => "1e-5,70,95,30", #array to set blast parse cutoff: E-value, Identify, Coverage, Match_length
'skip_blastn' => "F",
'prodigal_annotation' => "T",
'mlst' => "T",
'cgmlst' => "F",
'recreate_heatmap' => "F",
'recreate_figure' => "F",
'phylogenetic_tree' => undef,
'strain_reorder_file' => undef,
'test' => "F",
'version' => undef,
'help' => undef
);
GetOptions(
'd|genbank_file_directory=s' => \$options{genbank_file_directory},
'o|workplace_directory=s' => \$options{workplace_directory},
't|multiple_threads=i' => \$options{multiple_threads},
'Ss|skip_sequence_processing=s' => \$options{skip_sequence_processing},
'hgc|homologous_gene_cutoff=s' => \$options{homologous_gene_cutoff},
'Sb|skip_blastn=s' => \$options{skip_blastn},
'p|prodigal_annotation=s' => \$options{prodigal_annotation},
'm|mlst=s' => \$options{mlst},
'c|cgmlst=s' => \$options{cgmlst},
'Rh|recreate_heatmap=s' => \$options{recreate_heatmap},
'Rf|recreate_figure=s' => \$options{recreate_figure},
'tree|phylogenetic_tree=s' => \$options{phylogenetic_tree},
'srf|strain_reorder_file=s' => \$options{strain_reorder_file},
'Ts|test=s' => \$options{test},
'V|version' => \$options{version},
'h|help' => \$options{help}
);
if ( defined( $options{help} ) ) {
print $usage;
exit(0);
}
if (defined $options{version}) {
print "\nVersion: Pneumo-Typer v1.0.3\n\n";
exit(1);
}
my $now_time = localtime;
print "\n$now_time: pneumo-typer.pl start...\n\n";
my $home_directory = $FindBin::Bin; # obtaining the home directory where Pneumo-Typer.pl located
######################################################################################################
# Set the absolute path for four programs
my $tblastn = `which tblastn`; # "/usr/bin/tblastn"; mmseqs
$tblastn =~ s/\n//g;
my $blastn = `which blastn`; # "/usr/bin/blastn";
$blastn =~ s/\n//g;
my $makeblastdb = `which makeblastdb`; #"/usr/bin/makeblastdb";
$makeblastdb =~ s/\n//g;
######################################################################################################
#check for Pneumo-Typer.pl workplace options
if ($options{test} eq "T") {
$options{genbank_file_directory} = "$home_directory/Test_data";
&PTyper::check_tool($0, $options{genbank_file_directory});
exit(2);
}
#check for required options
if ( !( defined($options{genbank_file_directory}) ) ) {
print $usage;
exit(3);
}
my $path_genbank = File::Spec->rel2abs($options{genbank_file_directory});
my $db_file = "$home_directory/DATABASE/CPS_workplace/seq_file.fasta";
my $mappingList = "$home_directory/DATABASE/CPS_workplace/id_list";
my $thread_number = $options{multiple_threads};
my $prodigal_annotation = $options{prodigal_annotation};
my $workplace;
if ( defined( $options{workplace_directory} ) ) {
$workplace = File::Spec->rel2abs($options{workplace_directory});
mkdir $workplace;
}else {
$workplace = "$home_directory/pneumo-typer_workplace";
$workplace =~ s/\/\//\//g;
mkdir $workplace;
}
my $path_fa1 = $workplace."/Whole_fasta1"; #fasta sequences are extracted as contigs for each genome
mkdir $path_fa1;
my $path_fa2 = $workplace."/Whole_fasta2"; #fasta sequences are concatenated for each genome
mkdir $path_fa2;
my $path_protein = $workplace."/Whole_protein";
mkdir $path_protein;
my $path_gene = $workplace."/Whole_gene";
mkdir $path_gene;
my $directory_TFT = $workplace."/Whole_TFT";
mkdir $directory_TFT;
$options{skip_sequence_processing} = "T" if $options{skip_blastn} eq "T";
my $map_cmd = $workplace."/map_cmd.txt"; #store command to creat heatmap and figure
if ( ($options{recreate_heatmap} eq "F") && ($options{recreate_figure} eq "F") ){
system("rm -rf $workplace/result_statistics") if -d "$workplace/result_statistics"; #clear folder "result_statistics"
if ($options{skip_sequence_processing} eq "F"){
print "STEP-1: Dealing with genomes extract genome sequence, gene sequences and gene feature table (TFT); annotate genome which has no annotation information using prodigal>\n";
&PTyper::batch_genomenucleotide_extract_run ($path_genbank, $path_fa1, $path_fa2, $thread_number);
&PTyper::batch_genenucleotide_TFT_extract_run ($path_genbank, $directory_TFT, $path_protein, $path_gene, $thread_number, $prodigal_annotation, $path_fa1) if $prodigal_annotation eq "F";
&PTyper::prodigal_bacth_run ($path_fa1, $path_protein, $path_gene, $directory_TFT, $thread_number, $prodigal_annotation) if $prodigal_annotation eq "T";
}
print "\nSTEP-2: Determining the sequence type (ST/cgST)\n" if ( ($options{mlst} eq "T") or ($options{cgmlst} eq "T") );
if ($options{mlst} eq "T") {
print " \nSTEP-2.1: MLST analysis\n";
system ("perl $home_directory/ST_tool/ST_profile.pl $path_genbank $path_gene $home_directory/ST_tool/database/mlst $thread_number $workplace/ST_workplace");
}
if ($options{cgmlst} eq "T") {
print " \nSTEP-2.2: cgMLST analysis\n";
system ("perl $home_directory/ST_tool/ST_profile_cg.pl $path_genbank $path_fa2 $home_directory/ST_tool/database/cgmlst $thread_number $workplace/ST_workplace");
}
print "\nSTEP-3: Predicting serotype\n";
my $blastp_out_dir = "$workplace/blastp_out_dir";
mkdir $blastp_out_dir;
my $blastn_out_dir = "$workplace/blastn_out_dir";
mkdir $blastn_out_dir;
&PTyper::bacth_blast_best_run ($workplace, $path_protein, $blastp_out_dir, $path_gene, $blastn_out_dir, $db_file, $tblastn, $blastn, $makeblastdb, $thread_number, $options{homologous_gene_cutoff}) if $options{skip_blastn} eq "F";
#sed -i 's/.*\tGCA_001131025.1_112\t.*/10\t1000\tCDS\tGCA_001131025.1_112\tCKZO01000001/g' file
print " Process data and obtain serotype...";
my $all_vs_all_cluster = "$workplace/all_vs_all.cluster";
chdir $blastn_out_dir;
system ("find . -type f -name '*.parsedout' | xargs cat > $all_vs_all_cluster") if $options{skip_blastn} eq "F"; # For large number of files, directly using cat may causing error
my $filter_pseudogene = "$home_directory/DATABASE/filter_pseudogene.txt";
&PTyper::recheck_pseudogene_len($all_vs_all_cluster, $filter_pseudogene, $options{homologous_gene_cutoff});
############################################################
############################################################
my $map_table = "$workplace/CPS_Mapping_table.txt";
&PTyper::SARG_map_transformation($db_file, $mappingList, $map_table);
my $cluster_mapping;
$cluster_mapping = "$workplace/CPS_cluster_mapping.result";
my $serotype_negtive_strain = "$workplace/Serotype.no.detected.out";
&PTyper::mapping ($map_table, $all_vs_all_cluster, $cluster_mapping, $path_genbank, $serotype_negtive_strain);
### if $cluster_mapping is blank, quit due to no cps gene is detected in any analyzed genomes
my @feature = stat ($cluster_mapping);
die "\nWarning: no cps gene is detected in any analyzed genomes!!!\n" if $feature[7] == 0;
############################################################
############################################################
&PTyper::result_statistics($workplace, $directory_TFT, $cluster_mapping);
system ("perl $home_directory/script/serotype_correct.pl $home_directory/DATABASE/serotype_matrix.txt $workplace/result_statistics/Statistics_OUT/CPS_LocusTag_statistics $workplace/Serotype.out");
print "done\n"; #serotype prediction finished
print "\nSTEP-4: Output sequence type and serotype results\n";
system ("perl $home_directory/script/ser_join_ST.pl $workplace/Serotype.out $workplace/ST_out.txt $workplace/cgST_out.txt $workplace/Serotype_ST.out");
### Visualizing the result
##########################
open (MAP_CMD, ">$map_cmd");
print "\nSTEP-5: Heatmaping the cps gene distribution in genomes\n";
my $cmd_1 ="perl $home_directory/script/heatmap.pl -dir $workplace/result_statistics/tbl_heatmap_class -left 20 -scale 4 -label T -dis 9 -w 4 -l 0 -right 50 -cf $workplace/result_statistics/Statistics_OUT/classification_CPS -e $workplace/Serotype_ST.out -o $workplace";
system ("$cmd_1");
my $cmd_2 ="perl $home_directory/script/heatmap.pl -dir $workplace/result_statistics/tbl_heatmap_gene -left 20 -scale 4 -label T -dis 9 -w 4 -l 0 -right 50 -cf $workplace/result_statistics/Statistics_OUT/classification_gene -e $workplace/Serotype_ST.out -o $workplace";
system ("$cmd_2");
print "\nSTEP-6: Visualizing the cps gene cluster for genomes\n";
my $gcluster_workplace = "$workplace/cps_cluster_workplace";
mkdir $gcluster_workplace;
my $subtft = "$gcluster_workplace/Sub_TFT";
mkdir $subtft;
#obtain interested gene and sub TFT files, in which gene distance from (20 kb) cps genes were removed;
#only genome having the number of cps gene > 1 is shown
system ("perl $home_directory/script/interested_gene.pl $home_directory/DATABASE/gene.txt $workplace/Serotype.out $workplace/result_statistics/tbl_part $gcluster_workplace/interested_gene.txt $subtft 20000 1");
#obtain homologs cluster
my $homologs_cluster = "$gcluster_workplace/blast_homologs_cluster";
mkdir $homologs_cluster;
system ("perl $home_directory/script/mcr.pl $workplace/CPS_cluster_mapping.result $homologs_cluster/all_orthomcl.out");
my $cmd_3 = "perl $home_directory/script/cps_cluster.pl -dir $path_genbank -gene $gcluster_workplace/interested_gene.txt -m $thread_number -map T -o $gcluster_workplace -SVG T -n 40 -e $workplace/Serotype_ST.out";
system ("$cmd_3");
print MAP_CMD "heatmap_class:\n$cmd_1\n\nheatmap_gene:\n$cmd_2\n\ncps gene cluster:\n$cmd_3\n";
close MAP_CMD;
}
my ($remap_cmd1, $remap_cmd2, $remap_cmd3) = &PTyper::obtain_map_cmd ($map_cmd, \%options);
#remap heatmap
if ($options{recreate_heatmap} eq "T"){
print "\n Re-create the heatmap of cps gene distribution in genomes (STEP-5)\n\n";
system ("$remap_cmd1");
system ("$remap_cmd2");
}
#remap figure
if ($options{recreate_figure} eq "T"){
print "\n Re-create the figure of the genetic organlization of cps gene cluster for genomes (STEP-6)\n\n";
system ("$remap_cmd3");
}
my $finish_time = localtime;
print "\n$finish_time: done!\n\n";