List of usage examples for com.google.common.io LittleEndianDataInputStream readDouble
@Override public double readDouble() throws IOException
From source file:xyz.kuori.timeseries.TimeSeries.java
public int load(File archive) { FileInputStream fin = null;/* w w w. j a v a 2 s . com*/ try { fin = new FileInputStream(archive); } catch (Exception e) { init(0); return (-1); } int record_count = (int) (archive.length() / 16); init(record_count); LittleEndianDataInputStream in = new LittleEndianDataInputStream(fin); try { for (int i = 0; i < record_count; i++) { timestamps[i] = in.readLong(); values[i] = in.readDouble(); } } catch (Exception e) { init(0); return (-1); } return (record_count); }
From source file:net.sf.mzmine.modules.rawdatamethods.rawdataimport.fileformats.XcaliburRawFileReadTask.java
/** * This method reads the dump of the RAW data file produced by RAWdump.exe * utility (see RAWdump.cpp source for details). *//*from ww w. j a va2 s .co m*/ private void readRAWDump(InputStream dumpStream) throws IOException { String line; while ((line = TextUtils.readLineFromStream(dumpStream)) != null) { if (isCanceled()) { return; } if (line.startsWith("ERROR: ")) { throw (new IOException(line.substring("ERROR: ".length()))); } if (line.startsWith("NUMBER OF SCANS: ")) { totalScans = Integer.parseInt(line.substring("NUMBER OF SCANS: ".length())); } if (line.startsWith("SCAN NUMBER: ")) { scanNumber = Integer.parseInt(line.substring("SCAN NUMBER: ".length())); } if (line.startsWith("SCAN FILTER: ")) { /* * A typical filter line for MS/MS scan looks like this: * * ITMS - c ESI d Full ms3 587.03@cid35.00 323.00@cid35.00 */ Pattern p = Pattern.compile("ms(\\d).* (\\d+\\.\\d+)@"); Matcher m = p.matcher(line); if (m.find()) { msLevel = Integer.parseInt(m.group(1)); // Initially we obtain precursor m/z from this filter line, // even though the precision is not good. Later more precise // precursor m/z may be reported using PRECURSOR: line, but // sometimes it is missing (equal to 0) precursorMZ = Double.parseDouble(m.group(2)); } else { msLevel = 1; } } if (line.startsWith("RETENTION TIME: ")) { // Retention time in the RAW file is reported in minutes. retentionTime = Double.parseDouble(line.substring("RETENTION TIME: ".length())); } if (line.startsWith("PRECURSOR: ")) { String tokens[] = line.split(" "); double token2 = Double.parseDouble(tokens[1]); int token3 = Integer.parseInt(tokens[2]); if (token2 > 0) { precursorMZ = token2; precursorCharge = token3; } } if (line.startsWith("DATA POINTS: ")) { int numOfDataPoints = Integer.parseInt(line.substring("DATA POINTS: ".length())); DataPoint completeDataPoints[] = new DataPoint[numOfDataPoints]; // Because Intel CPU is using little endian natively, we // need to use LittleEndianDataInputStream instead of normal // Java DataInputStream, which is big-endian. LittleEndianDataInputStream dis = new LittleEndianDataInputStream(dumpStream); for (int i = 0; i < numOfDataPoints; i++) { double mz = dis.readDouble(); double intensity = dis.readDouble(); completeDataPoints[i] = new SimpleDataPoint(mz, intensity); } dis.close(); boolean centroided = ScanUtils.isCentroided(completeDataPoints); DataPoint optimizedDataPoints[] = ScanUtils.removeZeroDataPoints(completeDataPoints, centroided); /* * If this scan is a full scan (ms level = 1), it means that the * previous scans stored in the stack, are complete and ready to * be written to the raw data file. */ if (msLevel == 1) { while (!parentStack.isEmpty()) { SimpleScan currentScan = parentStack.removeFirst(); newMZmineFile.addScan(currentScan); } } // Setting the current parentScan int parentScan = -1; if (msLevel > 1) { parentScan = parentTreeValue[msLevel - 1]; if (!parentStack.isEmpty()) { for (SimpleScan s : parentStack) { if (s.getScanNumber() == parentScan) { s.addFragmentScan(scanNumber); } } } } // Setting the parent scan number for this level of fragments parentTreeValue[msLevel] = scanNumber; SimpleScan newScan = new SimpleScan(null, scanNumber, msLevel, retentionTime, parentScan, precursorMZ, precursorCharge, null, optimizedDataPoints, centroided); parentStack.add(newScan); parsedScans++; // Clean the variables for next scan scanNumber = 0; msLevel = 0; retentionTime = 0; precursorMZ = 0; precursorCharge = 0; } } // Add remaining scans in the parentStack while (!parentStack.isEmpty()) { SimpleScan currentScan = parentStack.removeFirst(); newMZmineFile.addScan(currentScan); } }