Search in sources :

Example 1 with PrecursorCandidate

use of de.ipbhalle.metfraglib.candidate.PrecursorCandidate in project MetFragRelaunched by ipb-halle.

the class CheckPreProcessingSmartsFilter_Test method setUp.

@Before
public void setUp() {
    // init candidate objects
    toTestCandidates[0] = new PrecursorCandidate("InChI=1S/C12H19NO5S2/c1-12(2,3)18-11(14)13-9(8-17-20(4,15)16)10-6-5-7-19-10/h5-7,9H,8H2,1-4H3,(H,13,14)/t9-/m0/s1", "13877939");
    toTestCandidates[0].setProperty(VariableNames.INCHI_KEY_1_NAME, "LGXPPQPBQCFQPU");
    toTestCandidates[1] = new PrecursorCandidate("InChI=1S/C12H19NO5S2/c1-13(19(2,14)15)12-8-6-11(7-9-12)5-4-10-18-20(3,16)17/h6-9H,4-5,10H2,1-3H3", "59122053");
    toTestCandidates[1].setProperty(VariableNames.INCHI_KEY_1_NAME, "CNMCSJSREOGBCU");
    toTestCandidates[2] = new PrecursorCandidate("InChI=1S/C12H19NO5S2/c1-19(14,15)13-12-8-6-11(7-9-12)5-3-4-10-18-20(2,16)17/h6-9,13H,3-5,10H2,1-2H3", "54525898");
    toTestCandidates[2].setProperty(VariableNames.INCHI_KEY_1_NAME, "YTBWCCSOEYFHGQ");
    toTestCandidates[3] = new PrecursorCandidate("InChI=1S/C15H12O5/c16-9-3-1-8(2-4-9)13-7-12(19)15-11(18)5-10(17)6-14(15)20-13/h1-6,13,16-18H,7H2", "932");
    toTestCandidates[3].setProperty(VariableNames.INCHI_KEY_1_NAME, "FTVWIRXFELQLPI");
    this.settings = new Settings();
}
Also used : PrecursorCandidate(de.ipbhalle.metfraglib.candidate.PrecursorCandidate) Settings(de.ipbhalle.metfraglib.settings.Settings) Before(org.junit.Before)

Example 2 with PrecursorCandidate

use of de.ipbhalle.metfraglib.candidate.PrecursorCandidate in project MetFragRelaunched by ipb-halle.

the class CheckPreProcessingSuspectListFilter_Test method setUp.

@Before
public void setUp() {
    // init candidate objects
    toTestCandidates[0] = new PrecursorCandidate("InChI=1S/C12H19NO5S2/c1-12(2,3)18-11(14)13-9(8-17-20(4,15)16)10-6-5-7-19-10/h5-7,9H,8H2,1-4H3,(H,13,14)/t9-/m0/s1", "13877939");
    toTestCandidates[0].setProperty(VariableNames.INCHI_KEY_1_NAME, "LGXPPQPBQCFQPU");
    toTestCandidates[1] = new PrecursorCandidate("InChI=1S/C12H19NO5S2/c1-13(19(2,14)15)12-8-6-11(7-9-12)5-4-10-18-20(3,16)17/h6-9H,4-5,10H2,1-3H3", "59122053");
    toTestCandidates[1].setProperty(VariableNames.INCHI_KEY_1_NAME, "CNMCSJSREOGBCU");
    toTestCandidates[2] = new PrecursorCandidate("InChI=1S/C12H19NO5S2/c1-19(14,15)13-12-8-6-11(7-9-12)5-3-4-10-18-20(2,16)17/h6-9,13H,3-5,10H2,1-2H3", "54525898");
    toTestCandidates[2].setProperty(VariableNames.INCHI_KEY_1_NAME, "YTBWCCSOEYFHGQ");
    toTestCandidates[3] = new PrecursorCandidate("InChI=1S/C15H12O5/c16-9-3-1-8(2-4-9)13-7-12(19)15-11(18)5-10(17)6-14(15)20-13/h1-6,13,16-18H,7H2", "932");
    toTestCandidates[3].setProperty(VariableNames.INCHI_KEY_1_NAME, "FTVWIRXFELQLPI");
    this.settings = new Settings();
    this.candidateFilter = new PreProcessingCandidateSuspectListFilter(this.inChIKeys, "test", settings, false);
}
Also used : PrecursorCandidate(de.ipbhalle.metfraglib.candidate.PrecursorCandidate) Settings(de.ipbhalle.metfraglib.settings.Settings) Before(org.junit.Before)

