-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathShow_Calibration.php
397 lines (352 loc) · 16.4 KB
/
Show_Calibration.php
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<?php
// open and load site variables
require('../config.php');
// connect to mySQL server and select the Fossil Calibration database
$connection=mysql_connect($SITEINFO['servername'],$SITEINFO['UserName'], $SITEINFO['password']) or die ('Unable to connect!');
mysql_select_db('FossilCalibration') or die ('Unable to select database!');
$key=array_keys($_GET);
$value=array_values($_GET);
// Get details about calibration
$query = "SELECT * FROM View_Calibrations
WHERE ". mysql_real_escape_string($key[0]) ."='". mysql_real_escape_string($value[0]) ."'".
// non-admin users should only see *Published* calibrations
((isset($_SESSION['IS_ADMIN_USER']) && ($_SESSION['IS_ADMIN_USER'] == true)) ? '' :
" AND CalibrationID IN (SELECT CalibrationID FROM calibrations WHERE PublicationStatus = 4)"
);
$calibration_results= mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
$calibration_info=mysql_fetch_assoc($calibration_results);
if (!$calibration_info) {
die("The requested calibration was not found (or has not yet been published).");
}
// Get details about fossils associated with this calibration
$query = 'SELECT * FROM Link_CalibrationFossil L, View_Fossils F, fossiltaxa t WHERE L.CalibrationID='.$calibration_info['CalibrationID'].' AND L.FossilID=F.FossilID AND L.Species=t.TaxonName';
$fossil_results= mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
// find minimum age of fossils associated with this calibration
$query = 'SELECT max(L.MinAge) AS Min FROM Link_CalibrationFossil L, View_Fossils F WHERE L.CalibrationID='.$calibration_info['CalibrationID'].' AND L.FossilID=F.FossilID';
$fossil_minage_results= mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
$FossMinAge=mysql_fetch_assoc($fossil_minage_results);
/*
// Get details about tip pairs associated with this calibration
$query = 'SELECT * FROM Link_CalibrationPair L, View_TipPairs t WHERE L.CalibrationID='.$calibration_info['CalibrationID'].' AND L.TipPairsID=t.PairID ORDER BY TaxonA, TaxonB';
$tippair_results= mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
*/
// Get details about the calibrated-node definition for this calibration
// retrieve node-definition hints for side A
$query="SELECT *
FROM node_definitions
WHERE calibration_id = '". mysql_real_escape_string($calibration_info['CalibrationID']) ."' AND definition_side = 'A'
ORDER BY display_order";
$result=mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
$side_A_hint_data = array();
while($row=mysql_fetch_assoc($result)) {
$side_A_hint_data[] = $row;
}
mysql_free_result($result);
// retrieve node-definition hints for side B
$query="SELECT *
FROM node_definitions
WHERE calibration_id = '". mysql_real_escape_string($calibration_info['CalibrationID']) ."' AND definition_side = 'B'
ORDER BY display_order";
$result=mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
$side_B_hint_data = array();
while($row=mysql_fetch_assoc($result)) {
$side_B_hint_data[] = $row;
}
mysql_free_result($result);
// Fetch any image associated with this calibration (its publication)
if ($calibration_info['PublicationID']) {
$query = 'SELECT * FROM publication_images WHERE PublicationID='.$calibration_info['PublicationID'];
$image_info_results = mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
$image_info = mysql_fetch_assoc($image_info_results);
}
// Fetch any image for this calibration's tree (stuffed into the same table, using negative integers)
$treeImageID = $calibration_info['CalibrationID'] * -1;
$query = "SELECT * FROM publication_images WHERE PublicationID=". $treeImageID;
$tree_image_info_results = mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
$tree_image_info = mysql_fetch_assoc($tree_image_info_results);
// Fetch lineage from the most closely related NCBI node
$query = 'SELECT clade_root_multitree_id FROM calibrations_by_NCBI_clade WHERE calibration_id='.$calibration_info['CalibrationID'];
$results = mysql_query($query) or die ('Error in sql: '.$query.'|'. mysql_error());
$row = mysql_fetch_array($results);
$nearestNCBINodeMultitreeID = $row['clade_root_multitree_id'];
mysql_free_result($results);
// fetch information on the current node's ancestor path (NCBI only)
$query = 'CALL getAllAncestors("'. $nearestNCBINodeMultitreeID .'", "TEMP_ancestors", "NCBI" )';
$results = mysql_query($query) or die ('Error in sql: '.$query.'|'. mysql_error());
// more info about ancestors
$query = 'CALL getFullNodeInfo("TEMP_ancestors", "TEMP_ancestors_info" )';
$results = mysql_query($query) or die ('Error in sql: '.$query.'|'. mysql_error());
// filter results further
$query = 'SELECT * FROM TEMP_ancestors_info
WHERE source_tree = "NCBI"
AND multitree_node_id IN (SELECT multitree_node_id FROM calibration_browsing_tree)';
$result = mysql_query($query) or die ('Error in sql: '.$query.'|'. mysql_error());
// gather all results into an array
$ancestors = array();
while($row=mysql_fetch_assoc($result)) {
$ancestors[]=$row;
}
mysql_free_result($result);
$PageTitle = 'View fossil calibration for '.$calibration_info['NodeName'];
// open and print header template
require('header.php');
?>
<script type="text/javascript">
function toggleFossilDetails(clicked) {
var $toggle = $(clicked);
var $details = $toggle.closest('.single-fossil').find('.fossil-details');
if ($details.is(':visible')) {
$details.slideUp('fast');
$toggle.text('show fossil details');
} else {
$details.slideDown('fast');
$toggle.text('hide fossil details');
}
}
</script>
<p>
<? if (userIsAdmin()) { ?>
<input type="button" style="float: right;" onclick="window.location ='/protected/edit_calibration.php?id=<?= $calibration_info['CalibrationID'] ?>'; return false;" value="Edit calibration" />
<? } else { ?>
<a style="float: right;" href="mailto:[email protected]?subject=Comment%20on%20calibration%20<?= $calibration_info['CalibrationID'] ?>">
<img src="/images/flag-icon.png" title="" valign="middle" style="padding-right: 2px;"/>comment on this calibration
</a>
<? } ?>
<h1><?=$calibration_info['NodeName']?><!-- (ID: <?=$calibration_info['CalibrationID']?>) --></h1>
</p>
<? /*
<pre><?= var_dump($calibration_info) ?></pre>
*/ ?>
<div class="ancestor-path">
<strong>Lineage (NCBI)</strong>:
<?
if (count($ancestors) == 0) {
// NOTE: This should never happen, but perhaps if tables are stale...
?>
<i>This node has no ancestors.</i>
<?
} else {
$nthAncestor = 0;
foreach ($ancestors as $row) {
/* ?><br/><pre><? var_dump($row); ?></pre><? */
$nthAncestor++;
// show each ancestor as a breadcrumb/link in chain of ancestry ?>
<? if ($nthAncestor > 1) { ?><span class="path-divider">»</span><? } ?>
<a title="Browse to ancestor clade" href="/Browse.php?node=<?= $row['source_tree'] ?>:<?= $row['source_node_id'] ?>"><?= htmlspecialchars($row['uniquename']) ?><!-- [<?= $row['source_tree'] ?>] --></a>
<!-- TODO: provide a default identifier (eg, FCD-42:987) for unnamed nodes in submitted trees -->
<? }
} ?>
</div><!-- end of .ancestor-path -->
<p class="featured-information" style="overflow: hidden;">
<? // if there's an image mapped to this publication, show it
if (isset($image_info) && $image_info['image']) { ?>
<span class="optional-thumbnail" style="height: 120px; float: right;">
<img src="/publication_image.php?id=<?= $calibration_info['PublicationID'] ?>" style="height: 120px;"
alt="<?= $image_info['image_caption'] ?>" title="<?= $image_info['image_caption'] ?>"
/>
</span>
<? } ?>
<i>calibration from:</i><br />
<?=$calibration_info['FullReference']?>
<?php if(!empty($calibration_info['DOI'])) {
echo '<br><font class="small_text"><a href="'.
formatDOIForHyperlink($calibration_info['DOI'])
.'" target="_blank">[View electronic resource]</font></a>';
} ?></p>
<table width="100%">
<tr><td width="10%"> </td><td align="left" valign="top"><i class="small_orange">node name</i><br><b><?=$calibration_info['NodeName']?></b>
<font class="small_blue">Look for this name in
<a href="http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?name=<?=$calibration_info['NodeName']?>" target="_blank">NCBI</a>
<a href="http://en.wikipedia.org/wiki/<?=$calibration_info['NodeName']?>" target="_blank">Wikipedia</a>
<a href="http://animaldiversity.ummz.umich.edu/site/accounts/information/<?=$calibration_info['NodeName']?>.html" target="_blank">Animal Diversity Web</a></font>
</td><td width="10%"> </td></tr>
<tr><td width="10%"> </td>
<td align="left" valign="top">
<i class="small_orange">recommended citations</i><br>
<? if ($calibration_info['DOI']) { ?>
<a style="float: right;" target="_blank" href="<?= formatDOIForHyperlink($calibration_info['DOI']) ?>">
<b><?=$calibration_info['DOI']?></b>
</a>
<? } ?>
<b><?=$calibration_info['ShortName']?></b>
</td>
<td width="10%"> </td>
</tr>
<tr><td width="10%"> </td><td align="left" valign="top">
<i class="small_orange">node minimum age </i><br><b><?=$calibration_info['MinAge']?> Ma</b>
<?php if ($calibration_info['MinAgeExplanation']) { ?>
<font style="font-size: 90%;"><br/><?=$calibration_info['MinAgeExplanation']?></font>
<?php } ?>
</td><td width="10%"> </td></tr>
<tr><td width="10%"> </td><td align="left" valign="top">
<i class="small_orange">node maximum age </i><br>
<?php if ($calibration_info['MaxAgeExplanation']) { ?>
<b><?=$calibration_info['MaxAge']?> Ma</b>
<font style="font-size: 90%;"><br/><?=$calibration_info['MaxAgeExplanation']?></font>
<?php } else { ?>
<b>None specified</b>
<?php } ?>
</td><td width="10%"> </td></tr>
<tr><td width="10%"> </td><td align="left" valign="top"><i class="small_orange">primary fossil used to date this node</i></td><td width="10%"> </td></tr>
<?php
// peek ahead to first linked fossil and grab its ID, then reset pointer
$row = mysql_fetch_array($fossil_results);
if ($row && isset($row['FCLinkID'])) {
$firstLinkedFossilID = $row['FCLinkID'];
} else {
$firstLinkedFossilID = null;
}
if (mysql_num_rows($fossil_results) > 0) {
mysql_data_seek($fossil_results, 0);
}
/* Show the explicitly marked primary fossil and its phylogenetic justification.
* IF marker is NULL or empty, use the first (probably only) fossil.
* IF marker is no longer valid (ID of a fossil since un-linked), use the first fossil.
*/
$primaryLinkedFossil = null;
$primaryLinkedFossilID = empty($calibration_info['PrimaryLinkedFossilID']) ?
$firstLinkedFossilID :
$calibration_info['PrimaryLinkedFossilID'];
while ($row = mysql_fetch_array($fossil_results)) {
// treat this as the primary fossil? grab the first one by default, and override if we get a match
if ($primaryLinkedFossil == null || ($calibration_info['PrimaryLinkedFossilID'] == $row['FCLinkID'])) {
$primaryLinkedFossil = $row;
}
}
if ($primaryLinkedFossil !== null) {
$row = $primaryLinkedFossil; ?>
<tr><td width="10%"> </td><td><blockquote class="single-fossil odd" style="font-size: 90%;">
<b><?=$row['CollectionAcro']?> <?=$row['CollectionNumber']?></b>
<br />
<b>
<i><?=empty($row['Species']) ? 'NO SPECIES' : $row['Species'] ?></i>,
<?=empty($row['TaxonAuthor']) ? 'NO REFERENCE' : $row['TaxonAuthor'] ?>
</b>
<br />
<i>Location relative to the calibrated node:</i>
<? if ($row['FossilLocationRelativeToNode'] == null) { ?>
<b>???</b>
<? } else {
// describe the relative location of this fossil
$query = "SELECT * FROM `L_FossilRelativeLocation`
WHERE
RelLocationID = '". mysql_real_escape_string($row['FossilLocationRelativeToNode']) ."'";
$result = mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
$matching_location = mysql_fetch_assoc($result);
mysql_free_result($result); ?>
<b><?= $matching_location['RelLocation'] ?></b>
<? } ?>
<br />
<br />
<font class="small_blue">[<a href="#" onclick="toggleFossilDetails(this); return false;">show fossil details</a>]</font>
<div class="fossil-details" style="margin-bottom: -1em;">
<i>Locality:</i> <b>
<?=empty($row['LocalityName']) ? 'NO NAME' : $row['LocalityName'] ?>
</b> <br />
<?php if (!empty($row['Stratum'])) { ?>
<i>Stratum:</i> <b><?=$row['Stratum']?></b><br />
<?php } ?>
<i>Geological age:</i> <b>
<? $ageLabel = empty($row['Age']) ? '' : $row['Age'].', ';
$ageLabel .= empty($row['Epoch']) ? '' : $row['Epoch'].', ';
$ageLabel .= empty($row['Period']) ? '' : $row['Period'].', ';
$ageLabel .= empty($row['System']) ? '' : $row['System'];
?>
<?= $ageLabel ?></b><br />
<!-- <i>Minimum age:</i> <b><?=$row['MinAge']?> Ma</b> <i>Maximum age:</i> <b><?=$row['MaxAge']?> Ma</b><br /> -->
<?php if($row['PBDBCollectionNum']>0) { ?>
<font class="small_blue">[<a href="http://fossilworks.org/?a=collectionSearch&collection_no=<?=$row['PBDBCollectionNum']?>" target="_new">View locality in Paleobiology Database</a>]</font>
<?php } ?>
<!-- TODO: show all calibrated nodes that link to this fossil?
<font class="small_blue">[all nodes with this fossil]</font>
-->
</div>
<?php if($row['PBDBTaxonNum']>0) {?>
<br />
<br />
<font class="small_blue">
More information in
<a href="http://fossilworks.org/?a=taxonInfo&taxon_no=<?=$row['PBDBTaxonNum']?>" target="_blank">
Fossilworks
</a>
<a href="http://paleobiodb.org/cgi-bin/bridge.pl?a=basicTaxonInfo&taxon_no=<?=$row['PBDBTaxonNum']?>" target="_blank">
PaleoBioDB
</a>
</font>
<?php } ?>
</blockquote></td><td width="10%"> </td></tr>
<? } ?>
<tr><td width="10%"> </td><td align="left" valign="top"><p></p></td><td width="10%"> </td></tr>
<? // show the primary phylogenetic justification, if any
if ($primaryLinkedFossil) { ?>
<tr>
<td width="10%"> </td>
<td align="left" valign="top">
<i class="small_orange">phylogenetic justification</i>
<br/>
<?= $primaryLinkedFossil['PhyJustification'] ?>
</td>
<td width="10%"> </td>
</tr>
<tr>
<td width="10%"> </td>
<td align="left" valign="top">
<i class="small_orange">phylogenetic reference(s)</i>
<br/>
<? // retrieve phylogeny pub(s)
$query="SELECT * FROM publications WHERE PublicationID IN (SELECT PhyloPublicationID FROM Link_PhyloPublication_LinkedFossil WHERE LinkedFossilID='".$primaryLinkedFossil['FCLinkID']."')";
$result=mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
$phylo_pubs = array();
while($pprow = mysql_fetch_assoc($result)){
$phylo_pubs[] = $pprow;
}
mysql_free_result($result);
if (count($phylo_pubs) == 0) {
?><i>The linked fossil has no phylogentic references.</i><?
} else {
foreach ($phylo_pubs as $pubref) { ?>
<div class="reference-block">
<?= $pubref['FullReference'] ?>
<?php if(!empty($pubref['DOI'])) {
echo '<br><font class="small_text"><a href="'.
formatDOIForHyperlink($pubref['DOI'])
.'" target="_blank">[View electronic resource]</font></a>';
} ?>
</div>
<? }
}
?>
</td>
<td width="10%"> </td>
</tr>
<? } ?>
<? // if there's a tree image mapped to this calibration, show it
if (isset($tree_image_info) && $tree_image_info['image']) {
$usingDefaultCaption = $tree_image_info['caption'] && strpos($tree_image_info['caption'], 'Tree for calibration ') === 0;
?>
<tr><td width="10%"> </td><td align="left" valign="top"><i class="small_orange">tree image (click image for full size)</i></td><td width="10%"> </td></tr>
<tr>
<td width="10%"></td>
<td align="left" valign="top">
<a href="/publication_image.php?id=<?= $treeImageID ?>" target="_blank" title="Click to see full-size image in a new window">
<img src="/publication_image.php?id=<?= $treeImageID ?>"
style="background-color: #eee; margin-top: 12px; max-width: 744px;"
alt="tree image" />
</a>
<? if ($tree_image_info['caption'] && !($usingDefaultCaption)) { ?>
<div class="image-caption">
<?= $tree_image_info['caption'] ?>
</div>
<? } ?>
</td>
<td width="10%"></td>
</tr>
<? } ?>
</table>
<?php
//open and print page footer template
require('footer.php');
?>