JPRED-2 Initial commit of software for the Jpred website (some files excluded due...
[jpred.git] / websoft / bin / concise2simplehtml
1 #!/usr/bin/perl
2
3 ## CC 18/05/2006
4 # New version of script as the original (OO perl) version
5 # doesn't work on the new cluster. As it's a very simple 
6 # parser it can be easily re-implemented
7
8 use strict;
9 use warnings;
10 use Getopt::Long;
11 use Jpred;
12
13 my $file;
14 my $out;
15
16 GetOptions(
17         'file=s' => \$file,
18         'out=s'  => \$out
19 ) or die $!;
20
21 $file or die "no --file argument\n";
22
23 open(my $FH, $file) or die "$!";
24 my $query;
25 my $pred;
26 while(<$FH>) {
27         # jnet concise file is a series of outputs preceeded by 
28         # a definition separated by ':' on each line e.g.:
29         #
30         # align1;QUERY:M,F,L,A,Q,E,I,I,R,K,K,R,D,G,H,A,L,S,D,E,E,I,...,
31         # jpred:-,-,H,H,H,H,H,H,H,H,H,H,-,-,-,-,-,-,H,H,H,H,H,H,H,...,
32         #
33         # Find the two lines above and extract the query sequence and the
34         # jpred prediction.
35         
36         chomp;
37
38         my ($def, $data) = split /:/, $_ or next;
39
40         if ($def eq 'jnetpred') {
41                 $pred = $data;
42                 $pred =~ s/\,//g;   # remove all the ',' in prediction
43         }
44         if ($def =~ /align1/) {
45                 next if $query;     # skip any hits to align1x sequences. We only want the 1st hit.
46                 $query = $data;
47                 $query =~ s/\,//g;  # remove all ',' in sequence
48         }
49 }
50 close($FH);
51 if (!$query || !$pred) {
52         die "no jpred output or query sequence found in $file";
53 }
54
55 # colour the predictions
56 $pred =~ s{([H]+)}{<font color="#e90055">$1</font>}g;
57 $pred =~ s{([E]+)}{<font color="#ffa800">$1</font>}g;
58
59 if ($out) {
60         open(my $OUT, ">$out") or die "$out: $!";
61         select($OUT);
62 }
63
64
65 my $html = '<?xml version="1.0" encoding="iso-8859-1"?>
66 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
67 <html lang="en-GB" xml:lang="en-GB">
68 <head><title>Simple JNet Output</title>
69 <link rel="stylesheet" type="text/css" href="http:/webservices:12345/jpred.css" />
70 </head><body><pre><code>';
71 $html .= "$query\n";
72 $html .= "$pred\n";
73 $html .= "</code></pre>
74 $JPREDFOOT</body></html>";
75 print $html;
76
77 exit;
78