~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to network/wwwblast/config_setup.pl

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/local/bin/perl
 
2
 
 
3
# make_config_files.pl
 
4
#
 
5
# the purpose of this script is to make it easier to set up the
 
6
# Standalone WWW Blast server.
 
7
#
 
8
# this script accepts as arguments a directory with formatted databases
 
9
# and a temporary directory (where it will write output files). for example
 
10
#
 
11
#   make_config_files.pl $BLASTDB out
 
12
#
 
13
# It then creates a blast.rc and a psiblast.rc file in this temporary 
 
14
# directory.  It also creates blastdb_options.html and 
 
15
# psiblastdb_options.html files in this directory.
 
16
# The blast.rc and psiblast.rc files can just replace the ones 
 
17
# in the blast directory.  You can then cut and paste the 
 
18
# <option> entries from the html files into the corresponding place
 
19
# in the blast.html, blast_cs.html, xmlblast.html, megablast.html, 
 
20
# psiblast.html, and psiblast_cs.html 
 
21
# (overwriting the test_aa_db and test_na_db <options>)
 
22
 
23
# you may want to adjust the default number of processors in the rc files.
 
24
#
 
25
# finally you will probably want to create a symbolic link from the 
 
26
# blast database directory that you passed to this script to the
 
27
# db directory that currently contains the test_aa_db and test_na_db
 
28
# files.  Assuming you are in the blast directory created by the 
 
29
# blast server distribution, the following should work:
 
30
 
31
#    mv db db.orig
 
32
#    ln -s $BLASTDB db
 
33
 
34
# Author: Joseph Ryan <jfryan@nhgri.nih.gov>
 
35
#
 
36
 
 
37
use strict;
 
38
use vars qw($VERSION);
 
39
 
 
40
$VERSION = 0.01;
 
41
 
 
42
MAIN: {
 
43
    my $blastdb = $ARGV[0] or die "usage: $0 BLASTDB OUTPUT_DIR\n";
 
44
    my $output_dir = $ARGV[1] or die "usage:$0 BLASTDB OUTPUT_DIR\n";
 
45
    unless (-d $output_dir) {
 
46
        mkdir $output_dir, 0755 or die "cannot mkdir $output_dir:$!";
 
47
    }
 
48
    my ($ra_nts,$ra_aas) = get_dbs($blastdb);
 
49
    print_blast_html($output_dir,$ra_nts,$ra_aas);
 
50
    print_psiblast_config($output_dir,$ra_aas);
 
51
    print_blast_config($output_dir,$ra_nts,$ra_aas);
 
52
    print_psiblast_html($output_dir,$ra_aas);
 
53
    print "Four files were created in the directory: $output_dir\n";
 
54
}
 
55
 
 
56
sub print_psiblast_config {
 
57
    my $output_dir = shift;
 
58
    my $ra_aas     = shift;
 
59
    open OUT, ">$output_dir/psiblast.rc" 
 
60
         or die "cannot open >$output_dir/psiblast.rc:$!";
 
61
    print OUT "NumCpuToUse     4\n\n";
 
62
    print OUT "blastp ";
 
63
    foreach my $aa (@{$ra_aas}) {
 
64
        print OUT "$aa ";
 
65
    }
 
66
    print OUT "\n";
 
67
}
 
68
 
 
69
sub print_blast_config {
 
70
    my $output_dir = shift;
 
71
    my $ra_nts     = shift;
 
72
    my $ra_aas     = shift;
 
73
    open OUT, ">$output_dir/blast.rc" 
 
74
         or die "cannot open >$output_dir/blast.rc:$!";
 
75
    print OUT "NumCpuToUse     4\n\n";
 
76
    foreach my $p ("blastn", "tblastn", "tblastx") {
 
77
        print OUT "$p ";
 
78
        foreach my $nt (@{$ra_nts}) {
 
79
            print OUT "$nt ";
 
80
        }
 
81
        print OUT "\n";
 
82
    }
 
83
    foreach my $p ("blastp", "blastx") {
 
84
        print OUT "$p ";
 
85
        foreach my $aa (@{$ra_aas}) {
 
86
            print OUT "$aa ";
 
87
        }
 
88
        print OUT "\n";
 
89
    }
 
90
}
 
91
 
 
92
sub print_psiblast_html {
 
93
    my $dir    = shift;
 
94
    my $ra_aas = shift;
 
95
    open OUT, ">$dir/psiblastdb_options.html" 
 
96
         or die "cannot open >$dir/psiblastdb_options.html:$!";
 
97
    foreach my $aa (@{$ra_aas}) {
 
98
        print OUT "    <option>$aa\n";
 
99
    }
 
100
}
 
101
 
 
102
sub print_blast_html {
 
103
    my $dir    = shift;
 
104
    my $ra_nts = shift; 
 
105
    my $ra_aas = shift;
 
106
    my %redundants = ();
 
107
    open OUT, ">$dir/blastdb_options.html" 
 
108
         or die "cannot open $dir/blastdb_options.html:$!";
 
109
    my @dbs = sort @{$ra_nts}, @{$ra_aas};
 
110
    foreach my $db (@dbs) {
 
111
        next if $redundants{$db};
 
112
        print OUT "    <option>$db\n";
 
113
        $redundants{$db}++;
 
114
    }
 
115
}
 
116
 
 
117
sub get_dbs {
 
118
    my $dir = shift;
 
119
    my @nts = ();
 
120
    my @aas = ();
 
121
 
 
122
    opendir DIR, $dir or die "cannot open $dir:$!";
 
123
    my @files = grep /\.[np]in$/, readdir DIR;
 
124
    foreach my $f (@files) {
 
125
        $f =~ m/(.*)\.([pn])in$/;
 
126
        push @nts, $1 if ($2 eq 'n');
 
127
        push @aas, $1 if ($2 eq 'p');
 
128
    }
 
129
    return \@nts, \@aas;
 
130
}
 
131
 
 
132