-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqtl_phenotype.php
executable file
·84 lines (73 loc) · 2.29 KB
/
qtl_phenotype.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
<?php
header("Content-type:text/plain");
include("includes/bootstrap.inc");
connect();
//include("cookie/cookie.php");
//$mycookie = new MyCookie($_SESSION['username']);
/* Ouput the heading
---------------------*/
echo "Experiment Inbred ";
/* TODO: Don't select all phenotypes */
$sql = "SELECT phenotype_uid, phenotypes_name FROM phenotypes WHERE 1";
$res = mysql_query($sql);
$phenotype_ids = array();
while ($phenotype = mysql_fetch_assoc($res)){
echo str_replace(' ', '_', trim($phenotype[phenotypes_name])) ." N ";
array_push($phenotype_ids, $phenotype[phenotype_uid]);
}
echo "\n";
/*---------------------*/
/* The user's selected lines */
$where_lines = 'line_records.line_record_uid = \'207\'';
//$where_lines = $mycookie->gen_where('lines', 'line_records.line_record_uid');
$sql = <<< SQL
SELECT
line_records.line_record_name,
experiments.experiment_name,
line_records.line_record_uid,
experiments.experiment_uid
FROM
line_records LEFT JOIN (tht_base, experiments)
ON
(experiments.experiment_uid = tht_base.experiment_uid
AND tht_base.line_record_uid = line_records.line_record_uid)
WHERE
$where_lines
GROUP BY line_records.line_record_uid
SQL;
$res = mysql_query($sql) or die(mysql_error());
while ($line = mysql_fetch_assoc($res)){
echo str_replace(' ', '_', trim($line[experiment_name])) . " ";
echo str_replace(' ', '_', trim($line[line_record_name])) . " ";
foreach ($phenotype_ids as $phenotype_id)
if ($data = getData($line['line_record_uid'], $line['experiment_uid'], $phenotype_id)){
echo "$data[0] $data[1] ";
}
else
{
echo "N/A N/A ";
}
echo "\n";
}
function getData($line_record_uid, $experiment_uid, $phenotype_uid){
$sql = <<< SQL
SELECT
AVG(phenotype_data.value), COUNT(*)
FROM
phenotype_data, line_records, tht_base, experiments
WHERE
line_records.line_record_uid = $line_record_uid
AND experiments.experiment_uid = $experiment_uid
AND tht_base.experiment_uid = experiments.experiment_uid
AND phenotype_data.tht_base_uid = tht_base.tht_base_uid
AND phenotype_data.phenotype_uid = $phenotype_uid
GROUP BY
line_records.line_record_uid
SQL;
$res = mysql_query($sql) or die(mysql_error().'<br/>'.$sql);
if (mysql_num_rows($res) > 0){
return mysql_fetch_array($res);
}
return FALSE;
}
?>