| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | convert_hmmscan_to_htab.pl - creates an htab file from hmmscan or hmmpfam raw input depending on the version of hmmer passed using HmmTools.pm | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | USAGE: hmmer2htab.pl | ||
| 10 | --input_file=/path/to/hmmer.raw | ||
| 11 | --output_htab=/path/to/hmmer.htab | ||
| 12 | |||
| 13 | =head1 OPTIONS | ||
| 14 | |||
| 15 | B<--input_file,-i> | ||
| 16 | Raw output from hmmscan or hmmpfam run | ||
| 17 | |||
| 18 | B<--output_htab,-o> | ||
| 19 | HTAB output file | ||
| 20 | |||
| 21 | B<--mldbm_file,-m> | ||
| 22 | MLDBM perl data structure (tied hash) containing HMM information. This was previously | ||
| 23 | queried out of egad.hmm2. See hmmlib_to_mldbm.pl for more information. | ||
| 24 | |||
| 25 | B<--prog_ver,-p> | ||
| 26 | The version of hmmer [hmmer2 or hmmer3] used to produce the raw output. Default is hmmer3 | ||
| 27 | |||
| 28 | B<--donotrun> | ||
| 29 | skip pretty much any noticeble activity | ||
| 30 | |||
| 31 | B<--log,-l> | ||
| 32 | Logfile. | ||
| 33 | |||
| 34 | B<--help,-h> | ||
| 35 | Print this message | ||
| 36 | |||
| 37 | =head1 DESCRIPTION | ||
| 38 | |||
| 39 | This script is used to convert the output from hmmscan or hmmpfam into htab using $ANNOT_DEVEL/hmm/bin/HmmTools.pm | ||
| 40 | |||
| 41 | =head1 INPUT | ||
| 42 | |||
| 43 | Output can be in multisequence format (generated from hmmscan or hmmpfam from multifasta input). | ||
| 44 | |||
| 45 | Can also be a list of file names. | ||
| 46 | |||
| 47 | example hmmscan raw output: | ||
| 48 | |||
| 49 | # hmmscan :: search sequence(s) against a profile database | ||
| 50 | # HMMER 3.0 (March 2010); http://hmmer.org/ | ||
| 51 | # Copyright (C) 2010 Howard Hughes Medical Institute. | ||
| 52 | # Freely distributed under the GNU General Public License (GPLv3). | ||
| 53 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 54 | # query sequence file: /usr/local/projects/aengine/sagrawal/output_repository/translate_sequence/2722941276_translate/i1/g1/testApr6.polypeptide.2723277720.1.fsa | ||
| 55 | # target HMM database: /export/test_sagrawal/combined_hmm.lib | ||
| 56 | # output directed to file: /export/test_sagrawal/polytest1.raw | ||
| 57 | # prefer accessions over names: yes | ||
| 58 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 59 | |||
| 60 | Query: testApr6.polypeptide.2723277720.1 [L=285] | ||
| 61 | Scores for complete sequence (score includes all domains): | ||
| 62 | --- full sequence --- --- best 1 domain --- -#dom- | ||
| 63 | E-value score bias E-value score bias exp N Model Description | ||
| 64 | ------- ------ ----- ------- ------ ----- ---- -- -------- ----------- | ||
| 65 | 7.8e-76 254.9 35.0 8.9e-76 254.7 24.2 1.0 1 PF00950.11 ABC 3 transport family | ||
| 66 | 7.7e-42 143.7 31.1 8.7e-42 143.5 21.6 1.0 1 TIGR03770 anch_rpt_perm: anchored repeat-type ABC transport | ||
| 67 | 9.3e-07 28.0 30.3 9.3e-07 28.0 21.0 1.3 1 PF01032.12 FecCD transport family | ||
| 68 | ------ inclusion threshold ------ | ||
| 69 | 0.18 11.1 0.8 0.31 10.3 0.5 1.4 1 PF08690.4 GET complex subunit GET2 | ||
| 70 | |||
| 71 | |||
| 72 | Domain annotation for each model (and alignments): | ||
| 73 | >> PF00950.11 ABC 3 transport family | ||
| 74 | # score bias c-Evalue i-Evalue hmmfrom hmm to alifrom ali to envfrom env to acc | ||
| 75 | --- ------ ----- --------- --------- ------- ------- ------- ------- ------- ------- ---- | ||
| 76 | 1 ! 254.7 24.2 2.2e-79 8.9e-76 1 257 [. 10 265 .. 10 266 .. 0.99 | ||
| 77 | |||
| 78 | Alignments for each domain: | ||
| 79 | == domain 1 score: 254.7 bits; conditional E-value: 2.2e-79 | ||
| 80 | PF00950.11 1 qyeflqrallasilvslvagilgsfvvlrrqsllgdalsHaalpGvalafllginlllgailvgliaavaiellkr 76 | ||
| 81 | q+ f+ +all+s++vs+ +++l++f+vl+ ++l+gda+sHa++pG++la++lg++l++ga+++g+++ava ++lk | ||
| 82 | testApr6.polypeptide.2723277720.1 10 QFTFMSHALLISLVVSIPCALLSVFLVLKSWALMGDAMSHAVFPGIVLAWILGLPLATGAFVAGVFCAVATGYLKD 85 | ||
| 83 | 689************************************************************************* PP | ||
| 84 | |||
| 85 | ... | ||
| 86 | ... | ||
| 87 | ... | ||
| 88 | |||
| 89 | Internal pipeline statistics summary: | ||
| 90 | ------------------------------------- | ||
| 91 | Query sequence(s): 1 (285 residues) | ||
| 92 | Target model(s): 16296 (3513130 nodes) | ||
| 93 | Passed MSV filter: 920 (0.0564556); expected 325.9 (0.02) | ||
| 94 | Passed bias filter: 260 (0.0159548); expected 325.9 (0.02) | ||
| 95 | Passed Vit filter: 34 (0.0020864); expected 16.3 (0.001) | ||
| 96 | Passed Fwd filter: 13 (0.000797742); expected 0.2 (1e-05) | ||
| 97 | Initial search space (Z): 16296 [actual number of targets] | ||
| 98 | Domain search space (domZ): 4 [number of targets reported over threshold] | ||
| 99 | # CPU time: 0.52u 3.87s 00:00:04.39 Elapsed: 00:00:07.35 | ||
| 100 | # Mc/sec: 136.22 | ||
| 101 | // | ||
| 102 | |||
| 103 | example hmmscan raw output: | ||
| 104 | |||
| 105 | Logical Depth LDhmmpfam v1.5.4 | ||
| 106 | Copyright (C) Logical Depth, Inc. All rights reserved. | ||
| 107 | TIGR and TIGR Affiliates 300 CPU-socket License | ||
| 108 | |||
| 109 | hmmpfam | ||
| 110 | HMMER 2.3-compatible (LDhmmpfam) | ||
| 111 | |||
| 112 | HMM file: /usr/local/db/HMM_LIB/ALL_LIB_bin.HMM | ||
| 113 | Sequence file: /usr/local/annotation/MOORE/output_repository/translate_sequence/8422_translate_promoted/12/cya1.polypeptide.724320.1.fsa | ||
| 114 | |||
| 115 | Query sequence: cya1.polypeptide.724320.1 | ||
| 116 | Accession: [none] | ||
| 117 | Description: [none] | ||
| 118 | |||
| 119 | Scores for sequence family classification (score includes all domains): | ||
| 120 | Model Description Score E-value #D | ||
| 121 | -------- ----------- ----- ------- -- | ||
| 122 | TIGR01730 RND_mfp: efflux transporter, RND family, MF 114.8 3.5e-31 1 | ||
| 123 | TIGR00998 8a0101: efflux pump membrane protein -97.8 1.2e-06 1 | ||
| 124 | TIGR00999 8a0102: Membrane Fusion Protein cluster 2 p -0.3 4.9e-06 1 | ||
| 125 | TIGR01843 type_I_hlyD: type I secretion membrane fusi -170.3 0.00012 1 | ||
| 126 | |||
| 127 | ... | ||
| 128 | ... | ||
| 129 | ... | ||
| 130 | |||
| 131 | Parsed for domains: | ||
| 132 | Model Domain Seq-f Seq-t HMM-f HMM-t Score E-value | ||
| 133 | -------- ------ ----- ----- ----- ----- ----- ------- | ||
| 134 | TIGR03007 1/1 23 432 .. 1 510 [] -337.6 0.54 | ||
| 135 | TIGR01000 1/1 29 442 .. 1 476 [] -289.8 0.25 | ||
| 136 | TIGR01133 1/1 30 293 .. 1 368 [] -183.6 8.9 | ||
| 137 | TIGR00998 1/1 32 434 .. 1 379 [] -97.8 1.2e-06 | ||
| 138 | |||
| 139 | ... | ||
| 140 | ... | ||
| 141 | ... | ||
| 142 | |||
| 143 | Alignments of top-scoring domains: | ||
| 144 | TIGR03007: domain 1 of 1, from 23 to 432: score -337.6, E = 0.54 | ||
| 145 | *->eqllsYlkgiWrr.RwlfvavAwvVmivGwvvvyvlPdrYeAsarVY | ||
| 146 | e+ + + +++Rwl+ +v + +i+ w | ||
| 147 | cya1.polyp 23 EENRQNTTKNKQFpRWLIPIVILGGGITLWQ---------------- 53 | ||
| 148 | |||
| 149 | VDTQsvLrPLlkGlAvtPnvdqkirIlsrtLlS.....RpnLekVirmlD | ||
| 150 | + +PL+ + t n + ++ +LlS+++++R + +++ +++ | ||
| 151 | cya1.polyp 54 -----IFSPLVIPTTETNNQTPPPKPVETVLLSsgqgnRQV--RLLGQVE 96 | ||
| 152 | |||
| 153 | LDvgakspaqlEalitklqknIsIslagrdNLFtISYeDkdPelA..... | ||
| 154 | + +a+ q + ++k+ + s++ + + +D+d++ A + + | ||
| 155 | cya1.polyp 97 AGAKATLSSQVSGTVEKILVKEGDSITS--GMIVAILDDADGKIAlaeaq 144 | ||
| 156 | |||
| 157 | =head1 OUTPUT | ||
| 158 | |||
| 159 | Description of the output format (tab-delimited, one line per domain hit) | ||
| 160 | |||
| 161 | col perl-col description | ||
| 162 | 1 [0] HMM accession | ||
| 163 | 2 [1] Date search was run (if available), otherwise date of htab parse | ||
| 164 | 3 [2] Length of the HMM (not populated if -s is used) | ||
| 165 | 4 [3] Search program | ||
| 166 | 5 [4] Database file path | ||
| 167 | 6 [5] Sequence accession | ||
| 168 | 7 [6] Alignment start position on HMM match - hmm-f | ||
| 169 | 8 [7] Alignment end position on HMM match - hmm-t | ||
| 170 | 9 [8] Alignment start position on sequence - seq-f | ||
| 171 | 10 [9] Alignment end position on sequence - seq-t | ||
| 172 | 11 [10] frame (only populated if --frames search is run on nucleotide sequence) | ||
| 173 | 12 [11] Domain score | ||
| 174 | 13 [12] Total score | ||
| 175 | 14 [13] Index of domain hit | ||
| 176 | 15 [14] | ||
| 177 | 16 [15] HMM description (may be truncated by hmmsearch or hmmpfam if -s is used) | ||
| 178 | 17 [16] Sequence description (may be truncated by hmmsearch or hmmpfam) | ||
| 179 | 18 [17] Total score trusted cutoff (not populated if -s is used) | ||
| 180 | 19 [18] Total score noise cutoff (not populated if -s is used) | ||
| 181 | 20 [19] Expect value for total hit | ||
| 182 | 21 [20] Expect value for domain hit | ||
| 183 | 22 [21] Domain score trusted cutoff (egad..hmm2.trusted_cutoff2) (not populated if -s is used) | ||
| 184 | 23 [22] Domain score noise cutoff (egad..hmm2.noise_cutoff2) (not populated if -s is used) | ||
| 185 | 24 [23] Total score gathering threshold (not populated if -s is used) | ||
| 186 | 25 [24] Domain score gathering threshold (not populated if -s is used) | ||
| 187 | |||
| 188 | =head1 CONTACT | ||
| 189 | |||
| 190 | Sonia Agrawal | ||
| 191 | sagrawal@som.umaryland.edu | ||
| 192 | |||
| 193 | =cut | ||
| 194 | |||
| 195 | use strict; | ||
| 196 | use warnings; | ||
| 197 | use Getopt::Long qw(:config no_ignore_case no_auto_abbrev pass_through); | ||
| 198 | use Pod::Usage; | ||
| 199 | use TIGR::HmmTools; | ||
| 200 | use MLDBM 'DB_File'; | ||
| 201 | use Fcntl qw( O_RDONLY ); | ||
| 202 | |||
| 203 | ####### GLOBALS AND CONSTANTS ########### | ||
| 204 | my @input_files; #Holds input files | ||
| 205 | my $output_htab; #Output htab file | ||
| 206 | my $output_alignment; #Output alignment file | ||
| 207 | my $debug; #The debug variable | ||
| 208 | my $donotrun = 0; | ||
| 209 | my $alignment_format; #Holds the format to print output formats | ||
| 210 | my %alignment_formats = #Accepted output alignment formats | ||
| 211 | ( 'mul' => 1, | ||
| 212 | 'mfs' => 1, | ||
| 213 | 'fasta' => 1 ); | ||
| 214 | |||
| 215 | ######################################## | ||
| 216 | |||
| 217 | my %options = (); | ||
| 218 | my $results = GetOptions (\%options, | ||
| 219 | 'donotrun=s', | ||
| 220 | 'input_file|i=s', | ||
| 221 | 'output_htab|o=s', | ||
| 222 | 'mldbm_file|m=s', | ||
| 223 | 'prog_ver|p=s', | ||
| 224 | 'log|l=s', | ||
| 225 | 'debug=s', | ||
| 226 | 'help|h') || &_pod; | ||
| 227 | |||
| 228 | if ($options{'donotrun'}) { | ||
| 229 | #$logger->warn("Exiting because --donotrun says to."); | ||
| 230 | exit(0); | ||
| 231 | } | ||
| 232 | |||
| 233 | # Check the options. | ||
| 234 | &check_parameters(\%options); | ||
| 235 | |||
| 236 | #Gather information about the hmms. | ||
| 237 | tie(my %hmm_info, 'MLDBM', $options{mldbm_file}, O_RDONLY ) or die("Unable to tie hash to $options{mldbm_file}"); | ||
| 238 | foreach my $file (@input_files) { | ||
| 239 | |||
| 240 | #Get the output file names; | ||
| 241 | my $htab_file = $output_htab; | ||
| 242 | if( -d $output_htab ) { | ||
| 243 | my $base = $1 if($file =~ m|.*/([^/]+)\.[^/\.]+$| ); | ||
| 244 | $htab_file = $output_htab.$base.".htab"; | ||
| 245 | } | ||
| 246 | |||
| 247 | #Generate the htab file. | ||
| 248 | system( "rm -f $htab_file" ) if( -e $htab_file ); | ||
| 249 | my $hmm_data = &generate_htab( $file, $htab_file, \%hmm_info ); | ||
| 250 | } | ||
| 251 | |||
| 252 | |||
| 253 | ######################## SUB ROUTINES ####################################### | ||
| 254 | sub generate_htab { | ||
| 255 | my ( $file, $outfile, $hmm_db_info ) = @_; | ||
| 256 | #If the hmmer output file is in multi sequence format, HmmTools.pm can't handle it. | ||
| 257 | #So we will add the functionality here. | ||
| 258 | my $tmp_dir = "/tmp/hmmpfam32htab/$options{prog_ver}/$$"; #append hmmer version and process id | ||
| 259 | my @tmp_files = &write_tmp_files( $file, $tmp_dir ); | ||
| 260 | |||
| 261 | foreach my $tmp_file ( @tmp_files ) { | ||
| 262 | my $data; | ||
| 263 | if ($options{'prog_ver'} eq 'hmmpfam') { | ||
| 264 | $data = &read_hmmer2_output( $tmp_file ); | ||
| 265 | } elsif ($options{'prog_ver'} eq 'hmmpfam3') { | ||
| 266 | $data = &read_hmmer3_output( $tmp_file ); | ||
| 267 | } | ||
| 268 | my $htab_h; | ||
| 269 | open( $htab_h, ">> $outfile") or die("Unable to open $outfile for writing ($!)"); | ||
| 270 | |||
| 271 | if ((keys %$data) <=0) { | ||
| 272 | die("No results to be reported in .htab file. Empty $outfile file created"); | ||
| 273 | #$logger->logdie("No results to be reported in .htab file. Empty $outfile file created"); | ||
| 274 | } else { | ||
| 275 | &print_htab( $data, $hmm_db_info, $htab_h ); | ||
| 276 | } | ||
| 277 | close( $htab_h ); | ||
| 278 | } | ||
| 279 | |||
| 280 | #Remove the tmp directory | ||
| 281 | system( "rm -rf $tmp_dir" ); | ||
| 282 | |||
| 283 | } | ||
| 284 | |||
| 285 | sub write_tmp_files { | ||
| 286 | my ($file, $outdir) = @_; | ||
| 287 | my @files; | ||
| 288 | my $header; | ||
| 289 | |||
| 290 | open( RAW, "< $file" ) or die("Unable to open $file ($!)"); | ||
| 291 | system( "mkdir -p $outdir" ); | ||
| 292 | my ($oh, $flag); | ||
| 293 | while( my $line = <RAW> ) { | ||
| 294 | chomp($line); | ||
| 295 | if((($line =~ /Query\:\s+(\S*)/) && ($options{'prog_ver'} eq 'hmmpfam3')) || (($line =~ /Query sequence\:\s+(.*)/) && ($options{'prog_ver'} eq 'hmmpfam'))) { | ||
| 296 | my $base = $1; | ||
| 297 | $base =~ s|/||g; # remove slashes from file name | ||
| 298 | my $tmp_file = "$outdir/$base.tmp.raw"; | ||
| 299 | push( @files, $tmp_file ); | ||
| 300 | close($oh) if($oh); | ||
| 301 | open( $oh, "> $tmp_file") or die("Can't open temp file for writing $tmp_file ($!)"); | ||
| 302 | print $oh "$header$line\n"; | ||
| 303 | $flag = 1; | ||
| 304 | } elsif( $flag ) { | ||
| 305 | print $oh $line."\n"; | ||
| 306 | } else { | ||
| 307 | $header .= $line."\n"; | ||
| 308 | } | ||
| 309 | } | ||
| 310 | close($oh) if($oh); | ||
| 311 | |||
| 312 | return @files; | ||
| 313 | |||
| 314 | } | ||
| 315 | |||
| 316 | |||
| 317 | sub check_parameters { | ||
| 318 | my $options = shift; | ||
| 319 | |||
| 320 | &_pod if($options{'help'}); | ||
| 321 | ## mldbm file must be passed | ||
| 322 | if ( ! $options{mldbm_file} ) { | ||
| 323 | die("Option mldbm_file is required\n"); | ||
| 324 | #$logger->logdie("Option mldbm_file is required\n"); | ||
| 325 | } | ||
| 326 | |||
| 327 | if (! $options{'prog_ver'}) { | ||
| 328 | $options{'prog_ver'} = 'hmmpfam3'; | ||
| 329 | } | ||
| 330 | |||
| 331 | if($options{'input_file'}) { | ||
| 332 | die("Option input_file ($options{'input_file'}) does not exist\n") unless(-e $options{'input_file'}); | ||
| 333 | #$logger->logdie("Option input_file ($options{'input_file'}) does not exist\n") unless(-e $options{'input_file'}); | ||
| 334 | my $infile = $options{'input_file'}; | ||
| 335 | open( IN, "< $infile") or die("Unable to open $infile ($!)"); | ||
| 336 | chomp( my $first_line = <IN> ); | ||
| 337 | if( -e $first_line ) { | ||
| 338 | chomp( @input_files = <IN> ); | ||
| 339 | push( @input_files, $first_line ); | ||
| 340 | } else { | ||
| 341 | push( @input_files, $infile ); | ||
| 342 | } | ||
| 343 | close IN; | ||
| 344 | |||
| 345 | } else { | ||
| 346 | die("Option input_file is required\n"); | ||
| 347 | #$logger->logdie("Option input_file is required\n"); | ||
| 348 | } | ||
| 349 | |||
| 350 | unless($options{'output_htab'}) { | ||
| 351 | die("Option output_htab is required\n"); | ||
| 352 | #$logger->logdie("Option output_htab is required\n"); | ||
| 353 | } else { | ||
| 354 | $output_htab = $options{'output_htab'}; | ||
| 355 | if( @input_files > 1 && -f $output_htab ) { | ||
| 356 | $output_htab = $1 if($output_htab =~ m|^(.*)/[^/]+|); | ||
| 357 | #$logger->warn("Using $output_htab as output directory because a list of files was passed in"); | ||
| 358 | } | ||
| 359 | |||
| 360 | } | ||
| 361 | |||
| 362 | if($options{'debug'}) { | ||
| 363 | $debug = $options{'debug'}; | ||
| 364 | } | ||
| 365 | |||
| 366 | } | ||
| 367 | |||
| 368 | sub _pod { | ||
| 369 | pod2usage( {-exitval => 0, -verbose => 2, -output => \*STDERR} ); | ||
| 370 | } |