annotate COG/bac-genomics-scripts/prot_finder/prot_finder.pl @ 14:5a5c9a6b047b draft

Uploaded
author dereeper
date Tue, 10 Dec 2024 16:20:53 +0000
parents e42d30da7a74
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
1 #!/usr/bin/perl
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
2
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
3 #######
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
4 # POD #
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
5 #######
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
6
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
7 =pod
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
8
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
9 =head1 NAME
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
10
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
11 C<prot_finder.pl> - search for query protein homologs in annotated
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
12 bacterial genomes with BLASTP
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
13
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
14 =head1 SYNOPSIS
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
15
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
16 C<perl prot_finder.pl -r report.blastp -s subject.faa E<gt> blast_hits.tsv>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
17
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
18 =head1 DESCRIPTION
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
19
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
20 This script is intended to search for homologous proteins in
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
21 annotated bacterial genomes. For this purpose, a previous
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
22 L<B<BLASTP>|http://blast.ncbi.nlm.nih.gov/Blast.cgi>), either
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
23 L<legacy or plus|https://blast.ncbi.nlm.nih.gov/Blast.cgi?PAGE_TYPE=BlastDocs&DOC_TYPE=Download>,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
24 needs to be run with query protein sequences against
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
25 a B<BLASTP> database of subject proteins (e.g. all proteins from
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
26 several I<Escherichia coli> genomes).
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
27
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
28 The script L<C<cds_extractor.pl>|/cds_extractor> (with options B<-p
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
29 -f>) can be used to create multi-FASTA protein files of all
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
30 non-pseudo CDS from RichSeq genome files to create the needed
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
31 subject B<BLASTP> database. Present locus tags will be used as FASTA
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
32 IDs, but see L<C<cds_extractor.pl>|/cds_extractor> for a description
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
33 of the format. Query protein sequences for the B<BLASTP> need a
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
34 unique FASTA ID.
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
35
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
36 The B<BLASTP> report file (option B<-r>), the subject protein
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
37 multi-FASTA file (option B<-s>), and optionally the query protein
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
38 (multi-)FASTA file (option B<-q>) are then given to
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
39 C<prot_finder.pl>. Significant B<BLASTP> subject hits are filtered
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
40 according to the given cutoffs (options B<-i>, B<-cov_q>, and
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
41 B<-cov_s>) and the result is printed as an informative tab-separated
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42 result table to C<STDOUT>. To apply global identity/coverage cutoffs
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
43 to subject hits high-scoring pairs (HSPs) are tiled (see
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
44 L<http://www.bioperl.org/wiki/HOWTO:Tiling> and
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
45 L<http://search.cpan.org/dist/BioPerl/Bio/Search/Hit/GenericHit.pm>).
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
46 Additionally, the subject protein sequences with significant query
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
47 hits are written to result multi-FASTA files, named according to the
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
48 respective query FASTA IDs (optionally including the query sequence
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
49 with option B<-q>).
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
50
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
51 Optionally, L<B<Clustal Omega>|http://www.clustal.org/omega/> can be
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
52 called (option B<-a> with optional B<-p>) to create multiple
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
53 alignments (FASTA format) for each of the resulting multi-FASTA
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
54 files. These alignments can be used to calculate phylogenies e.g.
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
55 with L<B<RAxML>|http://sco.h-its.org/exelixis/software.html> or
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
56 L<B<MEGA>|http://www.megasoftware.net/>.
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
57
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
58 Run the script L<C<cds_extractor.pl>|/cds_extractor> (with options
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
59 B<-p -f>) and the B<BLASTP> manually or use the bash shell wrapper
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
60 script C<prot_finder_pipe.sh> (see below L</"EXAMPLES">) to execute
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
61 the whole pipeline including C<prot_finder.pl> (with optional option
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
62 B<-q>). For a description of the pipeline and additional options see
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
63 option B<-h> of the shell script. Be aware that some options in
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
64 C<prot_finder_pipe.sh> corresponding to options in C<prot_finder.pl>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
65 have different names. If L<C<cds_extractor.pl>|/cds_extractor> is
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
66 used in the pipeline (option B<-f> of the shell script) the working
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
67 folder has to contain the annotated bacterial genome subject files
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
68 (in RichSeq format, e.g. EMBL or GENBANK format).
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
69
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
70 At last, the resulting tab-separated table can be given to the
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
71 script C<prot_binary_matrix.pl> to create a presence/absence matrix
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
72 of the query proteins for each genome. Again see option B<-h> of
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
73 C<prot_binary_matrix.pl> for additional info. The presence/absence
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
74 matrix can also be transposed with script C<transpose_matrix.pl>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
75 (see its help with B<-h>). These presence/absence matri(x|ces) can
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
76 e.g. be loaded into L<B<iTOL>|http://itol.embl.de/> to associate the
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
77 data with a phylogenetic tree. Also, you can use
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
78 C<binary_group_stats.pl> to calculate presence/absence statistics
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
79 for groups of columns and not simply single columns of the matrix.
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
80 C<binary_group_stats.pl> also has a comprehensive manual with its
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
81 option B<-h>.
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
82
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
83 =head1 OPTIONS
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
84
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
85 =head2 Mandatory options
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
86
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
87 =over 22
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
88
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
89 =item B<-r>=I<str>, B<-report>=I<str>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
90
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
91 Path to B<BLASTP> report/output
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
92
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
93 =item B<-s>=I<str>, B<-subject>=I<str>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
94
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
95 Path to subject multi-FASTA protein sequence file (*.faa) created
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
96 with L<C<cds_extractor.pl>|/cds_extractor> (and its options B<-p
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
97 -f>), which was used to create the B<BLASTP> database
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
98
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
99 =back
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
100
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
101 =head2 Optional options
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
102
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
103 =over 20
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
104
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
105 =item B<-h>, B<-help>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
106
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
107 Help (perldoc POD)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
108
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
109 =item B<-d>=I<str>, B<-dir_result>=I<str>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
110
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
111 Path to result folder [default = query identity and coverage
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
112 cutoffs, './results_i#_cq#']
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
113
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
114 =item B<-f>, B<-force_dir>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
115
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
116 Force output to an existing result folder, otherwise ask user to
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
117 remove content of existing folder. Careful, files from a previous
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
118 analysis might not be overwritten if different to current analysis.
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
119
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
120 =item B<-q>=I<str>, B<-query>=I<str>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
121
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
122 Path to query (multi-)FASTA protein sequence file (*.faa) with
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
123 B<unique> FASTA IDs, which was used as query in the B<BLASTP>. Will
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
124 include each query protein sequence in the respective multi-FASTA
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
125 F<query-ID_hits.faa> result file.
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
126
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
127 =item B<-b>, B<-best_hit>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
128
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
129 Give only the best hit (i.e. highest identity) for each subject
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
130 sequence if a subject has several hits with different queries
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
131
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
132 =item B<-i>=I<int>, B<-ident_cutoff>=I<int>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
133
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
134 Query identity cutoff for significant hits (not including gaps), has
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
135 to be an integer number >= 0 and <= 100 [default = 70]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
136
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
137 =item B<-cov_q>=I<int>, B<-cov_query_cutoff>=I<int>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
138
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
139 Query coverage cutoff, has to be an integer >= 0 and <= 100 [default
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
140 = 70]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
141
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
142 =item B<-cov_s>=I<int>, B<-cov_subject_cutoff>=I<int>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
143
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
144 Subject/hit coverage cutoff, has to be an integer >= 0 and <= 100
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
145 [default = 0]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
146
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
147 =item B<-a>, B<-align_clustalo>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
148
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
149 Call L<B<Clustal Omega>|http://www.clustal.org/omega/> for multiple
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
150 alignment of each F<query-ID_hits.faa> result file
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
151
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
152 =item B<-p>=I<str>, B<-path_clustalo>=I<str>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
153
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
154 Path to executable B<Clustal Omega> binary if not present in global
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
155 C<PATH> variable; requires option B<-a>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
156
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
157 =item B<-t>=I<int>, B<-threads_clustalo>=I<int>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
158
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
159 Number of threads for B<Clustal Omega> to use; requires option B<-a>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
160 [default = all processors on system]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
161
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
162 =item B<-v>, B<-version>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
163
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
164 Print version number to C<STDERR>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
165
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
166 =back
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
167
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
168 =head1 OUTPUT
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
169
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
170 =over 17
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
171
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
172 =item C<STDOUT>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
173
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
174 The resulting tab-delimited output table with the significant
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
175 subject B<BLASTP> hits is printed to C<STDOUT>. Redirect (e.g. to a
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
176 file in the result directory, options B<-d -f>) or pipe into another
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
177 tool as needed (e.g. C<prot_binary_matrix.pl>).
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
178
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
179 =item F<./results_i#_cq#>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
180
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
181 All result files are stored in a result folder
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
182
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
183 =item F<./results_i#_cq#/query-ID_hits.faa>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
184
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
185 Multi-FASTA protein files of significant subject hits for each query
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
186 protein (named after the respective query FASTA ID), optionally
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
187 include the respective query protein sequence (with option B<-q>)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
188
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
189 =item F<subject.faa.idx>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
190
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
191 Index file of the subject protein file for fast sequence retrieval
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
192 (can be deleted if no further B<BLASTPs> are needed with these
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
193 subject sequences)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
194
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
195 =item (F<./results_i#_cq#/queries_no_blastp-hits.txt>)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
196
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
197 Lists all query sequence IDs without significant subject hits; with
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
198 option B<-b> includes also queries with significant hits but
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
199 I<without> a best blast hit for a subject
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
200
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
201 =item (F<./results_i#_cq#/clustal_omega.log>)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
202
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
203 Optional log file of verbose B<Clustal Omega> C<STDOUT/STDERR> messages
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
204
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
205 =item (F<./results_i#_cq#/query-ID_aln.fasta>)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
206
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
207 Optional B<Clustal Omega> multiple alignment of each
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
208 F<query-ID_hits.faa> result file in FASTA alignment format
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
209
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
210 =item (F<./results_i#_cq#/query-ID_tree.nwk>)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
211
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
212 Optional B<Clustal Omega> NJ-guide tree in Newick format
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
213
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
214 =back
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
215
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
216 =head1 EXAMPLES
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
217
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
218 =head2 L<C<cds_extractor.pl>|/cds_extractor>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
219
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
220 =over
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
221
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
222 =item C<for file in *.(gbk|embl); do perl cds_extractor.pl -i "$file" -p -f; done>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
223
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
224 =item C<cat *.faa E<gt> subject.faa>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
225
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
226 =item C<rm !(subject).faa>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
227
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
228 =back
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
229
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
230 =head2 Legacy B<BLASTP>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
231
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
232 =over
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
233
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
234 =item C<formatdb -p T -i subject.faa -n prot_finder_db>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
235
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
236 =item C<blastall -p blastp -d prot_finder_db -i query.faa -o prot_finder.blastp -e 1e-10 -F F -s T -b 500>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
237
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
238 =back
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
239
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
240 B<or>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
241
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
242 =head2 B<BLASTP+>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
243
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
244 =over
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
245
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
246 =item C<makeblastdb -dbtype prot -in subject.faa -out prot_finder_db>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
247
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
248 =item C<blastp -db prot_finder_db -query query.faa -out prot_finder.blastp -evalue 1e-10 -seg no -use_sw_tback -num_alignments 500>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
249
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
250 =back
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
251
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
252 =head2 C<prot_finder.pl>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
253
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
254 =over
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
255
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
256 =item C<perl prot_finder.pl -r prot_finder.blastp -s subject.faa -cov_s 80 E<gt> blast_hits.tsv>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
257
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
258 =back
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
259
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
260 B<or>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
261
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
262 =over
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
263
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
264 =item C<perl prot_finder.pl -r prot_finder.blastp -s subject.faa -d result_dir -f -q query.faa -i 50 -cov_q 50 -b -a -p ~/bin/clustalo -t 6 E<gt> result_dir/blast_hits.tsv>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
265
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
266 =back
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
267
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
268 =head2 All-in-one with bash script pipeline
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
269
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
270 =over
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
271
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
272 =item C<./prot_finder_pipe.sh -q query.faa -s subject.faa E<gt> blast_hits.tsv>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
273
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
274 =back
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
275
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
276 B<or>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
277
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
278 =over
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
279
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
280 =item C<./prot_finder_pipe.sh -q query.faa -f (embl|gbk) -d result_dir -p legacy -e 0 -t 12 -i 50 -c 50 -k 30 -b -a -o ~/bin/clustalo -m E<gt> result_dir/blast_hits.tsv>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
281
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
282 =back
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
283
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
284 =head1 DEPENDENCIES
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
285
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
286 =over
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
287
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
288 =item L<B<BioPerl>|http://www.bioperl.org>>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
289
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
290 Tested with B<BioPerl> version 1.006923
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
291
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
292 =item L<B<Clustal Omega>|http://www.clustal.org/omega/>
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
293
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
294 Tested with B<Clustal Omega> version 1.2.1
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
295
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
296 =back
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
297
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
298 =head1 VERSION
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
299
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
300 0.7.1 update: 05-04-2016
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
301 0.1 03-09-2012
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
302
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
303 =head1 AUTHOR
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
304
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
305 Andreas Leimbach aleimba[at]gmx[dot]de
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
306
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
307 =head1 LICENSE
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
308
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
309 This program is free software: you can redistribute it and/or modify
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
310 it under the terms of the GNU General Public License as published by
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
311 the Free Software Foundation; either version 3 (GPLv3) of the
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
312 License, or (at your option) any later version.
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
313
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
314 This program is distributed in the hope that it will be useful, but
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
315 WITHOUT ANY WARRANTY; without even the implied warranty of
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
316 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
317 General Public License for more details.
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
318
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
319 You should have received a copy of the GNU General Public License
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
320 along with this program. If not, see L<http://www.gnu.org/licenses/>.
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
321
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
322 =cut
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
323
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
324
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
325 ########
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
326 # MAIN #
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
327 ########
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
328
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
329 use strict;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
330 use warnings;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
331 use autodie;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
332 use Getopt::Long;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
333 use Pod::Usage;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
334 use Bio::SeqIO; # BioPerl module to handle sequence input/output
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
335 use Bio::SearchIO; # BioPerl module to handle BLAST reports
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
336 use Bio::Index::Fasta; # BioPerl module to create an index for a multi-FASTA file for faster sequence retrieval
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
337
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
338 my $Cmdline = "$0 @ARGV"; # used call command
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
339
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
340 ### Get the options with Getopt::Long
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
341 my $Blastp_Report_File; # path to BLASTP report/output file
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
342 my $Subject_File; # multi-FASTA protein file from 'cds_extractor.pl' (with options '-p -f') which was used to create the BLASTP DB (the subjects)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
343 my $Result_Dir; # path to result folder; default is set below to '"./results_i".$Ident_Cutoff."_cq".$Cov_Query_Cutoff'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
344 my $Opt_Force_Result_Dir; # force output to existing results folder
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
345 my $Query_File; # optionally, needed to include the query proteins in the result/hit multi-FASTA protein file for subsequent alignment
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
346 my $Opt_Best_Hit; # optionally, give only the best hit (i.e. highest identity) for each subject sequence, even if a subject sequence has several hits with different queries; if option not given report all subjects hits for each query
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
347 my $Ident_Cutoff = 70; # query identity cutoff (without gaps)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
348 my $Cov_Query_Cutoff = 70; # query coverage cutoff
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
349 my $Cov_Subject_Cutoff = 0; # subject/hit coverage cutoff
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
350 my $Opt_Align_Clustal; # optionally, align the result sequences with Clustal Omega
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
351 my $Clustal_Path; # optionally, give path to the Clustal Omega binary
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
352 my $Clustal_Threads; # optionally, give number of threads Clustal Omega will use
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
353 my $VERSION = '0.7.1';
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
354 my ($Opt_Version, $Opt_Help);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
355 GetOptions ('report=s' => \$Blastp_Report_File,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
356 'subject=s' => \$Subject_File,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
357 'dir_result=s' => \$Result_Dir,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
358 'force_dir' => \$Opt_Force_Result_Dir,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
359 'query=s' => \$Query_File,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
360 'best_hit' => \$Opt_Best_Hit,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
361 'ident_cutoff=i' => \$Ident_Cutoff,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
362 'cov_query_cutoff=i' => \$Cov_Query_Cutoff,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
363 'cov_subject_cutoff=i' => \$Cov_Subject_Cutoff,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
364 'align_clustalo' => \$Opt_Align_Clustal,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
365 'path_clustalo=s' => \$Clustal_Path,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
366 'threads_clustalo=i' => \$Clustal_Threads,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
367 'version' => \$Opt_Version,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
368 'help|?' => \$Opt_Help)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
369 or pod2usage(-verbose => 1, -exitval => 2);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
370
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
371
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
372
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
373 ### Run perldoc on POD, enforce mandatory options, and check options
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
374 pod2usage(-verbose => 2) if ($Opt_Help);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
375 die "$0 $VERSION\n" if ($Opt_Version);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
376
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
377 if (!$Blastp_Report_File || !$Subject_File) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
378 my $warning = "\n### Fatal error: Mandatory options '-r' and '-s' or their arguments are missing!\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
379 pod2usage(-verbose => 1, -message => $warning, -exitval => 2);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
380 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
381 die "\n### Fatal error:\nBLASTP report file '$Blastp_Report_File' does not exist: $!\n" if (!-e $Blastp_Report_File);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
382 die "\n### Fatal error:\nSubject multi-FASTA protein sequence file '$Subject_File' does not exist: $!\n" if (!-e $Subject_File);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
383 die "\n### Fatal error:\nQuery multi-FASTA protein sequence file '$Query_File' does not exist: $!\n" if ($Query_File && !-e $Query_File);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
384
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
385 if (($Ident_Cutoff < 0 || $Ident_Cutoff > 100) || ($Cov_Query_Cutoff < 0 || $Cov_Query_Cutoff > 100) || ($Cov_Subject_Cutoff < 0 || $Cov_Subject_Cutoff > 100)) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
386 my $warning = "\n### Fatal error:\nAll cutoff options ('-i', '-cov_q', and '-cov_s') require an integer number >= 0 and <= 100 as value!\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
387 pod2usage(-verbose => 1, -message => $warning, -exitval => 2);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
388 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
389
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
390 die "\n### Fatal error:\nOption '-p' requires the path to an executable Clustal Omega binary as value, not '$Clustal_Path'!\n" if ($Clustal_Path && !-x $Clustal_Path); # without '-p': presence of 'clustalo' in global PATH checked by system call at end of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
391 if (!$Opt_Align_Clustal && ($Clustal_Path || $Clustal_Threads)) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
392 warn "\n### Warning: Options '-p' and/or '-t' set without their required option '-a', forcing option '-a'!\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
393 $Opt_Align_Clustal = 1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
394 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
395
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
396 if ($Clustal_Threads) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
397 my $max_cpus = qx{nproc --all 2> /dev/null} || die "\n### Fatal error:\nCouldn't run Unix GNU command 'nproc' to determine the overall number of processors on the local system!\n"; # get max number of processors on the system; '||' because success exit code is zero (in '$?')
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
398 chomp $max_cpus;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
399 if ($Clustal_Threads < 0 || $Clustal_Threads > $max_cpus) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
400 my $warning = "\n### Fatal error: Option '-t' requires an integer number > 0 and <= $max_cpus as value, not '$Clustal_Threads'!\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
401 pod2usage(-verbose => 1, -message => $warning, -exitval => 2);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
402 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
403 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
404
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
405 print STDERR "\nScript call command: $Cmdline\n"; # print call command after '-h|-v'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
406
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
407
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
408
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
409 ### Create result folder
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
410 if (!$Result_Dir) { # can't give default before 'GetOptions' in case cutoffs are set by the user
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
411 $Result_Dir = "./results_i".$Ident_Cutoff."_cq".$Cov_Query_Cutoff;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
412 } else {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
413 $Result_Dir =~ s/\/$//; # get rid of a potential '/' at the end of $Result_Dir path
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
414 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
415 if (-e $Result_Dir && !$Opt_Force_Result_Dir) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
416 empty_dir($Result_Dir); # subroutine to empty a directory with user interaction
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
417 } elsif (!$Opt_Force_Result_Dir) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
418 mkdir $Result_Dir;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
419 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
420
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
421
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
422
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
423 ### Parse the BLASTP report/output file; print queries, subject ID (e.g. locus tag) hits, and stats; or store in hash for option '-b'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
424 print STDERR "Parsing BLASTP report '$Blastp_Report_File' and looking for significant hits according to cutoffs ...\n"; # run status of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
425 print "# subject_organism\tsubject_ID\tsubject_gene\tsubject_protein_desc\tquery_ID\tquery_desc\tquery_coverage [%]\tquery_identities [%]\tsubject/hit_coverage [%]\te-value of best HSP\tbit-score of best HSP\n"; # header for output table with significant BLASTP hits
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
426
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
427 my %Query_Acc; # hash to check if query accessions/IDs are unique (which they have to be because of %Blast_Hits below) and to store all query_acc for '@Queries_No_Blasthit' below
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
428 my %Blast_Hits; # hash of array to store significant BLASTP hits for sequence retrieval afterwards; query_acc as key and subject ID hits as anonymous array
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
429 my %Best_Subject_Hit; # for option '-b'; hash of hash to store subject/query info/stats for only the best hit for each subject sequence ID (key)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
430
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
431 my $Blast_Report = new Bio::SearchIO(-file => "<$Blastp_Report_File", -format => 'blast'); # Bio::SearchIO object
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
432 while (my $result = $Blast_Report->next_result) { # Bio::Search::Result::GenericResult object; several query sequences possible ($result = entire analysis for a single query seq)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
433 my $hit_present = 0; # indicates if significant BLASTP hit found for a query
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
434 my @subject_ids; # array to store ALL significant subject ID hits for each query, for %Blast_Hits anonymous array
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
435
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
436 my $query_desc = $result->query_description;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
437 my $query_acc = $result->query_accession =~ s/\.$//r; # = query ID; rm a '.' if present at the end of the string (for non-NCBI FASTA headers); non-destructive modifier causes the result of the substitution to be returned instead of modifying $_ (see http://perldoc.perl.org/perlrequick.html#Search-and-replace)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
438 die "\n### Fatal error:\nQuery accession/ID '$query_acc' is not unique in the query file, but has to be. Please edit all repetitive occurences and rerun BLASTP or the bash script pipeline!\n" if ($Query_Acc{$query_acc});
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
439 $Query_Acc{$query_acc} = 1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
440
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
441 while (my $hit = $result->next_hit) { # Bio::Search::Hit::GenericHit object; several subject sequences in the database might have hits for a query
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
442 my $perc_identity = $hit->frac_identical('query'); # ignores gaps; method will call (requires) BioPerls HSP tiling 'tile_hsps()' to get value (see http://search.cpan.org/dist/BioPerl/Bio/Search/Hit/GenericHit.pm and for 'tile_hsps()' http://search.cpan.org/~cjfields/BioPerl-1.6.924/Bio/Search/SearchUtils.pm)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
443 $perc_identity *= 100;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
444 my $query_cov = $hit->frac_aligned_query; # method requires hsp tiling
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
445 $query_cov *= 100;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
446 my $hit_cov = $hit->frac_aligned_hit; # = subject coverage; method requires hsp tiling
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
447 $hit_cov *= 100;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
448
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
449 # "significant" hit according to cutoffs
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
450 if ($perc_identity >= $Ident_Cutoff && $query_cov >= $Cov_Query_Cutoff && $hit_cov >= $Cov_Subject_Cutoff) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
451 $hit_present = 1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
452 my $hit_id = $hit->name; # = subject_id
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
453 my ($gene, $product, $organism) = split_fasta_header($hit_id, $hit->description); # subroutine to split the subject FASTA ID lines (see cds_extractor.pl with option '-f')
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
454 $gene = '' if (!$gene); # empty string if gene tag doesn't exist for print; $product and $organism should always exist
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
455 my $evalue = $hit->significance;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
456 $evalue =~ s/\,$//; # rm ',' from the end of the evalue
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
457
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
458 if (!$Opt_Best_Hit) { # print all hits to STDOUT directly without option '-b'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
459 print "$organism\t$hit_id\t$gene\t$product\t$query_acc\t$query_desc\t$query_cov\t$perc_identity\t$hit_cov\t$evalue\t", $hit->bits, "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
460 push(@subject_ids, $hit_id); # store all hits for current query
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
461
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
462 } elsif ($Opt_Best_Hit) { # store only the best hit for each subject ID (need to be stored, not printed, to check all queries = $result); print to STDOUT is below
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
463 if (!$Best_Subject_Hit{$hit_id} || $Best_Subject_Hit{$hit_id}->{'perc_identity'} < $perc_identity) { # either hit/subject ID doesn't exist yet or replace with hit of higher identity
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
464 $Best_Subject_Hit{$hit_id} = {'organism' => $organism,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
465 'gene' => $gene,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
466 'product' => $product,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
467 'query_acc' => $query_acc,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
468 'query_desc' => $query_desc,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
469 'query_cov' => $query_cov,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
470 'perc_identity' => $perc_identity,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
471 'hit_cov' => $hit_cov,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
472 'evalue' => $evalue,
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
473 'bit_score' => $hit->bits}; # hash of hash; subject/hit ID keys are unique with '-b'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
474 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
475 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
476 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
477 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
478
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
479 # only if significant hit for current query; needed after 'next_hit'-while to collect all (subject) hits
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
480 $Blast_Hits{$query_acc} = \@subject_ids if ($hit_present && !$Opt_Best_Hit); # hash of array; the same hit/subject ID can be a hit for different queries (without option '-b'), thus subject IDs are not unique and hash of (anonymous) array data structure is suitable; done in the same way for option '-b' during print out below (not here to check all queries)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
481 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
482
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
483
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
484
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
485 ### Option '-b' given; print out only the best hit for each hit/subject sequence and store respective IDs in %Blast_Hits (as was already done without '-b' above)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
486 if ($Opt_Best_Hit) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
487 print STDERR "Printing only the best hit for each subject protein in the whole BLASTP analysis (option '-b') ...\n"; # run status of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
488 my $skip = ''; # skip queries that have already been processed
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
489
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
490 foreach my $hit_id (sort{lc $Best_Subject_Hit{$a}->{'query_acc'} cmp lc $Best_Subject_Hit{$b}->{'query_acc'}} keys %Best_Subject_Hit) { # sort hit/subject IDs (keys of %Best_Subject_Hit) by 'query_acc' to look at each query_acc only once by $skip-ing the others
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
491 next if ($Best_Subject_Hit{$hit_id}->{'query_acc'} eq $skip);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
492 $skip = $Best_Subject_Hit{$hit_id}->{'query_acc'};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
493
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
494 my @subject_ids = sort{lc $Best_Subject_Hit{$a}->{'organism'} cmp lc $Best_Subject_Hit{$b}->{'organism'}} grep($Best_Subject_Hit{$_}->{'query_acc'} eq $Best_Subject_Hit{$hit_id}->{'query_acc'}, keys %Best_Subject_Hit); # get all hit/subject IDs for the current 'query_acc', sorted by 'organism'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
495 $Blast_Hits{$skip} = \@subject_ids; # store all hit/subject IDs in hash of array with query_acc as key ($skip here), compatible to above without '-b'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
496
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
497 foreach my $subject_id (sort @subject_ids) { # print best hits to STDOUT, corresponding to the print of all hits without '-b' above
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
498 print "$Best_Subject_Hit{$subject_id}->{'organism'}\t".
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
499 "$subject_id\t".
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
500 "$Best_Subject_Hit{$subject_id}->{'gene'}\t".
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
501 "$Best_Subject_Hit{$subject_id}->{'product'}\t".
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
502 "$Best_Subject_Hit{$subject_id}->{'query_acc'}\t".
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
503 "$Best_Subject_Hit{$subject_id}->{'query_desc'}\t".
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
504 "$Best_Subject_Hit{$subject_id}->{'query_cov'}\t".
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
505 "$Best_Subject_Hit{$subject_id}->{'perc_identity'}\t".
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
506 "$Best_Subject_Hit{$subject_id}->{'hit_cov'}\t".
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
507 "$Best_Subject_Hit{$subject_id}->{'evalue'}\t".
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
508 "$Best_Subject_Hit{$subject_id}->{'bit_score'}\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
509 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
510 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
511 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
512
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
513 my @Queries_No_Blasthit = grep (!$Blast_Hits{$_}, sort{lc $a cmp lc $b} keys %Query_Acc); # get all 'query_acc' without a significant and (for '-b') best blast hit (can use '$hit_present' above only without '-b', but to make consistent use '%Blast_Hits' with and without '-b')
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
514 # With '-b' have to use the approach here in case a query protein has a significant hit but not the best hit in any subject, because then wouldn't be in the results (a significant query hit might also be overwritten by a higher identity subsequent hit to another query, thus $hit_present doesn't work with '-b')
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
515 if (keys %Query_Acc == @Queries_No_Blasthit) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
516 rmdir $Result_Dir;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
517 die "\nNo significant BLASTP hits could be found, exiting!\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
518 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
519
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
520
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
521 ### Create index for multi-FASTA subject protein file for faster sequence retrieval; indeces have to be unique (which works fine for locus tags, the most probable subject IDs with cds_extractor.pl)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
522 print STDERR "Indexing subject multi-FASTA file, '$Subject_File\.idx', for sequence retrieval ...\n"; # run status of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
523 my $Inx = Bio::Index::Fasta->new(-filename => "$Subject_File\.idx", -write_flag => 1); # see http://www.bioperl.org/wiki/HOWTO:Beginners#Indexing_for_Fast_Retrieval or http://www.bioperl.org/wiki/HOWTO:Local_Databases
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
524 $Inx->make_index($Subject_File); # by default the FASTA indexing code will use the string following the > character as a key, in this case the subject IDs
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
525
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
526
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
527
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
528 ### Get the significant BLASTP hit sequences from the indexed multi-FASTA protein subject file and the query protein file (w/o index) and write them to the result dir
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
529 print STDERR "Using the index to retrieve subject protein sequences from significant BLASTP hits for each query "; # run status of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
530 my $Query_Seqioobj;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
531 if ($Query_File) { # option '-q' with path to query multi-FASTA file; to retrieve respective query seq and write it as first seq into the hit multi-FASTA result files (*query*_hits.faa)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
532 print STDERR "including each query sequence from file '$Query_File' (option '-q') "; # run status of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
533 $Query_Seqioobj = Bio::SeqIO->new(-file => "<$Query_File", -format => 'fasta'); # Bio::SeqIO object
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
534 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
535 print STDERR "...\n"; # run status of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
536
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
537 my @Fasta_Files; # store all hit result FASTA filenames for Clustal Omega
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
538 foreach my $query_acc (sort keys %Blast_Hits) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
539 my $fasta_outfile = "$Result_Dir/$query_acc\_hits.faa";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
540 push (@Fasta_Files, $fasta_outfile);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
541 my $seqio_outobj = Bio::SeqIO->new(-file => ">$fasta_outfile"); # write a multi-FASTA file of hits for each query; format not needed, as everything is and should be FASTA anyway
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
542
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
543 # get the corresponding query_acc sequence if option '-q'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
544 if ($Query_File) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
545 my $query_found = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
546 while (my $query_seqinobj = $Query_Seqioobj->next_seq) { # Bio::Seq object; index not needed should be small file
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
547 if ($query_seqinobj->display_id eq $query_acc) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
548 $query_found = 1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
549 $seqio_outobj->write_seq($query_seqinobj); # print seq entry
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
550 seek($Query_Seqioobj->_fh, 0, 0); # set filepointer back to zero for the next query_acc/ID
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
551 last; # query accn/ID is found
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
552 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
553 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
554 die "\n### Fatal error:\nQuery ID '$query_acc' not found in the query file '$Query_File' given with option '-q'. Sure this is the correct file which was used for the BLASTP?\n" if (!$query_found);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
555 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
556
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
557 # get all hit-subject sequences for the query
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
558 foreach my $subject_id (sort @{ $Blast_Hits{$query_acc} }) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
559 my $subject_seqobj = $Inx->fetch($subject_id); # a Bio::Seq object; fetch subject seq from index
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
560 die "\n### Fatal error:\nSubject ID '$subject_id' not found in the subject file '$Subject_File' given with option '-s'. Sure this is the correct file which was used for the BLASTP?\n" if (!$subject_seqobj);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
561
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
562 ## used to have the following out-commented code, but why not use original desc from cds_extractor?
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
563 #my ($gene, $product, $organism) = split_fasta_header($subject_id, $subject_seqobj->desc);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
564 #if ($gene) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
565 #$subject_seqobj->desc("$organism $gene"); # set the description of the FASTA ID line to a new one, if a gene name exists
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
566 #} else {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
567 #$subject_seqobj->desc("$organism"); # w/o gene name
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
568 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
569
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
570 $seqio_outobj->write_seq($subject_seqobj);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
571 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
572 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
573
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
574
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
575
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
576 ### OPTIONAL method to extract the BLASTP hit protein sequences without BioPerl and without an index; works with out-commented sub 'read_fasta_entry'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
577 #print STDERR "Retrieving subject protein sequences from significant BLASTP hits for each query "; # run status of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
578 #open (my $Subject_Fh, "<", $Subject_File);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
579
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
580 #my $Query_Fh;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
581 #if ($Query_File) { # option '-q' with path to query multi-FASTA file; to retrieve respective query seq and write it as first seq into the hit multi-FASTA result files (*query*_hits.faa)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
582 #print STDERR "including each query sequence from file '$Query_File' (option '-q') "; # run status of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
583 #open ($Query_Fh, "<", $Query_File);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
584 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
585 #print STDERR "...\n"; # run status of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
586
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
587 #my @Fasta_Files; # store all hit result FASTA filenames for Clustal Omega
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
588 #foreach my $query_acc (sort keys %Blast_Hits) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
589 #my $fasta_outfile = "$Result_Dir/$query_acc\_hits.faa";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
590 #push (@Fasta_Files, $fasta_outfile);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
591 #open (my $fasta_out_fh, ">", $fasta_outfile); # write a multi-FASTA file of hits for each query
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
592
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
593 ## get the corresponding query_acc sequence if option '-q'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
594 #if ($Query_File) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
595 #my $query_found = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
596 #my $next_fasta_header; # for multi-line FASTA input files to store next entry header/ID line while parsing in subroutine 'read_fasta_entry'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
597 #while (<$Query_Fh>) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
598 #chomp;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
599 #(my $seq_entry, $next_fasta_header) = read_fasta_entry($_, $Query_Fh, $next_fasta_header); # subroutine to read each FASTA seq entry of a multi-seq file separately; return header (->[0]) and seq (->[1]) as anonymous array in $seq_entry
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
600 #if ($seq_entry->[0] =~ /^>$query_acc/) { # use '^' to anchor query acc/ID match (can't use ' ' as below for subjects, in case FASTA header has only one "word"/term after the '>')
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
601 #$query_found = 1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
602 #print $fasta_out_fh "$seq_entry->[0]\n$seq_entry->[1]\n\n"; # print seq entry
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
603 #seek $Query_Fh, 0, 0; # set filepointer back to zero for the next query acc/ID
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
604 #$. = 0; # set line number of seq file to 0 (seek doesn't do it automatically)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
605 #last; # query acc/ID found
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
606 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
607 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
608 #die "\n### Fatal error:\nQuery sequence '$query_acc' not found in the query file '$Query_File' given with option '-q'. Sure this is the correct file which was used for the BLASTP?\n" if (!$query_found);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
609 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
610
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
611 ## get all hit-subject sequences for the current query
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
612 #foreach my $subject_id (sort @{ $Blast_Hits{$query_acc} }) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
613 #my $subject_found = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
614 #my $next_fasta_header;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
615 #while (<$Subject_Fh>) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
616 #chomp;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
617 #(my $seq_entry, $next_fasta_header) = read_fasta_entry($_, $Subject_Fh, $next_fasta_header); # subroutine
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
618 #if ($seq_entry->[0] =~ /^>$subject_id /) { # use '^' and ' ' to force complete subject ID match (e.g. problem with ABU83972 'ECABU_c27750' and CFT073 'c2775')
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
619 #$subject_found = 1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
620
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
621 ### used to have the following out-commented code, but why not use original desc from cds_extractor?
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
622 ## print FASTA header/ID for subject sequence
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
623 ##$seq_entry->[0] =~ s/>.+\s(g=.+)$/$1/; # get rid of the subject ID for subroutine 'split_fasta_header' below
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
624 ##my ($gene, $product, $organism) = split_fasta_header($subject_id, $seq_entry->[0]);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
625 ##print $fasta_out_fh ">$subject_id $organism ";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
626 ##if ($gene) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
627 ##print $fasta_out_fh "$gene\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
628 ##} else {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
629 ##print $fasta_out_fh "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
630 ##}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
631 ##print $fasta_out_fh "$seq_entry->[1]\n\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
632
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
633 #print $fasta_out_fh "$seq_entry->[0]\n$seq_entry->[1]\n\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
634 #seek $Subject_Fh, 0, 0; # for the next $subject_id
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
635 #$. = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
636 #last;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
637 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
638 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
639 #die "\n### Fatal error:\nSubject sequence '$subject_id' not found in the subject sequence file '$Subject_File' given with option '-s'. Sure this is the correct file which was used for the BLASTP?\n" if (!$subject_found);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
640 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
641 #close $fasta_out_fh;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
642 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
643 #close $Subject_Fh;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
644 #close $Query_Fh if ($Query_File);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
645
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
646
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
647
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
648 ### Align with Clustal Omega if option '-a' is set
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
649 if ($Opt_Align_Clustal) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
650 print STDERR "Starting Clustal Omega alignment (option '-a') with file\n"; # run status of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
651 foreach my $fasta_file (@Fasta_Files) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
652 print STDERR " $fasta_file";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
653 my $out = $fasta_file =~ s/\_hits.faa$//r;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
654 my $clustal_call = " -i $fasta_file -o $out\_aln.fasta --verbose --guidetree-out=$out\_tree.nwk >> $Result_Dir/clustal_omega.log"; # redirect verbose STDOUT output to file (can't use clustalo option '-l' because will overwrite for each call)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
655 $clustal_call = " --threads=$Clustal_Threads" . $clustal_call if ($Clustal_Threads);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
656 if ($Clustal_Path) { # append path to Clustal Omega binary if option '-p'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
657 $clustal_call = $Clustal_Path . $clustal_call;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
658 } else { # otherwise 'clustalo' hopefully present in global path
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
659 $clustal_call = 'clustalo' . $clustal_call;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
660 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
661 system ($clustal_call) == 0 or die "\n### Fatal error:\nClustal Omega alignment with option '-a' for multi-FASTA output file '$fasta_file' could not be run. If Clustal Omega's binary 'clustalo' is not installed in your global \$PATH use option '-p' to give the path to the binary! $!\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
662 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
663 print STDERR "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
664 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
665
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
666
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
667
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
668 ### Final run status of script, state if queries without BLASTP hits
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
669 print STDERR "Result files were created in '$Result_Dir'"; # run status of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
670 if (@Queries_No_Blasthit) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
671 my $no_blasthit_file = "$Result_Dir/queries_no_blastp-hits.txt";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
672 print STDERR ", including '$no_blasthit_file' listing all queries without a significant BLASTP hit"; # run status of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
673 open (my $no_blasthit_fh, ">", "$no_blasthit_file");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
674 print $no_blasthit_fh join("\n", @Queries_No_Blasthit), "\n"; # print query_accs to file
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
675 close $no_blasthit_fh;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
676 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
677 print STDERR ".\n"; # run status of script
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
678 print STDERR "If no further BLASTPs with the subject sequences in file '$Subject_File' are needed the index file '$Subject_File.idx' can be deleted!\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
679
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
680
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
681 exit;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
682
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
683
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
684
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
685 ###############
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
686 # Subroutines #
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
687 ###############
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
688
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
689 ### Subroutine to empty a directory with user interaction
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
690 sub empty_dir {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
691 my $dir = shift;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
692 print STDERR "\nDirectory '$dir' already exists! You can use either option '-d' to set a different result directory name, or do you want to replace the directory and all its contents [y|n]? ";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
693 my $user_ask = <STDIN>;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
694 if ($user_ask =~ /y/i) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
695 unlink glob "$dir/*"; # remove all files in results directory
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
696 } else {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
697 die "\nScript abborted!\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
698 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
699 return 1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
700 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
701
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
702
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
703
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
704 ### Read sequence entries from FASTA file
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
705 #sub read_fasta_entry {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
706 #my ($line, $fh, $next_fasta_header) = @_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
707
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
708 ## possible multi-line seq in FASTA
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
709 #my ($seq, $header);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
710 #if ($. == 1) { # first line of file
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
711 #die "\n### Fatal error:\nNot a FASTA input file, first line of file should be a FASTA ID/header line and start with a '>':\n$line\n" if ($line !~ /^>/);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
712 #$header = $line;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
713 #} elsif ($next_fasta_header) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
714 #$header = $next_fasta_header;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
715 #$seq = $line;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
716 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
717 #while (<$fh>) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
718 #chomp;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
719 #if (/^>/) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
720 #$next_fasta_header = $_; # store ID/header for next seq entry
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
721 #return ([$header, $seq], $next_fasta_header); # return anonymous array with current header and seq
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
722 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
723 #$seq .= $_; # concatenate multi-line seq
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
724 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
725 #return ([$header, $seq], $next_fasta_header) if (eof);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
726 #return; # return undef
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
727 #}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
728
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
729
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
730
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
731 ### Subroutine to split the headers/IDs of the protein multi-FASTA files from 'cds_extractor.pl' and its '-f' option
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
732 sub split_fasta_header {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
733 my ($id, $desc) = @_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
734
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
735 my ($gene, $product, $length, $organism, $ec); # $length and $ec not used
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
736 $desc =~ s/^\s*//; # remove possible space at begin of desc string (might be introduced by BioPerl as explained below); needed in case no 'g=' but introduced space in front of 'p=', then split will not work below
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
737 $desc =~ s/\s(?!p=|l=|o=|ec=)//g; # if a FASTA ID line is too long the BLAST report hit desc is over several lines and BioPerl will introduce space characters for a newline, thus get rid of these extra spaces with a lookahead in the regex but leave the spaces in the cds_extractor file format intact
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
738 die "\n### Fatal error:\nFASTA 'annotation' from 'cds_extractor.pl' is not recognized on the following line. Please use 'cds_extractor.pl' with options '-p -f' to create your multi-FASTA protein subject files.\n>$id $desc\n" if ($desc !~ /(g=\w+)?\s? # optional gene tag
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
739 (p=\S+)?\s? # optional product tag; \S+ instead of \w needed for non-alphanumeric characters (e.g. commas)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
740 l=\d+\.\.\d+\s? # location always included
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
741 (o=\S+)?\s? # optional organism tag
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
742 (ec=\S+)? # optional EC number tag
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
743 /x); # for the format see 'cds_extractor.pl'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
744
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
745 foreach (split(/\s/, $desc)) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
746 if (/g=(.*)$/) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
747 $gene = $1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
748 } elsif (/p=(.*)$/) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
749 warn "\n### Warning:\nNo product annotation (p=) on line:\n>$id $desc\nProceeding ...\n" if (!$1);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
750 $product = $1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
751 $product =~ tr/_/ /; # replace the '_' back to spaces, as this was changed in 'cds_extractor.pl'
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
752 } elsif (/l=(\d+)\.\.(\d+)$/) { # $length not used
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
753 $length = abs($2 - $1) + 1; # abs(stop - start) + 1
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
754 } elsif (/o=(.*)$/) {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
755 $organism = $1; # don't replace the '_' back, no spaces might be better for phylogenetic programs
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
756 } elsif (/ec=(.*)$/) { # $ec not used
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
757 $ec = $1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
758 } else {
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
759 die "\n### Fatal error:\nFASTA 'annotation' is not recognized on the following line. Please use 'cds_extractor.pl' with options '-p -f' to create your multi-FASTA protein subject files.\n>$id $desc\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
760 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
761 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
762 return ($gene, $product, $organism);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
763 }