use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class PeakComparisonRowFilterTask method filterPeakListRows.
/**
* Filter the feature list rows by comparing peaks within a row.
*
* @param peakList feature list to filter.
* @return a new feature list with rows of the original feature list that pass the filtering.
*/
private PeakList filterPeakListRows(final PeakList peakList) {
// Create new feature list.
final PeakList newPeakList = new SimplePeakList(peakList.getName() + ' ' + parameters.getParameter(PeakComparisonRowFilterParameters.SUFFIX).getValue(), peakList.getRawDataFiles());
// Copy previous applied methods.
for (final PeakListAppliedMethod method : peakList.getAppliedMethods()) {
newPeakList.addDescriptionOfAppliedTask(method);
}
// Add task description to peakList.
newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod(getTaskDescription(), parameters));
// Get parameters.
final boolean evalutateFoldChange = parameters.getParameter(PeakComparisonRowFilterParameters.FOLD_CHANGE).getValue();
final boolean evalutatePPMdiff = parameters.getParameter(PeakComparisonRowFilterParameters.MZ_PPM_DIFF).getValue();
final boolean evalutateRTdiff = parameters.getParameter(PeakComparisonRowFilterParameters.RT_DIFF).getValue();
final int columnIndex1 = parameters.getParameter(PeakComparisonRowFilterParameters.COLUMN_INDEX_1).getValue();
final int columnIndex2 = parameters.getParameter(PeakComparisonRowFilterParameters.COLUMN_INDEX_2).getValue();
final Range<Double> foldChangeRange = parameters.getParameter(PeakComparisonRowFilterParameters.FOLD_CHANGE).getEmbeddedParameter().getValue();
final Range<Double> ppmDiffRange = parameters.getParameter(PeakComparisonRowFilterParameters.FOLD_CHANGE).getEmbeddedParameter().getValue();
final Range<Double> rtDiffRange = parameters.getParameter(PeakComparisonRowFilterParameters.FOLD_CHANGE).getEmbeddedParameter().getValue();
// Setup variables
final PeakListRow[] rows = peakList.getRows();
RawDataFile rawDataFile1;
RawDataFile rawDataFile2;
Feature peak1;
Feature peak2;
totalRows = rows.length;
final RawDataFile[] rawDataFiles = peakList.getRawDataFiles();
boolean allCriteriaMatched = true;
// doesn't exist.
if (columnIndex1 > rawDataFiles.length) {
setErrorMessage("Column 1 set too large.");
setStatus(TaskStatus.ERROR);
return null;
}
if (columnIndex2 > rawDataFiles.length) {
setErrorMessage("Column 2 set too large.");
setStatus(TaskStatus.ERROR);
return null;
}
// Loop over the rows & filter
for (processedRows = 0; !isCanceled() && processedRows < totalRows; processedRows++) {
if (isCanceled())
return null;
allCriteriaMatched = true;
// Default value in case of null peak
double peak1Area = 1.0;
double peak2Area = 1.0;
double peak1MZ = -1.0;
double peak2MZ = -1.0;
double peak1RT = -1.0;
double peak2RT = -1.0;
double foldChange = 0.0;
double ppmDiff = 0.0;
double rtDiff = 0.0;
final PeakListRow row = rows[processedRows];
rawDataFile1 = rawDataFiles[columnIndex1];
rawDataFile2 = rawDataFiles[columnIndex2];
peak1 = row.getPeak(rawDataFile1);
peak2 = row.getPeak(rawDataFile2);
if (peak1 != null) {
peak1Area = peak1.getArea();
peak1MZ = peak1.getMZ();
peak1RT = peak1.getRT();
}
if (peak2 != null) {
peak2Area = peak2.getArea();
peak2MZ = peak2.getMZ();
peak2RT = peak2.getRT();
}
// Fold change criteria checking.
if (evalutateFoldChange) {
foldChange = Math.log(peak1Area / peak2Area) / Math.log(2);
if (!foldChangeRange.contains(foldChange))
allCriteriaMatched = false;
// PPM difference evaluation
if (evalutatePPMdiff) {
ppmDiff = (peak1MZ - peak2MZ) / peak1MZ * 1E6;
if (!ppmDiffRange.contains(ppmDiff))
allCriteriaMatched = false;
}
// RT difference evaluation
if (evalutateRTdiff) {
rtDiff = peak1RT - peak2RT;
if (!rtDiffRange.contains(rtDiff))
allCriteriaMatched = false;
}
}
// Good row?
if (allCriteriaMatched)
newPeakList.addRow(copyPeakRow(row));
}
return newPeakList;
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class DuplicateFilterTask method filterDuplicatePeakListRows.
/**
* Filter our duplicate feature list rows.
*
* @param origPeakList the original feature list.
* @param suffix the suffix to apply to the new feature list name.
* @param mzTolerance m/z tolerance.
* @param rtTolerance RT tolerance.
* @param requireSameId must duplicate peaks have the same identities?
* @return the filtered feature list.
*/
private PeakList filterDuplicatePeakListRows(final PeakList origPeakList, final String suffix, final MZTolerance mzTolerance, final RTTolerance rtTolerance, final boolean requireSameId, FilterMode mode) {
final PeakListRow[] peakListRows = origPeakList.getRows();
final int rowCount = peakListRows.length;
RawDataFile[] rawFiles = origPeakList.getRawDataFiles();
// Create the new feature list.
final PeakList newPeakList = new SimplePeakList(origPeakList + " " + suffix, origPeakList.getRawDataFiles());
// sort rows
if (mode.equals(FilterMode.OLD_AVERAGE))
Arrays.sort(peakListRows, new PeakListRowSorter(SortingProperty.Area, SortingDirection.Descending));
else
Arrays.sort(peakListRows, new PeakListRowSorter(SortingProperty.ID, SortingDirection.Ascending));
// filter by average mz and rt
boolean filterByAvgRTMZ = !mode.equals(FilterMode.SINGLE_FEATURE);
// Loop through all feature list rows
processedRows = 0;
int n = 0;
totalRows = rowCount;
for (int firstRowIndex = 0; !isCanceled() && firstRowIndex < rowCount; firstRowIndex++) {
final PeakListRow mainRow = peakListRows[firstRowIndex];
if (mainRow != null) {
// copy first row
PeakListRow firstRow = copyRow(mainRow);
for (int secondRowIndex = firstRowIndex + 1; !isCanceled() && secondRowIndex < rowCount; secondRowIndex++) {
final PeakListRow secondRow = peakListRows[secondRowIndex];
if (secondRow != null) {
// Compare identifications
final boolean sameID = !requireSameId || PeakUtils.compareIdentities(firstRow, secondRow);
boolean sameMZRT = // average or single feature
filterByAvgRTMZ ? checkSameAverageRTMZ(firstRow, secondRow, mzTolerance, rtTolerance) : checkSameSingleFeatureRTMZ(rawFiles, firstRow, secondRow, mzTolerance, rtTolerance);
// Duplicate peaks?
if (sameID && sameMZRT) {
// create consensus row in new filter
if (!mode.equals(FilterMode.OLD_AVERAGE)) {
// copy all detected features of row2 into row1
// to exchange gap-filled against detected features
createConsensusFirstRow(rawFiles, firstRow, secondRow);
}
// second row deleted
n++;
peakListRows[secondRowIndex] = null;
}
}
}
// add to new list
newPeakList.addRow(firstRow);
}
processedRows++;
}
// finalize
if (!isCanceled()) {
// Load previous applied methods.
for (final PeakListAppliedMethod method : origPeakList.getAppliedMethods()) {
newPeakList.addDescriptionOfAppliedTask(method);
}
// Add task description to peakList
newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Duplicate feature list rows filter", parameters));
LOG.info("Removed " + n + " duplicate rows");
}
return newPeakList;
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class KovatsIndexExtractionDialog method addDialogComponents.
@Override
protected void addDialogComponents() {
super.addDialogComponents();
mainPanel.removeAll();
mainPanel.getParent().remove(mainPanel);
ddlKovats = new DelayedDocumentListener(e -> updateKovatsList());
DelayedDocumentListener ddlUpdateChart = new DelayedDocumentListener(e -> updateChart());
newMainPanel = new JPanel(new MigLayout("fill", "[right][grow,fill]", ""));
getContentPane().add(newMainPanel, BorderLayout.SOUTH);
JPanel pnCenter = new JPanel(new BorderLayout());
getContentPane().add(pnCenter, BorderLayout.CENTER);
pnChart = new JPanel(new BorderLayout());
pnCenter.add(pnChart, BorderLayout.CENTER);
Box sizedummy = new Box(BoxLayout.X_AXIS);
sizedummy.setMinimumSize(new Dimension(200, 450));
sizedummy.setPreferredSize(new Dimension(200, 450));
pnChart.add(sizedummy, BorderLayout.CENTER);
// left: Kovats: min max and list
JPanel west = new JPanel(new BorderLayout());
newMainPanel.add(west);
// add min max
JPanel pnKovatsParam = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
west.add(pnKovatsParam, BorderLayout.NORTH);
minc = (IntegerComponent) getComponentForParameter(KovatsIndexExtractionParameters.minKovats);
maxc = (IntegerComponent) getComponentForParameter(KovatsIndexExtractionParameters.maxKovats);
minc.addDocumentListener(ddlKovats);
maxc.addDocumentListener(ddlKovats);
pnKovatsParam.add(new JLabel("Min carbon:"));
pnKovatsParam.add(minc);
pnKovatsParam.add(new JLabel("Max carbon:"));
pnKovatsParam.add(maxc);
// kovats list
JPanel pnKovatsSelect = new JPanel(new BorderLayout());
west.add(pnKovatsSelect, BorderLayout.CENTER);
comboKovats = (MultiChoiceComponent) getComponentForParameter(KovatsIndexExtractionParameters.kovats);
comboKovats.addValueChangeListener(() -> handleKovatsSelectionChange());
pnKovatsSelect.add(comboKovats, BorderLayout.CENTER);
// center: Chart and parameters
JPanel center = new JPanel(new BorderLayout());
newMainPanel.add(center);
// all parameters on peak pick panel
JPanel pnSouth = new JPanel(new BorderLayout());
center.add(pnSouth, BorderLayout.SOUTH);
JPanel pnPeakPick = new JPanel(new MigLayout("", "[right][]", ""));
pnSouth.add(pnPeakPick, BorderLayout.CENTER);
valuesComponent = (StringComponent) getComponentForParameter(KovatsIndexExtractionParameters.pickedKovatsValues);
MZRangeComponent mzc = (MZRangeComponent) getComponentForParameter(KovatsIndexExtractionParameters.mzRange);
RTRangeComponent rtc = (RTRangeComponent) getComponentForParameter(KovatsIndexExtractionParameters.rtRange);
DoubleComponent noisec = (DoubleComponent) getComponentForParameter(KovatsIndexExtractionParameters.noiseLevel);
DoubleComponent edgeRatioC = (DoubleComponent) getComponentForParameter(KovatsIndexExtractionParameters.ratioTopEdge);
valuesComponent.addDocumentListener(new DelayedDocumentListener(e -> kovatsValuesChanged()));
valuesComponent.setLayout(new GridLayout(1, 1));
pnCenter.add(valuesComponent, BorderLayout.SOUTH);
JPanel pnButtonFlow = new JPanel();
pnPeakPick.add(pnButtonFlow, "cell 0 0 2 1");
JButton btnUpdateChart = new JButton("Update chart");
btnUpdateChart.addActionListener(e -> updateChart());
pnButtonFlow.add(btnUpdateChart);
JButton btnPickRT = new JButton("Pick peaks");
btnPickRT.addActionListener(e -> pickRetentionTimes());
pnButtonFlow.add(btnPickRT);
JButton btnSaveFile = new JButton("Save to file");
btnSaveFile.setToolTipText("Save Kovats index file");
btnSaveFile.addActionListener(e -> saveToFile());
pnButtonFlow.add(btnSaveFile);
JButton btnLoad = new JButton("Load");
btnLoad.setToolTipText("Load Kovats index file");
btnLoad.addActionListener(e -> loadFile());
pnButtonFlow.add(btnLoad);
JButton btnCombineFiles = new JButton("Combine files");
btnCombineFiles.setToolTipText("Select multiple Kovats index files to be combined into one");
btnCombineFiles.addActionListener(e -> combineFiles());
pnButtonFlow.add(btnCombineFiles);
// add combo for raw data file
dataFiles = MZmineCore.getProjectManager().getCurrentProject().getDataFiles();
comboDataFileName = new JComboBox<RawDataFile>(dataFiles);
comboDataFileName2 = new JComboBox<RawDataFile>(dataFiles);
cbSecondRaw = new JCheckBox();
initRawDataFileSelection();
pnPeakPick.add(new JLabel("Raw data file(s)"), "cell 0 1");
pnPeakPick.add(comboDataFileName);
cbSecondRaw.addItemListener(e -> useSecondDataFile(cbSecondRaw.isSelected()));
pnPeakPick.add(cbSecondRaw, "cell 0 2");
pnPeakPick.add(comboDataFileName2);
// direct alkane selection < CxH2x+1 >
JPanel pnAlkaneSelect = new JPanel();
Dimension dim = new Dimension(SIZE, SIZE);
JButton btnPrevAlkane = new JButton(iconPrev);
btnPrevAlkane.addActionListener(e -> setMzRangeByAlkane(-1));
btnPrevAlkane.setPreferredSize(dim);
btnPrevAlkane.setMaximumSize(dim);
JButton btnNextAlkane = new JButton(iconNext);
btnNextAlkane.addActionListener(e -> setMzRangeByAlkane(1));
btnNextAlkane.setPreferredSize(dim);
btnNextAlkane.setMaximumSize(dim);
lbCurrentAlkane = new JLabel("");
cbCurrentAlkaneSubH = new JCheckBox("-H");
cbCurrentAlkaneSubH.setSelected(true);
cbCurrentAlkaneSubH.addItemListener(e -> setMzRangeByAlkane(0));
pnAlkaneSelect.add(btnPrevAlkane);
pnAlkaneSelect.add(lbCurrentAlkane);
pnAlkaneSelect.add(btnNextAlkane);
pnAlkaneSelect.add(cbCurrentAlkaneSubH);
pnPeakPick.add(pnAlkaneSelect, "cell 1 3");
pnPeakPick.add(new JLabel("m/z range"), "cell 0 4");
pnPeakPick.add(mzc);
pnPeakPick.add(new JLabel(KovatsIndexExtractionParameters.rtRange.getName()), "cell 0 5");
pnPeakPick.add(rtc);
pnPeakPick.add(new JLabel(KovatsIndexExtractionParameters.noiseLevel.getName()), "cell 0 6");
pnPeakPick.add(noisec);
pnPeakPick.add(new JLabel(KovatsIndexExtractionParameters.ratioTopEdge.getName()), "cell 0 7");
pnPeakPick.add(edgeRatioC);
// add listeners
comboDataFileName.addItemListener(e -> updateChart());
mzc.addDocumentListener(ddlUpdateChart);
rtc.addDocumentListener(ddlUpdateChart);
// show
revalidate();
updateMinimumSize();
pack();
updateChart();
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class KovatsIndexExtractionDialog method initRawDataFileSelection.
/**
* Init raw data selection to last used raw data file or "kovats" or "dro"
*/
private void initRawDataFileSelection() {
if (dataFiles != null && dataFiles.length <= 0)
return;
RawDataFilesSelection select = parameterSet.getParameter(KovatsIndexExtractionParameters.dataFiles).getValue();
RawDataFile[] raw = null;
// set to parameters files - if they exist in this project
if (select != null && select.getMatchingRawDataFiles().length > 0) {
RawDataFile[] exists = Arrays.stream(select.getMatchingRawDataFiles()).filter(r -> Arrays.stream(dataFiles).anyMatch(d -> r.getName().equals(d.getName()))).toArray(RawDataFile[]::new);
if (exists.length > 0)
raw = exists;
}
if (raw == null) {
// find kovats or dro file
// first use all kovats named files and then dro (max 2)
RawDataFile[] kovats = Arrays.stream(dataFiles).filter(d -> d.getName().toLowerCase().contains("kovats")).toArray(RawDataFile[]::new);
RawDataFile[] dro = Arrays.stream(dataFiles).filter(d -> d.getName().toLowerCase().contains("dro")).toArray(RawDataFile[]::new);
// maximum of two files are chosen (0,1,2)
int size = Math.min(2, kovats.length + dro.length);
raw = new RawDataFile[size];
for (int i = 0; i < raw.length; i++) {
if (i < kovats.length)
raw[i] = kovats[i];
else
raw[i] = dro[i - kovats.length];
}
}
if (raw.length > 0) {
selectedDataFile = raw;
comboDataFileName.setSelectedItem(selectedDataFile[0]);
if (raw.length > 1) {
comboDataFileName2.setSelectedItem(selectedDataFile[1]);
}
}
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class SortDataFilesModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
List<RawDataFile> dataFiles = Arrays.asList(parameters.getParameter(SortDataFilesParameters.dataFiles).getValue().getMatchingRawDataFiles());
RawDataTreeModel model = null;
if (project instanceof MZmineProjectImpl) {
model = ((MZmineProjectImpl) project).getRawDataTreeModel();
} else if (MZmineCore.getDesktop() instanceof MainWindow) {
ProjectTree tree = ((MainWindow) MZmineCore.getDesktop()).getMainPanel().getRawDataTree();
model = (RawDataTreeModel) tree.getModel();
}
if (model == null)
throw new MSDKRuntimeException("Cannot find raw data file tree model for sorting. Different MZmine project impl?");
final DefaultMutableTreeNode rootNode = model.getRoot();
// Get all tree nodes that represent selected data files, and remove
// them from
final ArrayList<DefaultMutableTreeNode> selectedNodes = new ArrayList<DefaultMutableTreeNode>();
for (int row = 0; row < rootNode.getChildCount(); row++) {
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) rootNode.getChildAt(row);
Object selectedObject = selectedNode.getUserObject();
if (dataFiles.contains(selectedObject)) {
selectedNodes.add(selectedNode);
}
}
// Get the index of the first selected item
final ArrayList<Integer> positions = new ArrayList<Integer>();
for (DefaultMutableTreeNode node : selectedNodes) {
int nodeIndex = rootNode.getIndex(node);
if (nodeIndex != -1)
positions.add(nodeIndex);
}
if (positions.isEmpty())
return ExitCode.ERROR;
int insertPosition = Collections.min(positions);
// Sort the data files by name
Collections.sort(selectedNodes, new Comparator<DefaultMutableTreeNode>() {
@Override
public int compare(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) {
return o1.getUserObject().toString().compareTo(o2.getUserObject().toString());
}
});
// Reorder the nodes in the tree model
for (DefaultMutableTreeNode node : selectedNodes) {
model.removeNodeFromParent(node);
model.insertNodeInto(node, rootNode, insertPosition);
insertPosition++;
}
return ExitCode.OK;
}
Aggregations