setFontFile($fontpath); //中間ファイル設定 // $buffer = '../data/buffer/easygraphtrack_sample.txt'; $buffer = $buffer_tmp_dir.'/'.$_REQUEST['sid']."_graph.txt"; $utgd->openBufferFile($buffer); // //XMLファイル設定 // $xml = '../data/xml/easygenetrack_sample.xml'; // $xml = $xml_tmp_dir.'/'.$_REQUEST['sid'].".xml"; while (!feof ($file)) { //graphチェック $line = trim(fgets($file)); if(strncmp($line, "graph", 5) != 0) continue; //targetチェック $target_line = substr(( strchr ($line, 'target=') ), 7); list($target, $remain) = split("[ \t]", $target_line); if(strcmp($target, $req['target']) != 0) continue; //range取得 $range_line = substr(strchr ($line, 'range='), 6); list($range_start, $range_end, $remain) = split("[, \t]", $range_line); if($range_start > $range_end) { $tmp = $range_start; $range_start = $range_end; $range_end = $tmp; } if(($range_start > $end) || ($range_end < $start)) continue; //グラフユニット値(1つの数値に対応する塩基数)取得 $unit_line = substr(strchr ($line, 'unit='), 5); list($unit, $remain) = split("[, \t]", $unit_line); //グラフ数値取得 if(($nums_pos = strpos ($line, 'nums=')) === FALSE) return; $nums = substr($line, $nums_pos + 5); ////グラフ数値配列格納 $nums_array = explode(",",$nums); //グラフ中間ファイル出力 $utgd->drawContents($nums_array,$range_start,$unit,1,1,'',$colstring,$max,$min,2); } //test用 // $utgd->drawStringTTF(1,'with LIB',4000,6,'black','RIGHT',0,0,NULL,NULL,NULL,FALSE); //中間ファイルクローズ $utgd->closeBufferFile(); //サイズの設定 $utgd->setImageSize($req['width'],$height,1,$height,$req['start'],$req['end'],0,0); //その他オプション設定 $utgd->setImageOptions($white,$white,10); //中間ファイルのパース $utgd->parseBufferFile($buffer,'TILING'); //画像枠の作成 $utgd->createImage(); // //XMLファイルオープン // $utgd->openXMLFile($xml); //図形の描画 $utgd->drawImage(); //画像出力 $utgd->outputImage(); // //XML出力 // $utgd->outputXMLFile(); } function draw_graph($file, $line1){ $max = 100; $min = 0; $req = pre_get_request($_REQUEST); if($req['start'] < $req['end']){ $start = $req['start']; $end = $req['end']; }else { $start = $req['end']; $end = $req['start']; } $basewidth = $end - $start +1; // イメージの生成 $height = 40; $image = imagecreatetruecolor( $req['width'], $height ); $color = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); // color if(($color_pos = strpos($line1,'color=')) !== FALSE){ list($color_r, $color_g, $color_b, $remain) = split("[ ,\t]", substr($line1, $color_pos + 6), 4); $color = imagecolorallocate( $image, $color_r, $color_g, $color_b); } # imagefill( $image, 0, 0, $white); imagefilledrectangle($image, 0, 0, $req['width']-1,$height-1, $white); //min if(($min_pos = strpos($line1,'min=')) !== FALSE){ list($min, $remain) = split("[ ,\t]", substr($line1, $min_pos + 4), 2); } //max if(($max_pos = strpos($line1,'max=')) !== FALSE){ list($max, $remain) = split("[ ,\t]", substr($line1, $max_pos + 4), 2); } // イメージの作成 while (!feof ($file)) { $line = trim(fgets($file)); if(strncmp($line, "graph", 5) != 0) continue; // for($num=0; $num < $num_genes; $num++){ // $line = $genes[$num]; $target_line = substr(( strchr ($line, 'target=') ), 7); list($target, $remain) = split("[ \t]", $target_line); if(strcmp($target, $req['target']) != 0) continue; $range_line = substr(strchr ($line, 'range='), 6); list($range_start, $range_end, $remain) = split("[, \t]", $range_line); if($range_start > $range_end) { $tmp = $range_start; $range_start = $range_end; $range_end = $tmp; } if(($range_start > $end) || ($range_end < $start)) continue; $unit_line = substr(strchr ($line, 'unit='), 5); list($unit, $remain) = split("[, \t]", $unit_line); if(($nums_pos = strpos ($line, 'nums=')) === FALSE) return; $nums = substr($line, $nums_pos + 5); for($i=$range_start;$i<=$range_end; $i+=$unit){ if($i > $end){break;} list($num, $remain) = split("[, \t]", $nums, 2); $nums = $remain; if($i + $unit <= $start){continue;} if($req['start'] == $start){ $startpos = $req['width'] * ($i - $req['start']) / $basewidth; $endpos = $req['width'] * ($i + $unit - $req['start']) / $basewidth -1; }else { $endpos = $req['width'] * ($req['start'] - $i) / $basewidth; $startpos = $req['width'] * ($req['start'] - $i - $unit) / $basewidth -1; } //echo($num); $h = floor($height * ( $max - $num) / ($max - $min)); imagefilledrectangle($image, $startpos, $h, $endpos, $height, $color); } } // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); fclose( $file ); } ?>