4

我有一个二进制数据字符串,我使用 php 使用以下代码解压缩并解压到一个数组中(此 php 页面的完整代码包含在此问题的底部):

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
  $glycopeptide[$hits] = $row[1];
  echo $row[4];
  // $row[4] contains the binaryString
  $mz = base64_decode($row[4]);
  $unc_mz = gzuncompress($mz);
  $max = strlen($unc_mz);
  $counter = 0;
  for ($i = 0; $i < $max; $i = $i+4) {
    $temp = substr($unc_mz,$i,4);
    $temp = unpack("f",$temp);
    $mz_array[$counter] = $temp[1];
    $counter++;
  }
  $hits++;
}

我发现 mz_array (上面的代码,X-coords)都有 9 个未定义的值(全部在末尾),但是 int_array(类似的代码,Y-coords)也有 9 个未定义的值(分布在整个数组中(不是分组或在开头/结尾)。

这是我添加到页面中的一个小测试块的示例:

测试代码:

for ($i = 0; $i < $counter; $i++) {
  echo $i;
  echo " -  ";
  echo $mz_array[$i];
  echo " - ";
  echo $int_array[$i];
  echo "<br/>";
} 

输出的“选择”(注意缺失值):

671 - 274.20001220703 - 429
672 - 274.39999389648 -
673 - 274.60000610352 - 1098
-- skipping a few lines --
10299 - 2199.8000488281 - 0
10300 - 2200 - 0
10301 - - 0
10302 - - 0

最奇怪的部分是,如果我在完整/原始代码中手动输入字符串(见页面底部),我会得到未定义的值,而如果我手动输入通过执行“echo $row[4]”返回的字符串(包含binaryString) 在下面的代码中它不会产生未定义的值。

<?php
  $string = " /* Copy the string in the spoiler (on this page) here */ ";
  $int = base64_decode($string);
  $unc_int = gzuncompress($int);
  $max = strlen($unc_int);
  $counter = 0; 
  $max_int = 0;
  for ($i = 0; $i < $max; $i = $i + 4) {
     $temp= substr($unc_int,$i,4);
     $temp = unpack("f",$temp);
     $int_array[$counter] = $temp[1];
     echo $counter;
     echo " -- ";
     echo $int_array[$counter];
     echo "<br/>";
     $counter++;
  }
?>

有没有人有任何建议或想法为什么会发生这种情况?

PS:有人可以添加标签 gzuncompress 吗?(我没有这方面的声誉)。

编辑 1

我已经包含了一个示例 bin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+j1T67sJci009jjbdo8t3ZPnk48e5RF79KvLOkBurFax3qlZxlNxbl/SBL0/SuruMr08H1DuVvVa79ixEjRowYMWJUDeZHnFln188ZphgxYsSIESNGjBgxYsSIESNGjBgxooB473oF783vaDT11Vj2njJz7jFixOhwiL/PuDE+Mxej5vF/owjA3A==

完整代码:

<?php
  require 'phplot/phplot.php';
      $type = $_GET['type'];
      $gp = $_GET['gp'];
      $site = $_GET['site'];
      $prec = $_GET['prec'];
      $link = mysql_connect("localhost","reader","") or die (mysql_error());
      mysql_select_db('leidenGlycoPeptide') or die ();
      $query = sprintf("select precursor.mzValue, glycoPeptide.protein, binaryDataArray.arrayLength, binaryDataArray.encodedLength, binaryDataArray.arrayData, precursor.chargeState, run.pepMass, run.PepSeq from glycoPeptide, spectrum, binaryDataArray, run, precursor where run.glycoPeptide = glycoPeptide.id AND spectrum.run = run.id AND precursor.run = run.id AND binaryDataArray.spectrum = spectrum.id AND precursor.id = spectrum.precursor AND spectrum.spectrum like 'm/z' AND precursor.mzValue like '%s' and glycoPeptide.protein like '%s' and run.glycoSite like '%s' and run.glycoType like '%s' ORDER by glycoPeptide.protein, spectrum.spectrum",(string)$prec, (string)$gp, (string)$site, (string)$type);
      $result = mysql_query($query);
      $hits = 0;
      while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        $charge = $row[5];
        $pepmass = $row[6];
        $pepseq = $row[7];
        $glycopeptide[$hits] = $row[1];
        /* Manually entering string here also gives undefined values */
        /* $mz = " I was not able to include the mz string due to message size limit "; */
        $mz = base64_decode($row[4]);
        $unc_mz = gzuncompress($mz);
        $max = strlen($unc_mz);
        $counter = 0;
        for ($i = 0; $i < $max; $i = $i+4) {
          $temp = substr($unc_mz,$i,4);
          $temp = unpack("f",$temp);
          $mz_array[$counter] = $temp[1];
          $counter++;
        }
        $hits++;
      }
      $query = sprintf("select precursor.mzValue, glycoPeptide.protein, binaryDataArray.arrayLength, binaryDataArray.encodedLength, binaryDataArray.arrayData from glycoPeptide, spectrum, binaryDataArray, run, precursor where run.glycoPeptide = glycoPeptide.id AND spectrum.run = run.id AND precursor.run = run.id AND binaryDataArray.spectrum = spectrum.id AND precursor.id = spectrum.precursor AND spectrum.spectrum like 'intensity' AND precursor.mzValue like '%s' and glycoPeptide.protein like '%s' and run.glycoSite like '%s' and run.glycoType like '%s' ORDER by glycoPeptide.protein, spectrum.spectrum",(string)$prec, (string)$gp, (string)$site, (string)$type);
      $result = mysql_query($query);
      while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        /* Manually entering string here also gives undefined values */
        /* $int = " Copy the string from above in here "; */
        $int = base64_decode($row[4]);
        /* The result from this is the above binaryString */
        /* echo $row[4]; */ 
        $unc_int = gzuncompress($int);
        $max = strlen($unc_int);
        $counter = 0;
        $max_int = 0;
        for ($i = 0; $i < $max; $i = $i + 4) {
          $temp= substr($unc_int,$i,4);
          $temp = unpack("f",$temp);
          $int_array[$counter] = $temp[1];
          $counter++;
          if ($temp[1] > $max_int) {
            $max_int = $temp[1];
            $counter++;
          }
        }
      }
      /* The following chunk is just to test the arrays */
      for ($i = 0; $i < $counter; $i++) {
        echo $i;
        echo " -  ";
        echo $mz_array[$i];
        echo " - ";
        echo $int_array[$i];
        echo "<br/>";
      }
      for ($i = 0; $i < $counter; $i++) {
        $plot_data[$i] = array('',$mz_array[$i],$int_array[$i]);
      }
      // Plot the regular spectrum
      $width = 1024;
      $height = 768;
      $plot = new PHPlot($width,$height);
      $plot->SetMarginsPixels(NULL,NULL,NULL,35);
      $plot->SetPrintImage(False);
      $plot->SetPlotType('thinbarline');
      //$plot->SetXTitle('m/z Values');
      $plot->SetXTickAnchor('400');
      $plot->SetDataColors('red');
      $plot->SetXTickIncrement('200');
      $plot->SetXDataLabelPos('none');
      $plot->SetYTitle('Intensity');
      $plot->SetYTickAnchor('0');
      //Might need to define this dynamically with nested if/else loops
      $plot->SetYTickIncrement('100000');
      $plot->SetDataType('data-data');
      $plot->SetDataValues($plot_data);
      $plot->SetTitle('Fragmentation Spectrum');
      //$plot->DrawGraph();

      mysql_close($link);
    ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title>Query result page</title>
    <script src="jquery-1.9.1.min.js"></script>
  </head>
  <script>
    var gp = '<?php echo htmlspecialchars($_GET['gp']); ?>';
    $(document).ready(function() {
      $('.button').click(function() {
        window.open('http://www.uniprot.org/uniprot/?query='+gp+'+AND+organism:human&sort=score');
      });
      $('.XY').click(function() {
        var mz_array = <?php echo json_encode($mz_array) ?>;
        var int_array = <?php echo json_encode($int_array) ?>;
        var table = 
          "<table border=\"1\">"
            +"<tr>"
              +"<th>m/z</th>"
              +"<th>intensity<t/h>"
            +"</tr>";
        var max = <?php echo $counter ?>;
        for (var i = 0; i < max; i++) {
        table += "<tr>"
                   +"<td>"+mz_array[i]+"</td>"
                   +"<td>"+int_array[i]+"</td>"
                 +"</tr>";
        }
        table += "</table>";
        var disp = window.open();
        $(disp.document.body).html(table); 
      });
    });
  </script>
  <body>
    <p>The displayed spectrum belongs to <?php echo $gp ?> with a precursor [M+H] of <?php echo (($prec*$charge)-($charge+1)); ?>.<br>
    The peptide belonging to this glycopeptide has a mass of <?php echo $pepmass ?> and sequence: <?php echo $pepseq ?>.<br>
    <button class="button">Uniprot search</button> <button class="XY">Display XY data</button></p>
    <img src="<?php echo $plot->EncodeImage();?>" alt="Plot Image">
  </body>
