use of net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan in project mzmine2 by mzmine.
the class ExportScansTask method exportmzML.
/**
* Export the chromatogram - mzML format
*
* @throws IOException if there are i/o problems.
*/
public void exportmzML() throws MSDKException {
// Initialize objects
SimpleRawDataFile msdkRawFile = new SimpleRawDataFile("MZmine 2 mzML export", Optional.empty(), FileType.MZML);
for (Scan scan : scans) {
MsScan MSDKscan = new MZmineToMSDKMsScan(scan);
msdkRawFile.addScan(MSDKscan);
}
// Actually write to disk
MzMLFileExportMethod method = new MzMLFileExportMethod(msdkRawFile, exportFile, MzMLCompressionType.ZLIB, MzMLCompressionType.ZLIB);
method.execute();
}
use of net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan in project mzmine2 by mzmine.
the class SiriusThread method run.
@Override
public void run() {
List<MsSpectrum> ms1list = new ArrayList<>(), ms2list = new ArrayList<>();
try {
Scan ms1Scan = peakListRow.getBestPeak().getRepresentativeScan();
Collection<Scan> top10ms2Scans = ScanUtils.selectBestMS2Scans(peakListRow, massListName, 10);
// Convert to MSDK data model
ms1list.add(new MZmineToMSDKMsScan(ms1Scan));
for (Scan s : top10ms2Scans) {
ms2list.add(new MZmineToMSDKMsScan(s));
}
} catch (MissingMassListException f) {
releaseResources();
task.remoteCancel("Scan does not have requested Mass List name [" + massListName + "]");
return;
}
FormulaConstraints constraints = ConstraintsGenerator.generateConstraint(range);
IonType siriusIon = IonTypeUtil.createIonType(ionType.toString());
List<IonAnnotation> siriusResults = null;
SiriusIdentificationMethod siriusMethod = null;
/*
* Code block below gives SiriusMethod specific amount of time to be executed, if it expires ->
* log error and continue
*/
try {
final SiriusIdentificationMethod method = new SiriusIdentificationMethod(ms1list, ms2list, peakListRow.getAverageMZ(), siriusIon, siriusCandidates, constraints, deviationPpm);
// On some spectra it may never stop (halting problem), that's why interruptable thread is
// used
final Future<List<IonAnnotation>> f = service.submit(() -> {
return method.execute();
});
siriusResults = f.get(siriusTimer, TimeUnit.SECONDS);
siriusMethod = method;
if (ms2list.isEmpty()) {
/* If no MSMS spectra - add sirius results */
addSiriusCompounds(siriusResults, peakListRow, siriusCandidates);
} else {
/* Initiate FingerId processing */
Ms2Experiment experiment = siriusMethod.getExperiment();
for (int index = 0; index < siriusCandidates; index++) {
SiriusIonAnnotation annotation = (SiriusIonAnnotation) siriusResults.get(index);
try {
FingerIdWebMethodTask task = new FingerIdWebMethodTask(annotation, experiment, fingeridCandidates, peakListRow);
MZmineCore.getTaskController().addTask(task, TaskPriority.NORMAL);
Thread.sleep(1000);
} catch (InterruptedException interrupt) {
logger.error("Processing of FingerWebMethods were interrupted");
/* If interrupted, store last item */
List<IonAnnotation> lastItem = new LinkedList<>();
lastItem.add(annotation);
addSiriusCompounds(lastItem, peakListRow, 1);
}
}
}
} catch (InterruptedException | TimeoutException ie) {
logger.error("Timeout on Sirius method expired, abort. Row id = {}", peakListRow.getID());
} catch (ExecutionException ce) {
logger.error("Concurrency error during Sirius method. Row id = {}", peakListRow.getID());
} finally {
// Do not forget to release resources!
releaseResources();
}
}
use of net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan in project mzmine2 by mzmine.
the class ADAP3DTask method run.
/**
* @see Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Started ADAP3D on " + dataFile);
List<Scan> selectedScans = Arrays.asList(scanSelection.getMatchingScans(dataFile));
// Check if we have any scans
if (selectedScans.size() == 0) {
setStatus(TaskStatus.ERROR);
setErrorMessage("No scans match the selected criteria");
return;
}
// Check if the scans are properly ordered by RT
double prevRT = Double.NEGATIVE_INFINITY;
for (Scan s : selectedScans) {
if (s.getRetentionTime() < prevRT) {
setStatus(TaskStatus.ERROR);
final String msg = "Retention time of scan #" + s.getScanNumber() + " is smaller then the retention time of the previous scan." + " Please make sure you only use scans with increasing retention times." + " You can restrict the scan numbers in the parameters, or you can use the Crop filter module";
setErrorMessage(msg);
return;
}
prevRT = s.getRetentionTime();
}
// Run MSDK module
MZmineToMSDKRawDataFile msdkRawDataFile = new MZmineToMSDKRawDataFile(dataFile);
Predicate<MsScan> scanSelectionPredicate = scan -> selectedScans.contains(((MZmineToMSDKMsScan) scan).getMzmineScan());
msdkADAP3DMethod = new ADAP3DFeatureDetectionMethod(msdkRawDataFile, scanSelectionPredicate, new ADAP3DFeatureDetectionParameters());
List<Feature> features = null;
try {
if (isCanceled())
return;
features = msdkADAP3DMethod.execute();
if (isCanceled())
return;
} catch (Exception e) {
e.printStackTrace();
setStatus(TaskStatus.ERROR);
setErrorMessage("Error in ADAP3D: " + e.getMessage());
}
if (features == null)
features = new ArrayList<>(0);
logger.info("ADAP3D detected " + features.size() + " features in " + dataFile + ", converting to MZmine peaklist");
// Create new MZmine 2 feature list
SimplePeakList newPeakList = new SimplePeakList(dataFile + " " + suffix, dataFile);
int rowId = 1;
for (Feature msdkFeature : features) {
if (isCanceled())
return;
SimpleFeature mzmineFeature = new SimpleFeature(dataFile, FeatureStatus.DETECTED, msdkFeature);
PeakListRow row = new SimplePeakListRow(rowId);
row.addPeak(dataFile, mzmineFeature);
newPeakList.addRow(row);
rowId++;
}
// Add new peaklist to the project
project.addPeakList(newPeakList);
// Add quality parameters to peaks
QualityParameters.calculateQualityParameters(newPeakList);
setStatus(TaskStatus.FINISHED);
logger.info("Finished ADAP3D feature detection on " + dataFile);
}
Aggregations