<?php
/*
* chr.php
* http://tasuke.dna.affrc.go.jp/
*
* Author: Ryutaro Itoh
*
* Copyright (c) 2013 National Institute of Agrobiological Sciences   
*
* This software is released under the MIT License.
*
* http://opensource.org/licenses/mit-license.php
*/

require '../conf/config.php';

//////////////////////////////////  Connecting with DB
if( !$conn = new mysqli($host, $user, $pswd, $db)) {
    error_log("Connection failed.\n");
    exit;
}

////////////////////////////////////////////////////////// Chromosome
$chr = array();
$size = array();
$centomeres = array();

$query = "SELECT id,size,centromere_s+(centromere_e-centromere_s)/2 FROM sys_chromosome order by seq";
$stmt = $conn->stmt_init();
$stmt->prepare($query);
$stmt->execute();
$stmt->bind_result($row0,$row1,$row2);
while ($stmt->fetch()) {
    $chr[]=$row0;
    $size[]=$row1;
    $centromeres[]=(int)$row2;
}
$stmt->close();
mysqli_close($conn);

$str="[";
for ($i=0; $i<count($chr); $i++) {
    $str=$str."{\"id\":\"".$chr[$i]."\",\"size\":\"".$size[$i]."\",\"centromere\":\"".$centromeres[$i]."\"}"; 
    if($i<count($chr)-1) $str=$str.",";
}
$str=$str."]";
echo $str;
?>

