Search in sources :

Example 1 with OnlineExtendedPubChemDatabase

use of de.ipbhalle.metfraglib.database.OnlineExtendedPubChemDatabase 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 OnlineExtendedPubChemDatabase

use of de.ipbhalle.metfraglib.database.OnlineExtendedPubChemDatabase in project MetFragRelaunched by ipb-halle.

the class DownloadEntriesFromPubChem method downloadFromString.

public static void downloadFromString(String idString) {
    String[] ids = idString.trim().split(",");
    MetFragGlobalSettings settings = new MetFragGlobalSettings();
    settings.set(VariableNames.PRECURSOR_DATABASE_IDS_NAME, ids);
    OnlineExtendedPubChemDatabase db = new OnlineExtendedPubChemDatabase(settings);
    CandidateList candidates = null;
    try {
        candidates = db.getCandidateByIdentifier(db.getCandidateIdentifiers());
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    for (int i = 0; i < candidates.getNumberElements(); i++) {
        ICandidate candidate = candidates.getElement(i);
        try {
            System.out.println(candidate.getIdentifier() + "|" + candidate.getInChI() + "|" + candidate.getMolecularFormula().toString() + "|" + candidate.getMolecularFormula().getMonoisotopicMass() + "|" + candidate.getProperty(VariableNames.PUBCHEM_XLOGP_NAME) + "|" + candidate.getProperty(VariableNames.INCHI_KEY_1_NAME) + "|" + candidate.getProperty(VariableNames.INCHI_KEY_2_NAME) + "|" + candidate.getProperty(VariableNames.PUBCHEM_NUMBER_PATENTS_NAME) + "|" + candidate.getProperty(VariableNames.PUBCHEM_NUMBER_PUBMED_REFERENCES_NAME) + "|" + candidate.getProperty(VariableNames.SMILES_NAME));
        } catch (AtomTypeNotKnownFromInputListException e) {
            e.printStackTrace();
        }
    }
}
Also used : MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) CandidateList(de.ipbhalle.metfraglib.list.CandidateList) OnlineExtendedPubChemDatabase(de.ipbhalle.metfraglib.database.OnlineExtendedPubChemDatabase) AtomTypeNotKnownFromInputListException(de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException) DatabaseIdentifierNotFoundException(de.ipbhalle.metfraglib.exceptions.DatabaseIdentifierNotFoundException) AtomTypeNotKnownFromInputListException(de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException) MultipleHeadersFoundInInputDatabaseException(de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException) ICandidate(de.ipbhalle.metfraglib.interfaces.ICandidate)

Aggregations

OnlineExtendedPubChemDatabase (de.ipbhalle.metfraglib.database.OnlineExtendedPubChemDatabase)2 AtomTypeNotKnownFromInputListException (de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException)2 DatabaseIdentifierNotFoundException (de.ipbhalle.metfraglib.exceptions.DatabaseIdentifierNotFoundException)2 MultipleHeadersFoundInInputDatabaseException (de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException)2 ICandidate (de.ipbhalle.metfraglib.interfaces.ICandidate)2 CandidateList (de.ipbhalle.metfraglib.list.CandidateList)2 MetFragGlobalSettings (de.ipbhalle.metfraglib.settings.MetFragGlobalSettings)2 LocalPSVDatabase (de.ipbhalle.metfraglib.database.LocalPSVDatabase)1 CandidateListWriterPSV (de.ipbhalle.metfraglib.writer.CandidateListWriterPSV)1