Search in sources :

Example 1 with Settings

use of de.ipbhalle.metfraglib.settings.Settings in project MetFragRelaunched by ipb-halle.

the class CheckPreProcessingSmartsFilter_Test method setUp.

@Before
public void setUp() {
    // init candidate objects
    toTestCandidates[0] = new PrecursorCandidate("InChI=1S/C12H19NO5S2/c1-12(2,3)18-11(14)13-9(8-17-20(4,15)16)10-6-5-7-19-10/h5-7,9H,8H2,1-4H3,(H,13,14)/t9-/m0/s1", "13877939");
    toTestCandidates[0].setProperty(VariableNames.INCHI_KEY_1_NAME, "LGXPPQPBQCFQPU");
    toTestCandidates[1] = new PrecursorCandidate("InChI=1S/C12H19NO5S2/c1-13(19(2,14)15)12-8-6-11(7-9-12)5-4-10-18-20(3,16)17/h6-9H,4-5,10H2,1-3H3", "59122053");
    toTestCandidates[1].setProperty(VariableNames.INCHI_KEY_1_NAME, "CNMCSJSREOGBCU");
    toTestCandidates[2] = new PrecursorCandidate("InChI=1S/C12H19NO5S2/c1-19(14,15)13-12-8-6-11(7-9-12)5-3-4-10-18-20(2,16)17/h6-9,13H,3-5,10H2,1-2H3", "54525898");
    toTestCandidates[2].setProperty(VariableNames.INCHI_KEY_1_NAME, "YTBWCCSOEYFHGQ");
    toTestCandidates[3] = new PrecursorCandidate("InChI=1S/C15H12O5/c16-9-3-1-8(2-4-9)13-7-12(19)15-11(18)5-10(17)6-14(15)20-13/h1-6,13,16-18H,7H2", "932");
    toTestCandidates[3].setProperty(VariableNames.INCHI_KEY_1_NAME, "FTVWIRXFELQLPI");
    this.settings = new Settings();
}
Also used : PrecursorCandidate(de.ipbhalle.metfraglib.candidate.PrecursorCandidate) Settings(de.ipbhalle.metfraglib.settings.Settings) Before(org.junit.Before)

Example 2 with Settings

use of de.ipbhalle.metfraglib.settings.Settings in project MetFragRelaunched by ipb-halle.

the class CheckPreProcessingSuspectListFilter_Test method setUp.

@Before
public void setUp() {
    // init candidate objects
    toTestCandidates[0] = new PrecursorCandidate("InChI=1S/C12H19NO5S2/c1-12(2,3)18-11(14)13-9(8-17-20(4,15)16)10-6-5-7-19-10/h5-7,9H,8H2,1-4H3,(H,13,14)/t9-/m0/s1", "13877939");
    toTestCandidates[0].setProperty(VariableNames.INCHI_KEY_1_NAME, "LGXPPQPBQCFQPU");
    toTestCandidates[1] = new PrecursorCandidate("InChI=1S/C12H19NO5S2/c1-13(19(2,14)15)12-8-6-11(7-9-12)5-4-10-18-20(3,16)17/h6-9H,4-5,10H2,1-3H3", "59122053");
    toTestCandidates[1].setProperty(VariableNames.INCHI_KEY_1_NAME, "CNMCSJSREOGBCU");
    toTestCandidates[2] = new PrecursorCandidate("InChI=1S/C12H19NO5S2/c1-19(14,15)13-12-8-6-11(7-9-12)5-3-4-10-18-20(2,16)17/h6-9,13H,3-5,10H2,1-2H3", "54525898");
    toTestCandidates[2].setProperty(VariableNames.INCHI_KEY_1_NAME, "YTBWCCSOEYFHGQ");
    toTestCandidates[3] = new PrecursorCandidate("InChI=1S/C15H12O5/c16-9-3-1-8(2-4-9)13-7-12(19)15-11(18)5-10(17)6-14(15)20-13/h1-6,13,16-18H,7H2", "932");
    toTestCandidates[3].setProperty(VariableNames.INCHI_KEY_1_NAME, "FTVWIRXFELQLPI");
    this.settings = new Settings();
    this.candidateFilter = new PreProcessingCandidateSuspectListFilter(this.inChIKeys, "test", settings, false);
}
Also used : PrecursorCandidate(de.ipbhalle.metfraglib.candidate.PrecursorCandidate) Settings(de.ipbhalle.metfraglib.settings.Settings) Before(org.junit.Before)

Example 3 with Settings

use of de.ipbhalle.metfraglib.settings.Settings in project MetFragRelaunched by ipb-halle.

the class CombinedMetFragProcess method initExternalProperties.

/**
 * @param path
 * @param candidateList
 * @return
 */
