Search in sources :

Example 1 with BitArrayNeutralLoss

use of de.ipbhalle.metfraglib.fragment.BitArrayNeutralLoss in project MetFragRelaunched by ipb-halle.

the class NeutralLosses method getMatchingAtoms.

public BitArrayNeutralLoss[] getMatchingAtoms(DefaultPrecursor precursorMolecule) {
    SMARTSQueryTool[] smartsQuerytools = new SMARTSQueryTool[smartPatterns.length];
    for (int i = 0; i < smartsQuerytools.length; i++) {
        smartsQuerytools[i] = new SMARTSQueryTool(smartPatterns[i], DefaultChemObjectBuilder.getInstance());
    }
    java.util.ArrayList<BitArrayNeutralLoss> matchedNeutralLossTypes = new java.util.ArrayList<BitArrayNeutralLoss>();
    for (byte i = 0; i < smartsQuerytools.length; i++) {
        try {
            if (smartsQuerytools[i].matches(precursorMolecule.getStructureAsIAtomContainer())) {
                /*
					 * get atom indeces containing to a neutral loss
					 */
                java.util.List<java.util.List<Integer>> matchingAtoms = smartsQuerytools[i].getMatchingAtoms();
                /*
					 * store which is a valid loss based on the number of hydrogens
					 */
                boolean[] validMatches = new boolean[matchingAtoms.size()];
                FastBitArray[] allMatches = new FastBitArray[matchingAtoms.size()];
                int numberOfValidNeutralLosses = 0;
                /*
					 * check each part that is marked as neutral loss
					 */
                for (int ii = 0; ii < matchingAtoms.size(); ii++) {
                    java.util.List<Integer> part = matchingAtoms.get(ii);
                    /*
						 * count number of implicit hydrogens of this neutral loss
						 */
                    int numberImplicitHydrogens = 0;
                    allMatches[ii] = new FastBitArray(precursorMolecule.getNonHydrogenAtomCount());
                    /*
						 * check all atoms 
						 */
                    for (int iii = 0; iii < part.size(); iii++) {
                        allMatches[ii].set(part.get(iii));
                        /*
							 * count number of implicit hydrogens of this neutral loss
							 */
                        numberImplicitHydrogens += precursorMolecule.getNumberHydrogensConnectedToAtomIndex(part.get(iii));
                    }
                    /*
						 * valid neutral loss match if number implicit hydrogens are at least the number of hydrogens
						 * needed for the certain neutral loss
						 */
                    if (numberImplicitHydrogens >= minimumNumberImplicitHydrogens[i]) {
                        validMatches[ii] = true;
                        numberOfValidNeutralLosses++;
                    }
                }
                /*
					 * create BitArrayNeutralLosses of valid neutral loss part detections
					 */
                if (numberOfValidNeutralLosses != 0) {
                    BitArrayNeutralLoss newDetectedNeutralLoss = new BitArrayNeutralLoss(numberOfValidNeutralLosses, i, precursorMolecule);
                    int neutralLossIndexOfBitArrayNeutralLoss = 0;
                    for (int k = 0; k < validMatches.length; k++) {
                        if (validMatches[k]) {
                            newDetectedNeutralLoss.setNeutralLoss(neutralLossIndexOfBitArrayNeutralLoss, allMatches[k]);
                            neutralLossIndexOfBitArrayNeutralLoss++;
                        }
                    }
                    /*
						 * store them in vector
						 */
                    matchedNeutralLossTypes.add(newDetectedNeutralLoss);
                }
            }
        } catch (CDKException e) {
            e.printStackTrace();
        }
    }
    BitArrayNeutralLoss[] matchedNeutralLossTypesArray = new BitArrayNeutralLoss[matchedNeutralLossTypes.size()];
    for (int i = 0; i < matchedNeutralLossTypes.size(); i++) {
        matchedNeutralLossTypesArray[i] = matchedNeutralLossTypes.get(i);
    }
    return matchedNeutralLossTypesArray;
}
Also used : CDKException(org.openscience.cdk.exception.CDKException) SMARTSQueryTool(org.openscience.cdk.smiles.smarts.SMARTSQueryTool) BitArrayNeutralLoss(de.ipbhalle.metfraglib.fragment.BitArrayNeutralLoss) FastBitArray(de.ipbhalle.metfraglib.FastBitArray)

Aggregations

FastBitArray (de.ipbhalle.metfraglib.FastBitArray)1 BitArrayNeutralLoss (de.ipbhalle.metfraglib.fragment.BitArrayNeutralLoss)1 CDKException (org.openscience.cdk.exception.CDKException)1 SMARTSQueryTool (org.openscience.cdk.smiles.smarts.SMARTSQueryTool)1