Search in sources :

Example 26 with CandidateList

use of de.ipbhalle.metfraglib.list.CandidateList in project MetFragRelaunched by ipb-halle.

the class LocalLipidMapsDatabase method getCandidateByIdentifier.

public CandidateList getCandidateByIdentifier(ArrayList<String> identifiers) {
    if (identifiers.size() == 0)
        return new CandidateList();
    String query = "SELECT " + CID_COLUMN_NAME + ", " + INCHI_COLUMN_NAME + "," + INCHIKEY1_COLUMN_NAME + "," + INCHIKEY2_COLUMN_NAME + "," + FORMULA_COLUMN_NAME + "," + MASS_COLUMN_NAME + " from " + TABLE_NAME + " where " + CID_COLUMN_NAME + " =\"" + identifiers.get(0) + "\"";
    for (String cid : identifiers) query += " or " + CID_COLUMN_NAME + " = \"" + cid + "\"";
    query += ";";
    logger.trace(query);
    ResultSet rs = this.submitQuery(query);
    if (rs == null)
        return new CandidateList();
    CandidateList candidates = new CandidateList();
    try {
        while (rs.next()) {
            String inchi = rs.getString(INCHI_COLUMN_NAME);
            ICandidate candidate = new TopDownPrecursorCandidate(inchi, rs.getString(CID_COLUMN_NAME));
            candidate.setProperty(VariableNames.INCHI_KEY_1_NAME, rs.getString(INCHIKEY1_COLUMN_NAME));
            candidate.setProperty(VariableNames.INCHI_KEY_2_NAME, rs.getString(INCHIKEY2_COLUMN_NAME));
            candidate.setProperty(VariableNames.MOLECULAR_FORMULA_NAME, rs.getString(FORMULA_COLUMN_NAME));
            try {
                candidate.setProperty(VariableNames.MONOISOTOPIC_MASS_NAME, rs.getDouble(MASS_COLUMN_NAME));
            } catch (Exception e) {
                try {
                    candidate.setProperty(VariableNames.MONOISOTOPIC_MASS_NAME, Double.parseDouble((String) rs.getString(MASS_COLUMN_NAME)));
                } catch (Exception e1) {
                    continue;
                }
            }
            candidates.addElement(candidate);
        }
        rs.close();
        this.statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return candidates;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) TopDownPrecursorCandidate(de.ipbhalle.metfraglib.candidate.TopDownPrecursorCandidate) CandidateList(de.ipbhalle.metfraglib.list.CandidateList) ICandidate(de.ipbhalle.metfraglib.interfaces.ICandidate) SQLException(java.sql.SQLException)

Example 27 with CandidateList

use of de.ipbhalle.metfraglib.list.CandidateList in project MetFragRelaunched by ipb-halle.

the class LocalMetChemDatabase method getCandidateByIdentifier.

/**
 */
public CandidateList getCandidateByIdentifier(ArrayList<String> identifiers) {
    if (identifiers.size() == 0 || this.tempSubstanceIDs == null || this.tempCandidates == null || this.tempCandidates.getNumberElements() == 0)
        return new CandidateList();
    CandidateList candidates = new CandidateList();
    for (int j = 0; j < identifiers.size(); j++) {
        for (int i = 0; i < this.tempSubstanceIDs.size(); i++) {
            if (this.tempSubstanceIDs.get(i).equals(identifiers.get(j))) {
                candidates.addElement(this.tempCandidates.getElement(i));
                break;
            }
        }
    }
    this.tempCandidates = null;
    this.tempSubstanceIDs = null;
    return candidates;
}
Also used : CandidateList(de.ipbhalle.metfraglib.list.CandidateList)

Example 28 with CandidateList

use of de.ipbhalle.metfraglib.list.CandidateList in project MetFragRelaunched by ipb-halle.

the class LocalMetChemDatabase method fillCandidateArrayLists.

protected void fillCandidateArrayLists(ResultSet rs) {
    this.tempCandidates = new CandidateList();
    this.tempSubstanceIDs = new ArrayList<String>();
    try {
        while (rs.next()) {
            ICandidate candidate = new TopDownPrecursorCandidate(rs.getString(this.INCHI_COLUMN_NAME), rs.getString(this.CID_COLUMN_NAME));
            candidate.setProperty(VariableNames.INCHI_KEY_1_NAME, rs.getString(this.INCHIKEY1_COLUMN_NAME));
            candidate.setProperty(VariableNames.INCHI_KEY_2_NAME, rs.getString(this.INCHIKEY2_COLUMN_NAME));
            candidate.setProperty(VariableNames.INCHI_KEY_3_NAME, rs.getString(this.INCHIKEY3_COLUMN_NAME));
            candidate.setProperty(VariableNames.MOLECULAR_FORMULA_NAME, rs.getString(this.FORMULA_COLUMN_NAME).replaceAll("[\\+\\-][0-9]*", ""));
            candidate.setProperty(VariableNames.MONOISOTOPIC_MASS_NAME, rs.getDouble(this.MASS_COLUMN_NAME));
            candidate.setProperty(VariableNames.SMILES_NAME, rs.getString(this.SMILES_COLUMN_NAME));
            candidate.setProperty(VariableNames.COMPOUND_NAME_NAME, "NA");
            candidate.setProperty("XlogP3", "NA");
            try {
                candidate.setProperty("XlogP3", rs.getDouble("xlogp3_aa"));
            } catch (org.postgresql.util.PSQLException e) {
            }
            try {
                candidate.setProperty("XlogP3", rs.getDouble("xlogp3"));
            } catch (org.postgresql.util.PSQLException e) {
            }
            try {
                candidate.setProperty(VariableNames.COMPOUND_NAME_NAME, rs.getString(this.COMPOUND_NAME_COLUMN_NAME));
            } catch (org.postgresql.util.PSQLException e) {
            } catch (java.lang.NullPointerException e) {
            }
            this.tempSubstanceIDs.add(rs.getString("substance_id"));
            this.tempCandidates.addElement(candidate);
        }
        rs.close();
        this.statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) TopDownPrecursorCandidate(de.ipbhalle.metfraglib.candidate.TopDownPrecursorCandidate) CandidateList(de.ipbhalle.metfraglib.list.CandidateList) ICandidate(de.ipbhalle.metfraglib.interfaces.ICandidate)

Example 29 with CandidateList

use of de.ipbhalle.metfraglib.list.CandidateList in project MetFragRelaunched by ipb-halle.

the class OnlineMetaCycDatabase method main.

public static void main(String[] args) throws MultipleHeadersFoundInInputDatabaseException, Exception {
    MetFragGlobalSettings settings = new MetFragGlobalSettings();
    settings.set(VariableNames.PRECURSOR_NEUTRAL_MASS_NAME, 610.15331);
    settings.set(VariableNames.DATABASE_RELATIVE_MASS_DEVIATION_NAME, 10.0);
    settings.set(VariableNames.METACYC_PROXY_SERVER, "www-cache.ipb-halle.de");
    settings.set(VariableNames.METACYC_PROXY_PORT, 3128);
    OnlineMetaCycDatabase db = new OnlineMetaCycDatabase(settings);
    java.util.ArrayList<String> ids = db.getCandidateIdentifiers(610.15331, 10.0);
    System.out.println("got " + ids.size() + " candidates");
    CandidateList list = db.getCandidateByIdentifier(ids);
    System.out.println(list.getNumberElements());
// http://websvc.biocyc.org/META/monoisotopicwt?wts=360.15728850299996&tol=5.0
// http://www.biocyc.org/getxml?id=META:CPD-8908&detail=low
}
Also used : MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) CandidateList(de.ipbhalle.metfraglib.list.CandidateList)

Example 30 with CandidateList

use of de.ipbhalle.metfraglib.list.CandidateList in project MetFragRelaunched by ipb-halle.

the class PostProcessingCandidateHDGroupFlagFilter method filter.

public CandidateList filter(CandidateList candidateList) {
    this.numberPostFilteredCandidates = 0;
    if (candidateList.getNumberElements() == 0)
        return candidateList;
    CandidateList filteredCandidateList = new SortedScoredCandidateList();
    java.util.ArrayList<String> seenHDGroupFlags = new java.util.ArrayList<String>();
    java.util.HashMap<String, MatchList> hdGroupFlagToMatchList = new java.util.HashMap<String, MatchList>();
    java.util.HashMap<String, IMolecularStructure> hdGroupFlagToMolecularStructure = new java.util.HashMap<String, IMolecularStructure>();
    java.util.HashMap<String, java.util.Hashtable<String, Object>> hdGroupFlagToProperties = new java.util.HashMap<String, java.util.Hashtable<String, Object>>();
    for (int i = 0; i < candidateList.getNumberElements(); i++) {
        ICandidate currentCandidate = candidateList.getElement(i);
        if (currentCandidate.getProperty(VariableNames.HD_GROUP_FLAG_NAME) != null) {
            String hdGroupFlag = (String) currentCandidate.getProperty(VariableNames.HD_GROUP_FLAG_NAME);
            java.util.Hashtable<String, Object> currentProperties = currentCandidate.getProperties();
            if (currentProperties != null) {
                if (hdGroupFlagToProperties.containsKey(hdGroupFlag) && hdGroupFlagToProperties.get(hdGroupFlag) != null) {
                    java.util.Hashtable<String, Object> storedProperties = hdGroupFlagToProperties.get(hdGroupFlag);
                    java.util.Enumeration<String> e = currentProperties.keys();
                    while (e.hasMoreElements()) {
                        String currentKey = e.nextElement();
                        if (!storedProperties.containsKey(currentKey)) {
                            storedProperties.put(currentKey, currentProperties.get(currentKey));
                        }
                    }
                } else
                    hdGroupFlagToProperties.put(hdGroupFlag, currentProperties);
            }
            if (currentCandidate.getPrecursorMolecule() != null) {
                hdGroupFlagToMolecularStructure.put(hdGroupFlag, currentCandidate.getPrecursorMolecule());
                hdGroupFlagToProperties.put(hdGroupFlag, currentCandidate.getProperties());
            }
            if (currentCandidate.getMatchList() != null) {
                hdGroupFlagToMatchList.put(hdGroupFlag, currentCandidate.getMatchList());
            }
            if (!seenHDGroupFlags.contains(hdGroupFlag)) {
                filteredCandidateList.addElement(currentCandidate);
                seenHDGroupFlags.add(hdGroupFlag);
            } else {
                currentCandidate.nullify();
                currentCandidate = null;
            // this.numberPostFilteredCandidates++;
            }
        }
    }
    for (int i = 0; i < filteredCandidateList.getNumberElements(); i++) {
        String hdGroupFlag = (String) filteredCandidateList.getElement(i).getProperty(VariableNames.HD_GROUP_FLAG_NAME);
        // set matchlist
        filteredCandidateList.getElement(i).setMatchList(hdGroupFlagToMatchList.get(hdGroupFlag));
        // set precursor molecule
        filteredCandidateList.getElement(i).setPrecursorMolecule(hdGroupFlagToMolecularStructure.get(hdGroupFlag));
        // set properties (if necessary)
        java.util.Hashtable<String, Object> properties = hdGroupFlagToProperties.get(hdGroupFlag);
        java.util.Enumeration<String> e = properties.keys();
        while (e.hasMoreElements()) {
            String currentKey = e.nextElement();
            // check whether property is already set (so if there's a more candidate specific property present keep it)
            if (filteredCandidateList.getElement(i).getProperty(currentKey) == null) {
                filteredCandidateList.getElement(i).setProperty(currentKey, properties.get(currentKey));
            }
        }
        // remove hd group flag
        filteredCandidateList.getElement(i).removeProperty(VariableNames.HD_GROUP_FLAG_NAME);
    }
    return filteredCandidateList;
}
Also used : MatchList(de.ipbhalle.metfraglib.list.MatchList) ICandidate(de.ipbhalle.metfraglib.interfaces.ICandidate) IMolecularStructure(de.ipbhalle.metfraglib.interfaces.IMolecularStructure) SortedScoredCandidateList(de.ipbhalle.metfraglib.list.SortedScoredCandidateList) SortedScoredCandidateList(de.ipbhalle.metfraglib.list.SortedScoredCandidateList) CandidateList(de.ipbhalle.metfraglib.list.CandidateList)

Aggregations

CandidateList (de.ipbhalle.metfraglib.list.CandidateList)80 ICandidate (de.ipbhalle.metfraglib.interfaces.ICandidate)43 MetFragGlobalSettings (de.ipbhalle.metfraglib.settings.MetFragGlobalSettings)22 SortedScoredCandidateList (de.ipbhalle.metfraglib.list.SortedScoredCandidateList)20 MultipleHeadersFoundInInputDatabaseException (de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException)18 File (java.io.File)18 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)18 MatchList (de.ipbhalle.metfraglib.list.MatchList)17 ScoredCandidateList (de.ipbhalle.metfraglib.list.ScoredCandidateList)17 RelativeIntensityNotDefinedException (de.ipbhalle.metfraglib.exceptions.RelativeIntensityNotDefinedException)15 FileWriter (java.io.FileWriter)14 TopDownPrecursorCandidate (de.ipbhalle.metfraglib.candidate.TopDownPrecursorCandidate)12 LocalPSVDatabase (de.ipbhalle.metfraglib.database.LocalPSVDatabase)12 AtomTypeNotKnownFromInputListException (de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException)9 LocalCSVDatabase (de.ipbhalle.metfraglib.database.LocalCSVDatabase)7 Settings (de.ipbhalle.metfraglib.settings.Settings)7 SQLException (java.sql.SQLException)7 IDatabase (de.ipbhalle.metfraglib.interfaces.IDatabase)6 CombinedMetFragProcess (de.ipbhalle.metfraglib.process.CombinedMetFragProcess)6