Php uncompress & unpack gives an array containing multiple values ​​(9 in 10309) undefined

I have a binary string of data that I decompress and decompress into an array using php with the following code (full code for this php page is included at the bottom of this question):

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++; } 

I found that mz_array (the above code, X-coordinates) has 9 undefined values ​​(all at the end), but that int_array (the same Y-coordinate code) also has 9 undefined values ​​(distributed throughout the array (not grouped or in beginning / end).

Here is an example of a small piece of testing that I added to my page:

Test code:

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

"Selecting" the output signal (note the missing values):

 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 

The strangest part is that if I manually enter the lines in the full / source code (see the bottom of the page), I get undefined values, and if I manually enter the line that is returned by executing "echo $ row [4]" ( contains binaryString) in the following code, it does not give undefined values.

 <?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++; } ?> 

Does anyone have any suggestions or ideas why this might happen?

PS: Can someone add the gzuncompress tag? (I have no reputation).

EDIT 1

I have included the binaryString example (WARNING: Huge!)

Y-Coords (retrieved from echo $ row [4] comments in code):

eJztXQuQFMUZblQEQfEQUQSJYwRBSuLG + AAFHdmeRYOPS2lRgEgNvgpLhUuQkooYB5GXBLIaHwRQRwMpCqOuiciJhU4KjUoMnm98r2KUaKkXreBpSCXf3z3Lzu7Na3fn9nZhvqop2N2enu6 /// 7fPcdYjBgxYsSIESNGjBhVgvFGkqmLOWPjk77tlNs5a35AY9kdnBlPo + 3GMZ5tm87VmDULfXL / PnOwzkGfP0P7RLj2MUrAaNB0l2OtJuDzVu + 188XJnKmnYZ0a5DpZE7Fu3TVm / BOft5TZZ4yqwvwf1u + ne89ea7wM / Pke5vvI3jHfGGVA56xxEnTWKeCT / h588i5k3cEp1vyuxtQN + H / an 5 + ya9GuBf2t6zi + s2ZAHh / KC + V7BTDXoK / 15Y03uxD3zo1urmoKND4efXb17tPqgTZz0OYy / + eaB2uMHYP1UKOjVc1gDuy30TUuz3fWP82NJuy1nZyZx4GXDgO9M / acXgPd9w + mvXFrx66P + TLGNBnXBbXBB4tWwldYhvFcGmI8GbRJ1xGPhFjvPQXqvljDbZjv6jpan1pHfxcfjHyqm0Hra8vnraa + sGF68prmz4aeGtM3Y4wr3fd8I35nrxfZTU / g88YK / NbORAJ6owvG31Y49mwT / JJFXPrjYQBZSrGaAj97UMTrfFYJ4wkD9GUYtcuLBHU7Z / rzoO3dtT1OgQ0Y42neNqyFuSjrOcuamNMo7KPzecHvR45MsYtwKZfAFh7GBS9lv0LbH + BZH + 67v7KvcBEDdNrarV0hb77Ddy9VWT9AFmRfwJqtqR + 9pF8MGq / iwl7PId1bY62DQcMGB + 0hF5W1th8WIO / a7a0TsN + maDK + M9qdnynWao3H76fVAb87oN8K2 / s3XNDKfE5jzc0aW7sRNuYhkKM7bFpNt23g / XhhfBp6RtDKoW / UXmjzkaPNefg8j2Jj9UWXmgN4z7gnT0 N1IuTRZ5yle4Avdzi + HWK + / 0md + eNmsLwx TsT8z8zHyMvGDOzlbujnag // cmcyOtq11c8aNDCK5Ugb1 / hvsmw5ps7GOl1dphycHs5fNS7EM26prjzJ / HTZ + rJ6tnLrnZC / 74ePczadhX0 / LZp4VWY59OcB4IdmXqALaf + JPNUAj2dUQBvql3KbhqKx6ceMZVNnjGWT1qeY / jZ00Z / xTMP2bbzkBPEudLA6ksaHfxVvf02HbaV3wfy2JJn + MeyvP + K5C8D3m5NMfRb3rfaYH + k + l / yseRXGuAT 3XSHvI5tXjPk2Rz8Yi / kwl3GtiGyrxl6wff6FPr8oHK91v23D2dAX4 / NDhW1Itxvbq8DPB / jwixM9bNodBT6Yg / EO5OHoRD7t6dgr / fnekSvNBM + RYvw6fHt1n0Iakk9GMXurL / e5uz3onpYbQeMr2vvbyrd5uTgtrbXn + xJgvJeUcbGPQuiAr5IF7VoHYF4Dg2M0jSTXBvHd / NaZoDiFscuWC6Ycz / LFGN8MXA / ityXyO30bZwmsQevJ2O8j / HM3Tlh3oI / BlcWtyJ43 + uT7UFdCXn5ox418oDwlec28OYQtQDo / xF4XebkWjCdj10kkOGu8VGON + 4I3t + WfYS7P047sZv3X0j / M3pm / t1oQ9LflnwIby / g95kA0acuPIzEUdDrdzn9UIo8z0pcjWzmsHWCcgfFcX2J8akNSxsx8oA5Bvydx4Tu7Pvd59PEkxvspZy3naywN3m7dCv7ejPGbEawR2ZLTi / oZxlnDZMgJkmMjbX1DvtNheb / WmMKlv / t3XJuSrvI2vQJy7gKN6eR7ebQhmGtBgwcwH / CtiAGG3Ldh0KhpgbVd5C8KOVkEfW7p + fPGQaDbqTaPusgTiq1YS6LNkxnvS1uJ9q1ym3ctnToTzx4V0s7IYWR7X6OxK + Z3anvfWdnIhV1Idp2i2nQfHPwsYY + XQg / y 8buF039 + 0EdoMhaV4w1ar2uwt6bl + b4joHbDM36bfy7VNLa9jL09H3SdmV8f62aNKX / F5zvK H0ua6g5IbiX9 + yBZKPiyWBaEhKihXBD + XtE2QIZnn0OfOzEmj1qXzFSs3zUdEDMjWkWZ24AMURt59PmSMIDOJx9O6CGv / TKssO6oBTaigfFSjILNDh7zCOJb2FBsZlHbIBscMsu4qjAm7WVvks3LniiKoUIO6W / lbUJXvIXf3uC79TDZQtZk7 / h0tWEZLvy9PskSkJ + Jh2HvPIbx4uq + RmPTntbY2tUayxyF9XlX0kLUKOX2Nvxz6yJc2DeZE7EmvfIy2lwhbbrmp3DvX / D90iSzYAfp6xwxIuhoYfdh3T7ulmLKLLTVvW2THIxL0McrnE2cN5a1cFxDxrI + 08ey759MsSOvSrF + A1OCD4WtSfo0rGz9hks9c7h / e5oDa / G2Lwgq5KjgoWbZhnyg3XH7jsS3oDOrTFdZgxw1EPAnjH7h47sm / Avj0 / Y6nGpjjOv89YJxkFx74g / rStgW4zThPwqb3PZvyRYQ ​​+ ykn20h3UezGpz6 / ZJyA / slugX2jki15LN + 9jk60wjfIwm + opA6QbBi23Z + X / KCei / 23gbMJy6DPj9Rk7p3WPoFxXxfen6Z8p + BPoiPuV8gf / yI8v6p4dsPlcm1EnsNhEyqQH8p4 / Das0EYlH5T0soW92jJQkzbWljEiZiTqPF3Gnk3j + 39wUZ / GJsJ3 / B7 / P1zOWe2LZ9 + ej40akEGkW9iupOv6GZANxjP + sW2KW6rw + dkS2Y7sXWNT0bgg4422wu + Mn0OWLi3y36B3lCMwzy2gVXeMays + H4R // 8iOk9l7lmL + nrLiJsyR4s + P + Iy7aO9TvaTwN5w8Rr4 / aJ9QME7Ib2sSrpVcxDTYH3D9yvaN34QuwHibbsD6XSBjOSq + Ux5Fnzm + xzq0jJO5cZXiTI9hTX + J / iBLlc + 4jNGvt + XJpfjtfFmjri9Ae / hz1ufyHr91MJs5S3 + sse7Pgld + gX0HW8wgfgI9s / BxzPu5sAmdvkbD0WjDg2UX5S0S + 2A9IK / 3651i Iwal2IT78JxzMKdN6LeFs22fYX / TJ / 5ecPQFHaAO8K + Nng39p8ImNsGzZj / 015WLOAjRxNhfxhUaxqDf2fgNulZZhd9hY1ivc + HbsQ / QRQ + 7 / BGgfTYP + ncVnrPa234ScWdHrfMiPItkNbsBazTX5g / 7zID6DL77BD45fNmh92oiLpLokWKH9kyxlgupzsKO6Tn4rAV + TBb6Wx0bTa5jb4A1GHvgXtBrVZ5elD8OistRTkbEzmZUl84UAyYbTVngbc9SnZdCtnkFdX1U6yLyRBMD9m0ftCPbJODcHcVGhV1eho2gfC5jweXaU43TNVlnEXDesGpYxvN6drytZwPyM + pwO14dkDc3P + TC34kyhk + 1kyLvDTmpv4PxbgB / fUm2mXxGGvaguQKyGvrWSuZlkrEQ93UpLZ / ihyx0YgOHfBuKPfA1l / mQsHX + k3HfTFzQJ41vQk6 + XVrswhVe + sABw + LijEu1c / ICdyVlLqKMOnfrP1jjRzSRpzA + 8e5Dgc2oTnD4i21jAvep2sBZE / pW4ds2L9TYbOg38x061wl9e70mfEvqr61NE3tf1CDWE0LwRcWAjSXORDvWJTMJe3AO6KqXsC + qBOtJ2Fs97HO7FcZwd / Cj + 4h9hcvK8V5S + DND18FWvhYyfwz5jnL / ZWAbmWTv5WL7F0m7K8qYPNValnPmRvhOcyLm8anBtarWG3bdWEC8vntaY4m + WLvvku31FPlhAbEaNyxaAD79U2VyUf0dF7kyMcfiOcDPMkLUzkUOet5jZT53Cvj1tnC2u / B3Ovr80vakjAV67FeRD / TaP3RPB9URUHyFf FFnzWcxWg9MgQc0lrlDY9vWaOzygSk26qgUa4Wvag6A / n8VY3fUATGKITnz31SnAfnBXnZ5RiXxQzdaboVsfBrzuU / GA8z + mqwndmlLdST6Jv + zAxQjJ5 + 4VDlrLQddMuh7scMXgm2qQ06oFJd9ycFzsKWF / 2nLA1qTxBl2 / QjFn0E / GqNo E5ADscjPyN3XySAbky0N9nuqBeNF8Ab8TLU7F7QnnzO9n50LyMnifljv4aB9z8IYhb4IvgDFtVSbF6gOkHyDWYVzI70s4oW5OjOKe1VaSxwh9FOohiVft2eMA00eLD1HquzEfbAvzfmFPEl + LsVwnXLXJN9 + RXS + SJC9 + 0PH3oIPpE5x8SVesnMAJ3Dv8 / 1uc30e + w1rSblD8W4Ar3WA / UcxXVFDGJE9VQzSr1mi / bjgfFCtgOSQyBfcHa1NRXJh1KAUW / 6Kxhou0dhJQ1Iy / nmxw6bsBNA7JJbPxXwvzNv8 + i7w0HHwc5fh + zcxvtW23O7dPmaUOUjWtivYX ​​+ qxmoiHUg2bONNZj2cfw2CqowbOBcpd9L4pLmuqHTCSnZBDPs + n1uEWHvgeihj + oPOLYWuWIsEWHvjuMzp31kD78psq5Ko7EcKHKYF / jeGQa4 / KXEnY97yJ + 2wfU / gNz9TOGU7rBY2NOj3F + p2RYme / Ax97oSbrK + eBR5Z1zN6mvJf + YuEZCFFLU4ENoc + C3 / A1L7lu0twMPZPqpBqpWgbldGGLCru9I + X7pqSM77rUwUaFpj6arDXzkmPQb8ZNPjquTnFg7xRTeqVE7YzhUfsQBehcVnHMkfRLhs54Jxy + AXxFytlMWEpnKBx2TG8X / yGELKD + ldWytkPkCTvIB6l5wAYzbsy / S5Tywgr5BfTeAkdtZLabXRcUUY1UtpWzxCBZy + CM9YvzpS45H / 0hLmu0XGKGon58e8fvP7ULaPC4d33Eb mTBVwei7SEydyj86Ffb62x1Yek6JweRO6mWzRcAqjvSH8d + erG9z + ELt7j7BvT1iZ0zc8TqyZ9TH / X3e1zHNj9Zc7mkGBECezHovZKegMwXccMw9lud6nfDeVbEicH2WZdSztXsSUhwz / dpVRPZD + xYVdD7JNqSsq7rLp8xU13s3NrwDWsRdG6q4pqZHIh3cFHdZ4FsqAY / Xcs9zxd1JuhcsMg5OM9jefC119ke5bXy6 + zCgPJPmW5a4RnXHXYNW1TA + mTn82jfCxcG9PcDyH4e3gm8QTKn2M6i3M / RkG9t8CmWyZiXsN8c8knUSt1Ze7y8N0DUH5R5ZqSusML ++ xt7SCyazqQYr / Hy63RcYK0riqnWGyZGkPMf7VIfRqin9yxXE2SLmp1vQ5cD8ovS52rMPFNjVgTn8mN0LoTsqpH3uO / poNxeZH5UB8D6MZfngMvV998G5BMTdl1gBfrGOoTLOqw9PDbZcIQm / uZIqPe3Ua6wjt6rGRpkY + 8NdnZnoMz30e2poPNzIl / RST + MBSFyV27IFMbYqR + j1T67sJci009jjbdo8t3ZPnk48e5RF79KvLOkBurFax3qlZxlNxbl / SBL0 / SuruMr08H1DuVvVa79ixEjRowYMWJUDeZHnFln188ZphgxYsSIESNGjBgxYsSIESNGjBgxooB473oF783vaDT11Vj2njJz7 jFixOhwiL / PuDE + Mxej5vF / owjA3A ==

Full code:

 <?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
source share
2 answers

I incremented one of the indices where I didn’t have to, $ counter ++ inside if ($ temp [1]> $ max_int) {// stuff} threw the index when a new maximum value was found.

The new code for int_array now looks like this (using the Sectus trick and 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); } 

Also apply the following syntax (if you do not want to use the Sectus trick):

 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]; } } } 

I would like to thank everyone who also broke their heads.

0
source

It is very difficult:

 $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++; } 

use this instead:

 $mz_array = array_values(unpack("f*", $unc_mz)); 
+1
source

All Articles