typed search is being added
[jalview.git] / forester / archive / perl / multifetch.pl
1 #!/usr/bin/perl
2
3 # multifetch.pl [options] <list of seqs>
4 #
5 # Fetch all the seqs on the list. The list is a file with one line
6 # per sequence; the first field is the key.
7 #
8 # Options:
9 #    -d            : domain fetch - list is in GDF format
10 #    -n <extra 5'> : include this many extra residues upstream (-d only)
11 #    -c <extra 3'> : include this many extra residues downstream (-d only)
12 #    -f            : fetch in FASTA instead of native format
13 #    -g <file>     : use getseq from <file>, not fetch from main databases.
14 #                    This always gives FASTA output.
15 #    -D <database> : specify a source database, same usage as getseq:
16 #                           -Dsw  SwissProt
17 #                           -Dpir PIR
18 #                           -Dem  EMBL
19 #                           -Dgb  GenBank
20 #                           -Dwp  WormPep
21 #                           -Dowl OWL 
22  
23
24 use FindBin;
25 use lib $FindBin::Bin;
26 use rio_module;
27 require "getopts.pl";
28
29
30 &Getopts('c:n:dfg:D:');
31 if ($opt_c) { $extra_c  = $opt_c; }
32 if ($opt_n) { $extra_n  = $opt_n; }
33 if ($opt_d) { $domains  = 1;      }
34 if ($opt_f) { $fmtarg = "-Ffasta";} else {$fmtarg = ""; }
35 if ($opt_g) { $filearg = "-d$opt_g ";} else {$filearg = ""; }
36 if ($opt_D) { $dbarg = "-D$opt_D "; } else {$dbarg = ""; }
37
38
39 while (<>) {
40     if ($domains) {
41         if (($name, $from, $to, $source) = /^\s*(\S+)\s+(\d+)\s+(\d+)\s+(\S+)/){
42             if ($from < $to) {
43                 $from -= $opt_n;
44                 $to   += $opt_c;
45             }
46             else {
47                 $from += $opt_n;
48                 $to   -= $opt_c;
49             }
50             
51             system("$SFE $filearg $dbarg $fmtarg -r \"$name\" -f $from -t $to \"$source\"")
52             && die "\n\n$0: Unexpected error: Could not execute \"$SFE $filearg $dbarg $fmtarg -r \"$name\" -f $from -t $to \"$source\"\": $!";
53         }
54     } else {
55         if (/^\s*(\S+)/) {
56             $key = $1;
57              
58             system("$SFE $filearg $dbarg $fmtarg \"$key\"")
59             && die "\n\n$0: Unexpected error: Could not execute \"$SFE $filearg $dbarg $fmtarg \"$key\"\": $!";
60         }
61     }
62 }
63
64 # 01/30/02
65 # CZ
66 # Added usage of rio_module.pm, $SFE for sfetch.
67
68 # Thu Apr 10 18:27:40 1997
69 #   - added -D option
70 #   - simplified from six different getseq calls to two
71