$lines = file("res_example.txt");
$resArr = array();
foreach ($lines as $line_num => $line) {
$columns = explode("\t", $line);
$raws = $columns['1'];
$hits = $columns['2'];
$names = $columns['0'];
$models = $columns['3'];
$colors = $columns['4'];
$allModels[$models] = 1;
$resArr[] = array(
name => $names,
score => $raws,
hit => $hits,
model => $models,
color => $colors
);
}
$seqArr = array('A', 'T', 'C', 'G');
$randseq = array();
for ($i = 0; $i < 1000; $i++) {
$randseq[] = $seqArr[array_rand($seqArr)];
}
$res = "";
echo "<div id=\"coltext\" style=\"font-family:monospace;\">";
foreach ($allModels as $modName => $value) {
echo "<input ModelName=$modName type=\"checkbox\"
checked==\"TRUE\" onclick=\"toggle.apply(this)\" />$modName";
}
echo "<hr />";
$score = rawtransform($raw);
foreach ($randseq as $index => $nuc) {
$index = $index + 1;
foreach ($resArr as $hitArr) {
$hit = $hitArr['hit'];
$raw = $hitArr['score'];
$model = $hitArr['model'];
$colval = $hitArr['color'];
$score = rawtransform($raw);
$color = getcolor($score, $colval);
if (($hit+3) == $index) {
echo "</span>";
}
if ($hit == $index) {
echo "<span class=$model Title=\"position:$index,score:$raw\"
style=\"background:$color;\" color=\"$color\">";
//problem when theres overlap !?
}
}
echo $nuc;
if (($index%50)==0){
echo"<br />";
}
}
echo "</div>";
function rawtransform($raw) {
return (int)($raw/50)-9;
}
function getcolor($score,$ArrayModelval)
{
switch ($score){
// working. test each color.
case 1: /*500-550(Raw Score)*/
$col=$ArrayModelval;
return"hsl( $col,100%,90%)";
break;
case 2: //550-600
$col=$ArrayModelval;
return "hsl( $col,100%,85%)";
break;
case 3: //600-650
$col=$ArrayModelval;
return "hsl( $col,100%,85%)";
break;
case 4: //650-700
$col=$ArrayModelval;
return"hsl( $col,100%,80%)";
break;
case 5: //700-750
$col=$ArrayModelval;
return"hsl( $col,100%,70%)";
break;
case 6: //750-800
$col=$ArrayModelval;
return "hsl( $col,100%,60%)";
break;
case 7: //800-850
$col=$ArrayModelval;
return "hsl( $col,100%,50%)";
break;
case 8: //850-900;
$col=$ArrayModelval;
return "hsl( $col,100%,50%)";
break;
case 9: //900-950
$col=$ArrayModelval;
return "hsl( $col,100%,40%)";
break;
case 10: //950-1000
$col=$ArrayModelval;
return "hsl($col,100%,40%)";
break;
}
}
大多数情况下都是我想要的:我想为$hit
在外部文件上定义了 - 的随机序列的部分着色。我唯一的问题是当有任何重叠时,即如果两个命中在彼此的 3 个碱基内,则跨度被拉长并着色,就好像它的一个跨度一样。
外部文件具有开始跨度的位置,该跨度具有可变颜色,具体取决于外部文件中给出的分数。基本上,如果我有 3 个结果,其中 2 个具有几乎相同的命中 (+-1) 和另一个不同的命中,我只会看到两个部分着色,谁能看到我的问题是什么?抱歉,我知道我的措辞可能很糟糕,但很难解释。谢谢。
>chr1:2198584545754_genome_1000+ 500 1000 Model1 0
>chr2:2198581212154_genome_1000+ 510 992 Model2 180
>chr3:2115151215754_genome_1000+ 520 990 Model3 330
>chr4:2198584545754_genome_1000+ 530 980 Model3 330
>chr5:1218455145754_genome_1000+ 540 970 Model2 180
>chr6:1231354645454_genome_1000+ 550 960 Model1 0
>chr7:1231213211134_genome_1000+ 600 950 Model3 330
>chr7:1231213211134_genome_1000+ 650 940 Model3 330
javascript:
function toggle() {
var div= document.getElementById('coltext');
var modName=this.getAttribute('ModelName');
var spans=div.getElementsByTagName('span');
var spans_l=spans.length;
while (spans_l--){
span=spans[spans_l];
if(span.getAttribute('class')==modName && this.checked==true){
var color= span.getAttribute('color');
span.style.background=color;
}
if(span.getAttribute('class')==modName && this.checked==false){
span.style.background="white";
}
}
}