Changeset 4520
- Timestamp:
- Sep 10, 2013, 4:45:18 PM (10 years ago)
- Location:
- trunk/api/core/src
- Files:
-
- 4 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/api/core/src/org/proteios/io/Base64Util.java
r4381 r4520 25 25 26 26 import org.proteios.core.Base64Coder; 27 import ms.numpress.MSNumpress; 27 28 import java.nio.ByteBuffer; 28 29 import java.nio.ByteOrder; … … 33 34 34 35 /** 35 * This class supports conversion to/from Base64-coded data. 36 * 37 * Used e.g. to encode the data (peak) part of mass spectra 38 * in an mzData file. 36 * This class supports conversion to/from Base64-coded data. Used e.g. to encode 37 * the data (peak) part of mass spectra in an mzData file. 39 38 * 40 39 * @author Olle … … 44 43 public class Base64Util 45 44 { 45 46 46 private static final org.apache.log4j.Logger log = org.apache.log4j.LogManager 47 47 .getLogger("org.proteios.io"); 48 48 49 /** 50 * Decodes Base64 coded data String 51 * and returns a String 52 * containing the extracted data. 53 * 54 * Uses class org.proteios.core.Base64Coder to decode data. 55 * 49 50 /** 51 * Decodes Base64 coded data String and returns a String containing the 52 * extracted data. Uses class org.proteios.core.Base64Coder to decode data. 53 * 56 54 * @param dataString String A string with Base64 coded data. 57 55 * @return String A string with decoded data. … … 69 67 70 68 /** 71 * Decodes Base64 coded data String 72 * and returns an ArrayList<double> 73 * containing the extracted data. 74 * 75 * Uses class org.proteios.core.Base64Coder to decode data. 76 * 69 * Decodes Base64 coded data String and returns an ArrayList<double> 70 * containing the extracted data. Uses class org.proteios.core.Base64Coder 71 * to decode data. 72 * 77 73 * @param doublePrecision boolean flag, true if precision == "64". 78 74 * @param bigEndian boolean flag indicating endian type. … … 80 76 * @return ArrayList<double> with extracted values. 81 77 */ 82 public static List<Double> decode(boolean doublePrecision, boolean bigEndian, String dataString) 78 public static List<Double> decode(boolean doublePrecision, 79 boolean bigEndian, String numpress, String dataString) 83 80 { 84 81 /* … … 86 83 */ 87 84 boolean zLibCompression = false; 88 List<Double> resultArray = decode(doublePrecision, bigEndian, zLibCompression, dataString); 85 List<Double> resultArray = decode(doublePrecision, bigEndian, 86 zLibCompression, numpress, dataString); 89 87 /* 90 88 * Return result as list … … 95 93 96 94 /** 97 * Decodes Base64 coded data String 98 * and returns an ArrayList<double> 99 * containing the extracted data. 100 * 101 * Uses class org.proteios.core.Base64Coder to decode data. 102 * 95 * Decodes Base64 coded data String and returns an ArrayList<double> 96 * containing the extracted data. Uses class org.proteios.core.Base64Coder 97 * to decode data. 98 * 103 99 * @param doublePrecision boolean flag, true if precision == "64". 104 100 * @param bigEndian boolean flag indicating endian type. … … 107 103 * @return ArrayList<double> with extracted values. 108 104 */ 109 public static List<Double> decode(boolean doublePrecision, boolean bigEndian, boolean zLibCompression, String dataString) 105 public static List<Double> decode(boolean doublePrecision, 106 boolean bigEndian, boolean zLibCompression, String numpress, 107 String dataString) 110 108 { 111 109 /* … … 118 116 Inflater decompresser = new Inflater(); 119 117 decompresser.setInput(dataByteArray, 0, dataByteArray.length); 120 byte[] uncompressedByteArray = new byte[3 *dataByteArray.length];118 byte[] uncompressedByteArray = new byte[3 * dataByteArray.length]; 121 119 int uncompressedArrayLength = 0; 122 120 try 123 121 { 124 uncompressedArrayLength = decompresser.inflate(uncompressedByteArray); 122 uncompressedArrayLength = decompresser 123 .inflate(uncompressedByteArray); 125 124 } 126 125 catch (DataFormatException e) … … 131 130 // Use uncompressed byte array 132 131 dataByteArray = new byte[uncompressedArrayLength]; 133 for (int i =0; i < uncompressedArrayLength; i++)132 for (int i = 0; i < uncompressedArrayLength; i++) 134 133 { 135 134 dataByteArray[i] = uncompressedByteArray[i]; 136 135 } 137 136 } 138 ByteBuffer dataByteBuffer = ByteBuffer.wrap(dataByteArray);139 /*140 * Get size of result list from141 * byte array size and precision.142 */143 int arraySize = dataByteArray.length;144 int bytesPerValue = 4;145 if (doublePrecision) {146 /*147 * Precision == "64"148 */149 bytesPerValue = 8;150 }151 int dataLength = arraySize/bytesPerValue;152 137 /* 153 138 * Create result arrayList 154 139 */ 155 140 List<Double> resultArray = new ArrayList<Double>(1); 156 /* 157 * Java works with big endian by default. 158 * If the data is little endian, the 159 * byte order is changed. 160 * 161 * This configuration influences how data 162 * is retrieved using methods like 163 * getFloat() and getDouble(), 164 */ 165 if (!bigEndian) { 166 dataByteBuffer.order(ByteOrder.LITTLE_ENDIAN); 167 } 168 /* 169 * Put the data into the result list 170 */ 171 if (!doublePrecision) { 172 /* 173 * Precision == "32" 174 */ 175 for (int i = 0; i < dataLength; i++) { 176 float value = dataByteBuffer.getFloat(); 177 resultArray.add(i, new Float(value).doubleValue()); 178 } 179 } else { 180 /* 181 * Precision == "64" 182 */ 183 for (int i = 0; i < dataLength; i++) { 184 double value = dataByteBuffer.getDouble(); 185 resultArray.add(i, value); 141 if (numpress != null) 142 { 143 int length = dataByteArray.length; 144 log.debug("Numpress decompression:"+numpress+". Array length:"+length); 145 double[] result = MSNumpress.decode(numpress, dataByteArray, length); 146 for (int i=0;i<result.length;i++) 147 { 148 resultArray.add(result[i]); 149 } 150 } 151 else 152 { 153 ByteBuffer dataByteBuffer = ByteBuffer.wrap(dataByteArray); 154 /* 155 * Get size of result list from byte array size and precision. 156 */ 157 int arraySize = dataByteArray.length; 158 int bytesPerValue = 4; 159 if (doublePrecision) 160 { 161 /* 162 * Precision == "64" 163 */ 164 bytesPerValue = 8; 165 } 166 int dataLength = arraySize / bytesPerValue; 167 /* 168 * Java works with big endian by default. If the data is little 169 * endian, the byte order is changed. This configuration influences 170 * how data is retrieved using methods like getFloat() and 171 * getDouble(), 172 */ 173 if (!bigEndian) 174 { 175 dataByteBuffer.order(ByteOrder.LITTLE_ENDIAN); 176 } 177 /* 178 * Put the data into the result list 179 */ 180 if (!doublePrecision) 181 { 182 /* 183 * Precision == "32" 184 */ 185 for (int i = 0; i < dataLength; i++) 186 { 187 float value = dataByteBuffer.getFloat(); 188 resultArray.add(i, new Float(value).doubleValue()); 189 } 190 } 191 else 192 { 193 /* 194 * Precision == "64" 195 */ 196 for (int i = 0; i < dataLength; i++) 197 { 198 double value = dataByteBuffer.getDouble(); 199 resultArray.add(i, value); 200 } 186 201 } 187 202 } … … 194 209 195 210 /** 196 * Encodes Base64 coded data String 197 * and returns a String 198 * containing the encoded data. 199 * 200 * Uses class org.proteios.core.Base64Coder to encode data. 201 * 211 * Encodes Base64 coded data String and returns a String containing the 212 * encoded data. Uses class org.proteios.core.Base64Coder to encode data. 213 * 202 214 * @param dataString String A string with data to be Base64 encoded. 203 215 * @return String A string with encoded data. … … 215 227 216 228 /** 217 * Encodes Base64 coded data list<double> 218 * and returns a <String> 219 * containing the encoded data. 220 * 221 * Uses class org.proteios.core.Base64Coder to encode data. 222 * 229 * Encodes Base64 coded data list<double> and returns a <String> containing 230 * the encoded data. Uses class org.proteios.core.Base64Coder to encode 231 * data. 232 * 223 233 * @param doublePrecision boolean flag, true if precision == "64". 224 234 * @param bigEndian boolean flag indicating endian type. … … 226 236 * @return <String> with encoded values. 227 237 */ 228 public static String encode(boolean doublePrecision, boolean bigEndian, List<? extends Number> inDataList)229 {230 /*231 * Get size of byte array from232 * input list size and precision.238 public static String encode(boolean doublePrecision, boolean bigEndian, 239 List<? extends Number> inDataList) 240 { 241 /* 242 * Get size of byte array from input list size and precision. 233 243 */ 234 244 int dataLength = inDataList.size(); 235 245 int bytesPerValue = 4; 236 if (doublePrecision) { 246 if (doublePrecision) 247 { 237 248 /* 238 249 * Precision == "64" … … 240 251 bytesPerValue = 8; 241 252 } 242 int arraySize = bytesPerValue *dataLength;253 int arraySize = bytesPerValue * dataLength; 243 254 /* 244 255 * Create dataByteBuffer ByteBuffer … … 247 258 ByteBuffer dataByteBuffer = ByteBuffer.wrap(dataByteArray); 248 259 /* 249 * Java works with big endian by default. 250 * If the data is little endian, the 251 * byte order is changed. 252 * 253 * Note! This configuration must be set before 254 * the ByteBuffer is loaded with data using 255 * methods like putFloat() and putDouble(), 256 * as it influences how the data will be stored. 257 */ 258 if (!bigEndian) { 260 * Java works with big endian by default. If the data is little endian, 261 * the byte order is changed. Note! This configuration must be set 262 * before the ByteBuffer is loaded with data using methods like 263 * putFloat() and putDouble(), as it influences how the data will be 264 * stored. 265 */ 266 if (!bigEndian) 267 { 259 268 dataByteBuffer.order(ByteOrder.LITTLE_ENDIAN); 260 269 } … … 262 271 * Put the data into the byte buffer 263 272 */ 264 if (!doublePrecision) { 273 if (!doublePrecision) 274 { 265 275 /* 266 276 * Precision == "32" 267 277 */ 268 for (int i = 0; i < dataLength; i++) { 278 for (int i = 0; i < dataLength; i++) 279 { 269 280 if (inDataList.get(i) instanceof Double) 270 281 { 271 Double doubleVal = (Double) inDataList.get(i);282 Double doubleVal = (Double) inDataList.get(i); 272 283 dataByteBuffer.putFloat(doubleVal.floatValue()); 273 284 } 274 285 else if (inDataList.get(i) instanceof Integer) 275 286 { 276 Integer intVal = (Integer) inDataList.get(i);287 Integer intVal = (Integer) inDataList.get(i); 277 288 dataByteBuffer.putInt(intVal.intValue()); 278 289 } 279 290 } 280 } else { 291 } 292 else 293 { 281 294 /* 282 295 * Precision == "64" 283 296 */ 284 for (int i = 0; i < dataLength; i++) { 285 Double doubleVal = (Double)inDataList.get(i); 297 for (int i = 0; i < dataLength; i++) 298 { 299 Double doubleVal = (Double) inDataList.get(i); 286 300 dataByteBuffer.putDouble(doubleVal.doubleValue()); 287 301 } -
trunk/api/core/src/org/proteios/io/MzMLFileReader.java
r4304 r4520 28 28 package org.proteios.io; 29 29 30 import ms.numpress.MSNumpress; 30 31 import org.proteios.core.InvalidDataException; 31 32 import org.xml.sax.SAXException; … … 79 80 private final String ACC_CHARGE_STATE = "MS:1000041"; 80 81 private final String ACC_INTENSITY = "MS:1000042"; 82 81 83 private final HashMap<String, String> accInstrumentModelHashMap = new HashMap<String, String>(); 82 84 /* … … 98 100 private String precision = new String(""); 99 101 private String compression = new String(""); 102 private String numpress = null; 100 103 private String endian = new String(""); 101 104 private int dataLength = 0; … … 1205 1208 getSpectrumInstrumentData() 1206 1209 .setInstrumentSerialNo(instrumentSerialNo); 1207 log 1208 .debug("instrumentSerialNo: \"" + instrumentSerialNo + "\""); 1210 log.debug("instrumentSerialNo: \"" + instrumentSerialNo + "\""); 1209 1211 } 1210 1212 // Check if instrument model set in referenceable … … 1220 1222 getSpectrumInstrumentData().getAdditional() 1221 1223 .add(stringPair); 1222 log 1223 .debug("instrumentModel: \"" + instrumentModelStr + "\""); 1224 log.debug("instrumentModel: \"" + instrumentModelStr + "\""); 1224 1225 } 1225 1226 } … … 1255 1256 { 1256 1257 inIntensityTargetBinaryDataArrayBlock = true; 1257 log 1258 .debug("intensity binaryDataArray block found"); 1258 log.debug("intensity binaryDataArray block found"); 1259 1259 } 1260 1260 /* … … 1269 1269 { 1270 1270 setCompression(compression); 1271 log 1272 .debug("compression: \"" + compression + "\""); 1271 log.debug("compression: \"" + compression + "\""); 1273 1272 } 1274 1273 } … … 1322 1321 SpectrumImpl currentSpectrum = new SpectrumImpl(); 1323 1322 setSpectrum(currentSpectrum); 1324 log 1325 .debug("SpectrumId (" + spectrumIndex + ") = \"" + getCurrentSpectrumId() + "\" found."); 1323 log.debug("SpectrumId (" + spectrumIndex + ") = \"" + getCurrentSpectrumId() + "\" found."); 1326 1324 } 1327 1325 } … … 1492 1490 { 1493 1491 // Add analyzer data to last list entry 1494 analyzerList.get(listSize - 1).getAnalyzer() .add(1495 stringPair);1492 analyzerList.get(listSize - 1).getAnalyzer() 1493 .add(stringPair); 1496 1494 } 1497 1495 } … … 1592 1590 compression = new String("zlib"); 1593 1591 } 1592 else if (currentCvParamAccessionStr 1593 .equals(MSNumpress.ACC_NUMPRESS_LINEAR) || currentCvParamAccessionStr 1594 .equals(MSNumpress.ACC_NUMPRESS_SLOF) || currentCvParamAccessionStr 1595 .equals(MSNumpress.ACC_NUMPRESS_PIC)) 1596 { 1597 numpress = currentCvParamAccessionStr; 1598 log.debug ("Numpress compression detected:"+numpress); 1599 } 1600 1594 1601 else if (currentCvParamAccessionStr.equals(ACC_MZ_ARRAY)) 1595 1602 { … … 1681 1688 .getRetentionTimeInMinutes() == null) 1682 1689 { 1683 log 1684 .debug("Accession value when looking for scan time = \"" + currentCvParamAccessionStr + "\""); 1690 log.debug("Accession value when looking for scan time = \"" + currentCvParamAccessionStr + "\""); 1685 1691 cvParamProcessed = true; 1686 1692 // Check unit … … 1688 1694 String currentCvParamUnitAccessionStr = XMLImportUtil 1689 1695 .seekAttribute("unitAccession", parser); 1690 log 1691 .debug("currentCvParamUnitAccessionStr = \"" + currentCvParamUnitAccessionStr + "\""); 1696 log.debug("currentCvParamUnitAccessionStr = \"" + currentCvParamUnitAccessionStr + "\""); 1692 1697 if (currentCvParamUnitAccessionStr != null) 1693 1698 { … … 1717 1722 retentionTimeStr = XMLImportUtil.seekAttribute("value", 1718 1723 parser); 1719 log 1720 .debug("retentionTimeStr =\"" + retentionTimeStr + "\""); 1724 log.debug("retentionTimeStr =\"" + retentionTimeStr + "\""); 1721 1725 if (retentionTimeStr != null && !retentionTimeStr 1722 1726 .equals("")) … … 1737 1741 getSpectrum().setRetentionTimeInMinutes( 1738 1742 retentionTime); 1739 log 1740 .debug("cvParam block with retentionTimeInMinutes found, time = " + retentionTime); 1743 log.debug("cvParam block with retentionTimeInMinutes found, time = " + retentionTime); 1741 1744 } 1742 1745 } … … 1745 1748 .equals(ACC_SELECTED_MASS_TO_CHARGE_RATIO)) 1746 1749 { 1747 log 1748 .debug("Accession value when looking for precursor m/z = \"" + currentCvParamAccessionStr + "\""); 1750 log.debug("Accession value when looking for precursor m/z = \"" + currentCvParamAccessionStr + "\""); 1749 1751 cvParamProcessed = true; 1750 1752 if (inTargetPrecursorBlock) … … 1763 1765 .equals(ACC_CHARGE_STATE)) 1764 1766 { 1765 log 1766 .debug("Accession value when looking for precursor charge state = \"" + currentCvParamAccessionStr + "\""); 1767 log.debug("Accession value when looking for precursor charge state = \"" + currentCvParamAccessionStr + "\""); 1767 1768 cvParamProcessed = true; 1768 1769 if (inTargetPrecursorBlock) … … 1780 1781 else if (currentCvParamAccessionStr.equals(ACC_INTENSITY)) 1781 1782 { 1782 log 1783 .debug("Accession value when looking for precursor intensity = \"" + currentCvParamAccessionStr + "\""); 1783 log.debug("Accession value when looking for precursor intensity = \"" + currentCvParamAccessionStr + "\""); 1784 1784 cvParamProcessed = true; 1785 1785 if (inTargetPrecursorBlock) … … 1792 1792 Double.valueOf(intensity)); 1793 1793 } 1794 log 1795 .debug("precursor intensity =\"" + intensity + "\""); 1794 log.debug("precursor intensity =\"" + intensity + "\""); 1796 1795 } 1797 1796 } … … 1872 1871 { 1873 1872 // Add analyzer data to last list entry 1874 analyzerList.get(listSize - 1).getAnalyzer() .add(1875 stringPair);1873 analyzerList.get(listSize - 1).getAnalyzer() 1874 .add(stringPair); 1876 1875 } 1877 1876 } … … 1913 1912 setEndian("little"); 1914 1913 setDataLength(dataLength); 1914 numpress = null; 1915 1915 log.debug("dataLength: " + dataLength); 1916 log 1917 .debug("endian: \"" + endian + "\" dataLength: " + dataLength); 1916 log.debug("endian: \"" + endian + "\" dataLength: " + dataLength); 1918 1917 } 1919 1918 } … … 1925 1924 log.debug("binary block found"); 1926 1925 1927 log 1928 .debug("precision: \"" + precision + "\" endian: \"" + endian + "\" dataLength: " + dataLength); 1926 log.debug("precision: \"" + precision + "\" endian: \"" + endian + "\" dataLength: " + dataLength); 1929 1927 } 1930 1928 } … … 2028 2026 spectrumArray[i] = getSpectrum(); 2029 2027 spectrumTagsFound++; 2030 log 2031 .debug("SpectrumId (" + i + ") = \"" + getCurrentSpectrumId() + "\" processed, spectrumTagsFound = " + spectrumTagsFound); 2032 log 2033 .debug("-----------------------------------------------"); 2028 log.debug("SpectrumId (" + i + ") = \"" + getCurrentSpectrumId() + "\" processed, spectrumTagsFound = " + spectrumTagsFound); 2029 log.debug("-----------------------------------------------"); 2034 2030 } 2035 2031 } … … 2079 2075 */ 2080 2076 decodedBase64List = dataItem(doublePrecision, bigEndian, 2081 zLibCompression, dataBase64);2077 zLibCompression, numpress, dataBase64); 2082 2078 2083 2079 /* … … 2154 2150 */ 2155 2151 private List<Double> dataItem(boolean doublePrecision, boolean bigEndian, 2156 boolean zLibCompression, String dataBase64Raw)2152 boolean zLibCompression, String numpress, String dataBase64Raw) 2157 2153 { 2158 2154 /* … … 2197 2193 } 2198 2194 String dataBase64 = dataBase64StrBuf.toString(); 2199 log 2200 .debug("nLines = " + nLines + " lineLength = " + lineLength + " nChars = " + nChars + " dataBase64Raw.length() = " + dataBase64Raw 2201 .length()); 2195 log.debug("nLines = " + nLines + " lineLength = " + lineLength + " nChars = " + nChars + " dataBase64Raw.length() = " + dataBase64Raw 2196 .length()); 2202 2197 2203 2198 /* … … 2211 2206 { 2212 2207 decodedBase64 = Base64Util.decode(doublePrecision, bigEndian, 2213 zLibCompression, dataBase64);2208 zLibCompression, numpress, dataBase64); 2214 2209 } 2215 2210 } … … 2264 2259 List<SpectrumInterface> spectrumList = new ArrayList<SpectrumInterface>(); 2265 2260 spectrumList = fetchSpectrum(spectrumIds); 2266 log 2267 .debug("spectrumIds.size() = " + spectrumIds.size() + ", spectrumList.size() = " + spectrumList 2268 .size()); 2261 log.debug("spectrumIds.size() = " + spectrumIds.size() + ", spectrumList.size() = " + spectrumList 2262 .size()); 2269 2263 2270 2264 /* -
trunk/api/core/src/org/proteios/io/PeakListFileImpl.java
r3274 r4520 1540 1540 if (dataBase64.length() > 0) 1541 1541 { 1542 decodedBase64 = Base64Util.decode(doublePrecision, bigEndian, 1542 decodedBase64 = Base64Util.decode(doublePrecision, bigEndian, null, 1543 1543 dataBase64); 1544 1544 } -
trunk/api/core/src/org/proteios/io/mzdata/MzDataImpDataBlock.java
r3207 r4520 345 345 if (dataBase64 != null) { 346 346 if (dataBase64.length() > 0) { 347 decodedBase64 = Base64Util.decode(doublePrecision, bigEndian, dataBase64);347 decodedBase64 = Base64Util.decode(doublePrecision, bigEndian, null, dataBase64); 348 348 } 349 349 }
Note: See TracChangeset
for help on using the changeset viewer.