-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdetail.html
213 lines (209 loc) · 9.96 KB
/
detail.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<style> .fixedfont { font-size : 14px } </style>
<input type="hidden" name="species" value="<% $information->{species} %>">
<input type="hidden" name="accession" value="<% $information->{accession} %>">
<%init>
my $information;
my $stmt = qq"SELECT species, genome_id FROM gene_info WHERE accession = ?";
my $species_genome_id = $db->MySelect(statement => $stmt, type => 'row', vars => [$accession]);
my $species = $species_genome_id->[0];
my $genome_id = $species_genome_id->[1];
my $mt = "mfe_$species";
$mt = "mfe_virus" if ($mt =~ /virus/);
my $bt = "boot_$species";
$bt = 'boot_virus' if ($bt =~ /virus/);
$information->{species} = $species;
$information->{accession} = $accession;
$information->{slipstart} = $slipstart;
$db->Remove_Duplicates($accession);
my ($detail_stmt, $info);
if (!defined($slipstart) and !$mfeid) {
$detail_stmt = qq"SELECT $mt.*, gene_info.genename FROM $mt,gene_info WHERE gene_info.genome_id = ? AND gene_info.genome_id = $mt.genome_id ORDER BY start, seqlength DESC, mfe_method DESC";
$info = $db->MySelect(statement => $detail_stmt, vars => [$genome_id,], type => 'list_of_hashes') or Callstack(message => $detail_stmt , die => 0);
} elsif (!$slipstart) { ## then mfeid is defined
$detail_stmt = qq"SELECT $mt.*, gene_info.genename FROM $mt,gene_info WHERE gene_info.genome_id = ? AND gene_info.genome_id = $mt.genome_id AND $mt.id = ? ORDER BY seqlength DESC, mfe_method DESC";
$info = $db->MySelect(statement => $detail_stmt, vars => [$genome_id,$mfeid], type => 'list_of_hashes') or Callstack(message => $detail_stmt, die => 0);
} else {
$detail_stmt = qq"SELECT $mt.*, gene_info.genename FROM $mt,gene_info WHERE gene_info.genome_id = ? AND gene_info.genome_id = $mt.genome_id AND $mt.start = ? ORDER BY seqlength DESC, mfe_method DESC";
$info = $db->MySelect(statement => $detail_stmt, vars => [$genome_id,$slipstart], type => 'list_of_hashes') or Callstack(message => $detail_stmt, die => 0);
}
foreach my $entry_count (0 .. $#$info) {
foreach my $info_key (keys %{$info->[$entry_count]}) {
$information->{$info_key} = $info->[$entry_count]->{$info_key};
}
$information->{pk_input} =~ tr/atgcu/ATGCU/;
$information->{parsed} =~ s/\s+//g;
my @in = split(//, $information->{sequence});
my @par = split(//, $information->{parsed});
my @parens = split(//, $information->{parens});
## Added 2016-02 for better PARENS
sub open_close {
my $in = shift;
if ($in eq "(" or $in eq "[" or $in eq "<" or $in eq "{") {
return("open");
} elsif ($in eq ")" or $in eq "]" or $in eq ">" or $in eq "}") {
return("close");
} else {
return("unkown");
}
} # End open_close
if (!$information->{new_parens}) {
my $paren_string = "";
## print "No new parens!\n";
PLOOP: for my $c (0 .. $#par) {
my $old_paren = $parens[$c];
my $stem_num = $par[$c];
if ($stem_num eq ".") {
$paren_string .= ".";
next PLOOP;
}
my $stem_type = open_close($old_paren);
my $stem_mod = $stem_num % 4;
if ($stem_type eq "open") {
if ($stem_mod == 0) {
$paren_string .= '<';
} elsif ($stem_mod == 1) {
$paren_string .= '(';
} elsif ($stem_mod == 2) {
$paren_string .= '{';
} elsif ($stem_mod == 3) {
$paren_string .= '[';
} else {
$paren_string .= '/';
}
} elsif ($stem_type eq "close") {
if ($stem_mod == 0) {
$paren_string .= '>';
} elsif ($stem_mod == 1) {
$paren_string .= ')';
} elsif ($stem_mod == 2) {
$paren_string .= '}';
} elsif ($stem_mod == 3) {
$paren_string .= ']';
} else {
$paren_string .= '|';
}
} else {
$paren_string .= "?";
}
}
$information->{parens} = $paren_string;
} else {
$information->{parens} = $information->{new_parens};
}
my $misc = new SeqMisc(sequence => \@in);
$information->{gc_content} = $misc->{gc_content};
$information->{gc_stems} = $misc->Get_GC(\@in, \@par);
my $delta = $information->{seqlength} - length($information->{parsed});
$information->{parsed} .= '.' x $delta;
$information->{brackets} .= '.' x $delta;
$information->{minus_string} = HTMLMisc::Make_Minus($information->{sequence});
$information->{color_minus} = HTMLMisc::Color_Stems($information->{minus_string}, $information->{parsed}, $config->{graph_stem_colors});
# $information->{minus_stop} = HTMLMisc::Color_Stems($information->{color_minus}, $information->{parsed}, $config->{graph_stem_color});
$information->{numbers} = HTMLMisc::Make_Nums($information->{sequence});
$information->{pk_input_colored} = HTMLMisc::Color_Stems($information->{sequence}, $information->{parsed}, $config->{graph_stem_colors});
$information->{brackets_colored} = HTMLMisc::Color_Stems($information->{parens}, $information->{parsed}, $config->{graph_stem_colors});
$information->{parsed_colored} = HTMLMisc::Color_Stems($information->{parsed}, $information->{parsed}, $config->{graph_stem_colors});
## Check the status of the randomized distribution
my $boot_stmt = qq"SELECT mfe_values, mfe_mean, mfe_sd, mfe_se, zscore FROM $bt WHERE mfe_id = ?";
my $boot_info = $db->MySelect(statement => $boot_stmt, type => 'row', vars=>[$information->{id}],);
my $boot;
if (!defined($boot_info) and $config->{do_boot} == 2) {
## Add it to the webqueue
$db->Set_Queue(id => $information->{genome_id}, queue_table => 'webqueue');
} elsif (!defined($boot_info) and $config->{do_boot} == 1) {
$m->comp('generate_boot.html', information => $information); ## , width => 11, height => 1,
my $data = ">tmp
$information->{sequence}
";
my $inputfile = $db->Sequence_to_Fasta($data);
eval "use Bootlace; 1";
$boot = new Bootlace(config => $config,
genome_id => $information->{genome_id},
nupack_mfe_id => $information->{id},
pknots_mfe_id => $information->{id},
inputfile => $inputfile,
species => $information->{species},
accession => $information->{accession},
start => $information->{start},
seqlength => $information->{seqlength},
iterations => $config->{boot_iterations},
boot_mfe_methods => $config->{boot_mfe_methods},
randomizers => $config->{boot_randomizers},);
use Data::Dumper;
print Dumper $boot_info;
$boot_info = $boot->Go();
$db->Put_Boot($boot_info);
chdir($ENV{PRFDB_HOME});
}
## Theoretically we should now have the randomized distribution set,
## But for weird data this will not be, so after we make the feynman we
## will revisit this...
my $acc_slip = qq"$accession-$information->{slipstart}";
my $feynman_pic = new PRFGraph(config=> $config, mfe_id => $information->{id}, accession => $accession);
$information->{feynman_url} = $feynman_pic->Picture_Filename(type=> 'feynman', url => 'url',);
my $feynman_output_filename = $feynman_pic->Picture_Filename(type => 'feynman',);
my $feynman_dimensions = {};
if (!-r $feynman_output_filename) {
$feynman_dimensions = $feynman_pic->Make_Feynman();
} else {
$feynman_dimensions = $feynman_pic->Get_Feynman_ImageSize($feynman_output_filename);
}
$information->{feynman_height} = $feynman_dimensions->{height};
$information->{feynman_width} = $feynman_dimensions->{width};
## Revisiting the Boot and making the graph for it
print "TESTME: $boot_info\n";
if (defined($boot_info)) {
my $mfe_values = $boot_info->[0];
$mfe_values =~ s/^\s+//g;
my @mfe_values_array = split(/\s+/, $mfe_values);
my $chart = new PRFGraph(config => $config, real_mfe => $information->{mfe},
list_data => \@mfe_values_array, accession => $acc_slip, mfe_id => $information->{id},);
my $ppcc_values = $chart->Get_PPCC();
my $filename = $chart->Picture_Filename(type => 'distribution');
my $pre_charturl = $chart->Picture_Filename(type => 'distribution', url => 'url');
$information->{charturl} = $pre_charturl;
if (!-r $filename) {
$chart = $chart->Make_Distribution();
}
$information->{mfe_mean} = $boot_info->[1];
$information->{mfe_sd} = $boot_info->[2];
$information->{mfe_se} = $boot_info->[3];
$information->{boot_db} = $boot_info->[4];
if ($information->{mfe_sd} == 0) {
$information->{zscore} = 0;
} else {
$information->{mfe} = 0 if (!defined($information->{mfe}));
$information->{mfe_mean} = 0 if (!defined($information->{mfe_mean}));
$information->{mfe_sd} = 1 if (!defined($information->{mfe_sd}));
$information->{zscore} = sprintf("%.2f", ($information->{mfe} - $information->{mfe_mean}) / $information->{mfe_sd});
}
$information->{randmean} = sprintf("%.1f", $information->{mfe_mean});
$information->{randse} = sprintf("%.1f", $information->{mfe_se});
$information->{ppcc} = sprintf("%.4f", $ppcc_values);
} else { ##Boot is not defined!
$information->{chart} = "undef";
$information->{charturl} = qq"$ENV{PRFDB_HOME}/html/no_data.gif";
$information->{mfe_mean} = "undef";
$information->{mfe_sd} = "undef";
$information->{mfe_se} = "undef";
$information->{zscore} = "UNDEF";
$information->{randmean} = "UNDEF";
$information->{randse} = "UNDEF";
$information->{ppcc} = "UNDEF";
}
## Now we should have the randomized distribution picture created.
$m->comp('single_detail.html', information=>$information,);
} ## End foreach structure in the database
my $num_algos = 0;
$num_algos++ if ($config->{do_pknots} == 1);
$num_algos++ if ($config->{do_nupack} == 1);
$num_algos++ if ($config->{do_hotknots} == 1);
my $num_expected_mfes = scalar(@{$config->{seqlength}}) * $num_algos;
my $num_have = $db->MySelect(statement => qq"SELECT count(id) FROM $mt WHERE accession = '$accession' AND start = '$slipstart'", type => 'single');
$db->Put_Webqueue($information->{genome_id}) if ($num_have < $num_expected_mfes);
</%init>
<%args>
$accession => 'SGDID:S000001';
$slipstart => undef;
$mfeid => undef;
</%args>