JPRED-2 Initial commit of software for the Jpred website (some files excluded due...
[jpred.git] / websoft / bin / runcoils
diff --git a/websoft/bin/runcoils b/websoft/bin/runcoils
new file mode 100755 (executable)
index 0000000..8deebd8
--- /dev/null
@@ -0,0 +1,136 @@
+#!/usr/bin/perl
+#
+
+#
+# Wrapper for multicoil and ncoil to generate csv style output to STDOUT
+# Pass it the complete path to the sequence or multicoil will complain
+#
+# multicoils ignored as it's a bitch to setup
+
+use strict;
+use warnings;
+use POSIX;
+use Jpred;
+
+unless (@ARGV) { die("No arguments given\n"); }
+goto NCOILS;
+my ($path) = $ENV{'PWD'};
+my ($file) = ($ARGV[0] =~ /.*\/(.*)/);
+my ($multicoil) = ($ENV{'PAIRCOIL_CONFIG'} =~ /(.*)\/.*/);
+
+# Print multicoils cmd file to temp file
+my $multi_conf = tmpnam();
+open(FILE, ">$multi_conf") or die($!);
+print FILE "method = MultiCoil
+bound = .5
+no GUI
+window length = 28
+multi_lib 1 = 3 4 5
+multi_lib 2 = 2 3 4
+pair_lib = 1 2 4
+conversion dir = $multicoil/CONVERSION_FILES/
+table 1 = $multicoil/PROGRAM_DATA/cctb28
+table 2 = $multicoil/PROGRAM_DATA/tritb28
+pir = $multicoil/PROGRAM_DATA/sampled-pir.seq
+genbnk = $multicoil/PROGRAM_DATA/genbnk
+printfile dir = /homes/jon/jpred/src/MULTICOIL/TEST_RUNS/
+log dir = $path/
+seq scores dir = $path/ 
+out dir = $path/";
+close(FILE);
+
+my $tmp2 = tmpnam();
+xsystem("$BINDIR/readseq -f3 -p < $ARGV[0] > $tmp2");
+
+# 1, 2, 3! We hate multicoil! Have to be in the same path as it's exe
+# to run due to the hex editing on the multicoil exe to allow it to read
+# some of its data files, also it requires PIR input file, sigh...
+#my $pwd = $ENV{'PWD'};
+#chdir("$JPREDROOT/src/MULTICOIL/");
+#xsystem("$JPREDROOT/src/MULTICOIL/multicoil $tmp2 -config $multi_conf > /dev/null 2> /dev/null");
+#chdir($pwd);
+
+#my $co=0;
+#my (@prob, @dimprob, @trimprob);
+
+#$tmp2 =~ s/.*\///g;
+
+#open(IN, "<$path/$tmp2.out") or die($!);
+#while (<IN>) {
+#      if (/^[#|%]/) { next; }
+#      else {
+#              @_ = split(" ", $_);
+#              push @prob, $_[4];
+#              push @dimprob, $_[5];
+#              push @trimprob, $_[6];
+#              }
+#      }
+#close(IN);
+
+# remove junk
+#unlink("$tmp2.out");
+#unlink("$tmp2.seq_scores");
+#unlink("$tmp2.log");
+#unlink $multi_conf, $tmp2;
+
+# Takes the prob. array and decides whether it's definitely a coil,
+# maybe a coil, or not a coil.
+sub coil {
+       my @array;
+       foreach (@_) {
+               if ($_ >= 0.9) {
+                       push @array, "C";
+                       }
+               elsif ($_ >= 0.5) {
+                       push @array, "c";
+                       }
+               else {
+                       push @array, "-";
+                       }
+               }
+       return @array;
+       }
+
+# Prints a comma after each piece of data in array
+
+sub print_cvs {
+       foreach (@_) { print "$_,"; } 
+}
+
+#print "MULTCOIL:";
+#print_cvs(coil(@prob));
+#print "\n", "MULTCOIL_DIMER:";
+#print_cvs(coil(@dimprob));
+#print "\n", "MULTCOIL_TRIMER:";
+#print_cvs(coil(@trimprob));
+#print "\n";
+
+#
+# Finished with multicoil, now for lupas coils (?) Just runs ncoils with
+# different -win values
+#
+
+sub ncoils {
+       my ($file, $window) = @_;
+       my @temp;
+       open(PROG, "$BINDIR/ncoils -w -win $window < $file |") or die($!);
+       open(REALDATA, ">$ARGV[0].lupas_$window") or die($!);
+       while (<PROG>) {
+               print REALDATA "$_";
+               chop;
+               push @temp, substr($_, 19, 5);
+               }
+       close(PROG);
+       close(REALDATA);
+       return @temp;
+       }
+
+NCOILS:
+print "Lupas_21:";
+print_cvs(coil(ncoils($ARGV[0], 21)));         # 21 window
+print "\n", "Lupas_14:";
+print_cvs(coil(ncoils($ARGV[0], 14)));         # 14 window
+print "\n", "Lupas_28:";
+print_cvs(coil(ncoils($ARGV[0], 28)));         # 28 window
+print "\n";
+