Search in sources :

Example 1 with CandidateListWriterPSV

use of de.ipbhalle.metfraglib.writer.CandidateListWriterPSV in project MetFragRelaunched by ipb-halle.

the class DownloadEntriesFromPubChem method downloadFromCandidateFile.

public static void downloadFromCandidateFile(String filenameIn, String filenameOut) {
    MetFragGlobalSettings settingsIn = new MetFragGlobalSettings();
    settingsIn.set(VariableNames.LOCAL_DATABASE_PATH_NAME, filenameIn);
    LocalPSVDatabase dbIn = new LocalPSVDatabase(settingsIn);
    ArrayList<String> identifiers = null;
    try {
        identifiers = dbIn.getCandidateIdentifiers();
    } catch (MultipleHeadersFoundInInputDatabaseException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    CandidateList candidates = dbIn.getCandidateByIdentifier(identifiers);
    String[] ids = new String[candidates.getNumberElements()];
    for (int i = 0; i < ids.length; i++) ids[i] = candidates.getElement(i).getIdentifier();
    MetFragGlobalSettings settingsPubChem = new MetFragGlobalSettings();
    settingsPubChem.set(VariableNames.PRECURSOR_DATABASE_IDS_NAME, ids);
    OnlineExtendedPubChemDatabase pubchemDB = new OnlineExtendedPubChemDatabase(settingsPubChem);
    try {
        identifiers = pubchemDB.getCandidateIdentifiers();
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    CandidateList candidatesPubChem = null;
    try {
        candidatesPubChem = pubchemDB.getCandidateByIdentifier(identifiers);
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    for (int i = 0; i < candidatesPubChem.getNumberElements(); i++) {
        String identifier = candidatesPubChem.getElement(i).getIdentifier();
        try {
            ICandidate currentCandidate = dbIn.getCandidateByIdentifier(identifier);
            currentCandidate.setProperty(VariableNames.PUBCHEM_NUMBER_PUBMED_REFERENCES_NAME, candidatesPubChem.getElement(i).getProperty(VariableNames.PUBCHEM_NUMBER_PUBMED_REFERENCES_NAME));
            currentCandidate.setProperty(VariableNames.PUBCHEM_NUMBER_PATENTS_NAME, candidatesPubChem.getElement(i).getProperty(VariableNames.PUBCHEM_NUMBER_PATENTS_NAME));
        } catch (DatabaseIdentifierNotFoundException e) {
            e.printStackTrace();
        }
    }
    CandidateListWriterPSV writer = new CandidateListWriterPSV();
    String filename = filenameOut.replaceAll(".*\\/", "").replaceAll("\\..*$", "");
    String path = filenameOut.replaceAll(filename + "\\..*$", "");
    try {
        writer.write(candidates, filename, path);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) OnlineExtendedPubChemDatabase(de.ipbhalle.metfraglib.database.OnlineExtendedPubChemDatabase) DatabaseIdentifierNotFoundException(de.ipbhalle.metfraglib.exceptions.DatabaseIdentifierNotFoundException) AtomTypeNotKnownFromInputListException(de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException) MultipleHeadersFoundInInputDatabaseException(de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException) ICandidate(de.ipbhalle.metfraglib.interfaces.ICandidate) LocalPSVDatabase(de.ipbhalle.metfraglib.database.LocalPSVDatabase) CandidateList(de.ipbhalle.metfraglib.list.CandidateList) DatabaseIdentifierNotFoundException(de.ipbhalle.metfraglib.exceptions.DatabaseIdentifierNotFoundException) MultipleHeadersFoundInInputDatabaseException(de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException) CandidateListWriterPSV(de.ipbhalle.metfraglib.writer.CandidateListWriterPSV)

Example 2 with CandidateListWriterPSV

use of de.ipbhalle.metfraglib.writer.CandidateListWriterPSV in project MetFragRelaunched by ipb-halle.

the class ConvertSDFtoCSV method main.

/**
 * @param args
 * @throws CDKException
 */
public static void main(String[] args) throws CDKException {
    IteratingSDFReader reader;
    CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(DefaultChemObjectBuilder.getInstance());
    CandidateList candidates = new CandidateList();
    try {
        reader = new IteratingSDFReader(new java.io.FileReader(args[0]), DefaultChemObjectBuilder.getInstance());
        while (reader.hasNext()) {
            IAtomContainer molecule = reader.next();
            AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
            adder.addImplicitHydrogens(molecule);
            AtomContainerManipulator.convertImplicitToExplicitHydrogens(molecule);
            PrecursorCandidate candidate = new PrecursorCandidate((String) molecule.getProperty(VariableNames.INCHI_NAME), (String) molecule.getProperty(VariableNames.IDENTIFIER_NAME));
            java.util.Iterator<Object> keys = molecule.getProperties().keySet().iterator();
            while (keys.hasNext()) {
                String key = (String) keys.next();
                if (molecule.getProperty(key) != null)
                    candidate.setProperty(key, molecule.getProperty(key));
            }
            candidates.addElement(candidate);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    CandidateListWriterPSV writer = new CandidateListWriterPSV();
    try {
        writer.write(candidates, args[1], args[2]);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) FileNotFoundException(java.io.FileNotFoundException) IteratingSDFReader(org.openscience.cdk.io.iterator.IteratingSDFReader) PrecursorCandidate(de.ipbhalle.metfraglib.candidate.PrecursorCandidate) CDKException(org.openscience.cdk.exception.CDKException) FileNotFoundException(java.io.FileNotFoundException) CDKHydrogenAdder(org.openscience.cdk.tools.CDKHydrogenAdder) CandidateList(de.ipbhalle.metfraglib.list.CandidateList) CandidateListWriterPSV(de.ipbhalle.metfraglib.writer.CandidateListWriterPSV)

Example 3 with CandidateListWriterPSV

use of de.ipbhalle.metfraglib.writer.CandidateListWriterPSV 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 4 with CandidateListWriterPSV

use of de.ipbhalle.metfraglib.writer.CandidateListWriterPSV in project MetFragRelaunched by ipb-halle.

the class CalculateHydrogenDeuteriumScore method main.

public static void main(String[] args) {
    if (args == null || args.length != 7) {
        System.err.println("hydrogenResultFileName deuteriumResultFileName maxNumDeuteriums outputFileName mzppm mzabs isPositive");
        System.exit(1);
    }
    String hydrogenResultFileName = args[0];
    String deuteriumResultFileName = args[1];
    double maximumNumberDeuteriums = Double.parseDouble(args[2]);
    String outputFileName = args[3];
    ppm = Double.parseDouble(args[4]);
    abs = Double.parseDouble(args[5]);
    boolean isPositive = args[6].trim().toLowerCase().equals("true") ? true : false;
    MetFragGlobalSettings hydrogenSettings = new MetFragGlobalSettings();
    MetFragGlobalSettings deuteriumSettings = new MetFragGlobalSettings();
    hydrogenSettings.set(VariableNames.LOCAL_DATABASE_PATH_NAME, hydrogenResultFileName);
    deuteriumSettings.set(VariableNames.LOCAL_DATABASE_PATH_NAME, deuteriumResultFileName);
    IDatabase hydrogenDatabase = new LocalPSVDatabase(hydrogenSettings);
    IDatabase deuteriumDatabase = new LocalPSVDatabase(deuteriumSettings);
    ArrayList<String> hydrogenIdentifiers = null;
    ArrayList<String> deuteriumIdentifiers = null;
    try {
        hydrogenIdentifiers = hydrogenDatabase.getCandidateIdentifiers();
        deuteriumIdentifiers = deuteriumDatabase.getCandidateIdentifiers();
    } catch (MultipleHeadersFoundInInputDatabaseException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    CandidateList hydrogenCandidateList = null;
    CandidateList deuteriumCandidateList = null;
    try {
        hydrogenCandidateList = hydrogenDatabase.getCandidateByIdentifier(hydrogenIdentifiers);
        deuteriumCandidateList = deuteriumDatabase.getCandidateByIdentifier(deuteriumIdentifiers);
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    Hashtable<String, ICandidate> hashTableHydrogenResults = new Hashtable<String, ICandidate>();
    Hashtable<String, ICandidate> hashTableDeuteriumResults = new Hashtable<String, ICandidate>();
    for (int i = 0; i < hydrogenCandidateList.getNumberElements(); i++) {
        if (!hashTableHydrogenResults.containsKey(hydrogenCandidateList.getElement(i).getIdentifier()))
            hashTableHydrogenResults.put(hydrogenCandidateList.getElement(i).getIdentifier(), hydrogenCandidateList.getElement(i));
        else {
            System.err.println("Error: Identifier " + hydrogenCandidateList.getElement(i).getIdentifier() + " already found! Something wrong with the candidate list?");
            System.exit(1);
        }
    }
    for (int i = 0; i < deuteriumCandidateList.getNumberElements(); i++) {
        if (!hashTableDeuteriumResults.containsKey(deuteriumCandidateList.getElement(i).getIdentifier())) {
            hashTableDeuteriumResults.put(deuteriumCandidateList.getElement(i).getIdentifier(), deuteriumCandidateList.getElement(i));
        } else {
            System.err.println("Error: Identifier " + deuteriumCandidateList.getElement(i).getIdentifier() + " already found! Something wrong with the candidate list?");
            System.exit(1);
        }
    }
    System.out.println("#####");
    Iterator<String> deuteriumKeys = hashTableDeuteriumResults.keySet().iterator();
    Hashtable<String, Double> hd_score_1 = new Hashtable<String, Double>();
    Hashtable<String, Double> hd_score_2 = new Hashtable<String, Double>();
    java.util.ArrayList<String> lines = new java.util.ArrayList<String>();
    CandidateList mergedCandidateList = new CandidateList();
    /*
		 * 
		 */
    while (deuteriumKeys.hasNext()) {
        String identifier = deuteriumKeys.next();
        boolean specialCase = false;
        if (identifier.matches(".*-.*")) {
            identifier = identifier.replaceAll("-.*", "");
            specialCase = true;
        }
        if (specialCase) {
            ICandidate hydrogenCandidate = hashTableHydrogenResults.get(identifier);
            int add = 1;
            String nextIdentifier = identifier + "-" + add;
            while (hashTableDeuteriumResults.containsKey(nextIdentifier)) {
                hashTableHydrogenResults.put(nextIdentifier, hydrogenCandidate);
                add++;
                nextIdentifier = identifier + "-" + add;
            }
        }
    }
    deuteriumKeys = hashTableDeuteriumResults.keySet().iterator();
    while (deuteriumKeys.hasNext()) {
        String identifier = deuteriumKeys.next();
        ICandidate hydrogenCandidate = hashTableHydrogenResults.get(identifier);
        ICandidate deuteriumCandidate = hashTableDeuteriumResults.get(identifier);
        String formulasOfExplPeaksHydrogenString = (String) hydrogenCandidate.getProperty("FormulasOfExplPeaks");
        String formulasOfExplPeaksDeuteriumString = (String) deuteriumCandidate.getProperty("FormulasOfExplPeaks");
        int numberPeaksUsed = Math.min(Integer.parseInt((String) deuteriumCandidate.getProperty("NumberPeaksUsed")), Integer.parseInt((String) hydrogenCandidate.getProperty("NumberPeaksUsed")));
        int numberPeaksExplained = Math.min(Integer.parseInt((String) deuteriumCandidate.getProperty("NoExplPeaks")), Integer.parseInt((String) hydrogenCandidate.getProperty("NoExplPeaks")));
        if (formulasOfExplPeaksHydrogenString.equals("NA") || formulasOfExplPeaksDeuteriumString.equals("NA")) {
            hd_score_1.put(identifier, 0.0);
            hd_score_2.put(identifier, 0.0);
            continue;
        }
        String[] tmpHydrogen = formulasOfExplPeaksHydrogenString.split(";");
        String[] tmpDeuterium = formulasOfExplPeaksDeuteriumString.split(";");
        double[] massesHydrogen = new double[tmpHydrogen.length];
        double[] massesDeuterium = new double[tmpDeuterium.length];
        String[] formulasHydrogen = new String[tmpHydrogen.length];
        String[] formulasDeuterium = new String[tmpDeuterium.length];
        for (int i = 0; i < massesHydrogen.length; i++) {
            String[] tmp = tmpHydrogen[i].split(":");
            massesHydrogen[i] = Double.parseDouble(tmp[0]);
            formulasHydrogen[i] = tmp[1];
        }
        for (int i = 0; i < massesDeuterium.length; i++) {
            String[] tmp = tmpDeuterium[i].split(":");
            massesDeuterium[i] = Double.parseDouble(tmp[0]);
            formulasDeuterium[i] = tmp[1];
        }
        int[][] equalPeakPairs = getEqualPeakPairs2(massesHydrogen, massesDeuterium, ppm, abs);
        int[][] deuteriumEqualPeakPairs = getDeuteriumEqualPeakPairs2(massesHydrogen, massesDeuterium, ppm, abs, maximumNumberDeuteriums);
        String fragmentAtomFastBitArraysHydrogenString = (String) hydrogenCandidate.getProperty("FragmentAtomFastBitArrays");
        String fragmentAtomFastBitArraysDeuteriumString = (String) deuteriumCandidate.getProperty("FragmentAtomFastBitArrays");
        String[] fragmentAtomFastBitArraysHydrogen = fragmentAtomFastBitArraysHydrogenString.split(";");
        String[] fragmentAtomFastBitArraysDeuterium = fragmentAtomFastBitArraysDeuteriumString.split(";");
        int countEqualPeakPairs = 0;
        int countDeuteriumEqualPeakPairs = 0;
        ArrayList<Integer> hydrogenMassesUsedForEqualPairs = new ArrayList<Integer>();
        ArrayList<Integer> deuteriumMassesUsedForEqualPairs = new ArrayList<Integer>();
        for (int i = 0; i < equalPeakPairs.length; i++) {
            String[] singleFragmentAtomFastBitArraysHydrogen = fragmentAtomFastBitArraysHydrogen[equalPeakPairs[i][0]].split("/");
            String[] singleFragmentAtomFastBitArraysDeuterium = fragmentAtomFastBitArraysDeuterium[equalPeakPairs[i][1]].split("/");
            String[] singleFormulasOfExplPeaksDeuteriumString = formulasDeuterium[equalPeakPairs[i][1]].split("/");
            for (int k = 0; k < singleFragmentAtomFastBitArraysDeuterium.length; k++) {
                int numDeuteriums = containsDeuterium(singleFormulasOfExplPeaksDeuteriumString[k]);
                if (!isPositive)
                    numDeuteriums = containsDeuterium2(singleFormulasOfExplPeaksDeuteriumString[k]);
                boolean found = true;
                for (int l = 0; l < singleFragmentAtomFastBitArraysHydrogen.length; l++) {
                    if (singleFragmentAtomFastBitArraysDeuterium[k].equals(singleFragmentAtomFastBitArraysHydrogen[l]) && numDeuteriums == 0 && !hydrogenMassesUsedForEqualPairs.contains(equalPeakPairs[i][0]) && !deuteriumMassesUsedForEqualPairs.contains(equalPeakPairs[i][1])) {
                        countEqualPeakPairs++;
                        found = true;
                        hydrogenMassesUsedForEqualPairs.add(equalPeakPairs[i][0]);
                        deuteriumMassesUsedForEqualPairs.add(equalPeakPairs[i][1]);
                        System.out.println("equal " + massesHydrogen[equalPeakPairs[i][0]] + " " + massesDeuterium[equalPeakPairs[i][1]]);
                        break;
                    } else {
                    // System.out.println("no pair " + massesHydrogen[equalPeakPairs[i][0]] + " " + massesDeuterium[equalPeakPairs[i][1]]);
                    }
                }
                if (found)
                    break;
            }
        }
        ArrayList<Integer> hydrogenMassesUsedForDeuteriumEqualPairs = new ArrayList<Integer>();
        ArrayList<Integer> deuteriumMassesUsedForDeuteriumEqualPairs = new ArrayList<Integer>();
        for (int i = 0; i < deuteriumEqualPeakPairs.length; i++) {
            String[] singleFragmentAtomFastBitArraysHydrogen = fragmentAtomFastBitArraysHydrogen[deuteriumEqualPeakPairs[i][0]].split("/");
            String[] singleFragmentAtomFastBitArraysDeuterium = fragmentAtomFastBitArraysDeuterium[deuteriumEqualPeakPairs[i][1]].split("/");
            String[] singleFormulasOfExplPeaksDeuteriumString = formulasDeuterium[deuteriumEqualPeakPairs[i][1]].split("/");
            for (int k = 0; k < singleFragmentAtomFastBitArraysDeuterium.length; k++) {
                int numDeuteriums = containsDeuterium2(singleFormulasOfExplPeaksDeuteriumString[k]);
                boolean found = false;
                for (int l = 0; l < singleFragmentAtomFastBitArraysHydrogen.length; l++) {
                    if (singleFragmentAtomFastBitArraysDeuterium[k].equals(singleFragmentAtomFastBitArraysHydrogen[l]) && numDeuteriums > 0 && numDeuteriums == deuteriumEqualPeakPairs[i][2] && !hydrogenMassesUsedForEqualPairs.contains(deuteriumEqualPeakPairs[i][0]) && !deuteriumMassesUsedForEqualPairs.contains(deuteriumEqualPeakPairs[i][1]) && !hydrogenMassesUsedForDeuteriumEqualPairs.contains(deuteriumEqualPeakPairs[i][0]) && !deuteriumMassesUsedForDeuteriumEqualPairs.contains(deuteriumEqualPeakPairs[i][1])) {
                        countDeuteriumEqualPeakPairs++;
                        hydrogenMassesUsedForDeuteriumEqualPairs.add(deuteriumEqualPeakPairs[i][0]);
                        deuteriumMassesUsedForDeuteriumEqualPairs.add(deuteriumEqualPeakPairs[i][1]);
                        System.out.println("deuterium " + massesHydrogen[deuteriumEqualPeakPairs[i][0]] + " " + massesDeuterium[deuteriumEqualPeakPairs[i][1]]);
                        found = true;
                        break;
                    } else {
                    // System.out.println("no pair " + massesHydrogen[deuteriumEqualPeakPairs[i][0]] + " " + massesDeuterium[deuteriumEqualPeakPairs[i][1]]);
                    }
                }
                if (found)
                    break;
            }
        }
        deuteriumCandidate.setProperty(VariableNames.METFRAG_FRAGMENTER_SCORE_NAME, hydrogenCandidate.getProperty(VariableNames.METFRAG_FRAGMENTER_SCORE_NAME));
        deuteriumCandidate.setProperty("FragmenterDeuteriumScore", deuteriumCandidate.getProperty("Score"));
        // hydrogenCandidate.setProperty("HD-PairScore", (double)(countEqualPeakPairs + countDeuteriumEqualPeakPairs) / (double)numberPeaksUsed);
        deuteriumCandidate.setProperty("HD-PairScore", (double) (countEqualPeakPairs + countDeuteriumEqualPeakPairs) / (double) numberPeaksExplained);
        deuteriumCandidate.setProperty("NumberEqualPairs", countEqualPeakPairs);
        deuteriumCandidate.setProperty("NumberDeuteriumPairs", countDeuteriumEqualPeakPairs);
        double osnDeuteriums = Double.parseDouble((String) deuteriumCandidate.getProperty("OSN-Deuteriums"));
        double missedDeuteriums = Double.parseDouble((String) deuteriumCandidate.getProperty("MissedDeuteriums"));
        if (isPositive) {
            if ((maximumNumberDeuteriums - 1) == 0)
                deuteriumCandidate.setProperty("OSN-DeuteriumsScore", 0.0);
            else
                deuteriumCandidate.setProperty("OSN-DeuteriumsScore", (osnDeuteriums - missedDeuteriums) / (maximumNumberDeuteriums - 1));
        } else {
            if ((maximumNumberDeuteriums + 1) == 0)
                deuteriumCandidate.setProperty("OSN-DeuteriumsScore", 0.0);
            else
                deuteriumCandidate.setProperty("OSN-DeuteriumsScore", (osnDeuteriums - missedDeuteriums) / (maximumNumberDeuteriums + 1));
        }
        deuteriumCandidate.getProperties().remove("FragmentBrokenBondFastBitArrays");
        deuteriumCandidate.getProperties().remove("FragmentBondFastBitArrays");
        deuteriumCandidate.getProperties().remove("FragmentAtomFastBitArrays");
        mergedCandidateList.addElement(deuteriumCandidate);
        // System.out.println(identifier + " " + (double)(countEqualPeakPairs + countDeuteriumEqualPeakPairs) / (double)numberPeaksUsed + " " + countEqualPeakPairs + " " + countDeuteriumEqualPeakPairs + " " + (countEqualPeakPairs + countDeuteriumEqualPeakPairs) + " " + deuteriumCandidate.getProperty("AromaticDeuteriums") + " " + deuteriumCandidate.getProperty("Score") + " " + hydrogenCandidate.getProperty("Score"));
        /*	System.out.println(identifier + " " + (double)(countEqualPeakPairs + countDeuteriumEqualPeakPairs) / (double)numberPeaksUsed + " " + countEqualPeakPairs + " " + countDeuteriumEqualPeakPairs + " " + (countEqualPeakPairs + countDeuteriumEqualPeakPairs) + " " + deuteriumCandidate.getProperty("AromaticDeuteriums") + " " + deuteriumCandidate.getProperty("Score") + " " + hydrogenCandidate.getProperty("Score") 
					+ " " + hydrogenCandidate.getProperty("FragmenterDeuteriumScore") + " " + hydrogenCandidate.getProperty("HD-PairScore")
					+ " " + hydrogenCandidate.getProperty("OSN-DeuteriumsScore"));
			*/
        lines.add(identifier + " " + (double) (countEqualPeakPairs + countDeuteriumEqualPeakPairs) / (double) numberPeaksUsed + " " + countEqualPeakPairs + " " + countDeuteriumEqualPeakPairs + " " + (countEqualPeakPairs + countDeuteriumEqualPeakPairs) + " " + deuteriumCandidate.getProperty("AromaticDeuteriums") + " " + deuteriumCandidate.getProperty("Score") + " " + hydrogenCandidate.getProperty("Score") + " " + deuteriumCandidate.getProperty("FragmenterDeuteriumScore") + " " + deuteriumCandidate.getProperty("HD-PairScore") + " " + deuteriumCandidate.getProperty("OSN-DeuteriumsScore"));
    }
    java.io.File outputFile = new java.io.File(outputFileName);
    CandidateListWriterPSV candidateWriter = new CandidateListWriterPSV();
    try {
        candidateWriter.write(mergedCandidateList, outputFile.getName(), outputFile.getParent());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) ArrayList(java.util.ArrayList) ICandidate(de.ipbhalle.metfraglib.interfaces.ICandidate) CandidateList(de.ipbhalle.metfraglib.list.CandidateList) MultipleHeadersFoundInInputDatabaseException(de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException) CandidateListWriterPSV(de.ipbhalle.metfraglib.writer.CandidateListWriterPSV) IDatabase(de.ipbhalle.metfraglib.interfaces.IDatabase) Hashtable(java.util.Hashtable) MultipleHeadersFoundInInputDatabaseException(de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException) LocalPSVDatabase(de.ipbhalle.metfraglib.database.LocalPSVDatabase)

Example 5 with CandidateListWriterPSV

use of de.ipbhalle.metfraglib.writer.CandidateListWriterPSV in project MetFragRelaunched by ipb-halle.

the class IncludeValuesToResultFile method main.

/**
 * @param args
 */
public static void main(String[] args) {
    String filenameFrom = args[0];
    String filenameTo = args[1];
    String[] valuenames = args[3].trim().split(",");
    MetFragGlobalSettings settingsFrom = new MetFragGlobalSettings();
    settingsFrom.set(VariableNames.LOCAL_DATABASE_PATH_NAME, filenameFrom);
    LocalPSVDatabase dbFrom = new LocalPSVDatabase(settingsFrom);
    ArrayList<String> identifiersFrom = null;
    try {
        identifiersFrom = dbFrom.getCandidateIdentifiers();
    } catch (MultipleHeadersFoundInInputDatabaseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    CandidateList candidatesFrom = dbFrom.getCandidateByIdentifier(identifiersFrom);
    MetFragGlobalSettings settingsTo = new MetFragGlobalSettings();
    settingsTo.set(VariableNames.LOCAL_DATABASE_PATH_NAME, filenameTo);
    LocalPSVDatabase dbTo = new LocalPSVDatabase(settingsTo);
    ArrayList<String> identifiersTo = null;
    try {
        identifiersTo = dbTo.getCandidateIdentifiers();
    } catch (MultipleHeadersFoundInInputDatabaseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    CandidateList candidatesTo = dbTo.getCandidateByIdentifier(identifiersTo);
    if (candidatesFrom.getNumberElements() < candidatesTo.getNumberElements())
        System.out.println(filenameTo + " has more candidates than " + filenameTo);
    int touched = 0;
    for (int i = 0; i < candidatesFrom.getNumberElements(); i++) {
        ICandidate candidateFrom = candidatesFrom.getElement(i);
        ICandidate candidateTo = getCandidateById(candidateFrom.getIdentifier(), candidatesTo);
        if (candidateTo == null) {
            continue;
        }
        for (int k = 0; k < valuenames.length; k++) candidateTo.setProperty(valuenames[k], candidateFrom.getProperty(valuenames[k]));
        touched++;
    }
    if (touched != candidatesTo.getNumberElements()) {
        System.err.println("Only found " + touched + " candidates of " + candidatesTo.getNumberElements());
    }
    CandidateListWriterPSV writer = new CandidateListWriterPSV();
    String filename = args[2].replaceAll(".*\\/", "").replaceAll("\\..*$", "");
    String path = args[2].replaceAll(filename + "\\..*$", "");
    try {
        writer.write(candidatesTo, filename, path);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) LocalPSVDatabase(de.ipbhalle.metfraglib.database.LocalPSVDatabase) CandidateList(de.ipbhalle.metfraglib.list.CandidateList) MultipleHeadersFoundInInputDatabaseException(de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException) CandidateListWriterPSV(de.ipbhalle.metfraglib.writer.CandidateListWriterPSV) MultipleHeadersFoundInInputDatabaseException(de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException) ICandidate(de.ipbhalle.metfraglib.interfaces.ICandidate)

Aggregations

CandidateList (de.ipbhalle.metfraglib.list.CandidateList)6 CandidateListWriterPSV (de.ipbhalle.metfraglib.writer.CandidateListWriterPSV)6 MultipleHeadersFoundInInputDatabaseException (de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException)5 LocalPSVDatabase (de.ipbhalle.metfraglib.database.LocalPSVDatabase)4 ICandidate (de.ipbhalle.metfraglib.interfaces.ICandidate)4 MetFragGlobalSettings (de.ipbhalle.metfraglib.settings.MetFragGlobalSettings)4 PrecursorCandidate (de.ipbhalle.metfraglib.candidate.PrecursorCandidate)2 IDatabase (de.ipbhalle.metfraglib.interfaces.IDatabase)2 LocalCSVDatabase (de.ipbhalle.metfraglib.database.LocalCSVDatabase)1 OnlineExtendedPubChemDatabase (de.ipbhalle.metfraglib.database.OnlineExtendedPubChemDatabase)1 AtomTypeNotKnownFromInputListException (de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException)1 DatabaseIdentifierNotFoundException (de.ipbhalle.metfraglib.exceptions.DatabaseIdentifierNotFoundException)1 IPeak (de.ipbhalle.metfraglib.interfaces.IPeak)1 IPeakListReader (de.ipbhalle.metfraglib.interfaces.IPeakListReader)1 IWriter (de.ipbhalle.metfraglib.interfaces.IWriter)1 DefaultPeakList (de.ipbhalle.metfraglib.list.DefaultPeakList)1 SettingsChecker (de.ipbhalle.metfraglib.parameter.SettingsChecker)1 Settings (de.ipbhalle.metfraglib.settings.Settings)1 CandidateListWriterCSV (de.ipbhalle.metfraglib.writer.CandidateListWriterCSV)1 File (java.io.File)1