예제 #1
0
        public override Spectrum spectrum(int index, bool getBinaryData)
        {
            Spectrum s = base.spectrum(index, true);

            if (s.cvParam(CVID.MS_MSn_spectrum).empty() ||
                (int)s.cvParam(CVID.MS_ms_level).value == 1)
            {
                if (!getBinaryData)
                {
                    s.binaryDataArrays.Clear();
                }
                return(s);
            }

            PrecursorList pl = s.precursors;

            BinaryData            mzArray        = s.getMZArray().data;
            BinaryData            intensityArray = s.getIntensityArray().data;
            PointDataMap <double> mziMap         = new PointDataMap <double>();

            for (int i = 0; i < (int)s.defaultArrayLength; ++i)
            {
                mziMap.Insert(mzArray[i], intensityArray[i]);
            }

            Set <double> pointsToRemove = new Set <double>();

            foreach (Precursor p in pl)
            {
                foreach (SelectedIon si in p.selectedIons)
                {
                    double mz = (double)si.cvParam(CVID.MS_selected_ion_m_z).value;
                    PointDataMap <double> .Enumerator itr = mziMap.LowerBound(mz - 4.0);
                    if (itr != null && itr.IsValid)
                    {
                        while (itr.IsValid && itr.Current.Key - mz < 4.0)
                        {
                            pointsToRemove.Add(itr.Current.Key);
                            itr.MoveNext();
                        }
                    }

                    CVParam chargeParam = si.cvParam(CVID.MS_charge_state);
                    if (!chargeParam.empty())
                    {
                        int z = (int)chargeParam.value;
                        for (int i = 1; i < z; ++i)
                        {
                            double strippedMz = (mz * z) / (z - i);
                            itr = mziMap.LowerBound(strippedMz - 4.0);
                            if (itr != null && itr.IsValid)
                            {
                                while (itr.IsValid && itr.Current.Key - strippedMz < 4.0)
                                {
                                    pointsToRemove.Add(itr.Current.Key);
                                    itr.MoveNext();
                                }
                            }
                        }
                    }
                }
            }

            if (getBinaryData)
            {
                mzArray.Clear();
                intensityArray.Clear();
                foreach (PointDataMap <double> .MapPair pair in mziMap)
                {
                    if (pointsToRemove.Contains(pair.Key))
                    {
                        continue;
                    }

                    mzArray.Add(pair.Key);
                    intensityArray.Add(pair.Value);
                }
                s.defaultArrayLength = (ulong)mzArray.Count;
            }
            else
            {
                s.binaryDataArrays.Clear();
                s.defaultArrayLength -= (ulong)pointsToRemove.Count;
            }

            return(s);
        }