Search in sources :

Example 1 with IPeak

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;
}
Also used : DefaultFragmentToPeakMatch(de.ipbhalle.metfraglib.match.DefaultFragmentToPeakMatch) IPeak(de.ipbhalle.metfraglib.interfaces.IPeak) MatchList(de.ipbhalle.metfraglib.list.MatchList) IFragment(de.ipbhalle.metfraglib.interfaces.IFragment) TopDownBitArrayPrecursor(de.ipbhalle.metfraglib.precursor.TopDownBitArrayPrecursor) HDTopDownBitArrayPrecursor(de.ipbhalle.metfraglib.precursor.HDTopDownBitArrayPrecursor) HDTopDownBitArrayPrecursor(de.ipbhalle.metfraglib.precursor.HDTopDownBitArrayPrecursor)

Example 2 with IPeak

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;
}
Also used : IPeak(de.ipbhalle.metfraglib.interfaces.IPeak)

Example 3 with IPeak

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);
}
Also used : IPeak(de.ipbhalle.metfraglib.interfaces.IPeak)

Example 4 with IPeak

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);
}
Also used : IPeak(de.ipbhalle.metfraglib.interfaces.IPeak) IDatabase(de.ipbhalle.metfraglib.interfaces.IDatabase) IWriter(de.ipbhalle.metfraglib.interfaces.IWriter) DefaultPeakList(de.ipbhalle.metfraglib.list.DefaultPeakList) LocalCSVDatabase(de.ipbhalle.metfraglib.database.LocalCSVDatabase) MultipleHeadersFoundInInputDatabaseException(de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException) IPeakListReader(de.ipbhalle.metfraglib.interfaces.IPeakListReader) CandidateListWriterCSV(de.ipbhalle.metfraglib.writer.CandidateListWriterCSV) LocalPSVDatabase(de.ipbhalle.metfraglib.database.LocalPSVDatabase) SettingsChecker(de.ipbhalle.metfraglib.parameter.SettingsChecker) CandidateList(de.ipbhalle.metfraglib.list.CandidateList) MultipleHeadersFoundInInputDatabaseException(de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException) CandidateListWriterPSV(de.ipbhalle.metfraglib.writer.CandidateListWriterPSV) MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) Settings(de.ipbhalle.metfraglib.settings.Settings)

Example 5 with IPeak

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;
}
Also used : DefaultFragmentToPeakMatch(de.ipbhalle.metfraglib.match.DefaultFragmentToPeakMatch) IPeak(de.ipbhalle.metfraglib.interfaces.IPeak) MatchList(de.ipbhalle.metfraglib.list.MatchList) IFragment(de.ipbhalle.metfraglib.interfaces.IFragment) TopDownBitArrayPrecursor(de.ipbhalle.metfraglib.precursor.TopDownBitArrayPrecursor) HDTopDownBitArrayPrecursor(de.ipbhalle.metfraglib.precursor.HDTopDownBitArrayPrecursor) HDTopDownBitArrayPrecursor(de.ipbhalle.metfraglib.precursor.HDTopDownBitArrayPrecursor)

Aggregations

IPeak (de.ipbhalle.metfraglib.interfaces.IPeak)5 IFragment (de.ipbhalle.metfraglib.interfaces.IFragment)2 MatchList (de.ipbhalle.metfraglib.list.MatchList)2 DefaultFragmentToPeakMatch (de.ipbhalle.metfraglib.match.DefaultFragmentToPeakMatch)2 HDTopDownBitArrayPrecursor (de.ipbhalle.metfraglib.precursor.HDTopDownBitArrayPrecursor)2 TopDownBitArrayPrecursor (de.ipbhalle.metfraglib.precursor.TopDownBitArrayPrecursor)2 LocalCSVDatabase (de.ipbhalle.metfraglib.database.LocalCSVDatabase)1 LocalPSVDatabase (de.ipbhalle.metfraglib.database.LocalPSVDatabase)1 MultipleHeadersFoundInInputDatabaseException (de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException)1 IDatabase (de.ipbhalle.metfraglib.interfaces.IDatabase)1 IPeakListReader (de.ipbhalle.metfraglib.interfaces.IPeakListReader)1 IWriter (de.ipbhalle.metfraglib.interfaces.IWriter)1 CandidateList (de.ipbhalle.metfraglib.list.CandidateList)1 DefaultPeakList (de.ipbhalle.metfraglib.list.DefaultPeakList)1 SettingsChecker (de.ipbhalle.metfraglib.parameter.SettingsChecker)1 MetFragGlobalSettings (de.ipbhalle.metfraglib.settings.MetFragGlobalSettings)1 Settings (de.ipbhalle.metfraglib.settings.Settings)1 CandidateListWriterCSV (de.ipbhalle.metfraglib.writer.CandidateListWriterCSV)1 CandidateListWriterPSV (de.ipbhalle.metfraglib.writer.CandidateListWriterPSV)1