private boolean initExternalProperties(String path, CandidateList candidateList, String[] propertyValuesToScore) {
    Settings settings = new Settings();
    settings.set(VariableNames.LOCAL_DATABASE_PATH_NAME, path);
    LocalPropertyFileDatabase propertyDatabase = new LocalPropertyFileDatabase(settings);
    java.util.ArrayList<String> externalInChIKeys = new java.util.ArrayList<String>();
    java.util.ArrayList<String> externalPropertiesDefined = new java.util.ArrayList<String>();
    java.util.ArrayList<String> ids = null;
    try {
        ids = propertyDatabase.getCandidateIdentifiers();
    } catch (Exception e) {
        this.logger.error("Error: Problems reading ExternalPropertyFile: " + path);
        return false;
    }
    CandidateList externalCandidates = propertyDatabase.getCandidateByIdentifier(ids);
    for (int i = 0; i < externalCandidates.getNumberElements(); i++) {
        ICandidate externalCandidate = externalCandidates.getElement(i);
        if (!externalCandidate.getProperties().containsKey(VariableNames.INCHI_KEY_1_NAME) || externalCandidate.getProperty(VariableNames.INCHI_KEY_1_NAME) == null) {
            this.logger.error("Error: InChIKey1 field not defined for all candidate in ExternalPropertyFile: " + path);
            return false;
        }
        String externalInChIKey1 = (String) externalCandidate.getProperty(VariableNames.INCHI_KEY_1_NAME);
        if (externalInChIKeys.contains(externalInChIKey1)) {
            this.logger.error("Error: InChIKey1 " + externalInChIKey1 + " defined more than once in ExternalPropertyFile: " + path);
            return false;
        } else
            externalInChIKeys.add(externalInChIKey1);
        // try to set external values
        for (int j = 0; j < candidateList.getNumberElements(); j++) {
            ICandidate candidate = candidateList.getElement(j);
            String candidateInChIKey1 = (String) candidate.getProperty(VariableNames.INCHI_KEY_1_NAME);
            if (externalInChIKey1.equals(candidateInChIKey1)) {
                java.util.Enumeration<?> externalKeys = externalCandidate.getProperties().keys();
                while (externalKeys.hasMoreElements()) {
                    String currentKey = (String) externalKeys.nextElement();
                    for (int k = 0; k < propertyValuesToScore.length; k++) {
                        if (propertyValuesToScore[k].equals(currentKey)) {
                            if (!externalPropertiesDefined.contains(currentKey))
                                externalPropertiesDefined.add(currentKey);
                            Double value = null;
                            try {
                                value = (Double) externalCandidate.getProperty(currentKey);
                            } catch (Exception e1) {
                                try {
                                    value = Double.parseDouble((String) externalCandidate.getProperty(currentKey));
                                } catch (Exception e2) {
                                    this.logger.error("Error: Invalid value for candidate " + externalInChIKey1 + " for column " + currentKey + " in ExternalPropertyFile: " + path);
                                    return false;
                                }
                            }
                            candidate.setProperty(currentKey, value);
                        }
                    }
                }
            }
        }
    }
    // set property to zero (neutral element) in case not defined
    for (int i = 0; i < candidateList.getNumberElements(); i++) {
        ICandidate candidate = candidateList.getElement(i);
        for (int j = 0; j < externalPropertiesDefined.size(); j++) {
            if (!candidate.getProperties().containsKey(externalPropertiesDefined.get(j)) || candidate.getProperty(externalPropertiesDefined.get(j)) == null) {
                candidate.setProperty(externalPropertiesDefined.get(j), 0.0);
            }
        }
    }
    return true;
}
Also used : ScorePropertyNotDefinedException(de.ipbhalle.metfraglib.exceptions.ScorePropertyNotDefinedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ICandidate(de.ipbhalle.metfraglib.interfaces.ICandidate) LocalPropertyFileDatabase(de.ipbhalle.metfraglib.database.LocalPropertyFileDatabase) SortedScoredCandidateList(de.ipbhalle.metfraglib.list.SortedScoredCandidateList) CandidateList(de.ipbhalle.metfraglib.list.CandidateList) ScoredCandidateList(de.ipbhalle.metfraglib.list.ScoredCandidateList) MetFragGlobalSettings(de.ipbhalle.metfraglib.settings.MetFragGlobalSettings) Settings(de.ipbhalle.metfraglib.settings.Settings) MetFragSingleProcessSettings(de.ipbhalle.metfraglib.settings.MetFragSingleProcessSettings)

Example 4 with Settings

use of de.ipbhalle.metfraglib.settings.Settings in project MetFragRelaunched by ipb-halle.

the class HDTopDownFragmenterAssignerScorer method initialise.

@Override
public void initialise() throws AtomTypeNotKnownFromInputListException, Exception {
    /*
		 * initialise candidate
		 */
    this.candidates[0].setProperty(VariableNames.HD_NUMBER_EXCHANGED_HYDROGENS, this.settings.get(VariableNames.HD_NUMBER_EXCHANGED_HYDROGENS));
    this.candidateWrapper = new HDPrecursorCandidateWrapper(this.candidates[0]);
    this.candidateWrapper.initialisePrecursorCandidate();
    /*
		 * initialise fragmenter
		 */
    this.fragmenter = (AbstractTopDownFragmenter) Class.forName((String) settings.get(VariableNames.METFRAG_FRAGMENTER_TYPE_NAME)).getConstructor(Settings.class).newInstance(settings);
    /*
		 * initialise score
		 */
    String[] score_types = (String[]) this.settings.get(VariableNames.METFRAG_SCORE_TYPES_NAME);
    // init scores and add hd scores
    IScore[] scores = new IScore[score_types.length];
    for (int i = 0; i < score_types.length; i++) {
        logger.debug("\t\tinitialising " + score_types[i]);
        scores[i] = (IScore) Class.forName(ClassNames.getClassNameOfScore(score_types[i])).getConstructor(Settings.class).newInstance(this.settings);
    }
    // add hd fragmenter score
    this.scoreCollection = new ScoreCollection(scores);
    Object writer = this.settings.get(VariableNames.METFRAG_CANDIDATE_WRITER_NAME);
    if (writer != null) {
        String[] writers = (String[]) writer;
        for (int i = 0; i < writers.length; i++) {
            if (writers[i].equals("ExtendedHDCSV")) {
                this.extendedWriter = true;
                break;
            }
        }
    }
}
Also used : HDPrecursorCandidateWrapper(de.ipbhalle.metfraglib.candidate.HDPrecursorCandidateWrapper) ScoreCollection(de.ipbhalle.metfraglib.collection.ScoreCollection) IScore(de.ipbhalle.metfraglib.interfaces.IScore) Settings(de.ipbhalle.metfraglib.settings.Settings)

Example 5 with Settings

use of de.ipbhalle.metfraglib.settings.Settings in project MetFragRelaunched by ipb-halle.

the class LocalPropertyFileDatabase method main.

public static void main(String[] args) throws Exception {
    Settings settings = new Settings();
    settings.set(VariableNames.LOCAL_DATABASE_PATH_NAME, "/home/cruttkie/Documents/PhD/MetFrag/debugs/emma/msready/v2.0.16-msready/Eawag_rt_inchi.csv");
    // settings.set(VariableNames.LOCAL_DATABASE_PATH_NAME, "/tmp/test2.sdf");
    LocalPropertyFileDatabase db = new LocalPropertyFileDatabase(settings);
    System.out.println(db.getCandidateIdentifiers().size());
}
Also used : Settings(de.ipbhalle.metfraglib.settings.Settings)

Aggregations

Settings (de.ipbhalle.metfraglib.settings.Settings)19 File (java.io.File)9 CandidateList (de.ipbhalle.metfraglib.list.CandidateList)7 MetFragGlobalSettings (de.ipbhalle.metfraglib.settings.MetFragGlobalSettings)7 ArrayList (java.util.ArrayList)7 ICandidate (de.ipbhalle.metfraglib.interfaces.ICandidate)6 IPeakListReader (de.ipbhalle.metfraglib.interfaces.IPeakListReader)6 SettingsChecker (de.ipbhalle.metfraglib.parameter.SettingsChecker)6 LocalPSVDatabase (de.ipbhalle.metfraglib.database.LocalPSVDatabase)5 MultipleHeadersFoundInInputDatabaseException (de.ipbhalle.metfraglib.exceptions.MultipleHeadersFoundInInputDatabaseException)5 ExecutorService (java.util.concurrent.ExecutorService)5 BufferedWriter (java.io.BufferedWriter)4 FileWriter (java.io.FileWriter)4 LocalCSVDatabase (de.ipbhalle.metfraglib.database.LocalCSVDatabase)3 IDatabase (de.ipbhalle.metfraglib.interfaces.IDatabase)3 GetRankOfCandidateMultipleThreadCSV (de.ipbhalle.metfrag.ranking.GetRankOfCandidateMultipleThreadCSV)2 FastBitArray (de.ipbhalle.metfraglib.FastBitArray)2 PrecursorCandidate (de.ipbhalle.metfraglib.candidate.PrecursorCandidate)2 ScoreCollection (de.ipbhalle.metfraglib.collection.ScoreCollection)2 LocalPropertyFileDatabase (de.ipbhalle.metfraglib.database.LocalPropertyFileDatabase)2