use of net.sf.mzmine.datamodel.PeakIdentity in project mzmine2 by mzmine.
the class PeakListSaveHandler method fillRowElement.
/**
* Add the row information into the XML document
*
* @param row
* @param element
* @throws IOException
*/
private void fillRowElement(PeakListRow row, TransformerHandler hd) throws SAXException, IOException {
// <PEAK_IDENTITY>
PeakIdentity preferredIdentity = row.getPreferredPeakIdentity();
PeakIdentity[] identities = row.getPeakIdentities();
AttributesImpl atts = new AttributesImpl();
for (int i = 0; i < identities.length; i++) {
if (canceled)
return;
atts.addAttribute("", "", PeakListElementName.ID.getElementName(), "CDATA", String.valueOf(i));
atts.addAttribute("", "", PeakListElementName.PREFERRED.getElementName(), "CDATA", String.valueOf(identities[i] == preferredIdentity));
hd.startElement("", "", PeakListElementName.PEAK_IDENTITY.getElementName(), atts);
fillIdentityElement(identities[i], hd);
hd.endElement("", "", PeakListElementName.PEAK_IDENTITY.getElementName());
}
if (canceled)
return;
// atts.addAttribute("", "", PeakListElementName.ID.getElementName(),
// "CDATA", "INFORMATION");
hd.startElement("", "", PeakListElementName.PEAK_INFORMATION.getElementName(), atts);
fillInformationElement(row.getPeakInformation(), hd);
hd.endElement("", "", PeakListElementName.PEAK_INFORMATION.getElementName());
// <PEAK>
Feature[] peaks = row.getPeaks();
for (Feature p : peaks) {
if (canceled)
return;
atts.clear();
String dataFileID = dataFilesIDMap.get(p.getDataFile());
atts.addAttribute("", "", PeakListElementName.COLUMN.getElementName(), "CDATA", dataFileID);
atts.addAttribute("", "", PeakListElementName.MZ.getElementName(), "CDATA", String.valueOf(p.getMZ()));
// In the project file, retention time is represented in seconds,
// for historical reasons
double rt = p.getRT() * 60d;
atts.addAttribute("", "", PeakListElementName.RT.getElementName(), "CDATA", String.valueOf(rt));
atts.addAttribute("", "", PeakListElementName.HEIGHT.getElementName(), "CDATA", String.valueOf(p.getHeight()));
atts.addAttribute("", "", PeakListElementName.AREA.getElementName(), "CDATA", String.valueOf(p.getArea()));
atts.addAttribute("", "", PeakListElementName.STATUS.getElementName(), "CDATA", p.getFeatureStatus().toString());
atts.addAttribute("", "", PeakListElementName.CHARGE.getElementName(), "CDATA", String.valueOf(p.getCharge()));
atts.addAttribute("", "", PeakListElementName.PARENT_CHROMATOGRAM_ROW_ID.getElementName(), "CDATA", p.getParentChromatogramRowID() != null ? String.valueOf(p.getParentChromatogramRowID()) : "");
hd.startElement("", "", PeakListElementName.PEAK.getElementName(), atts);
fillPeakElement(p, hd);
hd.endElement("", "", PeakListElementName.PEAK.getElementName());
}
}
use of net.sf.mzmine.datamodel.PeakIdentity in project mzmine2 by mzmine.
the class ScatterPlotItemLabelGenerator method generateLabel.
/**
* @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset,
* int, int)
*/
public String generateLabel(XYDataset dataSet, int series, int item) {
ScatterPlotDataSet scatterDataSet = (ScatterPlotDataSet) dataSet;
PeakListRow row = scatterDataSet.getRow(series, item);
PeakIdentity identity = row.getPreferredPeakIdentity();
if (identity != null) {
return identity.getName();
} else {
return row.toString();
}
}
use of net.sf.mzmine.datamodel.PeakIdentity in project mzmine2 by mzmine.
the class SearchDefinition method conforms.
/**
* Checks whether given feature list row conforms to this search condition.
*/
public boolean conforms(PeakListRow row) {
switch(type) {
case NAME:
PeakIdentity identity = row.getPreferredPeakIdentity();
if (identity == null)
return false;
String name = identity.getName();
if (isEmpty(nameRegex.toString()) || isEmpty(name)) {
return false;
}
Matcher matcher = nameRegex.matcher(name);
return matcher.find();
case MASS:
return range.contains(row.getAverageMZ());
case RT:
return range.contains(row.getAverageRT());
}
return false;
}
use of net.sf.mzmine.datamodel.PeakIdentity in project mzmine2 by mzmine.
the class SameRangeTask method run.
public void run() {
logger.info("Started gap-filling " + peakList);
setStatus(TaskStatus.PROCESSING);
// Get total number of rows
totalRows = peakList.getNumberOfRows();
// Get feature list columns
RawDataFile[] columns = peakList.getRawDataFiles();
// Create new feature list
processedPeakList = new SimplePeakList(peakList + " " + suffix, columns);
/**
***********************************************************
* Creating a stream to process the data in parallel
*/
processedRowsAtomic = new AtomicInteger(0);
List<PeakListRow> outputList = Collections.synchronizedList(new ArrayList<>());
peakList.parallelStream().forEach(sourceRow -> {
// Canceled?
if (isCanceled())
return;
PeakListRow newRow = new SimplePeakListRow(sourceRow.getID());
// Copy comment
newRow.setComment(sourceRow.getComment());
// Copy identities
for (PeakIdentity ident : sourceRow.getPeakIdentities()) newRow.addPeakIdentity(ident, false);
if (sourceRow.getPreferredPeakIdentity() != null)
newRow.setPreferredPeakIdentity(sourceRow.getPreferredPeakIdentity());
// Copy each peaks and fill gaps
for (RawDataFile column : columns) {
// Canceled?
if (isCanceled())
return;
// Get current peak
Feature currentPeak = sourceRow.getPeak(column);
// If there is a gap, try to fill it
if (currentPeak == null)
currentPeak = fillGap(sourceRow, column);
// If a peak was found or created, add it
if (currentPeak != null)
newRow.addPeak(column, currentPeak);
}
outputList.add(newRow);
processedRowsAtomic.getAndAdd(1);
});
outputList.stream().forEach(newRow -> {
processedPeakList.addRow((PeakListRow) newRow);
});
// Canceled?
if (isCanceled())
return;
// Append processed feature list to the project
project.addPeakList(processedPeakList);
// Add quality parameters to peaks
QualityParameters.calculateQualityParameters(processedPeakList);
// Add task description to peakList
processedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Gap filling using RT and m/z range", parameters));
// Remove the original peaklist if requested
if (removeOriginal)
project.removePeakList(peakList);
setStatus(TaskStatus.FINISHED);
logger.info("Finished gap-filling " + peakList);
}
use of net.sf.mzmine.datamodel.PeakIdentity in project mzmine2 by mzmine.
the class CameraSearchTask method addPseudoSpectraIdentities.
/**
* Add pseudo-spectra identities.
*
* @param peaks peaks to annotate with identities.
* @param spectraExp the pseudo-spectra ids vector.
* @param isotopeExp the isotopes vector.
*/
private void addPseudoSpectraIdentities(final Feature[] peaks, final int[] spectra, final String[] isotopes, final String[] adducts) {
// Add identities for each peak.
int peakIndex = 0;
for (final Feature peak : peaks) {
// Create pseudo-spectrum identity
final SimplePeakIdentity identity = new SimplePeakIdentity("Pseudo-spectrum #" + String.format("%03d", spectra[peakIndex]));
identity.setPropertyValue(PeakIdentity.PROPERTY_METHOD, "Bioconductor CAMERA");
// Add isotope info, if any.
if (isotopes != null) {
final String isotope = isotopes[peakIndex].trim();
if (isotope.length() > 0) {
// Parse the isotope pattern.
final Matcher matcher = ISOTOPE_PATTERN.matcher(isotope);
if (matcher.matches()) {
// identity.setPropertyValue("Isotope", matcher.group(1));
identity.setPropertyValue("Isotope", isotope);
} else {
LOG.warning("Irregular isotope value: " + isotope);
}
}
}
if (adducts != null) {
final String adduct = adducts[peakIndex].trim();
if (adduct.length() > 0)
identity.setPropertyValue("Adduct", adduct);
}
// Add identity to peak's row.
PeakListRow row = peakList.getPeakRow(peak);
for (PeakIdentity peakIdentity : row.getPeakIdentities()) row.removePeakIdentity(peakIdentity);
peakList.getPeakRow(peak).addPeakIdentity(identity, true);
peakIndex++;
}
}
Aggregations