wiki:DeterimingIonSets

Tutorial for Determining Parameter Sets for Glycan Annotation

This page contains source code for determining parameter sets when the user specifies adducts, ion exchanges, and neutral loss or gains (see GELATO wizard).

	/**
	 * Initializes all the data structures with the varius adducts, loss/gain, exchnanges, and their counts.<br>
	 * <i>Technically, we should have different adducts, exchanges, etc 
	 * per analyte settings object, but this isn't implemented yet!</i>
	 * 
	 * @param _analayteSettings - the current AnalyteSettings object to use for GELATO annotation of the MS file
	 * 
	 */
	protected void initializeAdductsAndExchanges( AnalyteSettings _analayteSettings ) {
		lPosModeSettingsToAnalyze = new ArrayList<>();
		lPosModeSettingsToAnalyzeCounts = new ArrayList<>();
		GlycanStructureAnnotation.determineIonSettingSets(true, method.getIons(), method.getMaxIonCount(), lPosModeSettingsToAnalyze, lPosModeSettingsToAnalyzeCounts);

		lNegModeSettingsToAnalyze = new ArrayList<>();
		lNegModeSettingsToAnalyzeCounts = new ArrayList<>();
		GlycanStructureAnnotation.determineIonSettingSets(false, method.getIons(), method.getMaxIonCount(), lNegModeSettingsToAnalyze, lNegModeSettingsToAnalyzeCounts);

		lExchangesoAnalyze = new ArrayList<>();
		lExchangesToAnalyzeCounts = new ArrayList<>();
		GlycanStructureAnnotation.determineIonSettingSets(null, method.getIonExchanges(), method.getMaxIonCount(), lExchangesoAnalyze, lExchangesToAnalyzeCounts);

		lNeutralLossesToAnalyze = new ArrayList<>();
		lNeutralLossesToAnalyzeCounts = new ArrayList<>();
		GlycanStructureAnnotation.determineIonSettingSets(null, method.getNeutralLoss(), -1, lNeutralLossesToAnalyze, lNeutralLossesToAnalyzeCounts);
	}
/**
 * Static method to fill in the lSettingsToAnalyze and lSettingsToAnalyzeCounts lists with the 
 * options for positive mode and negative mode ions as well as neutral loss/gain and exchanges.<br><br> 
 * The lSettingsToConsider object contains the list of adducts (Molecules) specified.
 * The lSettingsToAnalyze and lSettingsToAnalyzeCounts contain the set of options to consider based on the max ion count specified.
 * <br><br>
 * Called from the initializeAdductsAndExchanges(..) method.
 * 
 * @param bIsPositive
 * 		true if the mode for the MS run is positive, false if negative
 * @param lSettingsToConsider
 * 		generically described list of Molecule objects
 * @param iMaxTotalCount
 * 		total number of ions for all Molecules
 * @param lSettingsToAnalyze
 * 		generically described List of List of Molecule objects
 * @param lSettingsToAnalyzeCounts
 * 		List of List of Integers for the max number of ions for each Molecule
 * @see Molecule
 * @see MoleculeSettings
 * @see IonSettings
 * @see Ion
 * 
 */
