JPRED-2 Initial commit of software for the Jpred website (some files excluded due...
[jpred.git] / websoft / bin / concise2simplehtml
diff --git a/websoft/bin/concise2simplehtml b/websoft/bin/concise2simplehtml
new file mode 100755 (executable)
index 0000000..fbdc770
--- /dev/null
@@ -0,0 +1,78 @@
+#!/usr/bin/perl
+
+## CC 18/05/2006
+# New version of script as the original (OO perl) version
+# doesn't work on the new cluster. As it's a very simple 
+# parser it can be easily re-implemented
+
+use strict;
+use warnings;
+use Getopt::Long;
+use Jpred;
+
+my $file;
+my $out;
+
+GetOptions(
+       'file=s' => \$file,
+       'out=s'  => \$out
+) or die $!;
+
+$file or die "no --file argument\n";
+
+open(my $FH, $file) or die "$!";
+my $query;
+my $pred;
+while(<$FH>) {
+       # jnet concise file is a series of outputs preceeded by 
+       # a definition separated by ':' on each line e.g.:
+       #
+       # align1;QUERY:M,F,L,A,Q,E,I,I,R,K,K,R,D,G,H,A,L,S,D,E,E,I,...,
+       # jpred:-,-,H,H,H,H,H,H,H,H,H,H,-,-,-,-,-,-,H,H,H,H,H,H,H,...,
+       #
+       # Find the two lines above and extract the query sequence and the
+       # jpred prediction.
+       
+       chomp;
+
+       my ($def, $data) = split /:/, $_ or next;
+
+       if ($def eq 'jnetpred') {
+               $pred = $data;
+               $pred =~ s/\,//g;   # remove all the ',' in prediction
+       }
+       if ($def =~ /align1/) {
+               next if $query;     # skip any hits to align1x sequences. We only want the 1st hit.
+               $query = $data;
+               $query =~ s/\,//g;  # remove all ',' in sequence
+       }
+}
+close($FH);
+if (!$query || !$pred) {
+       die "no jpred output or query sequence found in $file";
+}
+
+# colour the predictions
+$pred =~ s{([H]+)}{<font color="#e90055">$1</font>}g;
+$pred =~ s{([E]+)}{<font color="#ffa800">$1</font>}g;
+
+if ($out) {
+       open(my $OUT, ">$out") or die "$out: $!";
+       select($OUT);
+}
+
+
+my $html = '<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html lang="en-GB" xml:lang="en-GB">
+<head><title>Simple JNet Output</title>
+<link rel="stylesheet" type="text/css" href="http:/webservices:12345/jpred.css" />
+</head><body><pre><code>';
+$html .= "$query\n";
+$html .= "$pred\n";
+$html .= "</code></pre>
+$JPREDFOOT</body></html>";
+print $html;
+
+exit;
+