use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.
the class PeakListOpenHandler_2_0 method endElement.
/**
* @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
* java.lang.String)
*/
@Override
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
if (canceled)
throw new SAXException("Parsing canceled");
// <NAME>
if (qName.equals(PeakListElementName_2_0.PEAKLIST_NAME.getElementName())) {
name = getTextOfElement();
logger.info("Loading feature list: " + name);
peakListName = name;
}
// <PEAKLIST_DATE>
if (qName.equals(PeakListElementName_2_0.PEAKLIST_DATE.getElementName())) {
dateCreated = getTextOfElement();
}
// <QUANTITY>
if (qName.equals(PeakListElementName_2_0.QUANTITY.getElementName())) {
String text = getTextOfElement();
totalRows = Integer.parseInt(text);
}
// <RAW_FILE>
if (qName.equals(PeakListElementName_2_0.RAWFILE.getElementName())) {
rawDataFileID = getTextOfElement();
RawDataFile dataFile = dataFilesIDMap.get(rawDataFileID);
if (dataFile == null) {
throw new SAXException("Cannot open feature list, because raw data file " + rawDataFileID + " is missing.");
}
currentPeakListDataFiles.add(dataFile);
}
// <SCAN_ID>
if (qName.equals(PeakListElementName_2_0.SCAN_ID.getElementName())) {
byte[] bytes = Base64.decodeToBytes(getTextOfElement());
// make a data input stream
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
scanNumbers = new int[numOfMZpeaks];
for (int i = 0; i < numOfMZpeaks; i++) {
try {
scanNumbers[i] = dataInputStream.readInt();
} catch (IOException ex) {
throw new SAXException(ex);
}
}
}
// <REPRESENTATIVE_SCAN>
if (qName.equals(PeakListElementName_2_0.REPRESENTATIVE_SCAN.getElementName())) {
representativeScan = Integer.valueOf(getTextOfElement());
}
if (qName.equals(PeakListElementName_2_0.FRAGMENT_SCAN.getElementName())) {
fragmentScan = Integer.valueOf(getTextOfElement());
}
// <All_MS2_FRAGMENT_SCANS>
if (qName.equals(PeakListElementName_2_5.ALL_MS2_FRAGMENT_SCANS.getElementName())) {
Integer fragmentNumber = Integer.valueOf(getTextOfElement());
currentAllMS2FragmentScans.add(fragmentNumber);
}
// <MASS>
if (qName.equals(PeakListElementName_2_0.MZ.getElementName())) {
byte[] bytes = Base64.decodeToBytes(getTextOfElement());
// make a data input stream
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
masses = new double[numOfMZpeaks];
for (int i = 0; i < numOfMZpeaks; i++) {
try {
masses[i] = dataInputStream.readFloat();
} catch (IOException ex) {
throw new SAXException(ex);
}
}
}
// <HEIGHT>
if (qName.equals(PeakListElementName_2_0.HEIGHT.getElementName())) {
byte[] bytes = Base64.decodeToBytes(getTextOfElement());
// make a data input stream
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
intensities = new double[numOfMZpeaks];
for (int i = 0; i < numOfMZpeaks; i++) {
try {
intensities[i] = dataInputStream.readFloat();
} catch (IOException ex) {
throw new SAXException(ex);
}
}
}
// <PEAK>
if (qName.equals(PeakListElementName_2_0.PEAK.getElementName())) {
DataPoint[] mzPeaks = new DataPoint[numOfMZpeaks];
Range<Double> peakRTRange = null, peakMZRange = null, peakIntensityRange = null;
RawDataFile dataFile = dataFilesIDMap.get(peakColumnID);
if (dataFile == null)
throw new SAXException("Error in project: data file " + peakColumnID + " not found");
for (int i = 0; i < numOfMZpeaks; i++) {
Scan sc = dataFile.getScan(scanNumbers[i]);
double retentionTime = sc.getRetentionTime();
double mz = masses[i];
double intensity = intensities[i];
if ((peakRTRange == null) || (peakIntensityRange == null)) {
peakRTRange = Range.singleton(retentionTime);
peakIntensityRange = Range.singleton(intensity);
} else {
peakRTRange = peakRTRange.span(Range.singleton(retentionTime));
peakIntensityRange = peakIntensityRange.span(Range.singleton(intensity));
}
if (mz > 0.0) {
mzPeaks[i] = new SimpleDataPoint(mz, intensity);
if (peakMZRange == null)
peakMZRange = Range.singleton(mz);
else
peakMZRange = peakMZRange.span(Range.singleton(mz));
}
}
FeatureStatus status = FeatureStatus.valueOf(peakStatus);
// convert vector of allMS2FragmentScans to array
allMS2FragmentScanNumbers = new int[currentAllMS2FragmentScans.size()];
for (int i = 0; i < allMS2FragmentScanNumbers.length; i++) {
allMS2FragmentScanNumbers[i] = currentAllMS2FragmentScans.get(i);
}
// clear all MS2 fragment scan numbers list for next peak
currentAllMS2FragmentScans.clear();
SimpleFeature peak = new SimpleFeature(dataFile, mass, rt, height, area, scanNumbers, mzPeaks, status, representativeScan, fragmentScan, allMS2FragmentScanNumbers, peakRTRange, peakMZRange, peakIntensityRange);
peak.setCharge(currentPeakCharge);
if (currentIsotopes.size() > 0) {
SimpleIsotopePattern newPattern = new SimpleIsotopePattern(currentIsotopes.toArray(new DataPoint[0]), currentIsotopePatternStatus, currentIsotopePatternDescription);
peak.setIsotopePattern(newPattern);
currentIsotopes.clear();
}
buildingRow.addPeak(dataFile, peak);
}
// <IDENTITY_PROPERTY>
if (qName.equals(PeakListElementName_2_0.IDPROPERTY.getElementName())) {
identityProperties.put(identityPropertyName, getTextOfElement());
}
// <PEAK_IDENTITY>
if (qName.equals(PeakListElementName_2_0.PEAK_IDENTITY.getElementName())) {
String content = getTextOfElement();
if (identityProperties.get(PeakIdentity.PROPERTY_NAME) == null)
identityProperties.put(PeakIdentity.PROPERTY_NAME, content);
SimplePeakIdentity identity = new SimplePeakIdentity(identityProperties);
buildingRow.addPeakIdentity(identity, preferred);
}
// <ROW>
if (qName.equals(PeakListElementName_2_0.ROW.getElementName())) {
buildingPeakList.addRow(buildingRow);
buildingRow = null;
parsedRows++;
}
// <ISOTOPE>
if (qName.equals(PeakListElementName_2_0.ISOTOPE.getElementName())) {
String text = getTextOfElement();
String[] items = text.split(":");
double mz = Double.valueOf(items[0]);
double intensity = Double.valueOf(items[1]);
DataPoint isotope = new SimpleDataPoint(mz, intensity);
currentIsotopes.add(isotope);
}
if (qName.equals(PeakListElementName_2_0.METHOD_NAME.getElementName())) {
String appliedMethod = getTextOfElement();
appliedMethods.add(appliedMethod);
}
if (qName.equals(PeakListElementName_2_0.METHOD_PARAMETERS.getElementName())) {
String appliedMethodParam = getTextOfElement();
appliedMethodParameters.add(appliedMethodParam);
}
}
use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.
the class PeakListOpenHandler_2_3 method endElement.
/**
* @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
* java.lang.String)
*/
@Override
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
if (canceled)
throw new SAXException("Parsing canceled");
// <NAME>
if (qName.equals(PeakListElementName_2_3.PEAKLIST_NAME.getElementName())) {
name = getTextOfElement();
logger.info("Loading feature list: " + name);
peakListName = name;
}
// <PEAKLIST_DATE>
if (qName.equals(PeakListElementName_2_3.PEAKLIST_DATE.getElementName())) {
dateCreated = getTextOfElement();
}
// <QUANTITY>
if (qName.equals(PeakListElementName_2_3.QUANTITY.getElementName())) {
String text = getTextOfElement();
totalRows = Integer.parseInt(text);
}
// <RAW_FILE>
if (qName.equals(PeakListElementName_2_3.RAWFILE.getElementName())) {
rawDataFileID = getTextOfElement();
RawDataFile dataFile = dataFilesIDMap.get(rawDataFileID);
if (dataFile == null) {
throw new SAXException("Cannot open feature list, because raw data file " + rawDataFileID + " is missing.");
}
currentPeakListDataFiles.add(dataFile);
}
// <SCAN_ID>
if (qName.equals(PeakListElementName_2_3.SCAN_ID.getElementName())) {
byte[] bytes = Base64.decodeToBytes(getTextOfElement());
// make a data input stream
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
scanNumbers = new int[numOfMZpeaks];
for (int i = 0; i < numOfMZpeaks; i++) {
try {
scanNumbers[i] = dataInputStream.readInt();
} catch (IOException ex) {
throw new SAXException(ex);
}
}
}
// <REPRESENTATIVE_SCAN>
if (qName.equals(PeakListElementName_2_3.REPRESENTATIVE_SCAN.getElementName())) {
representativeScan = Integer.valueOf(getTextOfElement());
}
if (qName.equals(PeakListElementName_2_3.FRAGMENT_SCAN.getElementName())) {
fragmentScan = Integer.valueOf(getTextOfElement());
}
// <All_MS2_FRAGMENT_SCANS>
if (qName.equals(PeakListElementName_2_5.ALL_MS2_FRAGMENT_SCANS.getElementName())) {
Integer fragmentNumber = Integer.valueOf(getTextOfElement());
currentAllMS2FragmentScans.add(fragmentNumber);
}
// <MASS>
if (qName.equals(PeakListElementName_2_3.MZ.getElementName())) {
byte[] bytes = Base64.decodeToBytes(getTextOfElement());
// make a data input stream
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
masses = new double[numOfMZpeaks];
for (int i = 0; i < numOfMZpeaks; i++) {
try {
masses[i] = dataInputStream.readFloat();
} catch (IOException ex) {
throw new SAXException(ex);
}
}
}
// <HEIGHT>
if (qName.equals(PeakListElementName_2_3.HEIGHT.getElementName())) {
byte[] bytes = Base64.decodeToBytes(getTextOfElement());
// make a data input stream
DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
intensities = new double[numOfMZpeaks];
for (int i = 0; i < numOfMZpeaks; i++) {
try {
intensities[i] = dataInputStream.readFloat();
} catch (IOException ex) {
throw new SAXException(ex);
}
}
}
// <PEAK>
if (qName.equals(PeakListElementName_2_3.PEAK.getElementName())) {
DataPoint[] mzPeaks = new DataPoint[numOfMZpeaks];
Range<Double> peakRTRange = null, peakMZRange = null, peakIntensityRange = null;
RawDataFile dataFile = dataFilesIDMap.get(peakColumnID);
if (dataFile == null)
throw new SAXException("Error in project: data file " + peakColumnID + " not found");
for (int i = 0; i < numOfMZpeaks; i++) {
Scan sc = dataFile.getScan(scanNumbers[i]);
double retentionTime = sc.getRetentionTime();
double mz = masses[i];
double intensity = intensities[i];
if ((peakRTRange == null) || (peakIntensityRange == null)) {
peakRTRange = Range.singleton(retentionTime);
peakIntensityRange = Range.singleton(intensity);
} else {
peakRTRange = peakRTRange.span(Range.singleton(retentionTime));
peakIntensityRange = peakIntensityRange.span(Range.singleton(intensity));
}
if (mz > 0.0) {
mzPeaks[i] = new SimpleDataPoint(mz, intensity);
if (peakMZRange == null)
peakMZRange = Range.singleton(mz);
else
peakMZRange = peakMZRange.span(Range.singleton(mz));
}
}
FeatureStatus status = FeatureStatus.valueOf(peakStatus);
// convert vector of allMS2FragmentScans to array
allMS2FragmentScanNumbers = new int[currentAllMS2FragmentScans.size()];
for (int i = 0; i < allMS2FragmentScanNumbers.length; i++) {
allMS2FragmentScanNumbers[i] = currentAllMS2FragmentScans.get(i);
}
// clear all MS2 fragment scan numbers list for next peak
currentAllMS2FragmentScans.clear();
SimpleFeature peak = new SimpleFeature(dataFile, mass, rt, height, area, scanNumbers, mzPeaks, status, representativeScan, fragmentScan, allMS2FragmentScanNumbers, peakRTRange, peakMZRange, peakIntensityRange);
peak.setCharge(currentPeakCharge);
if (currentIsotopes.size() > 0) {
SimpleIsotopePattern newPattern = new SimpleIsotopePattern(currentIsotopes.toArray(new DataPoint[0]), currentIsotopePatternStatus, currentIsotopePatternDescription);
peak.setIsotopePattern(newPattern);
currentIsotopes.clear();
}
buildingRow.addPeak(dataFile, peak);
}
// <IDENTITY_PROPERTY>
if (qName.equals(PeakListElementName_2_3.IDPROPERTY.getElementName())) {
identityProperties.put(identityPropertyName, getTextOfElement());
}
// <PEAK_IDENTITY>
if (qName.equals(PeakListElementName_2_3.PEAK_IDENTITY.getElementName())) {
SimplePeakIdentity identity = new SimplePeakIdentity(identityProperties);
buildingRow.addPeakIdentity(identity, preferred);
}
// <ROW>
if (qName.equals(PeakListElementName_2_3.ROW.getElementName())) {
buildingPeakList.addRow(buildingRow);
buildingRow = null;
parsedRows++;
}
// <ISOTOPE>
if (qName.equals(PeakListElementName_2_3.ISOTOPE.getElementName())) {
String text = getTextOfElement();
String[] items = text.split(":");
double mz = Double.valueOf(items[0]);
double intensity = Double.valueOf(items[1]);
DataPoint isotope = new SimpleDataPoint(mz, intensity);
currentIsotopes.add(isotope);
}
if (qName.equals(PeakListElementName_2_3.METHOD_NAME.getElementName())) {
String appliedMethod = getTextOfElement();
appliedMethods.add(appliedMethod);
}
if (qName.equals(PeakListElementName_2_3.METHOD_PARAMETERS.getElementName())) {
String appliedMethodParam = getTextOfElement();
appliedMethodParameters.add(appliedMethodParam);
}
}
use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.
the class ExtendedPeak method finishExtendedPeak.
public void finishExtendedPeak() {
int[] allScanNumbers = Ints.toArray(dataPointsMap.keySet());
Arrays.sort(allScanNumbers);
scanNumbers = allScanNumbers;
// Calculate median m/z
double[] allMzValues = new double[allScanNumbers.length];
for (int i = 0; i < allScanNumbers.length; i++) {
allMzValues[i] = dataPointsMap.get(allScanNumbers[i]).getMZ();
}
mz = MathUtils.calcQuantile(allMzValues, 0.5f);
// Update raw data point ranges, height, rt and representative scan
height = Double.MIN_VALUE;
for (int i = 0; i < allScanNumbers.length; i++) {
DataPoint mzPeak = dataPointsMap.get(allScanNumbers[i]);
Scan aScan = dataFile.getScan(allScanNumbers[i]);
// Replace the MzPeak instance with an instance of SimpleDataPoint,
// to reduce the memory usage. After we finish this extended peak,
// we don't need the additional data provided by the MzPeak
SimpleDataPoint newDataPoint = new SimpleDataPoint(mzPeak);
dataPointsMap.put(allScanNumbers[i], newDataPoint);
if (i == 0) {
rawDataPointsIntensityRange = Range.singleton(mzPeak.getIntensity());
rawDataPointsMZRange = Range.singleton(mzPeak.getMZ());
rawDataPointsRTRange = Range.singleton(aScan.getRetentionTime());
} else {
rawDataPointsIntensityRange = rawDataPointsIntensityRange.span(Range.singleton(mzPeak.getIntensity()));
rawDataPointsMZRange = rawDataPointsMZRange.span(Range.singleton(mzPeak.getMZ()));
rawDataPointsRTRange = rawDataPointsRTRange.span(Range.singleton(aScan.getRetentionTime()));
}
if (height < mzPeak.getIntensity()) {
height = mzPeak.getIntensity();
rt = aScan.getRetentionTime();
representativeScan = allScanNumbers[i];
}
}
// Update area
area = 0;
for (int i = 1; i < allScanNumbers.length; i++) {
// For area calculation, we use retention time in seconds
double previousRT = dataFile.getScan(allScanNumbers[i - 1]).getRetentionTime() * 60d;
double currentRT = dataFile.getScan(allScanNumbers[i]).getRetentionTime() * 60d;
double previousHeight = dataPointsMap.get(allScanNumbers[i - 1]).getIntensity();
double currentHeight = dataPointsMap.get(allScanNumbers[i]).getIntensity();
area += (currentRT - previousRT) * (currentHeight + previousHeight) / 2;
}
// Update fragment scan
fragmentScan = ScanUtils.findBestFragmentScan(dataFile, dataFile.getDataRTRange(1), rawDataPointsMZRange);
allMS2FragmentScanNumbers = ScanUtils.findAllMS2FragmentScans(dataFile, dataFile.getDataRTRange(1), rawDataPointsMZRange);
if (fragmentScan > 0) {
Scan fragmentScanObject = dataFile.getScan(fragmentScan);
int precursorCharge = fragmentScanObject.getPrecursorCharge();
if ((precursorCharge > 0) && (this.charge == 0))
this.charge = precursorCharge;
}
}
use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.
the class MzMLReadTask method extractDataPoints.
private DataPoint[] extractDataPoints(Spectrum spectrum) {
BinaryDataArrayList dataList = spectrum.getBinaryDataArrayList();
if ((dataList == null) || (dataList.getCount().equals(0)))
return new DataPoint[0];
BinaryDataArray mzArray = dataList.getBinaryDataArray().get(0);
BinaryDataArray intensityArray = dataList.getBinaryDataArray().get(1);
Number[] mzValues = mzArray.getBinaryDataAsNumberArray();
Number[] intensityValues = intensityArray.getBinaryDataAsNumberArray();
DataPoint[] dataPoints = new DataPoint[mzValues.length];
for (int i = 0; i < dataPoints.length; i++) {
double mz = mzValues[i].doubleValue();
double intensity = intensityValues[i].doubleValue();
dataPoints[i] = new SimpleDataPoint(mz, intensity);
}
return dataPoints;
}
use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.
the class AgilentCsvReadTask method run.
/**
* Reads the file.
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
Scanner scanner;
try {
scanner = new Scanner(this.file);
this.dataSource = this.getMetaData(scanner, "file name");
String[] range = this.getMetaData(scanner, "mass range").split(",");
newMZmineFile.setMZRange(1, Range.closed(Double.parseDouble(range[0]), Double.parseDouble(range[1])));
range = this.getMetaData(scanner, "time range").split(",");
newMZmineFile.setRTRange(1, Range.closed(Double.parseDouble(range[0]), Double.parseDouble(range[1])));
totalScans = Integer.parseInt(this.getMetaData(scanner, "number of spectra"));
// advance to the spectrum data...
while (!scanner.nextLine().trim().equals("[spectra]")) {
}
scanner.useDelimiter(",");
for (parsedScans = 0; parsedScans < totalScans; parsedScans++) {
if (isCanceled()) {
return;
}
// if the task is canceled.
double retentionTime = scanner.nextDouble();
// not sure about this value
int msLevel = scanner.nextInt();
scanner.next();
scanner.next();
int charge = (scanner.next().equals("+") ? 1 : -1);
scanner.next();
int spectrumSize = scanner.nextInt();
DataPoint[] dataPoints = new DataPoint[spectrumSize];
for (int j = 0; j < spectrumSize; j++) {
dataPoints[j] = new SimpleDataPoint(scanner.nextDouble(), scanner.nextDouble());
}
newMZmineFile.addScan(new SimpleScan(null, parsedScans + 1, msLevel, retentionTime, 0.0, charge, null, dataPoints, ScanUtils.detectSpectrumType(dataPoints), PolarityType.UNKNOWN, "", null));
scanner.nextLine();
}
finalRawDataFile = newMZmineFile.finishWriting();
project.addFile(finalRawDataFile);
} catch (Exception e) {
setErrorMessage(e.getMessage());
this.setStatus(TaskStatus.ERROR);
return;
}
this.setStatus(TaskStatus.FINISHED);
}
Aggregations