Example 3 with PrecursorCandidate

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

use of de.ipbhalle.metfraglib.candidate.PrecursorCandidate in project MetFragRelaunched by ipb-halle.

the class OfflineMetFusionSpectralSimilarityScore method main.

public static void main(String[] args) throws Exception {
    MetFragGlobalSettings settings = new MetFragGlobalSettings();
    settings.set(VariableNames.PEAK_LIST_STRING_NAME, "65.0381 17.51663\n" + "108.0472 18.403548\n" + "125.0479 26.16408\n" + "156.0125 47.006652\n" + "173.0383 100");
    settings.set(VariableNames.PRECURSOR_NEUTRAL_MASS_NAME, 172.0306);
    FilteredStringTandemMassPeakListReader peaklistreader = new FilteredStringTandemMassPeakListReader(settings);
    DefaultPeakList peaklist = peaklistreader.read();
    settings.set(VariableNames.PEAK_LIST_NAME, peaklist);
    PrecursorCandidate candidate = new PrecursorCandidate("InChI=1S/C6H8N2O2S/c7-5-1-3-6(4-2-5)11(8,9)10/h1-4H,7H2,(H2,8,9,10)", "Sulfanilamide");
    settings.set(VariableNames.CANDIDATE_NAME, candidate);
    OfflineMetFusionSpectralSimilarityScore score = new OfflineMetFusionSpectralSimilarityScore(settings);
    score.calculate();
    System.out.println(score.getValue());
}
Also used : MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) FilteredStringTandemMassPeakListReader(de.ipbhalle.metfraglib.peaklistreader.FilteredStringTandemMassPeakListReader) DefaultPeakList(de.ipbhalle.metfraglib.list.DefaultPeakList) PrecursorCandidate(de.ipbhalle.metfraglib.candidate.PrecursorCandidate)

Example 5 with PrecursorCandidate

use of de.ipbhalle.metfraglib.candidate.PrecursorCandidate in project MetFragRelaunched by ipb-halle.

the class MoNARestWebService method performSpectrumSimilaritySearch.

