use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class ProjectParametersSetupDialog method copyParameterValuesToRawDataFiles.
private void copyParameterValuesToRawDataFiles() {
MZmineProject currentProject = MZmineCore.getProjectManager().getCurrentProject();
// Remove all previous parameters from project
UserParameter<?, ?>[] parameters = currentProject.getParameters();
for (UserParameter<?, ?> parameter : parameters) {
currentProject.removeParameter(parameter);
}
// Add new parameters
parameters = parameterValues.keySet().toArray(new UserParameter[0]);
for (UserParameter<?, ?> parameter : parameters) {
currentProject.addParameter(parameter);
}
// Set values for new parameters
for (int columnIndex = 0; columnIndex < parameterValues.keySet().size(); columnIndex++) {
UserParameter<?, ?> parameter = tablemodelParameterValues.getParameter(columnIndex + 1);
for (int dataFileIndex = 0; dataFileIndex < dataFiles.length; dataFileIndex++) {
RawDataFile file = dataFiles[dataFileIndex];
Object value = tablemodelParameterValues.getValueAt(dataFileIndex, columnIndex + 1);
if (parameter instanceof DoubleParameter) {
Double doubleValue = null;
if (value instanceof Double)
doubleValue = (Double) value;
if (value instanceof String)
doubleValue = Double.parseDouble((String) value);
currentProject.setParameterValue(parameter, file, doubleValue);
}
if (parameter instanceof StringParameter) {
if (value == null)
value = "";
currentProject.setParameterValue(parameter, file, (String) value);
}
if (parameter instanceof ComboParameter) {
if (value == null)
value = "";
currentProject.setParameterValue(parameter, file, (String) value);
}
}
}
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class ProjectParametersSetupDialog method copyParameterValuesFromRawDataFiles.
private void copyParameterValuesFromRawDataFiles() {
MZmineProject currentProject = MZmineCore.getProjectManager().getCurrentProject();
for (int dataFileIndex = 0; dataFileIndex < dataFiles.length; dataFileIndex++) {
RawDataFile file = dataFiles[dataFileIndex];
UserParameter<?, ?>[] parameters = currentProject.getParameters();
// Loop through all parameters defined for this file
for (UserParameter<?, ?> p : parameters) {
// Check if this parameter has been seen before?
Object[] values;
if (!(parameterValues.containsKey(p))) {
// No, initialize a new array of values for this parameter
values = new Object[dataFiles.length];
for (int i = 0; i < values.length; i++) values[i] = p.getValue();
parameterValues.put(p, values);
} else {
values = parameterValues.get(p);
}
// Set value of this parameter for the current raw data file
values[dataFileIndex] = currentProject.getParameterValue(p, file);
}
}
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class ProjectParametersSetupDialog method initComponents.
private void initComponents() {
panelParameterValues = new JPanel(new BorderLayout());
scrollParameterValues = new JScrollPane();
tablemodelParameterValues = new ParameterTableModel(new RawDataFile[0], new Hashtable<UserParameter<?, ?>, Object[]>());
tableParameterValues = new JTable(tablemodelParameterValues);
tableParameterValues.setColumnSelectionAllowed(true);
tableParameterValues.setRowSelectionAllowed(false);
scrollParameterValues.setViewportView(tableParameterValues);
scrollParameterValues.setMinimumSize(new Dimension(100, 100));
scrollParameterValues.setPreferredSize(new Dimension(100, 100));
panelRemoveParameterButton = new JPanel(new FlowLayout(FlowLayout.LEFT));
buttonAddParameter = new JButton("Add new parameter");
buttonAddParameter.addActionListener(this);
buttonImportParameters = new JButton("Import parameters and values...");
buttonImportParameters.addActionListener(this);
buttonRemoveParameter = new JButton("Remove selected parameter");
buttonRemoveParameter.addActionListener(this);
panelRemoveParameterButton.add(buttonAddParameter);
panelRemoveParameterButton.add(buttonImportParameters);
panelRemoveParameterButton.add(buttonRemoveParameter);
panelParameterValues.add(scrollParameterValues, BorderLayout.CENTER);
panelParameterValues.add(panelRemoveParameterButton, BorderLayout.SOUTH);
panelParameterValues.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
panelOKCancelButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
buttonOK = new JButton("OK");
buttonOK.addActionListener(this);
buttonCancel = new JButton("Cancel");
buttonCancel.addActionListener(this);
panelOKCancelButtons.add(buttonOK);
panelOKCancelButtons.add(buttonCancel);
setLayout(new BorderLayout());
add(panelParameterValues, BorderLayout.CENTER);
add(panelOKCancelButtons, BorderLayout.SOUTH);
pack();
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class RansacAlignerSetupDialog method updatePreview.
private void updatePreview() {
PeakList peakListX = (PeakList) peakListsComboX.getSelectedItem();
PeakList peakListY = (PeakList) peakListsComboY.getSelectedItem();
if ((peakListX == null) || (peakListY == null))
return;
// Select the rawDataFile which has more peaks in each peakList
int numPeaks = 0;
RawDataFile file = null;
RawDataFile file2 = null;
for (RawDataFile rfile : peakListX.getRawDataFiles()) {
if (peakListX.getPeaks(rfile).length > numPeaks) {
numPeaks = peakListX.getPeaks(rfile).length;
file = rfile;
}
}
numPeaks = 0;
for (RawDataFile rfile : peakListY.getRawDataFiles()) {
if (peakListY.getPeaks(rfile).length > numPeaks) {
numPeaks = peakListY.getPeaks(rfile).length;
file2 = rfile;
}
}
// Update the parameter set from dialog components
updateParameterSetFromComponents();
// Check the parameter values
ArrayList<String> errorMessages = new ArrayList<String>();
boolean parametersOK = super.parameterSet.checkParameterValues(errorMessages);
if (!parametersOK) {
StringBuilder message = new StringBuilder("Please check the parameter settings:\n\n");
for (String m : errorMessages) {
message.append(m);
message.append("\n");
}
MZmineCore.getDesktop().displayMessage(this, message.toString());
return;
}
// Ransac Alignment
Vector<AlignStructMol> list = this.getVectorAlignment(peakListX, peakListY, file, file2);
RANSAC ransac = new RANSAC(super.parameterSet);
ransac.alignment(list);
// Plot the result
this.chart.removeSeries();
this.chart.addSeries(list, peakListX.getName() + " vs " + peakListY.getName(), super.parameterSet.getParameter(RansacAlignerParameters.Linear).getValue());
this.chart.printAlignmentChart(peakListX.getName() + " RT", peakListY.getName() + " RT");
}
use of net.sf.mzmine.datamodel.RawDataFile in project mzmine2 by mzmine.
the class RansacAlignerTask method run.
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Running Ransac aligner");
// twice, first for score calculation, second for actual alignment.
for (int i = 0; i < peakLists.length; i++) {
totalRows += peakLists[i].getNumberOfRows() * 2;
}
// Collect all data files
List<RawDataFile> allDataFiles = new ArrayList<RawDataFile>();
for (PeakList peakList : peakLists) {
for (RawDataFile dataFile : peakList.getRawDataFiles()) {
// Each data file can only have one column in aligned feature list
if (allDataFiles.contains(dataFile)) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Cannot run alignment, because file " + dataFile + " is present in multiple feature lists");
return;
}
allDataFiles.add(dataFile);
}
}
// Create a new aligned feature list
alignedPeakList = new SimplePeakList(peakListName, allDataFiles.toArray(new RawDataFile[0]));
// Iterate source feature lists
for (PeakList peakList : peakLists) {
HashMap<PeakListRow, PeakListRow> alignmentMapping = this.getAlignmentMap(peakList);
PeakListRow[] allRows = peakList.getRows();
// Align all rows using mapping
for (PeakListRow row : allRows) {
PeakListRow targetRow = alignmentMapping.get(row);
// If we have no mapping for this row, add a new one
if (targetRow == null) {
targetRow = new SimplePeakListRow(newRowID);
newRowID++;
alignedPeakList.addRow(targetRow);
}
// Add all peaks from the original row to the aligned row
for (RawDataFile file : row.getRawDataFiles()) {
targetRow.addPeak(file, row.getPeak(file));
}
// Add all non-existing identities from the original row to the
// aligned row
PeakUtils.copyPeakListRowProperties(row, targetRow);
processedRows++;
}
}
// Next feature list
// Add new aligned feature list to the project
project.addPeakList(alignedPeakList);
// Edit by Aleksandr Smirnov
PeakListRow row = alignedPeakList.getRow(1);
double alignedRetTime = row.getAverageRT();
for (Feature peak : row.getPeaks()) {
double retTimeDelta = alignedRetTime - peak.getRT();
RawDataFile dataFile = peak.getDataFile();
SortedMap<Double, Double> chromatogram = new TreeMap<>();
for (int scan : peak.getScanNumbers()) {
DataPoint dataPoint = peak.getDataPoint(scan);
double retTime = dataFile.getScan(scan).getRetentionTime() + retTimeDelta;
if (dataPoint != null)
chromatogram.put(retTime, dataPoint.getIntensity());
}
}
// End of Edit
// Add task description to peakList
alignedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Ransac aligner", parameters));
logger.info("Finished RANSAC aligner");
setStatus(TaskStatus.FINISHED);
}
Aggregations