use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class MassListComponent method getMassListNames.
/**
* Method returns the list of all identified MassList names in scans
*
* @return unique MassList names
*/
public static List<String> getMassListNames() {
ArrayList<String> names = new ArrayList<>();
RawDataFile[] dataFiles = MZmineCore.getProjectManager().getCurrentProject().getDataFiles();
for (RawDataFile dataFile : dataFiles) {
int[] scanNums = dataFile.getScanNumbers();
for (int scanNum : scanNums) {
Scan scan = dataFile.getScan(scanNum);
MassList[] massLists = scan.getMassLists();
for (MassList massList : massLists) {
String name = massList.getName();
if (!names.contains(name))
names.add(name);
}
}
}
return names;
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class ScanUtils method findPrecursorScan.
/**
* Finds the first MS1 scan preceding the given MS2 scan. If no such scan exists, returns null.
*/
@Nullable
public static Scan findPrecursorScan(@Nonnull Scan scan) {
assert scan != null;
final RawDataFile dataFile = scan.getDataFile();
final int[] scanNumbers = dataFile.getScanNumbers();
int startIndex = Arrays.binarySearch(scanNumbers, scan.getScanNumber());
for (int i = startIndex; i >= 0; i--) {
Scan s = dataFile.getScan(scanNumbers[i]);
if (s.getMSLevel() == 1)
return s;
}
// Didn't find any MS1 scan
return null;
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class PeakXICComponent method paint.
public void paint(Graphics g) {
super.paint(g);
// use Graphics2D for antialiasing
Graphics2D g2 = (Graphics2D) g;
// turn on antialiasing
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// get canvas size
Dimension size = getSize();
// get scan numbers, one data point per each scan
RawDataFile dataFile = peak.getDataFile();
int[] scanNumbers = peak.getScanNumbers();
// If we have no data, just return
if (scanNumbers.length == 0)
return;
// for each datapoint, find [X:Y] coordinates of its point in painted
// image
int[] xValues = new int[scanNumbers.length];
int[] yValues = new int[scanNumbers.length];
// find one datapoint with maximum intensity in each scan
for (int i = 0; i < scanNumbers.length; i++) {
double dataPointIntensity = 0;
DataPoint dataPoint = peak.getDataPoint(scanNumbers[i]);
if (dataPoint != null)
dataPointIntensity = dataPoint.getIntensity();
// get retention time (X value)
double retentionTime = dataFile.getScan(scanNumbers[i]).getRetentionTime();
// calculate [X:Y] coordinates
final double rtLen = rtRange.upperEndpoint() - rtRange.lowerEndpoint();
xValues[i] = (int) Math.floor((retentionTime - rtRange.lowerEndpoint()) / rtLen * (size.width - 1));
yValues[i] = size.height - (int) Math.floor(dataPointIntensity / maxIntensity * (size.height - 1));
}
// create a path for a peak polygon
GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
path.moveTo(xValues[0], size.height - 1);
// add data points to the path
for (int i = 0; i < (xValues.length - 1); i++) {
path.lineTo(xValues[i + 1], yValues[i + 1]);
}
path.lineTo(xValues[xValues.length - 1], size.height - 1);
// close the path to form a polygon
path.closePath();
// fill the peak area
g2.setColor(XICColor);
g2.fill(path);
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class ADAP3AlignerTask method alignPeaks.
private PeakList alignPeaks() {
// Collect all data files
List<RawDataFile> allDataFiles = new ArrayList<>(peakLists.length);
for (final PeakList peakList : peakLists) {
RawDataFile[] dataFiles = peakList.getRawDataFiles();
if (dataFiles.length != 1)
throw new IllegalArgumentException("Found more then one data " + "file in some of the peaks lists");
allDataFiles.add(dataFiles[0]);
}
for (int i = 0; i < peakLists.length; ++i) {
PeakList peakList = peakLists[i];
Sample sample = new Sample(i);
for (final PeakListRow row : peakList.getRows()) {
Component component = getComponent(row);
if (component != null)
sample.addComponent(component);
}
alignment.addSample(sample);
}
process();
// Create new feature list
final PeakList alignedPeakList = new SimplePeakList(peakListName, allDataFiles.toArray(new RawDataFile[0]));
int rowID = 0;
List<ReferenceComponent> alignedComponents = alignment.getComponents();
Collections.sort(alignedComponents);
for (final ReferenceComponent referenceComponent : alignedComponents) {
SimplePeakListRow newRow = new SimplePeakListRow(++rowID);
for (int i = 0; i < referenceComponent.size(); ++i) {
Component component = referenceComponent.getComponent(i);
Peak peak = component.getBestPeak();
peak.getInfo().mzValue(component.getMZ());
PeakListRow row = findPeakListRow(referenceComponent.getSampleID(i), peak.getInfo().peakID);
if (row == null)
throw new IllegalStateException(String.format("Cannot find a feature list row for fileId = %d and peakId = %d", referenceComponent.getSampleID(), peak.getInfo().peakID));
RawDataFile file = row.getRawDataFiles()[0];
// Create a new MZmine feature
Feature feature = ADAPInterface.peakToFeature(file, peak);
// Add spectrum as an isotopic pattern
DataPoint[] spectrum = component.getSpectrum().entrySet().stream().map(e -> new SimpleDataPoint(e.getKey(), e.getValue())).toArray(DataPoint[]::new);
feature.setIsotopePattern(new SimpleIsotopePattern(spectrum, IsotopePattern.IsotopePatternStatus.PREDICTED, "Spectrum"));
newRow.addPeak(file, feature);
}
// Save alignment score
SimplePeakInformation peakInformation = (SimplePeakInformation) newRow.getPeakInformation();
if (peakInformation == null)
peakInformation = new SimplePeakInformation();
peakInformation.addProperty("Alignment score", Double.toString(referenceComponent.getScore()));
newRow.setPeakInformation(peakInformation);
alignedPeakList.addRow(newRow);
}
return alignedPeakList;
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class ADAP3AlignerTask method getComponent.
/**
* Convert a {@link PeakListRow} with one {@link Feature} into {@link Component}.
*
* @param row an instance of {@link PeakListRow}. This parameter cannot be null.
* @return an instance of {@link Component} or null if the row doesn't contain any peaks or isotope patterns.
*/
@Nullable
private Component getComponent(final PeakListRow row) {
if (row.getNumberOfPeaks() == 0)
return null;
// Read Spectrum information
NavigableMap<Double, Double> spectrum = new TreeMap<>();
IsotopePattern pattern = row.getBestIsotopePattern();
if (pattern == null)
throw new IllegalArgumentException("ADAP Alignment requires mass " + "spectra (or isotopic patterns) of peaks. No spectra found.");
for (DataPoint dataPoint : pattern.getDataPoints()) spectrum.put(dataPoint.getMZ(), dataPoint.getIntensity());
// Read Chromatogram
final Feature peak = row.getBestPeak();
final RawDataFile dataFile = peak.getDataFile();
NavigableMap<Double, Double> chromatogram = new TreeMap<>();
for (final int scan : peak.getScanNumbers()) {
final DataPoint dataPoint = peak.getDataPoint(scan);
if (dataPoint != null)
chromatogram.put(dataFile.getScan(scan).getRetentionTime(), dataPoint.getIntensity());
}
return new Component(null, new Peak(chromatogram, new PeakInfo().mzValue(peak.getMZ()).peakID(row.getID())), spectrum, null);
}
Aggregations