use of de.ipbhalle.metfraglib.settings.MetFragGlobalSettings 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();
}
}
use of de.ipbhalle.metfraglib.settings.MetFragGlobalSettings 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();
}
}
}
use of de.ipbhalle.metfraglib.settings.MetFragGlobalSettings in project MetFragRelaunched by ipb-halle.
the class MetFragRestController method process.
/**
* runs a metfrag query
*
* @param args
* @return
* @throws CouldNotWriteStatusException
* @throws CouldNotCreateProcessException
*/
@RequestMapping(method = RequestMethod.POST, value = "", produces = { MediaType.APPLICATION_JSON_VALUE })
@ResponseBody
public ResponseEntity<Resource<ProcessAssembler>> process(@RequestBody ProcessArguments args) throws CouldNotWriteStatusException, CouldNotCreateProcessException {
File resFolder;
String processid;
try {
resFolder = Files.createTempDirectory("java.io.tmpdir").toFile();
processid = resFolder.getName();
try {
MetFragGlobalSettings settings = args.getSettingsObject(resFolder);
// check settings
SettingsChecker settingsChecker = new SettingsChecker();
if (!settingsChecker.check(settings))
throw new CouldNotCreateProcessException("Error: Corrupt parameters");
logger.info("Storing in " + settings.get(VariableNames.STORE_RESULTS_PATH_NAME));
CombinedMetFragProcess mp = new CombinedMetFragProcess(settings);
this.writeStatus("RUNNING", processid);
this.writeHost(processid);
new Thread(() -> {
System.out.println("staring run");
try {
MetFragRestService.startMetFrag(mp, settings, resFolder.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
return;
}
}, "MyThread-" + processid).start();
} catch (ParameterNotKnownException e) {
e.printStackTrace();
this.writeStatus("ERROR", processid);
throw new CouldNotCreateProcessException("Error: Parameter not known");
} catch (IOException e) {
e.printStackTrace();
throw new CouldNotCreateProcessException("Error: Could not write status");
} catch (Exception e) {
e.printStackTrace();
this.writeStatus("ERROR", processid);
throw new CouldNotCreateProcessException("Error: Unknown error");
}
} catch (IOException e) {
throw new CouldNotWriteStatusException(e.getMessage());
}
Resource<ProcessAssembler> resource = new ProcessAssembler("process", processid).toResource();
resource.add(linkTo(MetFragRestController.class).slash("process").withSelfRel());
resource.add(linkTo(MetFragRestController.class).slash("status").slash(processid).withRel("status"));
resource.add(linkTo(MetFragRestController.class).slash("host").slash(processid).withRel("host"));
resource.add(linkTo(MetFragRestController.class).slash("result").slash(processid).withRel("result"));
resource.add(linkTo(MetFragRestController.class).slash("resultzip").slash(processid).withRel("resultzip"));
return new ResponseEntity<Resource<ProcessAssembler>>(resource, HttpStatus.CREATED);
}
use of de.ipbhalle.metfraglib.settings.MetFragGlobalSettings in project MetFragRelaunched by ipb-halle.
the class ProcessArguments method getSettingsObject.
public MetFragGlobalSettings getSettingsObject(File resFolder) throws ParameterNotKnownException {
MetFragGlobalSettings settings = new MetFragGlobalSettings();
if (fragmentpeakmatchabsolutemassdeviation != null)
settings.set(VariableNames.ABSOLUTE_MASS_DEVIATION_NAME, ParameterDataTypes.getParameter(fragmentpeakmatchabsolutemassdeviation, VariableNames.ABSOLUTE_MASS_DEVIATION_NAME));
if (fragmentpeakmatchrelativemassdeviation != null)
settings.set(VariableNames.RELATIVE_MASS_DEVIATION_NAME, ParameterDataTypes.getParameter(fragmentpeakmatchabsolutemassdeviation, VariableNames.RELATIVE_MASS_DEVIATION_NAME));
if (databasesearchrelativemassdeviation != null)
settings.set(VariableNames.DATABASE_RELATIVE_MASS_DEVIATION_NAME, ParameterDataTypes.getParameter(databasesearchrelativemassdeviation, VariableNames.DATABASE_RELATIVE_MASS_DEVIATION_NAME));
if (precursorcompoundids != null)
settings.set(VariableNames.PRECURSOR_DATABASE_IDS_NAME, ParameterDataTypes.getParameter(precursorcompoundids, VariableNames.PRECURSOR_DATABASE_IDS_NAME));
if (ionizedprecursormass != null)
settings.set(VariableNames.PRECURSOR_ION_MASS_NAME, ParameterDataTypes.getParameter(ionizedprecursormass, VariableNames.PRECURSOR_ION_MASS_NAME));
if (neutralprecursormass != null)
settings.set(VariableNames.PRECURSOR_NEUTRAL_MASS_NAME, ParameterDataTypes.getParameter(neutralprecursormass, VariableNames.PRECURSOR_NEUTRAL_MASS_NAME));
if (neutralprecursormolecularformula != null)
settings.set(VariableNames.PRECURSOR_MOLECULAR_FORMULA_NAME, ParameterDataTypes.getParameter(neutralprecursormolecularformula, VariableNames.PRECURSOR_MOLECULAR_FORMULA_NAME));
if (precursorionmode != null)
settings.set(VariableNames.PRECURSOR_ION_MODE_NAME, ParameterDataTypes.getParameter(precursorionmode, VariableNames.PRECURSOR_ION_MODE_NAME));
if (precursoriontype != null)
settings.set(VariableNames.PRECURSOR_ION_MODE_STRING_NAME, ParameterDataTypes.getParameter(precursoriontype, VariableNames.PRECURSOR_ION_MODE_STRING_NAME));
if (peakliststring != null)
settings.set(VariableNames.PEAK_LIST_STRING_NAME, ParameterDataTypes.getParameter(peakliststring, VariableNames.PEAK_LIST_STRING_NAME));
if (metfragdatabasetype != null)
settings.set(VariableNames.METFRAG_DATABASE_TYPE_NAME, ParameterDataTypes.getParameter(metfragdatabasetype, VariableNames.METFRAG_DATABASE_TYPE_NAME));
if (maximumtreedepth != null)
settings.set(VariableNames.MAXIMUM_TREE_DEPTH_NAME, ParameterDataTypes.getParameter(maximumtreedepth, VariableNames.MAXIMUM_TREE_DEPTH_NAME));
if (samplename != null)
settings.set(VariableNames.SAMPLE_NAME, ParameterDataTypes.getParameter(samplename, VariableNames.SAMPLE_NAME));
// local database
if (localmetchemdatabase != null)
settings.set(VariableNames.LOCAL_METCHEM_DATABASE_NAME, ParameterDataTypes.getParameter(localmetchemdatabase, VariableNames.LOCAL_METCHEM_DATABASE_NAME));
if (localmetchemdatabaseportnumber != null)
settings.set(VariableNames.LOCAL_METCHEM_DATABASE_PORT_NUMBER_NAME, ParameterDataTypes.getParameter(localmetchemdatabaseportnumber, VariableNames.LOCAL_METCHEM_DATABASE_PORT_NUMBER_NAME));
if (localmetchemdatabaseserverip != null)
settings.set(VariableNames.LOCAL_METCHEM_DATABASE_SERVER_IP_NAME, ParameterDataTypes.getParameter(localmetchemdatabaseserverip, VariableNames.LOCAL_METCHEM_DATABASE_SERVER_IP_NAME));
if (localmetchemdatabaseuser != null)
settings.set(VariableNames.LOCAL_METCHEM_DATABASE_USER_NAME, ParameterDataTypes.getParameter(localmetchemdatabaseuser, VariableNames.LOCAL_METCHEM_DATABASE_USER_NAME));
if (localmetchemdatabasepassword != null)
settings.set(VariableNames.LOCAL_METCHEM_DATABASE_PASSWORD_NAME, ParameterDataTypes.getParameter(localmetchemdatabasepassword, VariableNames.LOCAL_METCHEM_DATABASE_PASSWORD_NAME));
if (localmetchemdatabaselibrary != null)
settings.set(VariableNames.LOCAL_METCHEM_DATABASE_LIBRARY_NAME, ParameterDataTypes.getParameter(localmetchemdatabaselibrary, VariableNames.LOCAL_METCHEM_DATABASE_LIBRARY_NAME));
this.addAdditionalParameters(settings, resFolder);
return settings;
}
use of de.ipbhalle.metfraglib.settings.MetFragGlobalSettings in project MetFragRelaunched by ipb-halle.
the class CheckPubChemDatabase method readDatabaseConfigFromFile.
public MetFragGlobalSettings readDatabaseConfigFromFile() {
try {
String peakListFilePath = ClassLoader.getSystemResource("settings.properties").getFile();
MetFragGlobalSettings settings = MetFragGlobalSettings.readSettings(new java.io.File(peakListFilePath), null);
return settings;
} catch (Exception e) {
return null;
}
}
Aggregations