use of de.ipbhalle.metfraglib.interfaces.IPeak in project MetFragRelaunched by ipb-halle.
the class SimulateSpectrumHDX method generateDeuteratedSpectrumNegative.
/**
* @param candidate
* @return
* @throws AtomTypeNotKnownFromInputListException
* @throws Exception
*/
public static double[][] generateDeuteratedSpectrumNegative(ICandidate candidate, int method) throws AtomTypeNotKnownFromInputListException, Exception {
int numberPositions = searchForDeuteriumExchangeablePositions((TopDownBitArrayPrecursor) candidate.getPrecursorMolecule()).length;
HDTopDownBitArrayPrecursor preHDX = new HDTopDownBitArrayPrecursor(candidate.getImplicitHydrogenAtomContainer(), (byte) numberPositions);
preHDX.preprocessPrecursor();
MatchList matchList = candidate.getMatchList();
double[][] spectrumHDX = null;
if (method == 3)
spectrumHDX = new double[matchList.getNumberElements() * 2][2];
else
spectrumHDX = new double[matchList.getNumberElements()][2];
for (int i = 0; i < matchList.getNumberElements(); i++) {
IFragment frag = matchList.getElement(i).getBestMatchedFragment();
IPeak peak = matchList.getElement(i).getMatchedPeak();
int[] setAtoms = ((DefaultBitArrayFragment) frag).getAtomsFastBitArray().getSetIndeces();
int numberDeuteriums = 0;
for (int k = 0; k < setAtoms.length; k++) {
numberDeuteriums += preHDX.getNumberDeuteriumsConnectedToAtomIndex(0, setAtoms[k]);
}
spectrumHDX[i][1] = peak.getAbsoluteIntensity();
// [M-D]-
if (method == 1) {
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
spectrumHDX[i][0] += Constants.HYDROGEN_MASS - Constants.getMonoisotopicMassOfAtom("D");
} else // [M]-
if (method == 2) {
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
// nothing to do
} else // [M]- [M-D]-
if (method == 3) {
spectrumHDX[i * 2][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
spectrumHDX[(i * 2) + 1][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
spectrumHDX[(i * 2) + 1][0] += Constants.HYDROGEN_MASS - Constants.getMonoisotopicMassOfAtom("D");
} else // predict based on deuteriums
if (method == 4) {
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
if (numberDeuteriums != 0)
spectrumHDX[i][0] += Constants.HYDROGEN_MASS - Constants.getMonoisotopicMassOfAtom("D");
} else // predict based on adduct
if (method == 5) {
byte adductTypeIndex = ((DefaultFragmentToPeakMatch) matchList.getElement(i)).getBestMatchedFragmentAdductTypeIndex();
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
if (adductTypeIndex == 1)
spectrumHDX[i][0] += Constants.getMonoisotopicMassOfAtom("D") - Constants.HYDROGEN_MASS;
}
}
return spectrumHDX;
}
use of de.ipbhalle.metfraglib.interfaces.IPeak in project MetFragRelaunched by ipb-halle.
the class AutomatedPeakFingerprintAnnotationScoreInitialiser method matchesToPeak.
protected int matchesToPeak(Double mass, DefaultPeakList peaklist, int peakPointer, double mzabs, double mzppm) {
IPeak peak = (IPeak) peaklist.getElement(peakPointer);
boolean matches = MathTools.matchMasses(peak.getMass(), mass, mzppm, mzabs);
if (matches)
return 0;
if (mass < peak.getMass())
return -1;
return 1;
}
use of de.ipbhalle.metfraglib.interfaces.IPeak in project MetFragRelaunched by ipb-halle.
the class AbstractPeakListReader method deleteByMaximumNumberPeaksUsed.
protected void deleteByMaximumNumberPeaksUsed(int peakLimit, DefaultPeakList peaklist) {
if (peakLimit < 0)
return;
java.util.Vector<Integer> sortedIntensityIndexes = new java.util.Vector<Integer>();
for (int i = 0; i < peaklist.getNumberElements(); i++) {
IPeak currentPeak = ((IPeak) peaklist.getElement(i));
double currentIntensity = currentPeak.getAbsoluteIntensity();
int index = 0;
while (index < sortedIntensityIndexes.size() && currentIntensity > ((IPeak) peaklist.getElement(sortedIntensityIndexes.get(index))).getAbsoluteIntensity()) index++;
sortedIntensityIndexes.add(index, i);
}
java.util.ArrayList<Object> toRemovePeaks = new java.util.ArrayList<Object>();
int numberOfKeptPeaks = 0;
for (int k = sortedIntensityIndexes.size() - 1; k >= 0; k--) {
if (numberOfKeptPeaks >= peakLimit)
toRemovePeaks.add(peaklist.getElement(sortedIntensityIndexes.get(k)));
else
numberOfKeptPeaks++;
}
peaklist.removeAll(toRemovePeaks);
}
use of de.ipbhalle.metfraglib.interfaces.IPeak in project MetFragRelaunched by ipb-halle.
the class AddMissingNonExplainedPeaks method main.
public static void main(String[] args) throws Exception {
String paramfile = args[0];
String resultfile = args[1];
String outputfile = args[2];
Settings settings = getSettings(paramfile);
settings.set(VariableNames.LOCAL_DATABASE_PATH_NAME, resultfile);
IPeakListReader peakListReader = (IPeakListReader) Class.forName((String) settings.get(VariableNames.METFRAG_PEAK_LIST_READER_NAME)).getConstructor(Settings.class).newInstance(settings);
SettingsChecker settingsChecker = new SettingsChecker();
if (!settingsChecker.check(settings)) {
System.err.println("Problems reading settings");
return;
}
settings.set(VariableNames.PEAK_LIST_NAME, peakListReader.read());
IDatabase db = null;
String dbFilename = (String) settings.get(VariableNames.LOCAL_DATABASE_PATH_NAME);
if (dbFilename.endsWith("psv"))
db = new LocalPSVDatabase(settings);
else
db = new LocalCSVDatabase(settings);
ArrayList<String> ids = null;
try {
ids = db.getCandidateIdentifiers();
} catch (MultipleHeadersFoundInInputDatabaseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
CandidateList candidates = null;
try {
candidates = db.getCandidateByIdentifier(ids);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (candidates.getNumberElements() == 0) {
System.out.println("No candidates found in " + (String) settings.get(VariableNames.LOCAL_DATABASE_PATH_NAME));
return;
}
DefaultPeakList peaklist = (DefaultPeakList) settings.get(VariableNames.PEAK_LIST_NAME);
for (int i = 0; i < candidates.getNumberElements(); i++) {
String explPeaks = (String) candidates.getElement(i).getProperty("ExplPeaks");
String[] explPeaksArray = explPeaks.split(";");
Double[] explPeaksMasses = null;
if (!explPeaks.equals("NA"))
explPeaksMasses = getDoubleArrayFromPeakList(explPeaksArray);
String nonExplPeaksString = "";
for (int k = 0; k < peaklist.getNumberElements(); k++) {
if (explPeaks.equals("NA")) {
nonExplPeaksString += ((IPeak) peaklist.getElement(k)).getMass() + ";";
} else if (!isContained(((IPeak) peaklist.getElement(k)).getMass(), explPeaksMasses)) {
nonExplPeaksString += ((IPeak) peaklist.getElement(k)).getMass() + ";";
}
}
if (nonExplPeaksString.length() == 0)
nonExplPeaksString = "NA";
if (nonExplPeaksString.endsWith(";"))
nonExplPeaksString = nonExplPeaksString.substring(0, nonExplPeaksString.length() - 1);
candidates.getElement(i).setProperty("NonExplainedMasses", nonExplPeaksString);
}
IWriter writer = null;
if (outputfile.endsWith("psv"))
writer = new CandidateListWriterPSV();
else
writer = new CandidateListWriterCSV();
writer.write(candidates, outputfile);
}
use of de.ipbhalle.metfraglib.interfaces.IPeak in project MetFragRelaunched by ipb-halle.
the class SimulateSpectrumHDX method generateDeuteratedSpectrumPositive.
/**
* @param candidate
* @return
* @throws AtomTypeNotKnownFromInputListException
* @throws Exception
*/
public static double[][] generateDeuteratedSpectrumPositive(ICandidate candidate, int method) throws AtomTypeNotKnownFromInputListException, Exception {
int numberPositions = searchForDeuteriumExchangeablePositions((TopDownBitArrayPrecursor) candidate.getPrecursorMolecule()).length;
HDTopDownBitArrayPrecursor preHDX = new HDTopDownBitArrayPrecursor(candidate.getImplicitHydrogenAtomContainer(), (byte) numberPositions);
preHDX.preprocessPrecursor();
MatchList matchList = candidate.getMatchList();
double[][] spectrumHDX = null;
if (method == 3)
spectrumHDX = new double[matchList.getNumberElements() * 2][2];
else
spectrumHDX = new double[matchList.getNumberElements()][2];
for (int i = 0; i < matchList.getNumberElements(); i++) {
IFragment frag = matchList.getElement(i).getBestMatchedFragment();
IPeak peak = matchList.getElement(i).getMatchedPeak();
int[] setAtoms = ((DefaultBitArrayFragment) frag).getAtomsFastBitArray().getSetIndeces();
int numberDeuteriums = 0;
for (int k = 0; k < setAtoms.length; k++) {
numberDeuteriums += preHDX.getNumberDeuteriumsConnectedToAtomIndex(0, setAtoms[k]);
}
if (method != 3) {
spectrumHDX[i][1] = peak.getAbsoluteIntensity();
} else {
spectrumHDX[i * 2][1] = peak.getAbsoluteIntensity();
spectrumHDX[(i * 2) + 1][1] = peak.getAbsoluteIntensity();
}
// [M+D]+
if (method == 1) {
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
spectrumHDX[i][0] += Constants.getMonoisotopicMassOfAtom("D") - Constants.HYDROGEN_MASS;
} else // [M]+
if (method == 2) {
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
// nothing to do
} else // [M]+ [M+D]+
if (method == 3) {
spectrumHDX[i * 2][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
spectrumHDX[(i * 2) + 1][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
spectrumHDX[(i * 2) + 1][0] += Constants.getMonoisotopicMassOfAtom("D") - Constants.HYDROGEN_MASS;
} else // predict based on in silico added deuteriums
if (method == 4) {
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
if (numberDeuteriums != 0)
spectrumHDX[i][0] += Constants.getMonoisotopicMassOfAtom("D") - Constants.HYDROGEN_MASS;
} else // predict based on adduct
if (method == 5) {
byte adductTypeIndex = ((DefaultFragmentToPeakMatch) matchList.getElement(i)).getBestMatchedFragmentAdductTypeIndex();
spectrumHDX[i][0] = peak.getMass() - (numberDeuteriums) * Constants.HYDROGEN_MASS + (numberDeuteriums) * Constants.getMonoisotopicMassOfAtom("D");
if (adductTypeIndex == 2)
spectrumHDX[i][0] += Constants.getMonoisotopicMassOfAtom("D") - Constants.HYDROGEN_MASS;
}
if (method != 3) {
spectrumHDX[i][0] = MathTools.round(spectrumHDX[i][0]);
} else {
spectrumHDX[i * 2][0] = MathTools.round(spectrumHDX[i * 2][0]);
spectrumHDX[(i * 2) + 1][0] = MathTools.round(spectrumHDX[(i * 2) + 1][0]);
}
}
return spectrumHDX;
}
Aggregations