-2

我已经完成了这段代码,但是它没有按照我想要的方式工作。我正在尝试为一段字符串着色。颜色由一个函数getcolor决定,该函数由一个名为 raw transform 的函数决定,该函数会将原始分数转换为我的 switch case 的 1-9 分数。任何人都可以提供一些帮助吗?$col由另一个函数分配-为了参数,可以说它定义为:$col= 0.

<?php

$raw= 650;
function rawtransform($raw) {
  $score = (int)($raw/50)-9;
}
    //==========================================================================
//            Function to decide which color system                         //
//==========================================================================   
function getcolor($score, $col)
{
switch ($score){
// to return the function best way is to declare the case outcome as a variable eg.$truecol
case 1: /*500-550(Raw Score)*/
    $truecol="<span style=\"color: hsl($col,100%,90%);\">";
    break;
case 2: //550-600
    $truecol="<span style=\"color: hsl($col,100%,80%);\">";
    break;
case 3: //600-650
    $truecol="<span style=\"color: hsl($col,100%,70%);\">";
    break;
case 4: //650-700
    $truecol="<span style=\"color: hsl($col,100%,60%);\">";
    break;
case 5: //700-750
    $truecol="<span style=\"color: hsl($col,100%,50%);\">";
    break;
case 6: //750-800
    $truecol="<span style=\"color: hsl($col,100%,40%);\">";
    break;
case 6: //800-850
    $truecol="<span style=\"color: hsl($col,100%,30%);\">";
    break;
case 7: //850-900;
    break;
case 8: //900-950
    $truecol="<span style=\"color: hsl($col,100%,20%);\">";
    break;
case 9: //950-1000
    $truecol="<span style=\"color: hsl($col,100%,10%);\">";
    break;
   }
}

   $query="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC";

$seq=chunk_split($query,50,"<br />");
getcolor($score);
function colorSequence ($seq,$position,$truecol,$TFBSlength){
    $nucleotides = str_split($seq);
    foreach ($nucleotides as $index => $nucl){
        if ($index == $position){
            echo $truecol;
        }
        if ($index == $position + $TFBSlength){
            echo "</span>";
        }

        echo $nucl;
    }
    echo "\n";
}
colorSequence($seq,49,$truecol,1);
?>

输出不包括所选核苷酸的颜色。有谁知道为什么?

4

1 回答 1

0

您不将返回值分配给getcolor($score);变量。我打赌它应该像$truecol = getcolor($score);打电话之前一样colorSequence($seq,49,$truecol,1);

于 2012-05-03T11:49:12.950 回答