Note that there are some explanatory texts on larger screens.

plurals
  1. POphp uncompress & unpack gives array containing a few (9 in 10309) undefined values
    primarykey
    data
    text
    <p>I have a binary data string that i uncompress and unpack into an array using php with the following code (complete code for this php page is included at the bottom of this question):</p> <pre><code>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 &lt; $max; $i = $i+4) { $temp = substr($unc_mz,$i,4); $temp = unpack("f",$temp); $mz_array[$counter] = $temp[1]; $counter++; } $hits++; } </code></pre> <p>I find that both the mz_array (the above code, X-coords) has 9 undefined values (all at the end) but that the int_array (similar code, Y-coords) also has 9 undefined values (distributed throughout the whole array (not grouped or at the beginning/end).</p> <p>Here is an example of a small testing chunk that I added to my page:</p> <p>Test code:</p> <pre><code>for ($i = 0; $i &lt; $counter; $i++) { echo $i; echo " - "; echo $mz_array[$i]; echo " - "; echo $int_array[$i]; echo "&lt;br/&gt;"; } </code></pre> <p>A "selection" of the output (Note the missing values):</p> <pre><code>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 </code></pre> <p>The weirdest part is that if i manually enter the strings in the complete/original code (see bottom of page) I get the undefined values while if I manually enter the string that is returned by doing "echo $row[4]" (contains the binaryString) in the following code it yields no undefined values. </p> <pre><code>&lt;?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 &lt; $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 "&lt;br/&gt;"; $counter++; } ?&gt; </code></pre> <p>Does anyone have any suggestions or idea's why this might occur?</p> <p>PS: Can someone add the tag gzuncompress? (I don't have the reputation for it).</p> <p><strong>EDIT 1</strong></p> <p>I have included an example binaryString (WARNING: Huge!)</p> <p>Y-Coords (retrieved by the commented echo $row[4] in the code):</p> <blockquote class="spoiler"> <p> eJztXQuQFMUZblQEQfEQUQSJYwRBSuLG+AAFHdmeRYOPS2lRgEgNvgpLhUuQkooYB5GXBLIaHwRQRwMpCqOuiciJhU4KjUoMnm98r2KUaKkXreBpSCXf3z3Lzu7Na3fn9nZhvqop2N2enu6///7fPcdYjBgxYsSIESNGjBhVgvFGkqmLOWPjk77tlNs5a35AY9kdnBlPo+3GMZ5tm87VmDULfXL/PnOwzkGfP0P7RLj2MUrAaNB0l2OtJuDzVu+188XJnKmnYZ0a5DpZE7Fu3TVm/BOft5TZZ4yqwvwf1u+ne89ea7wM/Pke5vvI3jHfGGVA56xxEnTWKeCT/h588i5k3cEp1vyuxtQN+H/an5+ya9GuBf2t6zi+s2ZAHh/KC+V7BTDXoK/15Y03uxD3zo1urmoKND4efXb17tPqgTZz0OYy/+eaB2uMHYP1UKOjVc1gDuy30TUuz3fWP82NJuy1nZyZx4GXDgO9M/acXgPd9w+mvXFrx66P+TLGNBnXBbXBB4tWwldYhvFcGmI8GbRJ1xGPhFjvPQXqvljDbZjv6jpan1pHfxcfjHyqm0Hra8vnraa+sGF68prmz4aeGtM3Y4wr3fd8I35nrxfZTU/g88YK/NbORAJ6owvG31Y49mwT/JJFXPrjYQBZSrGaAj97UMTrfFYJ4wkD9GUYtcuLBHU7Z/rzoO3dtT1OgQ0Y42neNqyFuSjrOcuamNMo7KPzecHvR45MsYtwKZfAFh7GBS9lv0LbH+BzH+67v7KvcBEDdNrarV0hb77Ddy9VWT9AFmRfwJqtqR+9pF8MGq/iwl7PId1bY62DQcMGB+0hF5W1th8WIO/a7a0TsN+maDK+M9qdnynWao3H76fVAb87oN8K2/s3XNDKfE5jzc0aW7sRNuYhkKM7bFpNt23g/XhhfBp6RtDKo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6MZfngMvV998G5BMTdl1gBfrGOoTLOqw9PDbZcIQm/uZIqPe3Ua6wjt6rGRpkY+8NdnZnoMz30e2poPNzIl/rst+MBSFyV27IFMbYqR+j1T67sJci009jjbdo8t3ZPnk48e5RF79KvLOkBurFax3qlZxlNxbl/SBL0/SuruMr08H1DuVvVa79ixEjRowYMWJUDeZHnFln188ZphgxYsSIESNGjBgxYsSIESNGjBgxooB473oF783vaDT11Vj2njJz7jFixOhwiL/PuDE+Mxej5vF/owjA3A== </p> </blockquote> <p>Complete code:</p> <pre><code>&lt;?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 &lt; $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 &lt; $max; $i = $i + 4) { $temp= substr($unc_int,$i,4); $temp = unpack("f",$temp); $int_array[$counter] = $temp[1]; $counter++; if ($temp[1] &gt; $max_int) { $max_int = $temp[1]; $counter++; } } } /* The following chunk is just to test the arrays */ for ($i = 0; $i &lt; $counter; $i++) { echo $i; echo " - "; echo $mz_array[$i]; echo " - "; echo $int_array[$i]; echo "&lt;br/&gt;"; } for ($i = 0; $i &lt; $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-&gt;SetMarginsPixels(NULL,NULL,NULL,35); $plot-&gt;SetPrintImage(False); $plot-&gt;SetPlotType('thinbarline'); //$plot-&gt;SetXTitle('m/z Values'); $plot-&gt;SetXTickAnchor('400'); $plot-&gt;SetDataColors('red'); $plot-&gt;SetXTickIncrement('200'); $plot-&gt;SetXDataLabelPos('none'); $plot-&gt;SetYTitle('Intensity'); $plot-&gt;SetYTickAnchor('0'); //Might need to define this dynamically with nested if/else loops $plot-&gt;SetYTickIncrement('100000'); $plot-&gt;SetDataType('data-data'); $plot-&gt;SetDataValues($plot_data); $plot-&gt;SetTitle('Fragmentation Spectrum'); //$plot-&gt;DrawGraph(); mysql_close($link); ?&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Query result page&lt;/title&gt; &lt;script src="jquery-1.9.1.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;script&gt; var gp = '&lt;?php echo htmlspecialchars($_GET['gp']); ?&gt;'; $(document).ready(function() { $('.button').click(function() { window.open('http://www.uniprot.org/uniprot/?query='+gp+'+AND+organism:human&amp;sort=score'); }); $('.XY').click(function() { var mz_array = &lt;?php echo json_encode($mz_array) ?&gt;; var int_array = &lt;?php echo json_encode($int_array) ?&gt;; var table = "&lt;table border=\"1\"&gt;" +"&lt;tr&gt;" +"&lt;th&gt;m/z&lt;/th&gt;" +"&lt;th&gt;intensity&lt;t/h&gt;" +"&lt;/tr&gt;"; var max = &lt;?php echo $counter ?&gt;; for (var i = 0; i &lt; max; i++) { table += "&lt;tr&gt;" +"&lt;td&gt;"+mz_array[i]+"&lt;/td&gt;" +"&lt;td&gt;"+int_array[i]+"&lt;/td&gt;" +"&lt;/tr&gt;"; } table += "&lt;/table&gt;"; var disp = window.open(); $(disp.document.body).html(table); }); }); &lt;/script&gt; &lt;body&gt; &lt;p&gt;The displayed spectrum belongs to &lt;?php echo $gp ?&gt; with a precursor [M+H] of &lt;?php echo (($prec*$charge)-($charge+1)); ?&gt;.&lt;br&gt; The peptide belonging to this glycopeptide has a mass of &lt;?php echo $pepmass ?&gt; and sequence: &lt;?php echo $pepseq ?&gt;.&lt;br&gt; &lt;button class="button"&gt;Uniprot search&lt;/button&gt; &lt;button class="XY"&gt;Display XY data&lt;/button&gt;&lt;/p&gt; &lt;img src="&lt;?php echo $plot-&gt;EncodeImage();?&gt;" alt="Plot Image"&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload