use of net.sf.mzmine.datamodel.impl.SimpleScan in project mzmine2 by mzmine.
the class CsvReadTask method run.
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
Scanner scanner;
logger.setLevel(Level.ALL);
try {
scanner = new Scanner(file);
dataSource = getFileName(scanner);
if (dataSource == null) {
setErrorMessage("Could not open data file " + file.getAbsolutePath());
setStatus(TaskStatus.ERROR);
return;
}
logger.info("opening raw file " + dataSource);
String acquisitionDate = getAcqusitionDate(scanner);
if (acquisitionDate == null) {
setErrorMessage("Could not find acquisition date in file " + file.getAbsolutePath());
setStatus(TaskStatus.ERROR);
return;
}
logger.info("Date of acquisition " + acquisitionDate);
// scanner.useDelimiter(",");
List<String> mzsList = new ArrayList<String>();
String mstype = "";
String ions = "";
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
logger.fine("checking line: " + line + " for 'Time'...");
if (line.startsWith("Time")) {
String[] axes = line.split(",");
logger.fine("Found axes" + Arrays.toString(axes));
for (int i = 1; i < axes.length; i++) {
String axis = axes[i];
ions += axis + ", ";
if (axis.contains("->")) {
mstype = "MS/MS";
logger.fine("axis " + axis + " is an ms^2 scan");
String mz = axis.substring(axis.indexOf("-> ") + 3);
mz.trim();
logger.fine("Axis " + axis + " was scanned at m/z = '" + mz + "'");
mzsList.add(mz);
} else {
String mz = axis.replaceAll("[^0-9]", "");
logger.fine("axis " + axis + " was scanned at " + mz);
mzsList.add(mz);
}
}
break;
}
}
int[] mzs = new int[mzsList.size()];
for (int i = 0; i < mzsList.size(); i++) mzs[i] = Integer.valueOf(mzsList.get(i));
Range<Double> mzRange = Range.closed((double) mzs[0] - 10, (double) mzs[1] + 10);
int scanNumber = 1;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line == null || line.trim().equals(""))
continue;
String[] columns = line.split(",");
if (columns == null || columns.length != mzs.length + 1)
continue;
double rt = Double.valueOf(columns[0]) / 60;
DataPoint[] dataPoints = new SimpleDataPoint[mzs.length];
for (int i = 0; i < dataPoints.length; i++) {
String intensity = columns[i + 1];
dataPoints[i] = new SimpleDataPoint(mzs[i], Double.valueOf(intensity));
}
Scan scan = new SimpleScan(null, scanNumber, 1, rt, 0.0, 1, null, dataPoints, MassSpectrumType.CENTROIDED, PolarityType.POSITIVE, "ICP-" + mstype + " " + ions.substring(0, ions.length() - 2), mzRange);
newMZmineFile.addScan(scan);
scanNumber++;
}
finalRawDataFile = newMZmineFile.finishWriting();
project.addFile(finalRawDataFile);
} catch (Exception e) {
setErrorMessage(e.getMessage());
setStatus(TaskStatus.ERROR);
return;
}
this.setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.impl.SimpleScan in project mzmine2 by mzmine.
the class MeanFilter method filterScan.
@Override
public Scan filterScan(Scan sc, ParameterSet parameters) {
double windowLength = parameters.getParameter(MeanFilterParameters.oneSidedWindowLength).getValue();
// changed to also allow MS2 if selected in ScanSelection
Vector<Double> massWindow = new Vector<Double>();
Vector<Double> intensityWindow = new Vector<Double>();
double currentMass;
double lowLimit;
double hiLimit;
double mzVal;
double elSum;
DataPoint[] oldDataPoints = sc.getDataPoints();
DataPoint[] newDataPoints = new DataPoint[oldDataPoints.length];
int addi = 0;
for (int i = 0; i < oldDataPoints.length; i++) {
currentMass = oldDataPoints[i].getMZ();
lowLimit = currentMass - windowLength;
hiLimit = currentMass + windowLength;
// low limit
if (massWindow.size() > 0) {
mzVal = massWindow.get(0).doubleValue();
while ((massWindow.size() > 0) && (mzVal < lowLimit)) {
massWindow.remove(0);
intensityWindow.remove(0);
if (massWindow.size() > 0) {
mzVal = massWindow.get(0).doubleValue();
}
}
}
// limit
while ((addi < oldDataPoints.length) && (oldDataPoints[addi].getMZ() <= hiLimit)) {
massWindow.add(oldDataPoints[addi].getMZ());
intensityWindow.add(oldDataPoints[addi].getIntensity());
addi++;
}
elSum = 0;
for (int j = 0; j < intensityWindow.size(); j++) {
elSum += (intensityWindow.get(j)).doubleValue();
}
newDataPoints[i] = new SimpleDataPoint(currentMass, elSum / intensityWindow.size());
}
// Create filtered scan
Scan newScan = new SimpleScan(sc.getDataFile(), sc.getScanNumber(), sc.getMSLevel(), sc.getRetentionTime(), sc.getPrecursorMZ(), sc.getPrecursorCharge(), sc.getFragmentScanNumbers(), newDataPoints, MassSpectrumType.CENTROIDED, sc.getPolarity(), sc.getScanDefinition(), sc.getScanningMZRange());
return newScan;
}
use of net.sf.mzmine.datamodel.impl.SimpleScan in project mzmine2 by mzmine.
the class ResampleFilter method filterScan.
public Scan filterScan(Scan scan, ParameterSet parameters) {
double binSize = parameters.getParameter(ResampleFilterParameters.binSize).getValue();
Range<Double> mzRange = scan.getDataPointMZRange();
int numberOfBins = (int) Math.round((mzRange.upperEndpoint() - mzRange.lowerEndpoint()) / binSize);
if (numberOfBins == 0) {
numberOfBins++;
}
// ScanUtils.binValues needs arrays
DataPoint[] dps = scan.getDataPoints();
double[] x = new double[dps.length];
double[] y = new double[dps.length];
for (int i = 0; i < dps.length; i++) {
x[i] = dps[i].getMZ();
y[i] = dps[i].getIntensity();
}
// the new intensity values
double[] newY = ScanUtils.binValues(x, y, mzRange, numberOfBins, scan.getSpectrumType() == MassSpectrumType.PROFILE, ScanUtils.BinningType.AVG);
SimpleDataPoint[] newPoints = new SimpleDataPoint[newY.length];
// set the new m/z value in the middle of the bin
double newX = mzRange.lowerEndpoint() + binSize / 2.0;
// creates new DataPoints
for (int i = 0; i < newY.length; i++) {
newPoints[i] = new SimpleDataPoint(newX, newY[i]);
newX += binSize;
}
// Create updated scan
SimpleScan newScan = new SimpleScan(scan);
newScan.setDataPoints(newPoints);
newScan.setSpectrumType(MassSpectrumType.CENTROIDED);
return newScan;
}
use of net.sf.mzmine.datamodel.impl.SimpleScan in project mzmine2 by mzmine.
the class LocMaxCentroidingAlgorithm method centroidScan.
public Scan centroidScan() {
// Copy all scan properties
this.newScan = new SimpleScan(inputScan);
// Load data points
for (int i = 0; i < dataPoints.length; ++i) {
mzBuffer[i] = dataPoints[i].getMZ();
intensityBuffer[i] = dataPoints[i].getIntensity();
}
final int numOfDataPoints = inputScan.getNumberOfDataPoints();
int newNumOfDataPoints = 0;
// If there are no data points, just return the scan
ArrayList<DataPoint> newDataPoints = new ArrayList<DataPoint>();
if (numOfDataPoints == 0) {
for (int i = 0; i < numOfDataPoints; ++i) {
newDataPoints.add(new SimpleDataPoint(mzBuffer[i], intensityBuffer[i]));
}
newScan.setDataPoints(newDataPoints.toArray(new SimpleDataPoint[newDataPoints.size()]));
newScan.setSpectrumType(MassSpectrumType.CENTROIDED);
return newScan;
}
int localMaximumIndex = 0;
int rangeBeginning = 0, rangeEnd;
boolean ascending = true;
// Iterate through all data points
for (int i = 0; i < numOfDataPoints - 1; i++) {
final boolean nextIsBigger = intensityBuffer[i + 1] > intensityBuffer[i];
final boolean nextIsZero = intensityBuffer[i + 1] == 0f;
final boolean currentIsZero = intensityBuffer[i] == 0f;
// Ignore zero intensity regions
if (currentIsZero) {
continue;
}
// Add current (non-zero) data point to the current m/z peak
rangeEnd = i;
// Check for local maximum
if (ascending && (!nextIsBigger)) {
localMaximumIndex = i;
ascending = false;
continue;
}
// Check for the end of the peak
if ((!ascending) && (nextIsBigger || nextIsZero)) {
final int numOfPeakDataPoints = rangeEnd - rangeBeginning;
// Add the m/z peak if it has at least 4 data points
if (numOfPeakDataPoints >= 4) {
// Add the new data point
mzBuffer[newNumOfDataPoints] = mzBuffer[localMaximumIndex];
intensityBuffer[newNumOfDataPoints] = intensityBuffer[localMaximumIndex];
newNumOfDataPoints++;
}
// Reset and start with new peak
ascending = true;
rangeBeginning = i;
}
}
// Store the new data points
for (int i = 0; i < newNumOfDataPoints; ++i) {
newDataPoints.add(new SimpleDataPoint(mzBuffer[i], intensityBuffer[i]));
}
newScan.setDataPoints(newDataPoints.toArray(new SimpleDataPoint[newDataPoints.size()]));
newScan.setSpectrumType(MassSpectrumType.CENTROIDED);
return newScan;
}
use of net.sf.mzmine.datamodel.impl.SimpleScan in project mzmine2 by mzmine.
the class RawFileMergeTask method run.
@Override
public void run() {
try {
setStatus(TaskStatus.PROCESSING);
// total number of scans
StringBuilder s = new StringBuilder();
s.append("Merge files: ");
for (RawDataFile r : raw) {
s.append(r.getName());
s.append(", ");
}
LOG.info(s.toString());
// put all in a list and sort by rt
List<Scan> scans = new ArrayList<>();
for (RawDataFile r : raw) {
// some files are only for MS2
boolean isMS2Only = useMS2Marker && r.getName().contains(ms2Marker);
int[] snarray = r.getScanNumbers();
for (int sn : snarray) {
if (isCanceled())
return;
Scan scan = r.getScan(sn);
if (!isMS2Only || scan.getMSLevel() > 1) {
scans.add(scan);
}
}
}
// sort by rt
scans.sort(new Comparator<Scan>() {
@Override
public int compare(Scan a, Scan b) {
return Double.compare(a.getRetentionTime(), b.getRetentionTime());
}
});
// create new file
RawDataFileWriter rawDataFileWriter = MZmineCore.createNewFile(raw[0].getName() + " " + suffix);
int i = 0;
for (Scan scan : scans) {
if (isCanceled())
return;
// copy, reset scan number
SimpleScan scanCopy = new SimpleScan(scan);
scanCopy.setScanNumber(i);
rawDataFileWriter.addScan(scanCopy);
i++;
}
RawDataFile filteredRawDataFile = rawDataFileWriter.finishWriting();
project.addFile(filteredRawDataFile);
if (getStatus() == TaskStatus.PROCESSING)
setStatus(TaskStatus.FINISHED);
} catch (IOException e) {
throw new MSDKRuntimeException(e);
}
}
Aggregations