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();
}
}
Aggregations