Supply TEMPLATE and SUFFIX for temporary query sequence files.
[bioperl-run.git] / scripts / multi_hmmsearch.PLS
blob2f7741929723b88726872769533f47a2f35286cb
1 #!/usr/bin/perl -w
2 # $Id: multi_hmmsearch.PLS,v 1.3 2006-07-04 22:23:36 mauricio Exp $
4 use strict;
6 =head1 NAME
8 multi_hmmsearch - perform a hmmsearch into multiple FASTA files using
9 an INDEX file
11 =head1 SYNOPSIS
13 multi_hmmsearch -p hmm_file [-i] -f index_file
15 =head1 DESCRIPTION
17 Not technically a Bio::Tools::Run script as this doesn't use any
18 Bioperl or Bioperl-run components but it's useful.
20 =head2 Mandatory Options:
22 -p HMM profile to use for the search.
23 -f INDEX file that contains a list of FASTA files for the multiple
24 search.
26 =head2 Special Options:
28 -i Create a new index file with the resulting hmms files. This is
29 useful if you want to pass this list as input arguments into
30 another programs.
31 -h Show this documentation.
33 =head1 FEEDBACK
35 =head2 Mailing Lists
37 User feedback is an integral part of the evolution of this and other
38 Bioperl modules. Send your comments and suggestions preferably to the
39 Bioperl mailing list. Your participation is much appreciated.
41 bioperl-l@bioperl.org - General discussion
42 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
44 =head2 Reporting Bugs
46 Report bugs to the Bioperl bug tracking system to help us keep track
47 of the bugs and their resolution. Bug reports can be submitted via the
48 web:
50 http://redmine.open-bio.org/projects/bioperl/
52 =head1 AUTHOR
54 Mauricio Herrera Cuadra <mauricio-at-open-bio.org>
56 =cut
58 # Modules, pragmas and variables to use
59 use Getopt::Long;
60 use vars qw($opt_p $opt_i $opt_f $opt_h $index_file);
62 # Gets options from the command line
63 GetOptions qw(-p=s -i -f=s -h);
65 # Print documentation if help switch was given
66 exec('perldoc', $0) and exit() if $opt_h;
68 # If no mandatory options are given prints an error and exits
69 if (!$opt_p) {
70 print "ERROR: No HMM profile has been specified.\n Use '-h' switch
71 for documentation.\n" and exit();
72 } elsif (!$opt_f) {
73 print "ERROR: No INDEX file has been specified.\n Use '-h' switch for
74 documentation.\n" and exit();
77 # Locates hmmsearch in the filesystem
78 my $hmmsearch = `which hmmsearch`;
79 chomp $hmmsearch;
81 # Creates a directory for writing the resulting files
82 mkdir("multi", 0755) unless -e "multi" and -d "multi";
84 # Creates a new INDEX file if the option was given
85 if ($opt_i) {
86 my $prefix = $opt_f;
87 $prefix =~ s/\.INDEX$//;
88 $index_file = "$prefix.hmms.INDEX";
89 open(HMMSINDEX, ">", $index_file) or die("Unable to create file:
90 $index_file ($!)");
93 # Opens the INDEX file sent as input
94 open(FH, "<", $opt_f) or die("Unable to open INDEX file: $opt_f ($!)");
95 print "==> Opening INDEX file:\t\t\t\t$opt_f\n";
96 print "==> HMM profile file is:\t\t\t$opt_p\n";
98 # Cycle that extracts one line for every loop until finding the end of
99 # file
100 while (my $line = <FH>) {
102 # Deletes the new line characters from the line
103 chomp $line;
105 # Gets the name for the result file
106 my $out = $line;
107 $out =~ s/^split\///;
108 $out =~ s/\.faa$//;
110 # Performs the hmmsearch for the FASTA file in turn
111 print "--> Performing hmmsearch in file:\t\t$line\n";
112 system("$hmmsearch $opt_p $line > multi/$out.hmms");
113 print "==> hmmsearch results stored in file:\t\tmulti/$out.hmms\n";
115 # Prints the result file name into the new INDEX file if the
116 # option was given
117 print HMMSINDEX "multi/$out.hmms\n" if $opt_i;
120 # Closes INDEX files
121 close(FH);
122 if ($opt_i) {
123 print "==> New INDEX stored in file:\t\t\t$index_file\n";
124 close(HMMSINDEX);
127 # Exits the program
128 exit();