use of net.sf.mzmine.project.impl.MZmineProjectImpl in project mzmine2 by mzmine.
the class SimplePeakList method removeRow.
/**
* @see net.sf.mzmine.datamodel.PeakList#removeRow(net.sf.mzmine.datamodel.PeakListRow)
*/
@Override
public void removeRow(PeakListRow row) {
peakListRows.remove(row);
// We have to update the project tree model
MZmineProjectImpl project = (MZmineProjectImpl) MZmineCore.getProjectManager().getCurrentProject();
PeakListTreeModel treeModel = project.getPeakListTreeModel();
treeModel.removeObject(row);
updateMaxIntensity();
}
use of net.sf.mzmine.project.impl.MZmineProjectImpl in project mzmine2 by mzmine.
the class MassDetectionTask method run.
/**
* @see Runnable#run()
*/
public void run() {
// make arrays to contain everything you need
ArrayList<Integer> pointsInScans = new ArrayList<>();
ArrayList<Double> allMZ = new ArrayList<>();
ArrayList<Double> allIntensities = new ArrayList<>();
// idecies of full mass list where scan starts?
ArrayList<Integer> startIndex = new ArrayList<>();
ArrayList<Double> scanAcquisitionTime = new ArrayList<>();
// XCMS needs this one
ArrayList<Double> totalIntensity = new ArrayList<>();
double curTotalIntensity;
int lastPointCount = 0;
startIndex.add(0);
try {
setStatus(TaskStatus.PROCESSING);
logger.info("Started mass detector on " + dataFile);
final Scan[] scans = scanSelection.getMatchingScans(dataFile);
totalScans = scans.length;
// Process scans one by one
for (Scan scan : scans) {
if (isCanceled())
return;
MassDetector detector = massDetector.getModule();
DataPoint[] mzPeaks = detector.getMassValues(scan, massDetector.getParameterSet());
SimpleMassList newMassList = new SimpleMassList(name, scan, mzPeaks);
// Add new mass list to the scan
scan.addMassList(newMassList);
if (this.saveToCDF) {
curTotalIntensity = 0;
for (int a = 0; a < mzPeaks.length; a++) {
DataPoint curMzPeak = mzPeaks[a];
allMZ.add(curMzPeak.getMZ());
allIntensities.add(curMzPeak.getIntensity());
curTotalIntensity += curMzPeak.getIntensity();
}
scanAcquisitionTime.add(scan.getRetentionTime());
pointsInScans.add(0);
startIndex.add(mzPeaks.length + lastPointCount);
totalIntensity.add(curTotalIntensity);
lastPointCount = mzPeaks.length + lastPointCount;
}
processedScans++;
}
// Update the GUI with all new mass lists
MZmineProjectImpl project = (MZmineProjectImpl) MZmineCore.getProjectManager().getCurrentProject();
final RawDataTreeModel treeModel = project.getRawDataTreeModel();
treeModel.updateGUIWithNewObjects();
;
if (this.saveToCDF) {
// ************** write mass list *******************************
final String outFileNamePath = outFilename.getPath();
logger.info("Saving mass detector results to netCDF file " + outFileNamePath);
NetcdfFileWriter writer = NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf3, outFileNamePath, null);
Dimension dim_massValues = writer.addDimension(null, "mass_values", allMZ.size());
Dimension dim_intensityValues = writer.addDimension(null, "intensity_values", allIntensities.size());
Dimension dim_scanIndex = writer.addDimension(null, "scan_index", startIndex.size() - 1);
Dimension dim_scanAcquisitionTime = writer.addDimension(null, "scan_acquisition_time", scanAcquisitionTime.size());
Dimension dim_totalIntensity = writer.addDimension(null, "total_intensity", totalIntensity.size());
Dimension dim_pointsInScans = writer.addDimension(null, "point_count", pointsInScans.size());
// add dimensions to list
List<Dimension> dims = new ArrayList<>();
dims.add(dim_massValues);
dims.add(dim_intensityValues);
dims.add(dim_scanIndex);
dims.add(dim_scanAcquisitionTime);
dims.add(dim_totalIntensity);
dims.add(dim_pointsInScans);
// make the variables that contain the actual data I think.
Variable var_massValues = writer.addVariable(null, "mass_values", DataType.DOUBLE, "mass_values");
Variable var_intensityValues = writer.addVariable(null, "intensity_values", DataType.DOUBLE, "intensity_values");
Variable var_scanIndex = writer.addVariable(null, "scan_index", DataType.INT, "scan_index");
Variable var_scanAcquisitionTime = writer.addVariable(null, "scan_acquisition_time", DataType.DOUBLE, "scan_acquisition_time");
Variable var_totalIntensity = writer.addVariable(null, "total_intensity", DataType.DOUBLE, "total_intensity");
Variable var_pointsInScans = writer.addVariable(null, "point_count", DataType.INT, "point_count");
var_massValues.addAttribute(new Attribute("units", "M/Z"));
var_intensityValues.addAttribute(new Attribute("units", "Arbitrary Intensity Units"));
var_scanIndex.addAttribute(new Attribute("units", "index"));
var_scanAcquisitionTime.addAttribute(new Attribute("units", "seconds"));
var_totalIntensity.addAttribute(new Attribute("units", "Arbitrary Intensity Units"));
var_pointsInScans.addAttribute(new Attribute("units", "count"));
var_massValues.addAttribute(new Attribute("scale_factor", 1.0));
var_intensityValues.addAttribute(new Attribute("scale_factor", 1.0));
var_scanIndex.addAttribute(new Attribute("scale_factor", 1.0));
var_scanAcquisitionTime.addAttribute(new Attribute("scale_factor", 1.0));
var_totalIntensity.addAttribute(new Attribute("scale_factor", 1.0));
var_pointsInScans.addAttribute(new Attribute("scale_factor", 1.0));
// create file
writer.create();
ArrayDouble.D1 arr_massValues = new ArrayDouble.D1(dim_massValues.getLength());
ArrayDouble.D1 arr_intensityValues = new ArrayDouble.D1(dim_intensityValues.getLength());
ArrayDouble.D1 arr_scanIndex = new ArrayDouble.D1(dim_scanIndex.getLength());
ArrayDouble.D1 arr_scanAcquisitionTime = new ArrayDouble.D1(dim_scanAcquisitionTime.getLength());
ArrayDouble.D1 arr_totalIntensity = new ArrayDouble.D1(dim_totalIntensity.getLength());
ArrayDouble.D1 arr_pointsInScans = new ArrayDouble.D1(dim_pointsInScans.getLength());
for (int i = 0; i < allMZ.size(); i++) {
arr_massValues.set(i, allMZ.get(i));
arr_intensityValues.set(i, allIntensities.get(i));
}
int i = 0;
for (; i < scanAcquisitionTime.size(); i++) {
arr_scanAcquisitionTime.set(i, scanAcquisitionTime.get(i) * 60);
arr_pointsInScans.set(i, pointsInScans.get(i));
arr_scanIndex.set(i, startIndex.get(i));
arr_totalIntensity.set(i, totalIntensity.get(i));
}
// arr_scanIndex.set(i,startIndex.get(i));
// For tiny test file
// arr_intensityValues .set(0,200);
// arr_scanIndex .set(0,0);
// arr_scanAcquisitionTime .set(0,10);
// arr_totalIntensity .set(0,200);
// arr_pointsInScans .set(0,0);
// arr_intensityValues .set(1,300);
// arr_scanIndex .set(1,1);
// arr_scanAcquisitionTime .set(1,20);
// arr_totalIntensity .set(1,300);
// arr_pointsInScans .set(1,0);
writer.write(var_massValues, arr_massValues);
writer.write(var_intensityValues, arr_intensityValues);
writer.write(var_scanIndex, arr_scanIndex);
writer.write(var_scanAcquisitionTime, arr_scanAcquisitionTime);
writer.write(var_totalIntensity, arr_totalIntensity);
writer.write(var_pointsInScans, arr_pointsInScans);
writer.close();
}
} catch (Exception e) {
e.printStackTrace();
setErrorMessage(e.getMessage());
setStatus(TaskStatus.ERROR);
}
setStatus(TaskStatus.FINISHED);
logger.info("Finished mass detector on " + dataFile);
}
use of net.sf.mzmine.project.impl.MZmineProjectImpl in project mzmine2 by mzmine.
the class ProjectCloseModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
int selectedValue = JOptionPane.showInternalConfirmDialog(MZmineCore.getDesktop().getMainWindow().getContentPane(), "Are you sure you want to close the current project?", "Close project", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (selectedValue != JOptionPane.YES_OPTION)
return ExitCode.CANCEL;
// Close all windows related to previous project
GUIUtils.closeAllWindows();
// Create a new, empty project
MZmineProject newProject = new MZmineProjectImpl();
// Replace the current project with the new one
ProjectManager projectManager = MZmineCore.getProjectManager();
projectManager.setCurrentProject(newProject);
// Ask the garbage collector to free the previously used memory
System.gc();
logger.info("Project closed.");
return ExitCode.OK;
}
use of net.sf.mzmine.project.impl.MZmineProjectImpl in project mzmine2 by mzmine.
the class ProjectOpeningTask method run.
/**
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
try {
// Check if existing raw data files are present
ProjectManager projectManager = MZmineCore.getProjectManager();
if (projectManager.getCurrentProject().getDataFiles().length > 0) {
int dialogResult = JOptionPane.showConfirmDialog(null, "Loading the project will replace the existing raw data files and feature lists. Do you want to proceed?", "Warning", JOptionPane.YES_NO_OPTION);
if (dialogResult != JOptionPane.YES_OPTION) {
cancel();
return;
}
}
logger.info("Started opening project " + openFile);
setStatus(TaskStatus.PROCESSING);
// Create a new project
newProject = new MZmineProjectImpl();
newProject.setProjectFile(openFile);
// Close all windows related to previous project
GUIUtils.closeAllWindows();
// Replace the current project with the new one
projectManager.setCurrentProject(newProject);
// Open the ZIP file
ZipFile zipFile = new ZipFile(openFile);
// Get total uncompressed size
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
totalBytes += entry.getSize();
}
final Pattern rawFilePattern = Pattern.compile("Raw data file #([\\d]+) (.*)\\.xml$");
final Pattern scansFilePattern = Pattern.compile("Raw data file #([\\d]+) (.*)\\.scans$");
final Pattern peakListPattern = Pattern.compile("Peak list #([\\d]+) (.*)\\.xml$");
boolean versionInformationLoaded = false;
// Iterate over the entries and read them
entries = zipFile.entries();
while (entries.hasMoreElements()) {
if (isCanceled()) {
zipFile.close();
return;
}
ZipEntry entry = entries.nextElement();
String entryName = entry.getName();
cis = new CountingInputStream(zipFile.getInputStream(entry));
// Load version
if (entryName.equals(ProjectSavingTask.VERSION_FILENAME)) {
loadVersion(cis);
versionInformationLoaded = true;
}
// Load configuration
if (entryName.equals(ProjectSavingTask.CONFIG_FILENAME))
loadConfiguration(cis);
// Load user parameters
if (entryName.equals(ProjectSavingTask.PARAMETERS_FILENAME)) {
loadUserParameters(cis);
}
// Load a raw data file
final Matcher rawFileMatcher = rawFilePattern.matcher(entryName);
if (rawFileMatcher.matches()) {
final String fileID = rawFileMatcher.group(1);
final String fileName = rawFileMatcher.group(2);
loadRawDataFile(cis, fileID, fileName);
}
// Load the scan data of a raw data file
final Matcher scansFileMatcher = scansFilePattern.matcher(entryName);
if (scansFileMatcher.matches()) {
final String fileID = scansFileMatcher.group(1);
final String fileName = scansFileMatcher.group(2);
loadScansFile(cis, fileID, fileName);
}
// Load a feature list
final Matcher peakListMatcher = peakListPattern.matcher(entryName);
if (peakListMatcher.matches()) {
final String peakListName = peakListMatcher.group(2);
loadPeakList(cis, peakListName);
}
// Close the ZIP entry
cis.close();
// Add the uncompressed entry size finishedBytes
synchronized (this) {
finishedBytes += entry.getSize();
cis = null;
}
}
// Finish and close the project ZIP file
zipFile.close();
if (!versionInformationLoaded) {
throw new IOException("This file is not valid MZmine 2 project. It does not contain version information.");
}
// Final check for cancel
if (isCanceled())
return;
logger.info("Finished opening project " + openFile);
setStatus(TaskStatus.FINISHED);
// add to last loaded projects
MZmineCore.getConfiguration().getLastProjectsParameter().addFile(openFile);
} catch (Throwable e) {
// SAXException which can be safely ignored
if (isCanceled())
return;
setStatus(TaskStatus.ERROR);
e.printStackTrace();
setErrorMessage("Failed opening project: " + ExceptionUtils.exceptionToString(e));
}
}
use of net.sf.mzmine.project.impl.MZmineProjectImpl 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