public static void determineIonSettingSets( 
		Boolean bIsPositive, Object lSettingsToConsider, int iMaxTotalCount, 
		Object lSettingsToAnalyze, List<List<Integer>> lSettingsToAnalyzeCounts ) {
	try {
		// Because IonSettings inherits from Ion which inherits from Molecule
		// And MoleculeSettings inherits from Molecule
		// I couldn't create a common API. I don't want to write 3 methods that basically do the same thing!  
		// So cast to what they are!

		if( lSettingsToConsider == null || ((List<Molecule>) lSettingsToConsider).isEmpty() ) {
			return;
		}
		boolean bDone = false;
		int iStartLevel = 0; // starting charge count
		int[] iCurChargeCnts = new int[((List<Molecule>) lSettingsToConsider).size()];
		List<String> sProcessed = new ArrayList<>(); // stores String-based representation of the parameter set

		// Iterate until all parameter sets are determined
		while( ! bDone ) {
			List<Molecule> lCurSet = new ArrayList<>(); // current set of molecules to consider, e.g. Na + Li
			List<Integer> lCurCounts = new ArrayList<>(); // current set of molecule counts to consider for each molecule, e.g. 1 Na + 2 Li (assuming less than total count/charge)
			int iTotalCount = 0;
			int iLevelCnt = 0;
			String sCombo = "";
			// consider first "iStartLevel" Molecules for the param set
			for( iLevelCnt = 0; iLevelCnt<= iStartLevel; iLevelCnt++ ) {
				// Cast to current candidate ion to Molecule
				Molecule curSetting = ((List<Molecule>) lSettingsToConsider).get(iLevelCnt);
				
				// iLevelCnt is zero-based, so convert to 1-based for count (or charge)
				int iCurCount = iCurChargeCnts[iLevelCnt] + 1;
				
				// if curSetting is instance of IonSettings, then use the IonSettings charge instead of raw count
				if( curSetting instanceof IonSettings ) {
					if( bIsPositive != null ) { // make sure polarity matches!
						if( (((IonSettings) curSetting).getPolarity() && ! bIsPositive) || 
								(!((IonSettings) curSetting).getPolarity() && bIsPositive) ) {
							continue;					
						}
					}
					iCurCount *= ((IonSettings) curSetting).getCharge();
				}					
				
				// to turn off the use of a max total count, pass in -1
				// if the current count/charge doesn't make the the total count/charge for the current parameter set 
				// surpass the max count/charge specified, create add the parameter set to the list of candidates
				if( iMaxTotalCount < 0 || (iTotalCount + iCurCount) <= iMaxTotalCount ) {
					iTotalCount += iCurCount;
					// determine String-based representation of the parameter set
					sCombo += "[" + iLevelCnt + ", " + iCurCount + "+]";
					
					// add the current setting and charge/counts
					lCurSet.add(curSetting);
					lCurCounts.add(iCurChargeCnts[iLevelCnt] + 1);
				} else {				
					;   // do nothing 
				}
			}
			
			
			// if the current total count/charge doesn't surpass the max count/charge specified, create add the parameter set to the list of total candidates
			if( (iMaxTotalCount < 0 || iTotalCount <= iMaxTotalCount) && ! sProcessed.contains(sCombo) ) {
				((List<List<Molecule>>) lSettingsToAnalyze).add(lCurSet);
				lSettingsToAnalyzeCounts.add(lCurCounts);
				sProcessed.add(sCombo);
			} else {
				; // do nothing
			}
			iStartLevel++;
			// if start level hasn't surpassed the number of Molecules to consider, pivot the indices to move to next level
			if( iStartLevel == iCurChargeCnts.length ) {
				for( int j = iCurChargeCnts.length - 1; j >= 0  && iStartLevel == iCurChargeCnts.length; j-- ) {
					Molecule curSetting = ((List<Molecule>) lSettingsToConsider).get(j);
					int iCurCnt = iCurChargeCnts[j]+1;
					int iMaxCnt = -1;
					if( curSetting instanceof IonSettings ) {
						iMaxCnt = ((IonSettings) curSetting).getCounts().get(0);
					} else {
						iMaxCnt = ((MoleculeSettings) curSetting).getCount();
					}
					if( iCurCnt < iMaxCnt ) {
						iCurChargeCnts[j]++;
						iStartLevel = j;
					} else {
						iCurChargeCnts[j] = 0;
					}
				}
			} 

			// stop when you reach end of Molecules to consider
			bDone = iStartLevel == iCurChargeCnts.length;
		}
	} catch( Exception e ) {
		logger.error("Error in determineIonSettingSets", e);
	}
}
Last modified 2 years ago Last modified on 07/06/2018 09:41:40 PM