-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfold.html
180 lines (155 loc) · 6 KB
/
fold.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
% if ($mfe_method or $input_fasta or $fold_sequence) {
<%perl>
my $tempfile_fh = new File::Temp(SUFFIX => ".fasta", DIR => "$ENV{PRFDB_HOME}/folds", UNLINK=>0);
my $new_filename = $tempfile_fh->filename();
use File::Basename;
my $short_filename = basename($new_filename);
my $contents;
if ($input_fasta) {
use Apache2::Upload;
my $req = new Apache2::Request($r);
my $upload = $req->upload("input_fasta");
my $upload_filename = $upload->filename();
my $size = $upload->slurp($contents);
} elsif ($fold_sequence) {
$contents = ">${short_filename}
${fold_sequence}
";
}
unless ($contents) {
print "<p>No input.</p>\n";
return;
}
$contents = lc($contents);
$contents =~ s/t/u/g;
print $tempfile_fh $contents;
close $tempfile_fh;
print "<pre>
$contents
</pre>\n";
my $new_url = "folds/$short_filename.html";
use Proc::Forkfunc;
my @child_args = ($config, $short_filename, $mfe_method, $num_refreshes);
forkfunc(\&tmp_fold, @child_args);
sub tmp_fold {
my $config = shift;
my $new_filename = shift;
my $function = shift;
my $refreshes = shift;
my $input_path = "$ENV{PRFDB_HOME}/folds/$new_filename";
my $fold = new RNAFolders(config => $config, file => $input_path, genome_id => 0, species => 'saccharomyces_cerevisiae', accession => 2, start => 0,);
my $mfe_info;
if ($function eq 'nupack') {
$mfe_info = $fold->Nupack_NOPAIRS();
} elsif ($function eq 'pknots') {
$mfe_info = $fold->Pknots('nopseudo');
} elsif ($function eq 'hotknots') {
$mfe_info = $fold->Hotknots(chdir => qq"$ENV{PRFDB_HOME}/folds");
} elsif ($function eq 'rnafold') {
$mfe_info = $fold->Vienna();
} elsif ($function eq 'pknots_pseudo') {
$mfe_info = $fold->Pknots();
} elsif ($function eq 'ilm') {
$mfe_info = $fold->ILM();
} elsif ($function eq 'unafold') {
$mfe_info = $fold->Unafold();
} else {
$mfe_info = $fold->Multiple(['hotknots','nupack','pknots']);
}
my $mfe = $mfe_info->{mfe};
my $parsed = $mfe_info->{parsed};
my $barcode = $mfe_info->{barcode};
my $output = $mfe_info->{output};
my $pairs = $mfe_info->{pairs};
my $sequence = $mfe_info->{sequence};
my $parens = $mfe_info->{parens};
my $bpseq_string = $fold->Make_ct(sequence => $sequence, output => $output, function => $function);
my $turner = $fold->Compute_Energy(sequence => $sequence, parens => $parens);
open(BPSEQ_FILE, ">${input_path}.ct");
print BPSEQ_FILE $bpseq_string;
close(BPSEQ_FILE);
my $pic_output = "$ENV{PRFDB_HOME}/folds/$new_filename.svg";
my $pictures = new PRFGraph(sequence=>$sequence, parsed => $parsed, output => $output);
my $dimensions = $pictures->Make_Feynman($pic_output, 0);
my $jviz_type = 'jviz_classic_structure';
my $jviz_url_string = '';
my $jviz_pic_output = $pic_output;
$jviz_pic_output =~ s/\.svg/-${jviz_type}\.png/g;
$jviz_pic_output =~ s/jviz_//g;
# $jviz_pic_output =~ s/\.fasta/\.bpseq/g;
my $jviz_pic_input = $pic_output;
$jviz_pic_input =~ s/\.svg//g;
# print STDERR "INFO: $jviz_pic_input $jviz_pic_output\n";
# my $jviz_output = $pictures->jViz(input_filename => "${jviz_pic_input}.ct", debug => 0, jviz_type => $jviz_type, output_filename => $jviz_pic_output);
my $jviz_output = $pictures->jViz(mfe_id => undef,
input_file => "${jviz_pic_input}.ct",
debug => 0,
jviz_type => $jviz_type,
output_file => $jviz_pic_output);
# my $mangle = $jviz_pic_input;
# $mangle =~ s/\.fasta/\.fasta-classic_structure\.png/g;
# my $cmd = qq"cp $jviz_output->{filename} $mangle";
# system($cmd);
my $url_file = basename($jviz_pic_output);
$jviz_url_string .= "<center><img src=\"$url_file\"><br>\n";
$jviz_url_string .= "</center>";
open (HANDLE, ">$input_path.html") or Callstack(message => "Cannot open HANDLE $new_filename.html");
print HANDLE qq(The minimum free using $function energy is: $mfe (Turner99: $turner)<br>
<pre>
$sequence
$parens
</pre><br>
<embed id=\"feynman\" src=\"$new_filename.svg\" align=\"bottom\"></embed>
<br>
$jviz_url_string
<br>
Download <a href=\"/download/svg2something.html?format=png&input=/folds/${new_filename}.svg\">png</a> or <a href=\"/download/svg2something.html?format=ps&intput=/folds/${new_filename}.svg\">ps</a> or <a href=\"/download/svg2something.html?format=pdf&intput=/folds/${new_filename}.svg\">pdf</a>
<br>
); ## This marks the end of the printed html fragment of the output
close(HANDLE);
}
</%perl>
<p>This will redirect you to the output page for your folding in 5 seconds.<br>
Keep in mind that these programs take exponentially more time with respect to length of query sequence.
For example:<br>
If you use pknots with pseudoknots and a 60 nt sequence, it should take 5 seconds or less,<br>
but 80 nt will take about 10 seconds, 90 nt will take 4 minutes, 100 nt will take 1.5 hours.<br>
Nupack and a 60 nt sequence takes about 0.5 seconds, 90 nt takes 5 seconds, 100 nt takes 4 minutes.<br>
RNAfold and 60 nt takes about 0.1 second, 90 nt takes 1 second, 150 nt takes 10 seconds, 180 nt takes 2 hours...
</p>
<& /js/refresh.html, refresh_url => "/folds/${short_filename}.html", seconds => 5 &>
<script>
function load() {
}
window.onload = mydoLoad;
</script>
% } else {
<FORM action="fold.html" enctype="multipart/form-data" method="POST">
Use this form to fold a _short_ sequence.<br>
Choose a fasta formatted file:
<input type="file" name="input_fasta"><br>
Or input some sequence below:<br>
<textarea name="fold_sequence" rows=5 cols=80></textarea><br>
and Fold it with:
<select name="mfe_method">
<option selected="selected" value="nupack">Nupack</option>
<option value="pknots">Pknots</option>
<option value="pknots_pseudo">Pknots with pseudoknots</option>
<option value="hotknots">HotKnots</option>
<option value="rnafold">RNAfold</option>
<option value="unafold">UNAfold</option>
<option value="all">all</option>
</select><br>
<input type="submit" name="fold submit" value="Fold"><br>
</form>
% }
<%init>
my $tempfile;
my $new_filename;
</%init>
<%args>
$fold_sequence => undef
$mfe_method => undef
$input_fasta => undef
$num_refreshes => 0
</%args>