Пример #1
0
        /// <summary>
        /// calculate the hash for the whole spectrum
        /// </summary>
        /// <param name="spec">the spectrum data (in mz:int pairs)</param>
        /// <returns>the Hash of the spectrum data</returns>
        private string getSpectrumBlock(ISpectrum spec)
        {
            List <Ion> ions = spec.getSortedIonsByMZ();

            StringBuilder strIons = new StringBuilder();

            foreach (Ion i in ions)
            {
                strIons.Append(string.Format("{0}:{1}", formatMZ(i.MZ), formatIntensity(i.Intensity)));
                strIons.Append(ION_SEPERATOR);
            }

            //string to hash
            strIons.Remove(strIons.Length - 1, 1);
            byte[] message = Encoding.UTF8.GetBytes(strIons.ToString());

            SHA256Managed hashString = new SHA256Managed();

            hashString.ComputeHash(message);

            string hash = BitConverter.ToString(hashString.Hash);

            hash = hash.Replace("-", "").Substring(0, maxCharactersForSpectrumBlockTruncation).ToLower();

            Debug.WriteLine(string.Format("hash block: {0}", hash));

            return(hash);
        }
Пример #2
0
        /// <summary>
        /// calculate the hash for the whole spectrum
        /// </summary>
        /// <param name="spec">the spectrum data (in mz:int pairs)</param>
        /// <returns>the Hash of the spectrum data</returns>
        private string getSpectrumBlock(ISpectrum spec)
        {
            List<Ion> ions = spec.getSortedIonsByMZ();

            StringBuilder strIons = new StringBuilder();
            foreach (Ion i in ions)
            {
                strIons.Append(string.Format("{0}:{1}", formatMZ(i.MZ), formatIntensity(i.Intensity)));
                strIons.Append(ION_SEPERATOR);
            }

            //string to hash
            strIons.Remove(strIons.Length - 1, 1);
            byte[] message = Encoding.UTF8.GetBytes(strIons.ToString());

            SHA256Managed hashString = new SHA256Managed();
            hashString.ComputeHash(message);

            string hash = BitConverter.ToString(hashString.Hash);
            hash = hash.Replace("-", "").Substring(0, maxCharactersForSpectrumBlockTruncation).ToLower();

            Debug.WriteLine(string.Format("hash block: {0}", hash));

            return hash;
        }