Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added progress bars to the File Identifier #1524

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2020 Lablicate GmbH.
* Copyright (c) 2016, 2023 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -240,8 +240,7 @@ private void loadMassSpectraFromFile(File file, IProgressMonitor monitor) throws
}
//
for(IScanMSD reference : massSpectraDatabase.getList()) {
if(reference instanceof IRegularLibraryMassSpectrum) {
IRegularLibraryMassSpectrum libraryMassSpectrum = (IRegularLibraryMassSpectrum)reference;
if(reference instanceof IRegularLibraryMassSpectrum libraryMassSpectrum) {
ILibraryInformation libraryInformation = libraryMassSpectrum.getLibraryInformation();
databaseNames.put(libraryInformation.getName(), reference);
databaseCasNumbers.put(libraryInformation.getCasNumber(), reference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ public IProcessingInfo<?> identify(IChromatogramSelectionMSD chromatogramSelecti

IProcessingInfo<?> processingInfo = validate(chromatogramSelection, chromatogramIdentifierSettings);
if(!processingInfo.hasErrorMessages()) {
if(chromatogramIdentifierSettings instanceof IdentifierSettings) {
if(chromatogramIdentifierSettings instanceof IdentifierSettings settings) {
try {
/*
* Settings
*/
IdentifierSettings settings = (IdentifierSettings)chromatogramIdentifierSettings;
boolean useNormalize = settings.isUseNormalizedScan();
CalculationType calculationType = settings.getCalculationType();
boolean usePeaksInsteadOfScans = settings.isUsePeaksInsteadOfScans();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2021 Lablicate GmbH.
* Copyright (c) 2014, 2023 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -35,8 +35,8 @@ public IProcessingInfo<IMassSpectra> identify(List<IScanMSD> massSpectraList, IM
//
try {
MassSpectrumIdentifierSettings massSpectrumIdentifierSettings;
if(identifierSettings instanceof MassSpectrumIdentifierSettings) {
massSpectrumIdentifierSettings = (MassSpectrumIdentifierSettings)identifierSettings;
if(identifierSettings instanceof MassSpectrumIdentifierSettings settings) {
massSpectrumIdentifierSettings = settings;
} else {
massSpectrumIdentifierSettings = PreferenceSupplier.getMassSpectrumIdentifierSettings();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015, 2022 Lablicate GmbH.
* Copyright (c) 2015, 2023 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -66,7 +66,6 @@ public class FileIdentifier {

public IMassSpectra runIdentification(List<IScanMSD> massSpectraList, ILibraryIdentifierSettings fileIdentifierSettings, IProgressMonitor monitor) throws FileNotFoundException {

SubMonitor subMonitor = SubMonitor.convert(monitor, "Running mass spectra identification", 100);
/*
* Pre-filter the mass spectra to identify.
*/
Expand All @@ -91,10 +90,9 @@ public IMassSpectra runIdentification(List<IScanMSD> massSpectraList, ILibraryId
* Load the mass spectra database only if the raw file or its content has changed.
*/
List<String> files = extractFiles(fileIdentifierSettings.getMassSpectraFiles());
Map<String, IMassSpectra> databases = databasesCache.getDatabases(files, subMonitor.split(10));
subMonitor.setWorkRemaining(databases.size() * 100);
Map<String, IMassSpectra> databases = databasesCache.getDatabases(files, monitor);
for(Map.Entry<String, IMassSpectra> database : databases.entrySet()) {
compareMassSpectraAgainstDatabase(massSpectra.getList(), database.getValue().getList(), fileIdentifierSettings, identifier, database.getKey(), subMonitor.split(100, SubMonitor.SUPPRESS_NONE));
compareMassSpectraAgainstDatabase(massSpectra.getList(), database.getValue().getList(), fileIdentifierSettings, identifier, database.getKey(), monitor);
}
//
return massSpectra;
Expand All @@ -112,7 +110,6 @@ public IMassSpectra runIdentification(List<IScanMSD> massSpectraList, ILibraryId
*/
public IPeakIdentificationResults runPeakIdentification(List<? extends IPeakMSD> peaks, PeakIdentifierSettings peakIdentifierSettings, IProcessingInfo<?> processingInfo, IProgressMonitor monitor) throws FileNotFoundException {

SubMonitor subMonitor = SubMonitor.convert(monitor, "Running mass spectra identification", 100);
/*
* Pre-filter the mass spectra to identify.
*/
Expand All @@ -138,10 +135,9 @@ public IPeakIdentificationResults runPeakIdentification(List<? extends IPeakMSD>
* Load the mass spectra database only if the raw file or its content has changed.
*/
List<String> files = extractFiles(peakIdentifierSettings.getMassSpectraFiles());
Map<String, IMassSpectra> databases = databasesCache.getDatabases(files, subMonitor.split(10));
subMonitor.setWorkRemaining(databases.size() * 100);
Map<String, IMassSpectra> databases = databasesCache.getDatabases(files, monitor);
for(Map.Entry<String, IMassSpectra> database : databases.entrySet()) {
comparePeaksAgainstDatabase(peaksToIdentify, database.getValue().getList(), peakIdentifierSettings, identifier, database.getKey(), subMonitor.split(100, SubMonitor.SUPPRESS_NONE));
comparePeaksAgainstDatabase(peaksToIdentify, database.getValue().getList(), peakIdentifierSettings, identifier, database.getKey(), monitor);
}
//
return identificationResults;
Expand Down Expand Up @@ -259,14 +255,6 @@ private static <T> int compareAgainstDatabase(Collection<T> unknownList, Functio
return matched;
}

private static boolean isValidTarget(IComparisonResult comparisonResult, float minMatchFactor, float minReverseMatchFactor) {

if(comparisonResult.getMatchFactor() >= minMatchFactor && comparisonResult.getReverseMatchFactor() >= minReverseMatchFactor) {
return true;
}
return false;
}

private static final class FindMatchingSpectras extends RecursiveTask<Map<IComparisonResult, IScanMSD>> {

private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -332,5 +320,13 @@ private Map<IComparisonResult, IScanMSD> findMatchingReferences() {
}
return results;
}

private static boolean isValidTarget(IComparisonResult comparisonResult, float minMatchFactor, float minReverseMatchFactor) {

if(comparisonResult.getMatchFactor() >= minMatchFactor && comparisonResult.getReverseMatchFactor() >= minReverseMatchFactor) {
return true;
}
return false;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2022 Lablicate GmbH.
* Copyright (c) 2014, 2023 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -30,7 +30,7 @@ public class MassSpectrumIdentifierSettings extends AbstractMassSpectrumIdentifi

@JsonProperty(value = "Library File", defaultValue = "")
@JsonPropertyDescription("Select the library file.")
@FileSettingProperty(dialogType = DialogType.OPEN_DIALOG, extensionNames = {"AMDIS (*.msl)", "NIST (*.msp)", "MassBank (.zip)"}, validExtensions = {"*.msl;*.MSL", "*.msp;*.MSP", "*.zip;*.ZIP"}, onlyDirectory = false)
@FileSettingProperty(dialogType = DialogType.OPEN_DIALOG, extensionNames = {"AMDIS (*.msl)", "NIST (*.msp)"}, validExtensions = {"*.msl;*.MSL", "*.msp;*.MSP"}, onlyDirectory = false)
private File libraryFile;
@JsonProperty(value = "Pre-Optimization", defaultValue = "false")
private boolean usePreOptimization = false;
Expand Down Expand Up @@ -139,4 +139,4 @@ public void setAlternateIdentifierId(String alternateIdentifierId) {

this.alternateIdentifierId = alternateIdentifierId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public IMassSpectra read(File file, IProgressMonitor monitor) throws IOException

List<String> massSpectraData = getMassSpectraData(file);
//
IMassSpectra massSpectra = extractMassSpectra(massSpectraData);
IMassSpectra massSpectra = extractMassSpectra(massSpectraData, monitor);
massSpectra.setConverterId(CONVERTER_ID);
massSpectra.setName(file.getName());
/*
Expand Down Expand Up @@ -300,7 +300,7 @@ private void addMassSpectrumData(StringBuilder builder, List<String> massSpectra
* @param massSpectraData
* @return IMassSpectra
*/
private IMassSpectra extractMassSpectra(List<String> massSpectraData) {
private IMassSpectra extractMassSpectra(List<String> massSpectraData, IProgressMonitor monitor) {

IMassSpectra massSpectra = new MassSpectra();
String referenceIdentifierMarker = org.eclipse.chemclipse.msd.converter.preferences.PreferenceSupplier.getReferenceIdentifierMarker();
Expand All @@ -309,8 +309,10 @@ private IMassSpectra extractMassSpectra(List<String> massSpectraData) {
* Iterates through the saved mass spectrum text data and converts it to
* a mass spectrum.
*/
monitor.beginTask("Extract mass spectra", massSpectraData.size());
for(String massSpectrumData : massSpectraData) {
addMassSpectrum(massSpectra, massSpectrumData, referenceIdentifierMarker, referenceIdentifierPrefix);
monitor.worked(1);
}
return massSpectra;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2022 Lablicate GmbH.
* Copyright (c) 2008, 2023 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -76,7 +76,7 @@ public IMassSpectra read(File file, IProgressMonitor monitor) throws IOException

List<String> massSpectraData = getMassSpectraData(file);
//
IMassSpectra massSpectra = extractMassSpectra(massSpectraData);
IMassSpectra massSpectra = extractMassSpectra(massSpectraData, monitor);
massSpectra.setConverterId(CONVERTER_ID);
massSpectra.setName(file.getName());
/*
Expand Down Expand Up @@ -163,7 +163,7 @@ private void addMassSpectrumData(StringBuilder builder, List<String> massSpectra
* @param massSpectraData
* @return IMassSpectra
*/
private IMassSpectra extractMassSpectra(List<String> massSpectraData) {
private IMassSpectra extractMassSpectra(List<String> massSpectraData, IProgressMonitor monitor) {

IMassSpectra massSpectra = new MassSpectra();
String referenceIdentifierMarker = org.eclipse.chemclipse.msd.converter.preferences.PreferenceSupplier.getReferenceIdentifierMarker();
Expand All @@ -174,8 +174,10 @@ private IMassSpectra extractMassSpectra(List<String> massSpectraData) {
* Iterates through the saved mass spectrum text data and converts it to
* a mass spectrum.
*/
monitor.beginTask("Extract mass spectra", massSpectraData.size());
for(String massSpectrumData : massSpectraData) {
addMassSpectrum(massSpectra, massSpectrumData, referenceIdentifierMarker, referenceIdentifierPrefix);
monitor.worked(1);
}
} else if(massSpectraData.size() == 1) {
/*
Expand Down