$bound){ return 0; } } } return 1; } function get_lbound_attr ($line, $lbound){ for ($i=0; $i= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start'] ) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } if($startpos < 0) $startpos = 0; if($endpos > $req['width']) $endpos = $req['width']-1; imageline($image, $startpos, $h, $endpos, $h, $color); # $strand = substr(strchr ($line, 'strand='), 7, 1); # if ( $strand == '+' xor $req['start'] >= $req['end']) { # for($i = $startpos; $i < $endpos-10; $i+=10){ # imageline($image, $i, $h-$hgene, $i+$hgene, $h, $color); # imageline($image, $i, $h+$hgene, $i+$hgene, $h, $color); # } # }else if ( $strand == '-' xor $req['start'] >= $req['end']) { # for($i = $startpos; $i < $endpos -10; $i+=10){ # imageline($image, $i, $h, $i+$hgene, $h-$hgene, $color); # imageline($image, $i, $h, $i+$hgene, $h+$hgene, $color); # } # } $exon_line = $line; for(;;){ if(($exon = strchr ($exon_line, 'exon=')) == FALSE) break; $exon_line = substr($exon, 5); list($exon_start, $exon_end, $remain) = split("[, \t]", $exon_line); if($exon_start > $exon_end) { $tmp = $exon_start; $exon_start = $exon_end; $exon_end = $tmp; } if($req['end'] >= $req['start']){ if ($exon_end < $req['start']) continue; if ($exon_start > $req['end']) continue; $startpos = $req['width'] * ($exon_start - $req['start'] ) / $basewidth; $endpos = $req['width'] * ($exon_end - $req['start'] + 1) / $basewidth; }else { if ($exon_end < $req['end']) continue; if ($exon_start > $req['start']) continue; $endpos = $req['width'] * ($req['start'] - $exon_start + 1) / $basewidth; $startpos = $req['width'] * ($req['start'] - $exon_end) / $basewidth; } if (($endpos < 0) || ($startpos >$req['width'] )) continue; if($startpos < 0) $startpos = 0; if($endpos > $req['width']) $endpos = $req['width']-1; imagefilledrectangle($image, $startpos, $h-$hgene, $endpos, $h+$hgene, $color); } } header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function draw_gene_style_full($genes, $req, $colorD, $h1, $hgene){ $num_genes = sizeof($genes); $basewidth = abs ($req['end'] - $req['start'] ) + 1; $h2 = 0; $height = $num_genes * $h1 + $h2; if ($num_genes == 0) $height = 5; $image = imagecreatetruecolor( $req['width'], $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); // imagefill( $image, 0, 0, $white); imagefilledrectangle($image, 0, 0, $req['width']-1,$height-1, $white); draw_ruler($image, $req, $height); for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $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; } // 色の取得 $colorRGB = $colorD; if(preg_match("/^(\w+)\-color$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_color($colorD, $line, $at[1], $req['color']); }else if(preg_match("/^(\w+)\-gradation$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_gradation($colorD, $line, $at[1], $req['gradation']); } if (array_key_exists ('foundGene', $req) ){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); if ($name == $req['foundGene']){ $colorRGB = array(230,159,0); } } } $color = imagecolorallocate( $image, $colorRGB[0], $colorRGB[1], $colorRGB[2] ); $h = $h1 / 2 + $h2 + $h1 * $num; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } if ($startpos < 0) $startpos = 0; if ($endpos >$req['width'] ) $endpos = $req['width']; imageline($image, $startpos, $h, $endpos, $h, $color); $strand = substr(strchr ($line, 'strand='), 7, 1); if ( $strand == '+' xor $req['start'] >= $req['end']) { for($i = $startpos; $i < $endpos-10; $i+=10){ imageline($image, $i, $h-$hgene, $i+$hgene, $h, $color); imageline($image, $i, $h+$hgene, $i+$hgene, $h, $color); } }else if ( $strand == '-' xor $req['start'] >= $req['end']) { for($i = $startpos; $i < $endpos -10; $i+=10){ imageline($image, $i, $h, $i+$hgene, $h-$hgene, $color); imageline($image, $i, $h, $i+$hgene, $h+$hgene, $color); } } $exon_line = $line; for(;;){ if(($exon = strchr ($exon_line, 'exon=')) == FALSE) break; $exon_line = substr($exon, 5); list($exon_start, $exon_end, $remain) = split("[, \t]", $exon_line); if($exon_start > $exon_end) { $tmp = $exon_start; $exon_start = $exon_end; $exon_end = $tmp; } if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($exon_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($exon_end - $req['start'] + 1) / $basewidth; }else { $endpos = $req['width'] * ($req['start'] - $exon_start + 1) / $basewidth; $startpos = $req['width'] * ($req['start'] - $exon_end ) / $basewidth; } if (($endpos < 0) || ($startpos >$req['width'] )) continue; if ($startpos < 0) $startpos = 0; if ($endpos >$req['width'] ) $endpos = $req['width']; imagefilledrectangle($image, $startpos, $h-$hgene, $endpos, $h+$hgene, $color); } } // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function get_pack_height ($genes, $req, &$gene_height, $h1, $distance){ $num_genes = sizeof($genes); $basewidth = abs ($req['end'] - $req['start'] + 1); if ($num_genes == 0) return 5; $base_end = array(); for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $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($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start']) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start) / $basewidth; } $height = sizeof ($base_end); $flag = 0; for($i=0; $i < $height; $i++){ if($base_end[$i] <= ($startpos - $distance)){ $base_end[$i] = $endpos; array_push ($gene_height, $i); $flag = 1; break; } } if ($flag == 0){ array_push ($base_end, $endpos); array_push ($gene_height, $height); } } return sizeof ($base_end) * $h1; } /** * 各styleのgeneを描画する(ついでにXML(キャッシュ)ファイルも出力) * @access public * @param array $genes easyGeneTrackの内容 * @param array $req GET/POST引数 * @param array $colorD デフォルトカラー(エクソン) * @param int $h1 一列の高さ * @param int $hgene エクソンの高さ * @param string $style 描画スタイル(dense/full/pack/small) * @param string $buffer 中間ファイルパス * @param string $xml XMLファイルパス * @param string $cache_id キャッシュID */ function draw_gene_style($genes, $req, $colorD, $h1, $hgene, $style,$buffer,$xml,$cache_id){ //easygenetrack文の解釈 //gene数計数 $num_genes = sizeof($genes); //縦の余白=marginy $h2 = 0; //画像縦幅? // $height = $num_genes * $h1 + $h2; if ($num_genes == 0){ $height = 5; }else{ $height = 0; } //UTGDインスタンス作成 $utgd = new UTGD4(); //色指定 $white = 'white'; $black = 'black'; //TTフォント設定 $fontpath = '../../../lib/UTGD4/fonts/Abadi MT Condensed Light.ttf'; $utgd->setFontFile($fontpath); //中間ファイル設定 $utgd->openBufferFile($buffer); //カテゴリ宣言 $utgd->insertCategory('GRAPH'); //スケール描画 if($style != 'dense'){ $scale_col = '#A0A0A0'; $utgd->drawScale('',$req['start'],$req['end'],0,100,1,500,$scale_col); } //test用文字追加 // $utgd->drawStringTTF(1,'with LIB',4000,6,'black','RIGHT',0,0,NULL,NULL,NULL,FALSE); //easygenetrack読み込み $rownum = 0; foreach($genes as $line){ //easygenetrackからデータ取得 ////EXONデータ取得 $exon_array = array(); $exon_line = $line; for(;;){ // geneTrackデータからexon部分取得 if(($exon = strchr ($exon_line, 'exon=')) == FALSE) break; $exon_line = substr($exon, 5); list($exon_start, $exon_end, $remain) = split("[, \t]", $exon_line); if($exon_start > $exon_end) { $tmp = $exon_start; $exon_start = $exon_end; $exon_end = $tmp; } // EXON開始、終了位置を格納 array_push($exon_array,array($exon_start,$exon_end)); } //// 色の取得 $colorRGB = $colorD; if(preg_match("/^(\w+)\-color$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_color($colorD, $line, $at[1], $req['color']); }else if(preg_match("/^(\w+)\-gradation$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_gradation($colorD, $line, $at[1], $req['gradation']); } //// gene name取得 if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); } //// strand取得 $strand = substr(strchr ($line, 'strand='), 7, 1); if($strand == '-'){ $strand_s = -1; }else{ $strand_s = 1; } //// 操作XML用URL取得 if (preg_match("/url=\"(\S+)\"/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); $operation = "mouse(link=$url[1])"; }else{ $operation = "mouse(link=$url[1])"; } //styleによる描画オプションのヴァリエーション if($style == 'full'){ $rownum++;//描画列加算 $col_foundGene = array(230,159,0);//foundGeneの色指定 $line_style = 4;//エクソン連結線スタイル(反復矢印) $name_draw = '';//遺伝子名描画文字列 $gene_size = 2*$hgene; //エクソン縦幅 }elseif($style == 'dense'){ $utgd->insertCategory('FORCE');//描画列を強制的に決定 $rownum = 1;//描画列は1に固定 $col_foundGene = $colorD;//foundGeneの色指定 $line_style = 1;//エクソン連結線スタイル(直線) $name_draw = '';//遺伝子名描画文字列 $gene_size = $h1; //エクソン縦幅 }elseif($style == 'small'){ $rownum = 1;//描画列は自動計算 $col_foundGene = array(230,159,0);//foundGeneの色指定 $line_style = 1;//エクソン連結線スタイル(直線) $name_draw = '';//遺伝子名描画文字列 $gene_size = 2*$hgene; //エクソン縦幅 }else{ $rownum = 1;//描画列は自動計算 $col_foundGene = array(230,159,0);//foundGeneの色指定 $line_style = 4;//エクソン連結線スタイル(反復矢印) $name_draw = $name;//遺伝子名描画文字列 $gene_size = 2*$hgene; //エクソン縦幅 } //直前処理 ////foundGeneチェック if (array_key_exists ('foundGene', $req) ){ if ($name == $req['foundGene']){ $colorRGB = $col_foundGene; } } ////色再変換(二度手間) $colorDS = getColorString($colorD); $colorRGBS = getColorString($colorRGB); //gene描画 $utgd->drawGene($exon_array,$rownum,$gene_size,'',$colorRGBS,$name_draw,8,'LEFT',$colorRGBS,$line_style,$colorRGBS,1,'',$strand_s,1,$operation,''); } //中間ファイルクローズ $utgd->closeBufferFile(); //サイズの設定 $utgd->setImageSize($req['width'],$height,1,$h1,$req['start'],$req['end'],0,$h2); //その他オプション設定 $utgd->setImageOptions($white,$white,10); //中間ファイルのパース $utgd->parseBufferFile($buffer,'TILING'); //画像枠の作成 $utgd->createImage(); //XMLファイルオープン $utgd->openXMLFile($xml); //図形の描画 $utgd->drawImage(); //画像出力 $utgd->outputImage(); //XML出力 // $utgd->outputXMLFile(); //XMLキャッシュ出力 $utgd->cacheXMLData($cache_id); } function draw_gene_style_pack($genes, $req, $colorD, $h1, $hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start']) + 1; $size = 8; $fontfile = $utgb_font_Abadi_file; # $h1 = 10; # $hgene = 3; # 20 # $h2 = 5; # $h2 = 1; $h2 = 0; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1, 100); $image = imagecreatetruecolor( $req['width'], $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); // imagefill( $image, 0, 0, $white); imagefilledrectangle($image, 0, 0, $req['width']-1,$height-1, $white); // イメージの作成 # for($i=50; $i < $req['width']; $i = $i +50){ # imageline($image, $i, 0, $i, $height, $black); # } draw_ruler($image, $req, $height); for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $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; } // 色の取得 $colorRGB = $colorD; if(preg_match("/^(\w+)\-color$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_color($colorD, $line, $at[1], $req['color']); }else if(preg_match("/^(\w+)\-gradation$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_gradation($colorD, $line, $at[1], $req['gradation']); } if (array_key_exists ('foundGene', $req) ){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); if ($name == $req['foundGene']){ $colorRGB = array(230,159,0); } } } $color = imagecolorallocate( $image, $colorRGB[0], $colorRGB[1], $colorRGB[2] ); $h = $h1 / 2 + $h2 + $h1 * $gene_height[$num]; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } if($startpos < 0) $startpos = 0; if($endpos > $req['width']) $endpos = $req['width']-1; imageline($image, $startpos, $h, $endpos, $h, $color); $strand = substr(strchr ($line, 'strand='), 7, 1); if ( $strand == '+' xor $req['start'] >= $req['end']) { for($i = $startpos; $i < $endpos-10; $i+=10){ imageline($image, $i, $h-$hgene, $i+$hgene, $h, $color); imageline($image, $i, $h+$hgene, $i+$hgene, $h, $color); } }else if ( $strand == '-' xor $req['start'] >= $req['end']) { for($i = $startpos; $i < $endpos -10; $i+=10){ imageline($image, $i, $h, $i+$hgene, $h-$hgene, $color); imageline($image, $i, $h, $i+$hgene, $h+$hgene, $color); } } if($startpos > 100){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); $strbox = imagettfbbox( $size, 0, $fontfile, $name ); imagettftext( $image, $size, 0, $startpos-$strbox[2]+$strbox[0]- 10, $h + (- $h2 + $strbox[3]-$strbox[5])/2, $color, $fontfile, $name); } } $exon_line = $line; for(;;){ if(($exon = strchr ($exon_line, 'exon=')) == FALSE) break; $exon_line = substr($exon, 5); list($exon_start, $exon_end, $remain) = split("[, \t]", $exon_line); if($exon_start > $exon_end) { $tmp = $exon_start; $exon_start = $exon_end; $exon_end = $tmp; } if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($exon_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($exon_end - $req['start'] + 1) / $basewidth; }else { $endpos = $req['width'] * ($req['start'] - $exon_start + 1) / $basewidth; $startpos = $req['width'] * ($req['start'] - $exon_end) / $basewidth; } if (($endpos < 0) || ($startpos >$req['width'] )) continue; if($startpos < 0) $startpos = 0; if($endpos > $req['width']) $endpos = $req['width']-1; imagefilledrectangle($image, $startpos, $h-$hgene, $endpos, $h+$hgene, $color); } } // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function draw_gene_style_small($genes, $req, $colorD, $h1, $hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start']) + 1; $size = 8; $fontfile = $utgb_font_Abadi_file; # $h1 = 10; # $hgene = 3; # 20 # $h2 = 5; # $h2 = 1; $h2 = 0; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1,10); $image = imagecreatetruecolor( $req['width'], $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); // imagefill( $image, 0, 0, $white); imagefilledrectangle($image, 0, 0, $req['width']-1,$height-1, $white); // イメージの作成 # for($i=50; $i < $req['width']; $i = $i +50){ # imageline($image, $i, 0, $i, $height, $black); # } draw_ruler($image, $req, $height); for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $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; } // 色の取得 $colorRGB = $colorD; if(array_key_exists('usecolor', $req)) { if(preg_match("/^(\w+)\-color$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_color($colorD, $line, $at[1], $req['color']); }else if(preg_match("/^(\w+)\-gradation$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_gradation($colorD, $line, $at[1], $req['gradation']); } } if (array_key_exists ('foundGene', $req) ){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); if ($name == $req['foundGene']){ $colorRGB = array(230,159,0); } } } $color = imagecolorallocate( $image, $colorRGB[0], $colorRGB[1], $colorRGB[2] ); $h = $h1 / 2 + $h2 + $h1 * $gene_height[$num]; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } if($startpos < 0) $startpos = 0; if($endpos > $req['width']) $endpos = $req['width']-1; imageline($image, $startpos, $h, $endpos, $h, $color); $exon_line = $line; for(;;){ if(($exon = strchr ($exon_line, 'exon=')) == FALSE) break; $exon_line = substr($exon, 5); list($exon_start, $exon_end, $remain) = split("[, \t]", $exon_line); if($exon_start > $exon_end) { $tmp = $exon_start; $exon_start = $exon_end; $exon_end = $tmp; } if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($exon_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($exon_end - $req['start'] + 1) / $basewidth; }else { $endpos = $req['width'] * ($req['start'] - $exon_start + 1) / $basewidth; $startpos = $req['width'] * ($req['start'] - $exon_end) / $basewidth; } if (($endpos < 0) || ($startpos >$req['width'] )) continue; if($startpos < 0) $startpos = 0; if($endpos > $req['width']) $endpos = $req['width']-1; imagefilledrectangle($image, $startpos, $h-$hgene, $endpos, $h+$hgene, $color); } } // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } /** * geneTrackを描画する。 * @access public * @param string $file geneファイルファイルポインタ * @param string $first_line geneファイル一行目 * @param string $buffer_tmp_dir 中間ファイル出力ディレクトリ * @param string $xml_tmp_dir XMLファイル出力ディレクトリ */ function draw_gene2($file,$first_line,$buffer_tmp_dir,$xml_tmp_dir){ // 一行目の行頭9文字を削除(geneTrack) $first_line = trim (substr($first_line, 9)); // 描画デフォルト色 $colorD = get_defaultcolor($first_line); // Option Attribute $opattrs = get_optional_attribute($first_line); // $_REQUEST取得 $req = get_request($_REQUEST, $opattrs, $colorD); // geneデータを配列に格納 $genes = get_display_genes($file,$req); // styleの取得 $style = $req['style']; // 中間ファイル、XMLファイル設定 $buffer= $buffer_tmp_dir."/".$_REQUEST['sid']."_".$style.".txt"; $xml= $xml_tmp_dir."/".$_REQUEST['sid']."_".$style.".xml"; $cache_id = $_REQUEST['sid']."_".$style; // style毎の遺伝子描画 if ($style == 'full'){ draw_gene_style($genes,$req,$colorD,9,3,$style,$buffer,$xml,$cache_id); }else if ($style == 'dense'){ draw_gene_style($genes,$req,$colorD,9,3,$style,$buffer,$xml,$cache_id); }else if ($style == 'pack'){ draw_gene_style($genes,$req,$colorD,9,3,$style,$buffer,$xml,$cache_id); }else if ($style == 'small'){ draw_gene_style($genes,$req,$colorD,4,1,$style,$buffer,$xml,$cache_id); } } function draw_gene($file,$first_line){ $first_line = trim (substr($first_line, 9)); $colorD = get_defaultcolor($first_line); $opattrs = get_optional_attribute($first_line); $req = get_request($_REQUEST, $opattrs, $colorD); $genes = get_display_genes($file,$req); // styleの取得 $style = $req['style']; // style毎の遺伝子描画 if ($style == 'full'){ draw_gene_style_full($genes,$req,$colorD,9,3); }else if ($style == 'dense'){ draw_gene_style_dense($genes,$req,$colorD,9); }else if ($style == 'pack'){ draw_gene_style_pack($genes,$req,$colorD, 9,3); }else if ($style == 'small'){ draw_gene_style_small($genes,$req,$colorD, 4,1); } } function draw_gene_index_style($genes, $req, $colorD, $h1, $hgene, $style,$buffer,$buffer_track){ global $utgb_font_Abadi_file; //easygenetrack文の解釈 //gene数計数 $num_genes = sizeof($genes); //縦の余白=marginy $h2 = 0; //画像縦幅? // $height = $num_genes * $h1 + $h2; if ($num_genes == 0){ $height = 5; }else{ $height = 0; } //インデックス画像設定 $size = 8; $width = 100; //UTGDインスタンス作成 $utgd = new UTGD4(); //色指定 $white = 'white'; $black = 'black'; //TTフォント設定 $fontpath = '../../../lib/UTGD4/fonts/Abadi MT Condensed Light.ttf'; $utgd->setFontFile($fontpath); //中間ファイル設定 $buffer = $buffer; $utgd->openBufferFile($buffer); //カテゴリ宣言 $utgd->insertCategory('INDEX'); //easygenetrack読み込み $rownum = 0; foreach($genes as $line){ //easygenetrackからデータ取得 //// 色の取得 $colorRGB = $colorD; if(preg_match("/^(\w+)\-color$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_color($colorD, $line, $at[1], $req['color']); }else if(preg_match("/^(\w+)\-gradation$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_gradation($colorD, $line, $at[1], $req['gradation']); } //// gene name取得 if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); } //styleによる描画オプションのヴァリエーション if($style == 'full'){ // $rownum++;//描画列加算 $col_foundGene = array(230,159,0);//foundGeneの色指定 }elseif($style == 'dense'){ // $utgd->insertCategory('FORCE');//描画列を強制的に決定 // $rownum = 1;//描画列は1に固定 $col_foundGene = $colorD;//foundGeneの色指定 // $name_draw = '';//遺伝子名描画文字列 }elseif($style == 'small'){ // $rownum = 1;//描画列は自動計算 $col_foundGene = array(230,159,0);//foundGeneの色指定 // $name_draw = '';//遺伝子名描画文字列 $size = 4; }else{ // $rownum = 1;//描画列は自動計算 $col_foundGene = array(230,159,0);//foundGeneの色指定 // $line_style = 4;//エクソン連結線スタイル(反復矢印) // $name_draw = $name;//遺伝子名描画文字列 // $gene_size = 2*$hgene; //エクソン縦幅 } //直前処理 ////foundGeneチェック if (array_key_exists ('foundGene', $req) ){ if ($name == $req['foundGene']){ $colorRGB = $col_foundGene; } } ////色再変換(二度手間) $colorDS = getColorString($colorD); $colorRGBS = getColorString($colorRGB); //Index描画 $utgd->drawIndex($name,1,$colorRGBS,$size,NULL,'CENTER','CENTER',0,0); } //中間ファイルクローズ $utgd->closeBufferFile(); //トラック画像サイズ取得 //トラック画像サイズの設定 $utgd->setImageSize($req['width'],$height,1,$h1,$req['start'],$req['end'],0,$h2); //その他オプション設定 $utgd->setImageOptions($white,$white,10); // $utgd->setDebugOptions(TRUE,10); $utgd->openLogFile('./log.txt'); //グラフ画像中間ファイルのパースシミュレート if(checkBufferFile($buffer_track)){ list($rownum,$height) = $utgd->parseBufferFile($buffer_track,'TILING',TRUE); // $utgd->addDebugMessage("$rownum,$height"); }else{ return FALSE; } //print $rownum; //インデックス画像描画 //インデックス画像サイズの設定 $utgd->setImageSize($width,$height,$rownum,$h1,$req['start'],$req['end'],0,$h2); //その他オプション設定 $utgd->setImageOptions($white,$white,0); //INDEX中間ファイルのパース $utgd->parseBufferFileIndex($buffer,'WITHIN',1,$rownum); //画像枠の作成 $utgd->createImage(); //図形の描画 $utgd->drawImage(); //画像出力 $utgd->outputImage(); } /** * 中間ファイルがオープンできるかチェックする * @access public * @param string $buffer 中間ファイルパス * @param int $limit ファイル読み込み待ち最大時間(秒) * @param int $wait 再読み込み間隔(秒) * @return boolean TRUE/FALSE */ function checkBufferFile($buffer,$limit=120,$wait=10){ if($limit<=0){ $limit = 120; } if($wait<=0){ $wait = 10; } for($i=0;$i<$limit;$i+=$wait){ if($fp = fopen($buffer,'r')){ //中間ファイルがオープンできた場合 fclose($fp); return TRUE; }else{ continue; } } //幾ら待っても中間ファイルが開かない return FALSE; } function draw_gene_index_style_full($genes,$req,$colorD, $h1, $hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); // イメージの生成 # $h1 = 10; # $hgene = 5; # 20 $h2 = 0; $size = 8; $fontfile = $utgb_font_Abadi_file; $height = $num_genes * $h1 + $h2; if ($num_genes == 0) $height = 5; $width = 100; $image = imagecreatetruecolor( $width, $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); // imagefill( $image, 0, 0, $white); imagefilledrectangle($image, 0, 0, $width-1,$height-1, $white); // イメージの作成 for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; // 色の取得 $colorRGB = $colorD; if(preg_match("/^(\w+)\-color$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_color($colorD, $line, $at[1], $req['color']); }else if(preg_match("/^(\w+)\-gradation$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_gradation($colorD, $line, $at[1], $req['gradation']); } if (array_key_exists ('foundGene', $req) ){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); if ($name == $req['foundGene']){ $colorRGB = array(230,159,0); } } } $color = imagecolorallocate( $image, $colorRGB[0], $colorRGB[1], $colorRGB[2] ); $h = $h1 * $num; if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); $strbox = imagettfbbox( $size, 0, $fontfile, $name ); imagettftext( $image, $size, 0, ($width-$strbox[2]+$strbox[0])/2, $h + ($h1 + $h2 + $strbox[3]-$strbox[5])/2, $color, $fontfile, $name); } } // イメージの出力 ( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function draw_gene_index_style_dense($genes,$req,$colorD,$height){ $num_genes = sizeof($genes); $width = 100; $image = imagecreatetruecolor( $width, $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); imagefilledrectangle($image, 0, 0, $width-1,$height-1, $white); // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function draw_gene_index_style_pack($genes,$req,$colorD, $h1,$hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start'] + 1); // イメージの生成 $h2 = 0; $size = 8; $fontfile = $utgb_font_Abadi_file; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1, 100); $width = 100; $image = imagecreatetruecolor( $width, $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); // imagefill( $image, 0, 0, $white); imagefilledrectangle($image, 0, 0, $width-1,$height-1, $white); // イメージの作成 for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $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; } // 色の取得 $colorRGB = $colorD; if(preg_match("/^(\w+)\-color$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_color($colorD, $line, $at[1], $req['color']); }else if(preg_match("/^(\w+)\-gradation$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_gradation($colorD, $line, $at[1], $req['gradation']); } if (array_key_exists ('foundGene', $req) ){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); if ($name == $req['foundGene']){ $colorRGB = array(230,159,0); } } } $color = imagecolorallocate( $image, $colorRGB[0], $colorRGB[1], $colorRGB[2] ); $h = $h1 * $gene_height[$num]; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start']) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start) / $basewidth; } if($startpos <= 100){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); #imagestring($image, 1, 10, $h-20, $name, $black); // Replace path by your own font path $strbox = imagettfbbox( $size, 0, $fontfile, $name ); imagettftext( $image, $size, 0, ($width-$strbox[2]+$strbox[0])/2, $h + ($h1 + $h2 + $strbox[3]-$strbox[5])/2, $color, $fontfile, $name); } } } // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function draw_gene_index_style_small($genes,$req,$colorD,$h1,$hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start'] + 1); // イメージの生成 $h2 = 0; $size = 8; $fontfile = $utgb_font_Abadi_file; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1, 10); $width = 100; $image = imagecreatetruecolor( $width, $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); // imagefill( $image, 0, 0, $white); imagefilledrectangle($image, 0, 0, $width-1,$height-1, $white); // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } /** * eastyGeneTrackのindex画像を描画する * @access public * @param string $file geneファイルファイルポインタ * @param string $first_line geneファイル一行目 * @param string $buffer_tmp_dir 中間ファイル出力ディレクトリ */ function draw_gene_index2($file, $first_line,$buffer_tmp_dir){ // 一行目の行頭9文字を削除(geneTrack) $first_line = trim (substr($first_line, 9)); // 描画デフォルト色 $colorD = get_defaultcolor($first_line); // Option Attribute $opattrs = get_optional_attribute($first_line); // $_REQUEST取得 $req = get_request($_REQUEST, $opattrs, $colorD); // geneデータを配列に格納 $genes = get_display_genes($file,$req); // styleの取得 $style = $req['style']; // インデックス中間ファイル、トラック画像中間ファイル設定 $buffer = $buffer_tmp_dir."/".$_REQUEST['sid']."_".$style."_index.txt"; $buffer_track = $buffer_tmp_dir."/".$_REQUEST['sid']."_".$style.".txt"; // style の検索 $style = $req['style']; if ($style == 'full'){ draw_gene_index_style($genes,$req,$colorD,9,3,$style,$buffer,$buffer_track); }else if ($style == 'dense'){ draw_gene_index_style($genes,$req,$colorD,9,3,$style,$buffer,$buffer_track); }else if ($style == 'pack'){ draw_gene_index_style($genes,$req,$colorD,9,3,$style,$buffer,$buffer_track); }else if ($style == 'small'){ draw_gene_index_style($genes,$req,$colorD,4,1,$style,$buffer,$buffer_track); } } function draw_gene_index($file, $first_line){ $first_line = trim (substr($first_line, 9)); $colorD = get_defaultcolor($first_line); $opattrs = get_optional_attribute($first_line); $req = get_request($_REQUEST, $opattrs, $colorD); $genes = get_display_genes($file,$req); // style の検索 $style = $req['style']; if ($style == 'full'){ draw_gene_index_style_full($genes,$req,$colorD,9,3); }else if ($style == 'dense'){ draw_gene_index_style_dense($genes,$req,$colorD,9); }else if ($style == 'pack'){ draw_gene_index_style_pack($genes,$req,$colorD,9,3); }else if ($style == 'small'){ draw_gene_index_style_small($genes,$req,$colorD,4,1); } } function def_gene_operation_style_full($genes,$req,$h1,$hgene){ $num_genes = sizeof($genes); $basewidth = abs ($req['end'] - $req['start']) + 1; // 共通パラメータ $h2 = 0; $height = $num_genes * $h1 + $h2; if ($num_genes == 0) $height = 5; // xml出力 header('Content-Type: text/xml'); print"\n"; print "\n"; for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $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($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } $h = $h1 / 2 + $h2 + $h1 * $num; $y1 = $h-$hgene; $y2 = $h+$hgene+1; if ($startpos < 0) { $x1 = 0; }else { $x1 = floor ($startpos); // 0; } if ($endpos >= $req['width']) { $x2 = $req['width']-1; }else { $x2 = ceil($endpos) ; // $req['width']-1; } // URLの取得 if (preg_match("/url=\"(\S+)\"/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; }else if (preg_match("/url=(\S+)/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; } } print ""; } function def_gene_operation_style_dense($genes,$req,$h1){ // xml出力 header('Content-Type: text/xml'); print "\n"; print "\n"; print ""; } function def_gene_operation_style_pack($genes, $req,$h1,$hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start'] + 1); $size = 8; $fontfile = $utgb_font_Abadi_file; # $h2 = 5; $h2 = 0; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1, 100); // xml出力 // header('Content-Type: text/xml'); print "\n"; print "\n"; for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $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; } $h = $h1 / 2 + $h2 + $h1 * $gene_height[$num]; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } if($startpos > 100){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); $strbox = imagettfbbox( $size, 0, $fontfile, $name ); $startpos = $startpos - $strbox[2] + $strbox[0] - 10; } } $y1 = $h-$hgene; $y2 = $h+$hgene+1; if ($startpos < 0) { $x1 = 0; }else { $x1 = floor ($startpos); // 0; } if ($endpos >= $req['width']) { $x2 = $req['width']-1; }else { $x2 = ceil($endpos) ; // $req['width']-1; } // URLの取得 if (preg_match("/url=\"(\S+)\"/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; }else if (preg_match("/url=(\S+)/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; } } print ""; } function def_gene_operation_style_small($genes, $req,$h1,$hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start'] + 1); $size = 8; $fontfile = $utgb_font_Abadi_file; # $h2 = 5; $h2 = 0; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1, 10); // xml出力 // header('Content-Type: text/xml'); print "\n"; print "\n"; for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $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; } $h = $h1 / 2 + $h2 + $h1 * $gene_height[$num]; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } # if($startpos > 100){ # if(($name_pos = strpos($line, 'name=')) !== FALSE) { # $name_line = substr($line, $name_pos + 5); # list($name, $remain) = split("[ \t]", $name_line); # $strbox = imagettfbbox( $size, 0, $fontfile, $name ); # $startpos = $startpos - $strbox[2] + $strbox[0] - 10; # } # } $y1 = $h-$hgene; $y2 = $h+$hgene+1; if ($startpos < 0) { $x1 = 0; }else { $x1 = floor ($startpos); // 0; } if ($endpos >= $req['width']) { $x2 = $req['width']-1; }else { $x2 = ceil($endpos) ; // $req['width']-1; } // URLの取得 if (preg_match("/url=\"(\S+)\"/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; }else if (preg_match("/url=(\S+)/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; } } print ""; } /** * geneTrackの操作XMLを標準出力する。(ソースとしてXMLキャッシュファイル使用) * @access public * @param string $xml_tmp_dir XMLファイル出力ディレクトリ * @param string $cache_id キャッシュID * @param string $style 描画スタイル */ function def_gene_operation2($xml_dir_path,$cache_id,$style){ //UTGDインスタンス作成 $utgd = new UTGD4(); //XMLファイルパス取得 $xml_file_path = $xml_dir_path."/".$_REQUEST['sid']."_".$style.".xml"; //print $xml_file_path; //print $cache_id; //キャッシュID if(!($cache_id)){ return FALSE; } //キャッシュを使う場合 //XMLファイル指定(XMLファイルパス、新規作成フラグ) $utgd->openXMLFile($xml_file_path,FALSE); //XMLデータ標準出力 $utgd->outputCachedXMLData($cache_id); } /** * geneTrackの操作XMLを標準出力する。(ソースとしてXMLファイル使用) * @access public * @param string $xml_file_path XMLファイル出力ディレクトリ * @param string $style 描画スタイル */ function def_gene_operation4($xml_dir_path,$style){ //UTGDインスタンス作成 $utgd = new UTGD4(); //XMLファイルパス取得 $xml_file_path = $xml_dir_path."/".$_REQUEST['sid']."_".$style.".xml"; //print $xml_file_path; //print $cache_id; //XMLファイルを使う場合 //XMLファイル指定(XMLファイルパス、新規作成フラグ) $utgd->openXMLFile($xml_file_path,FALSE); //XMLデータ標準出力 $utgd->outputXMLDataStandardFromFile(); } /** * geneTrackの操作XMLを標準出力する。(中間ファイルからgeneTrackの描画位置の再計算を行う) * @access public * @param array $req POST/GET引数配列 * @param string $style 描画スタイル * @param string $buffer 中間ファイルパス * @param string $xml XMLファイル出力ディレクトリ(形式的に必要) */ function def_gene_operation3($req,$style,$buffer,$xml){ //styleによる描画オプションのヴァリエーション if($style == 'full'){ $h1 = 9; }elseif($style == 'dense'){ $h1 = 9; }elseif($style == 'small'){ $h1 = 4; }else{ $h1 = 9; } //縦の余白=marginy $h2 = 0; //画像縦幅 $height = 0;//自動なので //UTGDインスタンス作成 $utgd = new UTGD4(); //色指定 $white = 'white'; $black = 'black'; //TTフォント設定 $fontpath = '../../../lib/UTGD4/fonts/Abadi MT Condensed Light.ttf'; $utgd->setFontFile($fontpath); //サイズの設定 $utgd->setImageSize($req['width'],$height,1,$h1,$req['start'],$req['end'],0,$h2); //その他オプション設定 $utgd->setImageOptions($white,$white,10); //中間ファイルのパース $utgd->parseBufferFile($buffer,'TILING'); //画像枠の作成 $utgd->createImage(); //XMLファイルオープン $utgd->openXMLFile($xml); //図形の描画 $utgd->drawImage(); // //画像出力 // $utgd->outputImage(); //XML出力 // $utgd->outputXMLFile(); // //XMLキャッシュ出力 // $utgd->cacheXMLData($cache_id); //XML標準出力 $utgd->outputXMLDataStandard(); } function def_gene_operation($file, $first_line){ // イメージサイズの取得 $first_line = trim (substr($first_line, 9)); $opattrs = get_optional_attribute($first_line); $req = get_request($_REQUEST, $opattrs, $colorD); $genes = get_display_genes($file,$req); // style の検索 $style = $req['style']; if ($style == 'full'){ def_gene_operation_style_full($genes,$req,9,3); }else if ($style == 'dense'){ def_gene_operation_style_dense($genes,$req,9); }else if ($style == 'pack'){ def_gene_operation_style_pack($genes,$req,9,3); }else if ($style == 'small'){ def_gene_operation_style_small($genes,$req,4,1); } } function def_gene_index_operation_style_full($genes,$req,$h1, $hgene){ $num_genes = sizeof($genes); // 共通パラメータ $h2 = 0; $height = $num_genes * $h1 + $h2; if($num_genes == 0) $height = 5; $width = 100; // xml出力 header('Content-Type: text/xml'); print "\n"; print "\n"; for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $h = $h1 / 2 + $h2 + $h1 * $num; $y1 = $h-$hgene; $y2 = $h+$hgene+1; $x1 = 0; $x2 = $width-1; // URLの取得 if (preg_match("/url=\"(\S+)\"/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; }else if (preg_match("/url=(\S+)/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; } } print ""; } function def_gene_index_operation_style_dense($genes,$req,$height){ // xml出力 header('Content-Type: text/xml'); print "\n"; print "\n"; print ""; } function def_gene_index_operation_style_pack($genes, $req,$h1,$hgene){ print_r($genes); $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start'] + 1); # $h2 = 5; $h2 = 0; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1, 100); $width = 100; // xml出力 header('Content-Type: text/xml'); print "\n"; print "\n"; for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $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; } $h = $h1 / 2 + $h2 + $h1 * $gene_height[$num]; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start']) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start) / $basewidth; } if($startpos <= 100){ $y1 = $h-$hgene; $y2 = $h+$hgene+1; $x1 = 0; $x2 = $width-1; // URLの取得 if (preg_match("/url=\"(\S+)\"/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; }else if (preg_match("/url=(\S+)/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; } } } print ""; } function def_gene_index_operation($file, $first_line){ $first_line = trim (substr($first_line, 9)); $opattrs = get_optional_attribute($first_line); $req = get_request($_REQUEST, $opattrs, $colorD); $genes = get_display_genes($file,$req); // style の検索 $style = $req['style']; if ($style == 'full'){ def_gene_index_operation_style_full($genes,$req,9,3); }else if ($style == 'dense'){ def_gene_index_operation_style_dense($genes,$req,10); }else if ($style == 'pack'){ def_gene_index_operation_style_pack($genes,$req,9,3); }else if ($style == 'small'){ def_gene_index_operation_style_dense($genes,$req,10); } } ?>