use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.
the class AddAdductsAction method actionPerformed.
@Override
public void actionPerformed(final ActionEvent e) {
// Parent component.
final AdductsComponent parent = (AdductsComponent) SwingUtilities.getAncestorOfClass(AdductsComponent.class, (Component) e.getSource());
if (parent != null) {
// Show dialog.
final ParameterSet parameters = new AddAdductParameters();
if (parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true) == ExitCode.OK) {
// Create new adduct.
final AdductType adduct = new AdductType(parameters.getParameter(AddAdductParameters.NAME).getValue(), parameters.getParameter(AddAdductParameters.MASS_DIFFERENCE).getValue());
// Add to list of choices (if not already present).
final Collection<AdductType> choices = new ArrayList<AdductType>(Arrays.asList((AdductType[]) parent.getChoices()));
if (!choices.contains(adduct)) {
choices.add(adduct);
parent.setChoices(choices.toArray(new AdductType[choices.size()]));
}
}
}
}
use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.
the class MzTabImportTask method importRawDataFiles.
private SortedMap<Integer, RawDataFile> importRawDataFiles(MZTabFile mzTabFile) throws Exception {
SortedMap<Integer, MsRun> msrun = mzTabFile.getMetadata().getMsRunMap();
SortedMap<Integer, RawDataFile> rawDataFiles = new TreeMap<>();
// If we are importing files, let's run RawDataImportModule
if (importRawFiles) {
List<File> filesToImport = new ArrayList<>();
for (Entry<Integer, MsRun> entry : msrun.entrySet()) {
File fileToImport = new File(entry.getValue().getLocation().getPath());
if (fileToImport.exists() && fileToImport.canRead())
filesToImport.add(fileToImport);
else {
// Check if the raw file exists in the same folder as the mzTab file
File checkFile = new File(inputFile.getParentFile(), fileToImport.getName());
if (checkFile.exists() && checkFile.canRead())
filesToImport.add(checkFile);
else {
// Append .gz & check again if file exists as a workaround to .gz not getting preserved
// when .mzML.gz importing
checkFile = new File(inputFile.getParentFile(), fileToImport.getName() + ".gz");
if (checkFile.exists() && checkFile.canRead())
filesToImport.add(checkFile);
else {
// One more level of checking, appending .zip & checking as a workaround
checkFile = new File(inputFile.getParentFile(), fileToImport.getName() + ".zip");
if (checkFile.exists() && checkFile.canRead())
filesToImport.add(checkFile);
}
}
}
}
RawDataImportModule RDI = MZmineCore.getModuleInstance(RawDataImportModule.class);
ParameterSet rdiParameters = RDI.getParameterSetClass().newInstance();
rdiParameters.getParameter(RawDataImportParameters.fileNames).setValue(filesToImport.toArray(new File[0]));
synchronized (underlyingTasks) {
RDI.runModule(project, rdiParameters, underlyingTasks);
}
if (underlyingTasks.size() > 0) {
MZmineCore.getTaskController().addTasks(underlyingTasks.toArray(new Task[0]));
}
// Wait until all raw data file imports have completed
while (true) {
if (isCanceled())
return null;
boolean tasksFinished = true;
for (Task task : underlyingTasks) {
if ((task.getStatus() == TaskStatus.WAITING) || (task.getStatus() == TaskStatus.PROCESSING))
tasksFinished = false;
}
if (tasksFinished)
break;
Thread.sleep(1000);
}
/*
* // Sort raw data files based on order in mzTab file MainWindow mainWindow = (MainWindow)
* MZmineCore.getDesktop(); ProjectTree rawDataTree = mainWindow.getMainPanel()
* .getRawDataTree(); final RawDataTreeModel treeModel = ((MZmineProjectImpl)
* project).getRawDataTreeModel(); final DefaultMutableTreeNode rootNode =
* treeModel.getRoot(); int[] selectedRows = new int[rootNode.getChildCount()]; for (int i =
* 1; i < rootNode.getChildCount() + 1; i++) { selectedRows[i - 1] = i; } final
* ArrayList<DefaultMutableTreeNode> selectedNodes = new ArrayList<DefaultMutableTreeNode>();
* for (int row : selectedRows) { TreePath path = rawDataTree.getPathForRow(row);
* DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) path
* .getLastPathComponent(); selectedNodes.add(selectedNode); }
*
* // Reorder the nodes in the tree model based on order in mzTab // file int fileCounter = 0;
* for (Entry<Integer, MsRun> entry : msrun.entrySet()) { fileCounter++; File f = new
* File(entry.getValue().getLocation().getPath()); for (DefaultMutableTreeNode node :
* selectedNodes) { if (node.toString().equals(f.getName())) {
* treeModel.removeNodeFromParent(node); treeModel.insertNodeInto(node, rootNode, fileCounter
* - 1); } } }
*/
} else {
finishedPercentage = 0.5;
}
// Find a matching RawDataFile for each MsRun entry
for (Entry<Integer, MsRun> entry : msrun.entrySet()) {
String rawFileName = new File(entry.getValue().getLocation().getPath()).getName();
RawDataFile rawDataFile = null;
// Check if we already have a RawDataFile of that name
for (RawDataFile f : project.getDataFiles()) {
if (f.getName().equals(rawFileName)) {
rawDataFile = f;
break;
}
}
// If no data file of that name exists, create a dummy one
if (rawDataFile == null) {
RawDataFileWriter writer = MZmineCore.createNewFile(rawFileName);
rawDataFile = writer.finishWriting();
project.addFile(rawDataFile);
}
// Save a reference to the new raw data file
rawDataFiles.put(entry.getKey(), rawDataFile);
}
return rawDataFiles;
}
use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.
the class SiriusExportModule method exportSinglePeakList.
public static void exportSinglePeakList(PeakListRow row) {
try {
ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(SiriusExportModule.class);
ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
if (exitCode != ExitCode.OK)
return;
// Open file
final SiriusExportTask task = new SiriusExportTask(parameters);
task.runSingleRow(row);
} catch (Exception e) {
e.printStackTrace();
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error while exporting feature to SIRIUS: " + ExceptionUtils.exceptionToString(e));
}
}
use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.
the class SiriusExportModule method exportSingleRows.
public static void exportSingleRows(PeakListRow[] row) {
try {
ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(SiriusExportModule.class);
ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
if (exitCode != ExitCode.OK)
return;
// Open file
final SiriusExportTask task = new SiriusExportTask(parameters);
task.runSingleRows(row);
} catch (Exception e) {
e.printStackTrace();
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error while exporting feature to SIRIUS: " + ExceptionUtils.exceptionToString(e));
}
}
use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.
the class DeconvolutionModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull final ParameterSet parameters, @Nonnull final Collection<Task> tasks) {
PeakList[] peakLists = parameters.getParameter(DeconvolutionParameters.PEAK_LISTS).getValue().getMatchingPeakLists();
// function to calculate center mz
CenterFunction mzCenterFunction = parameters.getParameter(DeconvolutionParameters.MZ_CENTER_FUNCTION).getValue();
// use a LOG weighted, noise corrected, maximum weight capped function
if (mzCenterFunction.getMeasure().equals(CenterMeasure.AUTO)) {
// data point with lowest intensity
// weight = LOG(value) - LOG(noise) (maxed to maxWeight)
double noise = Arrays.stream(peakLists).flatMap(pkl -> Arrays.stream(pkl.getRows())).map(r -> r.getPeaks()[0]).mapToDouble(peak -> peak.getRawDataPointsIntensityRange().lowerEndpoint()).filter(v -> v != 0).min().orElse(0);
// maxWeight 4 corresponds to a linear range of 4 orders of magnitude
// everything higher than this will be capped to this weight
// do not overestimate influence of very high data points on mass accuracy
double maxWeight = 4;
// use a LOG weighted, noise corrected, maximum weight capped function
mzCenterFunction = new CenterFunction(CenterMeasure.AVG, Weighting.LOG10, noise, maxWeight);
}
for (final PeakList peakList : peakLists) {
tasks.add(new DeconvolutionTask(project, peakList, parameters, mzCenterFunction));
}
return ExitCode.OK;
}
Aggregations