/// <summary> /// Creates a new spectrum based on a string of ions /// </summary> /// <param name="data"></param> public AbstractSpectrum(string data) { //checke data has data if ("" == data) { throw new ArgumentException ("The spectrum data can't be null or empty."); } ions = new List<Ion>(); Array splitData = data.Split (' '); foreach(string ion in splitData) { //get m/z double mz = double.Parse(ion.Split(':')[0]); //get intensity double intensity = double.Parse(ion.Split(':')[1]); Ion newIon = new Ion(mz, intensity); Ions.Add(newIon); } Ions = this.toRelative(MAX_RELATIVE_INTENSITY); }
//compares by mz value public int CompareTo(Object other) { if (this.GetType() != other.GetType()) { throw new ArgumentException(String.Format("Can't compare {0} with {1}.", this.GetType(), other.GetType())); } Ion otherCpy = (Ion)other; if (this.intensity < otherCpy.intensity) { return(-1); } else if (this.intensity > otherCpy.intensity) { return(1); } else { return(otherCpy.mz.CompareTo(this.mz)); } }
/// <summary> /// Creates a new spectrum based on a string of ions /// </summary> /// <param name="data"></param> public AbstractSpectrum(string data) { //checke data has data if ("" == data) { throw new ArgumentException("The spectrum data can't be null or empty."); } ions = new List <Ion>(); Array splitData = data.Split(' '); foreach (string ion in splitData) { //get m/z double mz = double.Parse(ion.Split(':')[0]); //get intensity double intensity = double.Parse(ion.Split(':')[1]); Ion newIon = new Ion(mz, intensity); Ions.Add(newIon); } Ions = this.toRelative(MAX_RELATIVE_INTENSITY); }
public void TestIonFormatedToString() { Ion ion = new Ion(4.083286, 142.545026); Assert.AreEqual("4.083286:142.545026", ion.ToString()); }