use of net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters in project mzmine2 by mzmine.
the class SpectraIdentificationLipidSearchTask method run.
/**
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
// create mass list for scan
DataPoint[] massList = null;
ArrayList<DataPoint> massListAnnotated = new ArrayList<>();
MassDetector massDetector = null;
ArrayList<String> allCompoundIDs = new ArrayList<>();
// Create a new mass list for MS/MS scan. Check if sprectrum is profile or centroid mode
if (currentScan.getSpectrumType() == MassSpectrumType.CENTROIDED) {
massDetector = new CentroidMassDetector();
CentroidMassDetectorParameters parameters = new CentroidMassDetectorParameters();
CentroidMassDetectorParameters.noiseLevel.setValue(noiseLevel);
massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
} else {
massDetector = new ExactMassDetector();
ExactMassDetectorParameters parameters = new ExactMassDetectorParameters();
ExactMassDetectorParameters.noiseLevel.setValue(noiseLevel);
massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
}
totalSteps = massList.length;
// loop through every peak in mass list
if (getStatus() != TaskStatus.PROCESSING) {
return;
}
// Check if lipids should be modified
if (searchForModifications == true) {
lipidModificationMasses = getLipidModificationMasses(lipidModification);
}
// Calculate how many possible lipids we will try
totalSteps = (((maxChainLength - minChainLength + 1) * (maxDoubleBonds - minDoubleBonds + 1)) * selectedLipids.length);
// Combine Strings
String annotation = "";
// Try all combinations of fatty acid lengths and double bonds
for (int j = 0; j < selectedLipids.length; j++) {
int numberOfAcylChains = selectedLipids[j].getNumberOfAcylChains();
int numberOfAlkylChains = selectedLipids[j].getNumberofAlkyChains();
for (int chainLength = minChainLength; chainLength <= maxChainLength; chainLength++) {
for (int chainDoubleBonds = minDoubleBonds; chainDoubleBonds <= maxDoubleBonds; chainDoubleBonds++) {
for (int i = 0; i < massList.length; i++) {
searchedMass = massList[i].getMZ();
// Task canceled?
if (isCanceled())
return;
// than minimal length, skip this lipid
if (((chainLength > 0) && (chainLength < minChainLength))) {
continue;
}
// doesn't make sense, so let's skip such lipids
if (((chainDoubleBonds > 0) && (chainDoubleBonds > chainLength - 1))) {
continue;
}
// Prepare a lipid instance
LipidIdentity lipidChain = new LipidIdentity(selectedLipids[j], chainLength, chainDoubleBonds, numberOfAcylChains, numberOfAlkylChains);
annotation = findPossibleLipid(lipidChain, searchedMass);
if (annotation != "") {
allCompoundIDs.add(annotation);
massListAnnotated.add(massList[i]);
}
annotation = findPossibleLipidModification(lipidChain, searchedMass);
if (annotation != "") {
allCompoundIDs.add(annotation);
massListAnnotated.add(massList[i]);
}
}
finishedSteps++;
}
}
}
// new mass list
DataPoint[] annotatedMassList = new DataPoint[massListAnnotated.size()];
massListAnnotated.toArray(annotatedMassList);
String[] annotations = new String[annotatedMassList.length];
allCompoundIDs.toArray(annotations);
DataPointsDataSet detectedCompoundsDataset = new DataPointsDataSet("Detected compounds", annotatedMassList);
// Add label generator for the dataset
SpectraDatabaseSearchLabelGenerator labelGenerator = new SpectraDatabaseSearchLabelGenerator(annotations, spectraPlot);
spectraPlot.addDataSet(detectedCompoundsDataset, Color.orange, true, labelGenerator);
spectraPlot.getXYPlot().getRenderer().setSeriesItemLabelGenerator(spectraPlot.getXYPlot().getSeriesCount(), labelGenerator);
spectraPlot.getXYPlot().getRenderer().setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_CENTER, 0.0), true);
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters in project mzmine2 by mzmine.
the class SpectraIdentificationOnlineDatabaseTask method run.
/**
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
// create mass list for scan
DataPoint[] massList = null;
ArrayList<DataPoint> massListAnnotated = new ArrayList<>();
MassDetector massDetector = null;
ArrayList<String> allCompoundIDs = new ArrayList<>();
// Create a new mass list for MS/MS scan. Check if sprectrum is profile or centroid mode
if (currentScan.getSpectrumType() == MassSpectrumType.CENTROIDED) {
massDetector = new CentroidMassDetector();
CentroidMassDetectorParameters parameters = new CentroidMassDetectorParameters();
CentroidMassDetectorParameters.noiseLevel.setValue(noiseLevel);
massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
} else {
massDetector = new ExactMassDetector();
ExactMassDetectorParameters parameters = new ExactMassDetectorParameters();
ExactMassDetectorParameters.noiseLevel.setValue(noiseLevel);
massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
}
numItems = massList.length;
for (int i = 0; i < massList.length; i++) {
// loop through every peak in mass list
if (getStatus() != TaskStatus.PROCESSING) {
return;
}
searchedMass = massList[i].getMZ() - ionType.getAddedMass();
try {
// find candidate compounds
String[] compoundIDs = gateway.findCompounds(searchedMass, mzTolerance, 1, db.getParameterSet());
// Combine strings
String annotation = "";
// max number of compounds to top three for visualization
int counter = 0;
for (int j = 0; !isCanceled() && j < compoundIDs.length; j++) {
final DBCompound compound = gateway.getCompound(compoundIDs[j], db.getParameterSet());
// In case we failed to retrieve data, skip this compound
if (compound == null)
continue;
if (counter < 3) {
int number = counter + 1;
annotation = annotation + " " + number + ". " + compound.getName();
counter++;
}
}
if (annotation != "") {
allCompoundIDs.add(annotation);
massListAnnotated.add(massList[i]);
}
} catch (Exception e) {
e.printStackTrace();
logger.log(Level.WARNING, "Could not connect to " + db, e);
setStatus(TaskStatus.ERROR);
setErrorMessage("Could not connect to " + db + ": " + ExceptionUtils.exceptionToString(e));
return;
}
finishedItems++;
}
// new mass list
DataPoint[] annotatedMassList = new DataPoint[massListAnnotated.size()];
massListAnnotated.toArray(annotatedMassList);
String[] annotations = new String[annotatedMassList.length];
allCompoundIDs.toArray(annotations);
DataPointsDataSet detectedCompoundsDataset = new DataPointsDataSet("Detected compounds", annotatedMassList);
// Add label generator for the dataset
SpectraDatabaseSearchLabelGenerator labelGenerator = new SpectraDatabaseSearchLabelGenerator(annotations, spectraPlot);
spectraPlot.addDataSet(detectedCompoundsDataset, Color.orange, true, labelGenerator);
spectraPlot.getXYPlot().getRenderer().setSeriesItemLabelGenerator(spectraPlot.getXYPlot().getSeriesCount(), labelGenerator);
spectraPlot.getXYPlot().getRenderer().setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_CENTER, 0.0), true);
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters in project mzmine2 by mzmine.
the class SpectraIdentificationSumFormulaTask method run.
/**
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.finest("Starting search for formulas for " + massRange + " Da");
// create mass list for scan
DataPoint[] massList = null;
ArrayList<DataPoint> massListAnnotated = new ArrayList<>();
MassDetector massDetector = null;
ArrayList<String> allCompoundIDs = new ArrayList<>();
// Create a new mass list for MS/MS scan. Check if sprectrum is profile or centroid mode
if (currentScan.getSpectrumType() == MassSpectrumType.CENTROIDED) {
massDetector = new CentroidMassDetector();
CentroidMassDetectorParameters parameters = new CentroidMassDetectorParameters();
CentroidMassDetectorParameters.noiseLevel.setValue(noiseLevel);
massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
} else {
massDetector = new ExactMassDetector();
ExactMassDetectorParameters parameters = new ExactMassDetectorParameters();
ExactMassDetectorParameters.noiseLevel.setValue(noiseLevel);
massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
}
numItems = massList.length;
// loop through every peak in mass list
if (getStatus() != TaskStatus.PROCESSING) {
return;
}
IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
for (int i = 0; i < massList.length; i++) {
massRange = mzTolerance.getToleranceRange((massList[i].getMZ() - ionType.getAddedMass()) / charge);
generator = new MolecularFormulaGenerator(builder, massRange.lowerEndpoint(), massRange.upperEndpoint(), elementCounts);
IMolecularFormula cdkFormula;
String annotation = "";
// create a map to store ResultFormula and relative mass deviation for sorting
Map<Double, String> possibleFormulas = new TreeMap<>();
while ((cdkFormula = generator.getNextFormula()) != null) {
if (isCanceled())
return;
// Mass is ok, so test other constraints
if (checkConstraints(cdkFormula) == true) {
String formula = MolecularFormulaManipulator.getString(cdkFormula);
// calc rel mass deviation
Double relMassDev = ((((//
massList[i].getMZ() - ionType.getAddedMass()) / //
charge) - (//
FormulaUtils.calculateExactMass(MolecularFormulaManipulator.getString(cdkFormula))) / charge) / ((//
massList[i].getMZ() - ionType.getAddedMass()) / charge)) * 1000000;
// write to map
possibleFormulas.put(relMassDev, formula);
}
}
Map<Double, String> treeMap = new TreeMap<>((Comparator<Double>) (o1, o2) -> Double.compare(Math.abs(o1), Math.abs(o2)));
treeMap.putAll(possibleFormulas);
// get top 3
int ctr = 0;
for (Map.Entry<Double, String> entry : treeMap.entrySet()) {
int number = ctr + 1;
if (ctr > 2)
break;
annotation = annotation + number + ". " + entry.getValue() + " Δ " + NumberFormat.getInstance().format(entry.getKey()) + " ppm; ";
ctr++;
if (isCanceled())
return;
}
if (annotation != "") {
allCompoundIDs.add(annotation);
massListAnnotated.add(massList[i]);
}
logger.finest("Finished formula search for " + massRange + " m/z, found " + foundFormulas + " formulas");
}
// new mass list
DataPoint[] annotatedMassList = new DataPoint[massListAnnotated.size()];
massListAnnotated.toArray(annotatedMassList);
String[] annotations = new String[annotatedMassList.length];
allCompoundIDs.toArray(annotations);
DataPointsDataSet detectedCompoundsDataset = new DataPointsDataSet("Detected compounds", annotatedMassList);
// Add label generator for the dataset
SpectraDatabaseSearchLabelGenerator labelGenerator = new SpectraDatabaseSearchLabelGenerator(annotations, spectraPlot);
spectraPlot.addDataSet(detectedCompoundsDataset, Color.orange, true, labelGenerator);
spectraPlot.getXYPlot().getRenderer().setSeriesItemLabelGenerator(spectraPlot.getXYPlot().getSeriesCount(), labelGenerator);
spectraPlot.getXYPlot().getRenderer().setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_CENTER, 0.0), true);
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters in project mzmine2 by mzmine.
the class SpectraIdentificationCustomDatabaseTask method run.
/**
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
// create mass list for scan
DataPoint[] massList = null;
ArrayList<DataPoint> massListAnnotated = new ArrayList<>();
MassDetector massDetector = null;
ArrayList<String> allCompoundIDs = new ArrayList<>();
// Create a new mass list for MS/MS scan. Check if sprectrum is profile or centroid mode
if (currentScan.getSpectrumType() == MassSpectrumType.CENTROIDED) {
massDetector = new CentroidMassDetector();
CentroidMassDetectorParameters parameters = new CentroidMassDetectorParameters();
CentroidMassDetectorParameters.noiseLevel.setValue(noiseLevel);
massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
} else {
massDetector = new ExactMassDetector();
ExactMassDetectorParameters parameters = new ExactMassDetectorParameters();
ExactMassDetectorParameters.noiseLevel.setValue(noiseLevel);
massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
}
numItems = massList.length;
// load custom database
try {
// read database contents in memory
FileReader dbFileReader = new FileReader(dataBaseFile);
databaseValues = CSVParser.parse(dbFileReader, fieldSeparator.charAt(0));
if (ignoreFirstLine)
finishedLines++;
for (; finishedLines < databaseValues.length; finishedLines++) {
if (isCanceled()) {
dbFileReader.close();
return;
}
int numOfColumns = Math.min(fieldOrder.length, databaseValues[finishedLines].length);
String lineName = null;
double lineMZ = 0;
for (int i = 0; i < numOfColumns; i++) {
if (fieldOrder[i] == FieldItem.FIELD_NAME)
lineName = databaseValues[finishedLines][i].toString();
if (fieldOrder[i] == FieldItem.FIELD_MZ)
lineMZ = Double.parseDouble(databaseValues[finishedLines][i].toString());
}
for (int i = 0; i < massList.length; i++) {
// loop through every peak in mass list
if (getStatus() != TaskStatus.PROCESSING) {
return;
}
double searchedMass = massList[i].getMZ();
Range<Double> mzRange = mzTolerance.getToleranceRange(searchedMass);
boolean mzMatches = (lineMZ == 0d) || mzRange.contains(lineMZ);
String annotation = "";
if (mzMatches) {
// calc rel mass deviation
double relMassDev = ((searchedMass - lineMZ) / searchedMass) * 1000000;
logger.finest("Found compound " + lineName + " m/z " + NumberFormat.getInstance().format(searchedMass) + " Δ " + NumberFormat.getInstance().format(relMassDev) + " ppm");
annotation = lineName + " Δ " + NumberFormat.getInstance().format(relMassDev) + " ppm";
}
if (annotation != "") {
allCompoundIDs.add(annotation);
massListAnnotated.add(massList[i]);
}
}
finishedLines++;
}
// close the file reader
dbFileReader.close();
} catch (Exception e) {
logger.log(Level.WARNING, "Could not read file " + dataBaseFile, e);
setStatus(TaskStatus.ERROR);
setErrorMessage(e.toString());
return;
}
// new mass list
DataPoint[] annotatedMassList = new DataPoint[massListAnnotated.size()];
massListAnnotated.toArray(annotatedMassList);
String[] annotations = new String[annotatedMassList.length];
allCompoundIDs.toArray(annotations);
DataPointsDataSet detectedCompoundsDataset = new DataPointsDataSet("Detected compounds", annotatedMassList);
// Add label generator for the dataset
SpectraDatabaseSearchLabelGenerator labelGenerator = new SpectraDatabaseSearchLabelGenerator(annotations, spectraPlot);
spectraPlot.addDataSet(detectedCompoundsDataset, Color.orange, true, labelGenerator);
spectraPlot.getXYPlot().getRenderer().setSeriesItemLabelGenerator(spectraPlot.getXYPlot().getSeriesCount(), labelGenerator);
spectraPlot.getXYPlot().getRenderer().setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_CENTER, 0.0), true);
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters in project mzmine2 by mzmine.
the class LipidSearchTask method searchMsmsFragments.
/**
* This method searches for MS/MS fragments. A mass list for MS2 scans will be used if present. If
* no mass list is present for MS2 scans it will create one using centroid or exact mass detection
* algorithm
*/
private void searchMsmsFragments(PeakListRow row, double lipidIonMass, LipidIdentity lipid) {
MassDetector massDetector = null;
// Check if selected feature has MSMS spectra
if (row.getAllMS2Fragmentations() != null) {
Scan[] msmsScans = row.getAllMS2Fragmentations();
for (Scan msmsScan : msmsScans) {
DataPoint[] massList = null;
// check if MS/MS scan already has a mass list
if (msmsScan.getMassLists().length != 0) {
massList = msmsScan.getMassLists()[0].getDataPoints();
} else {
// Create a new mass list for MS/MS scan. Check if sprectrum is profile or centroid mode
if (msmsScan.getSpectrumType() == MassSpectrumType.CENTROIDED) {
massDetector = new CentroidMassDetector();
CentroidMassDetectorParameters parametersMSMS = new CentroidMassDetectorParameters();
CentroidMassDetectorParameters.noiseLevel.setValue(noiseLevelMSMS);
massList = massDetector.getMassValues(msmsScan, parametersMSMS);
} else {
massDetector = new ExactMassDetector();
ExactMassDetectorParameters parametersMSMS = new ExactMassDetectorParameters();
ExactMassDetectorParameters.noiseLevel.setValue(noiseLevelMSMS);
massList = massDetector.getMassValues(msmsScan, parametersMSMS);
}
}
MSMSLipidTools msmsLipidTools = new MSMSLipidTools();
// check for negative polarity
if (msmsScan.getPolarity() == PolarityType.NEGATIVE) {
// check if lipid class has set negative fragments
String[] fragments = lipid.getLipidClass().getMsmsFragmentsNegativeIonization();
if (fragments.length > 0) {
ArrayList<String> listOfAnnotatedNegativeFragments = new ArrayList<String>();
for (int i = 0; i < massList.length; i++) {
Range<Double> mzTolRangeMSMS = mzToleranceMS2.getToleranceRange(massList[i].getMZ());
String annotatedNegativeFragment = msmsLipidTools.checkForNegativeClassSpecificFragment(mzTolRangeMSMS, row.getPreferredPeakIdentity(), lipidIonMass, fragments);
if (annotatedNegativeFragment.equals("") == false && row.getComment().contains(annotatedNegativeFragment) == false) {
listOfAnnotatedNegativeFragments.add(annotatedNegativeFragment);
}
}
if (listOfAnnotatedNegativeFragments.isEmpty() == false) {
// predict lipid fatty acid composition if possible
ArrayList<String> listOfPossibleFattyAcidCompositions = msmsLipidTools.predictFattyAcidComposition(listOfAnnotatedNegativeFragments, row.getPreferredPeakIdentity(), lipid.getLipidClass().getNumberOfAcylChains());
for (int i = 0; i < listOfPossibleFattyAcidCompositions.size(); i++) {
// Add possible composition to comment
if (row.getComment().equals(null)) {
row.setComment(" " + listOfPossibleFattyAcidCompositions.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
} else {
row.setComment(row.getComment() + ";" + " " + listOfPossibleFattyAcidCompositions.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
}
}
// add class specific fragments
for (int i = 0; i < listOfAnnotatedNegativeFragments.size(); i++) {
if (listOfAnnotatedNegativeFragments.get(i).contains("C") || listOfAnnotatedNegativeFragments.get(i).contains("H") || listOfAnnotatedNegativeFragments.get(i).contains("O")) {
// Add fragment to comment
if (row.getComment().equals(null)) {
row.setComment(" " + listOfAnnotatedNegativeFragments.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
} else {
row.setComment(row.getComment() + ";" + " " + listOfAnnotatedNegativeFragments.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
}
}
}
}
}
}
// check if lipid class has positive fragments
if (msmsScan.getPolarity() == PolarityType.POSITIVE) {
// check if lipid class has set postiev fragments
String[] fragments = lipid.getLipidClass().getMsmsFragmentsPositiveIonization();
if (fragments.length > 0) {
ArrayList<String> listOfAnnotatedPositiveFragments = new ArrayList<String>();
for (int i = 0; i < massList.length; i++) {
Range<Double> mzTolRangeMSMS = mzToleranceMS2.getToleranceRange(massList[i].getMZ());
String annotatedPositiveFragment = msmsLipidTools.checkForPositiveClassSpecificFragment(mzTolRangeMSMS, row.getPreferredPeakIdentity(), lipidIonMass, fragments);
if (annotatedPositiveFragment.equals("") == false && row.getComment().contains(annotatedPositiveFragment) == false) {
listOfAnnotatedPositiveFragments.add(annotatedPositiveFragment);
}
}
// predict lipid fatty acid composition if possible
ArrayList<String> listOfPossibleFattyAcidCompositions = msmsLipidTools.predictFattyAcidComposition(listOfAnnotatedPositiveFragments, row.getPreferredPeakIdentity(), lipid.getLipidClass().getNumberOfAcylChains());
for (int i = 0; i < listOfPossibleFattyAcidCompositions.size(); i++) {
// Add possible composition to comment
if (row.getComment().equals(null)) {
row.setComment(" " + listOfPossibleFattyAcidCompositions.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
} else {
row.setComment(row.getComment() + ";" + " " + listOfPossibleFattyAcidCompositions.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
}
}
// add class specific fragments
for (int i = 0; i < listOfAnnotatedPositiveFragments.size(); i++) {
if (listOfAnnotatedPositiveFragments.get(i).contains("C")) {
// Add fragment to comment
if (row.getComment().equals(null)) {
row.setComment(" " + listOfAnnotatedPositiveFragments.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
} else {
row.setComment(row.getComment() + ";" + " " + listOfAnnotatedPositiveFragments.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
}
}
}
}
}
}
}
}
Aggregations