<?php
/*
* chr_oracle.php
* http://tasuke.dna.affrc.go.jp/
*
* Author: Ryutaro Itoh
*
* Copyright (c) 2013 National Institute of Agrobiological Sciences   
*
*/

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

//////////////////////////////////  Connecting with DB
$conn = oci_connect($user, $pswd, $host."/".$db, "AL32UTF8");
if(!$conn) {
    $e = oci_error();
    error_log($e["message"]."\nConnection failed.\n");
    exit;
}

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

$query = "SELECT id,seq_size,centromere_s+(centromere_e-centromere_s)/2 FROM sys_chromosome order by seq";
$stmt = oci_parse($conn, $query);
oci_execute($stmt);
while (($row = oci_fetch_array($stmt, OCI_NUM + OCI_RETURN_NULLS))!= false) {
    $chr[]=$row[0];
    $size[]=$row[1];
    $centromeres[]=(int)$row[2];
}
oci_free_statement($stmt);
oci_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;
?>

