Search in sources :

Example 1 with MetFragGlobalSettings

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

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

Example 3 with MetFragGlobalSettings

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);
}
Also used : CouldNotCreateProcessException(de.ipbhalle.exception.CouldNotCreateProcessException) MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) CouldNotWriteStatusException(de.ipbhalle.exception.CouldNotWriteStatusException) IOException(java.io.IOException) ParameterNotKnownException(de.ipbhalle.metfraglib.exceptions.ParameterNotKnownException) CouldNotReadStatusException(de.ipbhalle.exception.CouldNotReadStatusException) CouldNotFetchResultsException(de.ipbhalle.exception.CouldNotFetchResultsException) ParameterNotKnownException(de.ipbhalle.metfraglib.exceptions.ParameterNotKnownException) CouldNotCreateProcessException(de.ipbhalle.exception.CouldNotCreateProcessException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CouldNotRemoveProcessException(de.ipbhalle.exception.CouldNotRemoveProcessException) ExecutionException(java.util.concurrent.ExecutionException) CouldNotReadHostException(de.ipbhalle.exception.CouldNotReadHostException) CouldNotWriteStatusException(de.ipbhalle.exception.CouldNotWriteStatusException) ResponseEntity(org.springframework.http.ResponseEntity) SettingsChecker(de.ipbhalle.metfraglib.parameter.SettingsChecker) File(java.io.File) ProcessAssembler(de.ipbhalle.model.ProcessAssembler) CombinedMetFragProcess(de.ipbhalle.metfraglib.process.CombinedMetFragProcess) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with MetFragGlobalSettings

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;
}
Also used : MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings)

Example 5 with MetFragGlobalSettings

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;
    }
}
Also used : MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) MultipleHeadersFoundInInputDatabaseException(de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException)

Aggregations

MetFragGlobalSettings (de.ipbhalle.metfraglib.settings.MetFragGlobalSettings)57 IOException (java.io.IOException)24 MultipleHeadersFoundInInputDatabaseException (de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException)22 CandidateList (de.ipbhalle.metfraglib.list.CandidateList)20 File (java.io.File)19 CombinedMetFragProcess (de.ipbhalle.metfraglib.process.CombinedMetFragProcess)14 AtomTypeNotKnownFromInputListException (de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException)13 ICandidate (de.ipbhalle.metfraglib.interfaces.ICandidate)13 ArrayList (java.util.ArrayList)8 LocalPSVDatabase (de.ipbhalle.metfraglib.database.LocalPSVDatabase)7 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)6 ParameterNotKnownException (de.ipbhalle.metfraglib.exceptions.ParameterNotKnownException)5 RelativeIntensityNotDefinedException (de.ipbhalle.metfraglib.exceptions.RelativeIntensityNotDefinedException)5 RetentionTimeNotFoundException (de.ipbhalle.metfraglib.exceptions.RetentionTimeNotFoundException)5 TooFewCandidatesException (de.ipbhalle.metfraglib.exceptions.TooFewCandidatesException)5 SortedScoredCandidateList (de.ipbhalle.metfraglib.list.SortedScoredCandidateList)5 FileNotFoundException (java.io.FileNotFoundException)5 CDKException (org.openscience.cdk.exception.CDKException)5 LocalCSVDatabase (de.ipbhalle.metfraglib.database.LocalCSVDatabase)4 DatabaseIdentifierNotFoundException (de.ipbhalle.metfraglib.exceptions.DatabaseIdentifierNotFoundException)3