public CandidateList performSpectrumSimilaritySearch() throws Exception {
    DefaultPeakList peaklist = (DefaultPeakList) this.settings.get(VariableNames.PEAK_LIST_NAME);
    String queryString = "{\"compound\":{},\"metadata\":[],\"tags\":[],\"match\":{\"spectra\":\"";
    for (int i = 0; i < peaklist.getNumberElements(); i++) {
        TandemMassPeak peak = (TandemMassPeak) peaklist.getElement(i);
        queryString += peak.getMass() + ":" + peak.getAbsoluteIntensity();
        if (i != (peaklist.getNumberElements() - 1))
            queryString += " ";
    }
    queryString += "\"}}";
    String result = performQuery(queryString, "http://mona.fiehnlab.ucdavis.edu/rest/spectra/search");
    JSONParser parser = new JSONParser();
    JSONArray jsonArray = (JSONArray) parser.parse(new java.io.InputStreamReader(IOUtils.toInputStream(result)));
    CandidateList spectralCandidates = new CandidateList();
    this.logger.info("Got " + jsonArray.size() + " results from MoNA.");
    java.util.ArrayList<String> inchikeys = new java.util.ArrayList<String>();
    java.util.ArrayList<Double> scores = new java.util.ArrayList<Double>();
    for (int i = 0; i < jsonArray.size(); i++) {
        try {
            JSONObject obj = (JSONObject) jsonArray.get(i);
            JSONObject compoundObject = (JSONObject) obj.get("chemicalCompound");
            JSONObject scoreObject = (JSONObject) obj.get("score");
            Double currentScore = (Double) scoreObject.get("score");
            String currentInChIKey1 = (String) compoundObject.get("inchiKey");
            // unique results by inchikey
            int index = inchikeys.indexOf(currentInChIKey1);
            if (index != -1) {
                double scoreAlreadyFound = scores.get(index);
                if (scoreAlreadyFound > currentScore)
                    continue;
                else {
                    spectralCandidates.removeElement(index);
                    scores.remove(index);
                    inchikeys.remove(index);
                }
            }
            ICandidate candidate = new PrecursorCandidate((String) compoundObject.get("inchi"), String.valueOf((Long) compoundObject.get("id")));
            candidate.setProperty(VariableNames.INCHI_KEY_NAME, (String) compoundObject.get("inchiKey"));
            candidate.setProperty(VariableNames.INCHI_KEY_1_NAME, ((String) compoundObject.get("inchiKey")).split("-")[0]);
            candidate.setProperty("scaledScore", scoreObject.get("scaledScore"));
            candidate.setProperty("score", currentScore);
            candidate.setProperty("relativeScore", scoreObject.get("relativeScore"));
            inchikeys.add(currentInChIKey1);
            scores.add(currentScore);
            spectralCandidates.addElement(candidate);
        } catch (Exception e) {
            System.err.println("performSpectrumSimilaritySearch MoNARestWebService error");
            spectralCandidates = new CandidateList();
            break;
        }
    }
    this.logger.info("After filtering " + spectralCandidates.getNumberElements() + " results left.");
    return spectralCandidates;
}
Also used : InputStreamReader(java.io.InputStreamReader) JSONArray(org.json.simple.JSONArray) DefaultPeakList(de.ipbhalle.metfraglib.list.DefaultPeakList) PrecursorCandidate(de.ipbhalle.metfraglib.candidate.PrecursorCandidate) ICandidate(de.ipbhalle.metfraglib.interfaces.ICandidate) ParseException(org.json.simple.parser.ParseException) IOException(java.io.IOException) JSONObject(org.json.simple.JSONObject) CandidateList(de.ipbhalle.metfraglib.list.CandidateList) JSONParser(org.json.simple.parser.JSONParser) TandemMassPeak(de.ipbhalle.metfraglib.peak.TandemMassPeak)

Aggregations

PrecursorCandidate (de.ipbhalle.metfraglib.candidate.PrecursorCandidate)8 ICandidate (de.ipbhalle.metfraglib.interfaces.ICandidate)4 CandidateList (de.ipbhalle.metfraglib.list.CandidateList)3 DefaultPeakList (de.ipbhalle.metfraglib.list.DefaultPeakList)2 Settings (de.ipbhalle.metfraglib.settings.Settings)2 CandidateListWriterPSV (de.ipbhalle.metfraglib.writer.CandidateListWriterPSV)2 File (java.io.File)2 IOException (java.io.IOException)2 Before (org.junit.Before)2 MultipleHeadersFoundInInputDatabaseException (de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException)1 ScoredCandidateList (de.ipbhalle.metfraglib.list.ScoredCandidateList)1 TandemMassPeak (de.ipbhalle.metfraglib.peak.TandemMassPeak)1 FilteredStringTandemMassPeakListReader (de.ipbhalle.metfraglib.peaklistreader.FilteredStringTandemMassPeakListReader)1 MetFragGlobalSettings (de.ipbhalle.metfraglib.settings.MetFragGlobalSettings)1 CandidateWriterXLS (de.ipbhalle.metfraglib.writer.CandidateWriterXLS)1 Molecule (de.ipbhalle.metfragweb.datatype.Molecule)1 ScoreSummary (de.ipbhalle.metfragweb.datatype.ScoreSummary)1 UploadedSuspectListFile (de.ipbhalle.metfragweb.datatype.UploadedSuspectListFile)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1