</html>
4

2 回答 2

1

这很复杂:

$max = strlen($unc_mz);
  $counter = 0;
  for ($i = 0; $i < $max; $i = $i+4) {
    $temp = substr($unc_mz,$i,4);
    $temp = unpack("f",$temp);
    $mz_array[$counter] = $temp[1];
    $counter++;
  }

改用这个:

$mz_array = array_values(unpack("f*", $unc_mz));
于 2013-02-20T04:44:53.903 回答
0

我正在增加我不应该拥有的索引之一,if ($temp[1] > $max_int) { // stuff } 中的 $counter++ 在检测到新的最大值时会碰撞索引。

int_array 的新代码现在看起来像这样(使用 Sectus 的技巧和 max(array)):

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
  $int = base64_decode($row[4]);
  $unc_int = gzuncompress($int);
  $int_array = array_values(unpack("f*",$unc_int));
  $max_int = max($int_array);
}

以下语法也是有效的(如果您不想使用 Sectus 的技巧):

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
  $int = base64_decode($row[4]);
  $unc_int = gzuncompress($int);
  $max = strlen($unc_int);
  $counter = 0; 
  $max_int = 0;
  for ($i = 0; $i < $max; $i = $i + 4) {
    $temp= substr($unc_int,$i,4);
    $temp = unpack("f",$temp);
    $int_array[$counter] = $temp[1];
    $counter++;
    if ($temp[1] > $max_int) {
      $max_int = $temp[1];
    } 
  } 
}

我还要感谢所有为此烦恼的人。

于 2013-02-20T09:43:04.803 回答