/// <summary> /// Calculates pairwise distances between features in the list of /// potential features to cluster. /// </summary> /// <param name="start">Start UMC index.</param> /// <param name="stop">Stop UMC index.</param> /// <param name="data">List of data to compute distances over.</param> /// <returns>List of UMC distances to consider during clustering.</returns> protected virtual List <PairwiseDistance <T> > CalculatePairWiseDistances(int start, int stop, List <T> data) { var massTolerance = Parameters.Tolerances.Mass; var netTolerance = Parameters.Tolerances.Net; var driftTolerance = Parameters.Tolerances.DriftTime; var onlyClusterSameChargeStates = Parameters.OnlyClusterSameChargeStates; var distances = new List <PairwiseDistance <T> >(); for (var i = start; i < stop; i++) { var featureX = data[i]; var driftTimeX = featureX.DriftTime; var netAlignedX = featureX.Net; var massAlignedX = featureX.MassMonoisotopicAligned; var chargeStateX = featureX.ChargeState; for (var j = i + 1; j <= stop; j++) { // Don't calculate distance to self. var featureY = data[j]; // Calculate the distances here (using a cube). We dont care if we are going to re-compute // these again later, because here we want to fall within the cube, the distance function used // later is more related to determining a scalar value instead. var withinRange = AreClustersWithinTolerance(featureX, featureY); //Parameters.RangeFunction(featureX, featureY); // Make sure we fall within the distance range before computing... if (withinRange) { // If IMS or equivalent only cluster similar charge states if (onlyClusterSameChargeStates) { // Make sure it's the same charge state if (chargeStateX == featureY.ChargeState) { // Calculate the pairwise distance var pairwiseDistance = new PairwiseDistance <T>(); pairwiseDistance.FeatureX = featureX; pairwiseDistance.FeatureY = featureY; pairwiseDistance.Distance = Parameters.DistanceFunction(featureX, featureY); distances.Add(pairwiseDistance); } } else { // Calculate the pairwise distance var pairwiseDistance = new PairwiseDistance <T>(); pairwiseDistance.FeatureX = featureX; pairwiseDistance.FeatureY = featureY; pairwiseDistance.Distance = Parameters.DistanceFunction(featureX, featureY); distances.Add(pairwiseDistance); } } } } return(distances); }
private List<PairwiseDistance<UMCLight>> CalculatePairwiseDistances(List<UMCLight> data, int start, int stop, double massTolerance, double netTolerance, double driftTolerance) { var distances = new List<PairwiseDistance<UMCLight>>(); for (var i = start; i < stop; i++) { var featureX = data[i]; var driftTimeX = featureX.DriftTime; var netAlignedX = featureX.Net; var massAlignedX = featureX.MassMonoisotopicAligned; var chargeStateX = featureX.ChargeState; for (var j = i + 1; j <= stop; j++) { // Don't calculate distance to self. var featureY = data[j]; // Calculate the distances here (using a cube). We dont care if we are going to re-compute // these again later, because here we want to fall within the cube, the distance function used // later is more related to determining a scalar value instead. var withinRange = AreClustersWithinTolerance(featureX, featureY, massTolerance, netTolerance, driftTolerance); //Parameters.RangeFunction(featureX, featureY); // Make sure we fall within the distance range before computing... if (withinRange) { // If IMS or equivalent only cluster similar charge states // Make sure it's the same charge state if (chargeStateX == featureY.ChargeState) { // Calculate the pairwise distance var pairwiseDistance = new PairwiseDistance<UMCLight>(); pairwiseDistance.FeatureX = featureX; pairwiseDistance.FeatureY = featureY; pairwiseDistance.Distance = DistanceFunction(featureX, featureY); distances.Add(pairwiseDistance); } } } } return distances; }
/// <summary> /// Calculates pairwise distances between features in the list of /// potential features to cluster. /// </summary> /// <param name="start">Start UMC index.</param> /// <param name="stop">Stop UMC index.</param> /// <param name="data">List of data to compute distances over.</param> /// <returns>List of UMC distances to consider during clustering.</returns> protected List <PairwiseDistance <U> > CalculateDistances(Dictionary <int, U> clusters) { var massTolerance = Parameters.Tolerances.Mass; var netTolerance = Parameters.Tolerances.Net; var driftTolerance = Parameters.Tolerances.DriftTime; var onlyClusterSameChargeStates = Parameters.OnlyClusterSameChargeStates; var distances = new List <PairwiseDistance <U> >(); foreach (var clusterI in clusters.Values) { var driftTimeX = clusterI.DriftTime; var netAlignedX = clusterI.Net; var massAlignedX = clusterI.MassMonoisotopicAligned; var chargeStateX = clusterI.ChargeState; foreach (var clusterJ in clusters.Values) { // Don't calculate distance to other features within same group if (clusterI == clusterJ) { continue; } // Calculate the distances here (using a cube). We dont care if we are going to re-compute // these again later, because here we want to fall within the cube, the distance function used // later is more related to determining a scalar value instead. var massDiff = Math.Abs(FeatureLight.ComputeMassPPMDifference(massAlignedX, clusterJ.MassMonoisotopicAligned)); var netDiff = Math.Abs(netAlignedX - clusterJ.Net); var driftDiff = Math.Abs(driftTimeX - clusterJ.DriftTime); // Make sure we fall within the distance range before computing... if (massDiff <= massTolerance && netDiff <= netTolerance && driftDiff <= driftTolerance) { // If IMS or equivalent only cluster similar charge states if (onlyClusterSameChargeStates) { // Make sure it's the same charge state if (chargeStateX == clusterJ.ChargeState) { // Calculate the pairwise distance var pairwiseDistance = new PairwiseDistance <U>(); pairwiseDistance.FeatureX = clusterI; pairwiseDistance.FeatureY = clusterJ; pairwiseDistance.Distance = GetAverageClusterDistance(clusterI, clusterJ, Parameters.DistanceFunction); distances.Add(pairwiseDistance); } } else { // Calculate the pairwise distance var pairwiseDistance = new PairwiseDistance <U>(); pairwiseDistance.FeatureX = clusterI; pairwiseDistance.FeatureY = clusterJ; pairwiseDistance.Distance = GetAverageClusterDistance(clusterI, clusterJ, Parameters.DistanceFunction); distances.Add(pairwiseDistance); } } } } return(distances); }