public BinaryTreeNode <T> FindFeatureWithGivenMass(double massValue, int toleranceInPPM) { BinaryTreeNode <T> node = this.head; while (node != null) { MSResultPeakWithLocation thisFeature = node.Value as MSResultPeakWithLocation; double ppmDifference = 1000000 * (massValue - thisFeature.MSPeak.XValue) / massValue; double absolutePPMDifference = Math.Abs(ppmDifference); //if (node.Value.Equals(value)) //parameter value found if (absolutePPMDifference <= toleranceInPPM) { return(node); } if (ppmDifference < 0) { //search left node = node.LeftChild; } else { node = node.RightChild; } } return(null); }
/// <summary> /// Adds a node to the tree /// </summary> public virtual void Add(BinaryTreeNode <T> node) { if (this.head == null) //first element being added { this.head = node; //set node as root of the tree node.Tree = this; size++; } else { if (node.Parent == null) { node.Parent = head; //start at head } //Node is inserted on the left side if it is smaller or equal to the parent int matchValue = comparer((IComparable)node.Value, (IComparable)node.Parent.Value); if (matchValue == 0) { //this means that the mass was within the tolerance, we should have to update the frame and scans map for this //peak //at this node we have a MSResultPeakWithLocation, . MSResultPeakWithLocation peakWithLoc = node.Value as MSResultPeakWithLocation; } bool insertLeftSide = matchValue < 0; if (insertLeftSide) //insert on the left { if (node.Parent.LeftChild == null) { node.Parent.LeftChild = node; //insert in left size++; node.Tree = this; //assign node to this binary tree } else { node.Parent = node.Parent.LeftChild; //scan down to left child this.Add(node); //recursive call } } else if (!insertLeftSide) //insert on the right { if (node.Parent.RightChild == null) { node.Parent.RightChild = node; //insert in right size++; node.Tree = this; //assign node to this binary tree } else { node.Parent = node.Parent.RightChild; this.Add(node); } } } }
public bool FindPeakWithinFeatures(IPeak value, int frameNum, int scanNum, int toleranceInPPM, int netTolRange, int driftTolRange) { BinaryTreeNode <T> node = this.head; while (node != null) { try { MSResultPeakWithLocation thisFeature = node.Value as MSResultPeakWithLocation; MSPeak msPeak = value as MSPeak; //now check if the peak value is within the mass tolerance of this UMC int number = thisFeature.containsPeak(msPeak, frameNum, scanNum, toleranceInPPM, netTolRange, driftTolRange); if (number == 0) { //we've found a node that contains that feature value return(true); } else if (number < 0) { //search in the left tree node = node.LeftChild; } else { //search in the right tree node = node.RightChild; } } catch (InvalidCastException invalidCast) { Console.WriteLine("The node is not of type UMC"); Console.WriteLine(invalidCast.Message); } } return(false); }