JPRED-2 Initial commit of software for the Jpred website (some files excluded due...
[jpred.git] / websoft / bin / runcoils
1 #!/usr/bin/perl
2 #
3
4 #
5 # Wrapper for multicoil and ncoil to generate csv style output to STDOUT
6 # Pass it the complete path to the sequence or multicoil will complain
7 #
8 # multicoils ignored as it's a bitch to setup
9
10 use strict;
11 use warnings;
12 use POSIX;
13 use Jpred;
14
15 unless (@ARGV) { die("No arguments given\n"); }
16 goto NCOILS;
17 my ($path) = $ENV{'PWD'};
18 my ($file) = ($ARGV[0] =~ /.*\/(.*)/);
19 my ($multicoil) = ($ENV{'PAIRCOIL_CONFIG'} =~ /(.*)\/.*/);
20
21 # Print multicoils cmd file to temp file
22 my $multi_conf = tmpnam();
23 open(FILE, ">$multi_conf") or die($!);
24 print FILE "method = MultiCoil
25 bound = .5
26 no GUI
27 window length = 28
28 multi_lib 1 = 3 4 5
29 multi_lib 2 = 2 3 4
30 pair_lib = 1 2 4
31 conversion dir = $multicoil/CONVERSION_FILES/
32 table 1 = $multicoil/PROGRAM_DATA/cctb28
33 table 2 = $multicoil/PROGRAM_DATA/tritb28
34 pir = $multicoil/PROGRAM_DATA/sampled-pir.seq
35 genbnk = $multicoil/PROGRAM_DATA/genbnk
36 printfile dir = /homes/jon/jpred/src/MULTICOIL/TEST_RUNS/
37 log dir = $path/
38 seq scores dir = $path/ 
39 out dir = $path/";
40 close(FILE);
41
42 my $tmp2 = tmpnam();
43 xsystem("$BINDIR/readseq -f3 -p < $ARGV[0] > $tmp2");
44
45 # 1, 2, 3! We hate multicoil! Have to be in the same path as it's exe
46 # to run due to the hex editing on the multicoil exe to allow it to read
47 # some of its data files, also it requires PIR input file, sigh...
48 #my $pwd = $ENV{'PWD'};
49 #chdir("$JPREDROOT/src/MULTICOIL/");
50 #xsystem("$JPREDROOT/src/MULTICOIL/multicoil $tmp2 -config $multi_conf > /dev/null 2> /dev/null");
51 #chdir($pwd);
52
53 #my $co=0;
54 #my (@prob, @dimprob, @trimprob);
55
56 #$tmp2 =~ s/.*\///g;
57
58 #open(IN, "<$path/$tmp2.out") or die($!);
59 #while (<IN>) {
60 #       if (/^[#|%]/) { next; }
61 #       else {
62 #               @_ = split(" ", $_);
63 #               push @prob, $_[4];
64 #               push @dimprob, $_[5];
65 #               push @trimprob, $_[6];
66 #               }
67 #       }
68 #close(IN);
69
70 # remove junk
71 #unlink("$tmp2.out");
72 #unlink("$tmp2.seq_scores");
73 #unlink("$tmp2.log");
74 #unlink $multi_conf, $tmp2;
75
76 # Takes the prob. array and decides whether it's definitely a coil,
77 # maybe a coil, or not a coil.
78 sub coil {
79         my @array;
80         foreach (@_) {
81                 if ($_ >= 0.9) {
82                         push @array, "C";
83                         }
84                 elsif ($_ >= 0.5) {
85                         push @array, "c";
86                         }
87                 else {
88                         push @array, "-";
89                         }
90                 }
91         return @array;
92         }
93
94 # Prints a comma after each piece of data in array
95
96 sub print_cvs {
97         foreach (@_) { print "$_,"; } 
98 }
99
100 #print "MULTCOIL:";
101 #print_cvs(coil(@prob));
102 #print "\n", "MULTCOIL_DIMER:";
103 #print_cvs(coil(@dimprob));
104 #print "\n", "MULTCOIL_TRIMER:";
105 #print_cvs(coil(@trimprob));
106 #print "\n";
107
108 #
109 # Finished with multicoil, now for lupas coils (?) Just runs ncoils with
110 # different -win values
111 #
112
113 sub ncoils {
114         my ($file, $window) = @_;
115         my @temp;
116         open(PROG, "$BINDIR/ncoils -w -win $window < $file |") or die($!);
117         open(REALDATA, ">$ARGV[0].lupas_$window") or die($!);
118         while (<PROG>) {
119                 print REALDATA "$_";
120                 chop;
121                 push @temp, substr($_, 19, 5);
122                 }
123         close(PROG);
124         close(REALDATA);
125         return @temp;
126         }
127
128 NCOILS:
129 print "Lupas_21:";
130 print_cvs(coil(ncoils($ARGV[0], 21)));          # 21 window
131 print "\n", "Lupas_14:";
132 print_cvs(coil(ncoils($ARGV[0], 14)));          # 14 window
133 print "\n", "Lupas_28:";
134 print_cvs(coil(ncoils($ARGV[0], 28)));          # 28 window
135 print "\n";
136