Search in sources :

Example 1 with SiriusNodePeak

use of de.ipbhalle.metfraglib.peak.SiriusNodePeak in project MetFragRelaunched by ipb-halle.

the class SiriusNodePeakList method parseDotFile.

/**
 * generate SiriusNodePeakList from dot file
 *
 * @param filename
 * @return
 */
public void parseDotFile(String filename) {
    java.util.Hashtable<String, SiriusNodePeak> nodes = new java.util.Hashtable<String, SiriusNodePeak>();
    double maxIntensity = 0.0;
    try {
        java.io.BufferedReader breader = new java.io.BufferedReader(new java.io.FileReader(new java.io.File(filename)));
        String line = breader.readLine();
        while ((line = breader.readLine()) != null) {
            line = line.trim();
            if (line.length() == 1)
                continue;
            if (line.contains("->")) {
                String[] tmp = line.split("\\s+");
                SiriusNodePeak curChild = nodes.get(tmp[2].trim());
                SiriusNodePeak curFather = nodes.get(tmp[0].trim());
                try {
                    curChild.setLossFormula(new ByteMolecularFormula(tmp[3].replaceFirst("\\[label=\"", "").replace("\"];", "").trim()));
                } catch (AtomTypeNotKnownFromInputListException e) {
                    e.printStackTrace();
                }
                curChild.setFather(curFather);
                curFather.addChild(curChild);
            } else {
                String properties = line.replaceFirst(".*label=\"", "").replace("\"];", "");
                String id = line.split("\\s+")[0].trim();
                String[] tmp = properties.split("\\\\n");
                String fragmentFormula = tmp[0];
                double mass = Double.parseDouble(tmp[1].split("\\s+")[0].trim());
                double intensity = 0.0;
                try {
                    intensity = Double.parseDouble(properties.split("Intensity=")[1].split("\\\\n")[0]);
                } catch (java.lang.ArrayIndexOutOfBoundsException e) {
                    // precursor has no intensity
                    intensity = 0.0;
                }
                if (intensity > maxIntensity)
                    maxIntensity = intensity;
                SiriusNodePeak curNode = null;
                try {
                    curNode = new SiriusNodePeak(mass, fragmentFormula, intensity);
                } catch (AtomTypeNotKnownFromInputListException e) {
                    e.printStackTrace();
                }
                curNode.setCompleteNodeLabel(properties);
                curNode.setIntensity(intensity);
                curNode.setSiriusID(id);
                nodes.put(id, curNode);
                /*
					 * add peak sorted
					 */
                this.addElement(curNode);
            }
        }
        breader.close();
    } catch (java.io.FileNotFoundException e) {
        e.printStackTrace();
    } catch (java.io.IOException e) {
        e.printStackTrace();
    }
    java.util.Enumeration<SiriusNodePeak> elems = nodes.elements();
    while (elems.hasMoreElements()) {
        SiriusNodePeak node = elems.nextElement();
        try {
            node.setIntensity((node.getIntensity() / maxIntensity) * 999.0);
        } catch (RelativeIntensityNotDefinedException e) {
            e.printStackTrace();
        }
        if (node.isRoot()) {
            this.root = node;
        }
        if (node.isLeaf())
            this.leaves.add(node);
    }
}
Also used : SiriusNodePeak(de.ipbhalle.metfraglib.peak.SiriusNodePeak) AtomTypeNotKnownFromInputListException(de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException) RelativeIntensityNotDefinedException(de.ipbhalle.metfraglib.exceptions.RelativeIntensityNotDefinedException) ByteMolecularFormula(de.ipbhalle.metfraglib.molecularformula.ByteMolecularFormula)

Example 2 with SiriusNodePeak

use of de.ipbhalle.metfraglib.peak.SiriusNodePeak in project MetFragRelaunched by ipb-halle.

the class AnalyseAnnotatedMetFragSiriusTree method detectReplacementRearrangement.

public boolean detectReplacementRearrangement(MatchList matchList) {
    java.util.ArrayList<SiriusNodePeak> leaves = this.peakList.getLeaves();
    for (int i = 0; i < leaves.size(); i++) {
        SiriusNodePeak currentNode = leaves.get(i);
        boolean hasMatch = false;
        while (!currentNode.isRoot()) {
            FragmentFormulaToPeakMatch peakMatch = getMatchToPeak(matchList, currentNode);
            if (peakMatch != null) {
                hasMatch = true;
                break;
            }
            currentNode = currentNode.getFather();
        }
        if (!hasMatch)
            return true;
    }
    return false;
}
Also used : FragmentFormulaToPeakMatch(de.ipbhalle.metfraglib.match.FragmentFormulaToPeakMatch) SiriusNodePeak(de.ipbhalle.metfraglib.peak.SiriusNodePeak)

Example 3 with SiriusNodePeak

use of de.ipbhalle.metfraglib.peak.SiriusNodePeak in project MetFragRelaunched by ipb-halle.

the class AnalyseAnnotatedMetFragSiriusTree method getAnnotatedDotTree.

/**
 * @param candidateNumber
 * @return
 */
public String getAnnotatedDotTree(ICandidate candidate, MatchList matchList) {
    String dotString = "strict digraph {\n";
    for (int i = 0; i < this.peakList.getNumberElements(); i++) {
        SiriusNodePeak currentPeak = (SiriusNodePeak) this.peakList.getElement(i);
        FragmentFormulaToPeakMatch peakMatch = getMatchToPeak(matchList, currentPeak);
        if (peakMatch != null) {
            try {
                dotString += currentPeak.getDotEntry("\\nInt: " + currentPeak.getIntensity() + "\\nMetFrag:\\n" + peakMatch.getBestMatchedFragment().getMolecularFormula(candidate.getPrecursorMolecule()) + "\\n" + peakMatch.getBestMatchedFragment().getSmiles(candidate.getPrecursorMolecule()), "red", "grey") + "\n";
            } catch (RelativeIntensityNotDefinedException e) {
                e.printStackTrace();
            }
        } else {
            try {
                dotString += currentPeak.getDotEntry("Int: " + currentPeak.getIntensity()) + "\n";
            } catch (RelativeIntensityNotDefinedException e) {
                e.printStackTrace();
            }
        }
    }
    dotString += "}\n";
    return dotString;
}
Also used : FragmentFormulaToPeakMatch(de.ipbhalle.metfraglib.match.FragmentFormulaToPeakMatch) SiriusNodePeak(de.ipbhalle.metfraglib.peak.SiriusNodePeak) RelativeIntensityNotDefinedException(de.ipbhalle.metfraglib.exceptions.RelativeIntensityNotDefinedException)

Aggregations

SiriusNodePeak (de.ipbhalle.metfraglib.peak.SiriusNodePeak)3 RelativeIntensityNotDefinedException (de.ipbhalle.metfraglib.exceptions.RelativeIntensityNotDefinedException)2 FragmentFormulaToPeakMatch (de.ipbhalle.metfraglib.match.FragmentFormulaToPeakMatch)2 AtomTypeNotKnownFromInputListException (de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException)1 ByteMolecularFormula (de.ipbhalle.metfraglib.molecularformula.ByteMolecularFormula)1