Search in sources :

Example 1 with DatabaseIdentifierNotFoundException

use of de.ipbhalle.metfraglib.exceptions.DatabaseIdentifierNotFoundException 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)

Aggregations

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