<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'WELCHgrape55';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'dasr';
mysql_select_db($dbname);

$bedfile_field = array ( 'bedfile_id','experiment_id','method_id','genome_id','filetype','name','upload_date','expiration','header','descr');
$bedfile_field = join(',',$bedfile_field);
$agbed_field = array('agbed_id','bedfile_id', 'chrom', 'chromstart', 'chromend', 'name', 'score', 'strand', 'thickstart', 'thickend', 'itemrgb', 'remainder', 'blockcount', 'blocksizes', 'blockstarts');
$agbed_field = join(',', $agbed_field);


## four
$bedfile_id = 4;
$q = "INSERT INTO bedfile_real (bedfile_id,filetype,name,upload_date,header) VALUES ('$bedfile_id','agbed','mm9Refseq',NOW(),'real bed file')";
mysql_query($q) or die (mysql_error());
$myFile = "../testing/DB_Data/Type_D_annotated_gene/mm9Refseq";
//system("ls ../testing/DB_Data/Type_B_summary_files/GHcont_responsive_DHS.bed");
$fh = fopen($myFile,'r') or die ("No such a file");
while( $line = fgets($fh))
{
if (!preg_match("/#bin/",$line))
	{
$line_array = explode("\t",$line);
$q="insert into agbed_real 
(bedfile_id,chrom,chromstart,chromend,name,strand) 
values 
('$bedfile_id','$line_array[2]','$line_array[4]','$line_array[5]','$line_array[1]','$line_array[3]')";
mysql_query($q) or die (mysql_error());
	}
}

?>