Example #1
0
        public LcMsPeakMatrix(LcMsRun run, LcMsFeatureLikelihood scorer = null, int minScanCharge = 1, int maxScanCharge = 60, int maxThreadCount = 0)
        {
            Run = run;
            _maxThreadCount = maxThreadCount;

            _ms1PeakList = new List<Ms1Peak>();
            Ms1Spectra = new List<Ms1Spectrum>();
            var ms1ScanNums = run.GetMs1ScanVector();

            NColumns = ms1ScanNums.Length;
            MinSearchCharge = minScanCharge;
            MaxSearchCharge = maxScanCharge;
            NRows = Math.Min(MaxSearchCharge - MinSearchCharge + 1, 35);

            for (var i = 0; i < Math.Min(ms1ScanNums.Length, ushort.MaxValue); i++)
            {
                var ms1Spec = run.GetMs1Spectrum(ms1ScanNums[i]);
                Ms1Spectra.Add(ms1Spec);
                foreach (var peak in ms1Spec.Peaks) _ms1PeakList.Add(peak as Ms1Peak);
            }
            _ms1PeakList.Sort();

            _distProfileAcrossCharge = new double[NRows];
            _corrProfileAcrossCharge = new double[NRows];
            _intensityAcrossCharge = new double[NRows];
            _summedEnvelopeColRange = new int[NRows, 2];
            
            _featureMatrix = null;
            Comparer = new MzComparerWithBinning(27); // 16ppm
            _scorer = scorer;
            _seedEnvelopes = new List<KeyValuePair<double, ObservedIsotopeEnvelope>>();
            _ms1Filter = null;
        }
Example #2
0
        public LcMsPeakScorer(Ms1Spectrum spec, int numBits4WinSize = 19) // 19 bits -> 4096 ppm,  20 bits -> 2048
        {
            Spectrum = spec;
            var peaks = spec.Peaks;
            _windowComparer = new MzComparerWithBinning(numBits4WinSize);
            _minBinNum = _windowComparer.GetBinNumber(peaks[0].Mz);
            _maxBinNum = _windowComparer.GetBinNumber(peaks[peaks.Length - 1].Mz);
            var numberOfbins = _maxBinNum - _minBinNum + 1;

            _peakStartIndex     = new int[2][];
            _peakRanking        = new int[2][][];
            var intensities     = new List<double>[2][];

            for (var i = 0; i < 2; i++)
            {
                _peakStartIndex[i]  = new int[numberOfbins];
                _peakRanking[i]     = new int[numberOfbins][];
                intensities[i]      = new List<double>[numberOfbins];

                for (var j = 0; j < numberOfbins; j++)
                {
                    _peakStartIndex[i][j]   = peaks.Length - 1;
                    intensities[i][j]       = new List<double>();
                }
            }

            for (var i = 0; i < peaks.Length; i++)
            {
                var binNum = _windowComparer.GetBinNumber(peaks[i].Mz);
                var binMzAverage = _windowComparer.GetMzAverage(binNum);
                var binIdx = binNum - _minBinNum;

                intensities[0][binIdx].Add(peaks[i].Intensity);
                if (i < _peakStartIndex[0][binIdx]) _peakStartIndex[0][binIdx] = i;

                if (peaks[i].Mz < binMzAverage)
                {
                    intensities[1][binIdx].Add(peaks[i].Intensity);
                    if (i < _peakStartIndex[1][binIdx]) _peakStartIndex[1][binIdx] = i;
                }
                else if (binNum < _maxBinNum) // skip this at the rightmost bin
                {
                    intensities[1][binIdx + 1].Add(peaks[i].Intensity);
                    if (i < _peakStartIndex[1][binIdx + 1]) _peakStartIndex[1][binIdx + 1] = i;
                }
            }

            for (var i = 0; i < 2; i++)
            {
                for (var binIdx = 0; binIdx < numberOfbins; binIdx++)
                {
                    if (intensities[i][binIdx].Count < 1) continue;

                    double medianIntensity;
                    _peakRanking[i][binIdx] = GetRankings(intensities[i][binIdx].ToArray(), out medianIntensity);
                }
            }
        }
Example #3
0
 public ProteinMassBinning(double minMass = 50, double maxMass = 50000, bool padZeroMassBin = false, int numBits = 28)
 {
     _mzComparer = new MzComparerWithBinning(numBits);
     MinMass = minMass;
     MaxMass = maxMass;
     _minBinIndex = _mzComparer.GetBinNumber(MinMass);
     _maxBinIndex = _mzComparer.GetBinNumber(MaxMass);
     _padZeroMassBin = padZeroMassBin;
     NumberOfBins = (_padZeroMassBin) ? _maxBinIndex - _minBinIndex + 2 : _maxBinIndex - _minBinIndex + 1;
 }
Example #4
0
 /// <summary>
 /// MaxEnt deconvolution algorithm constructor 
 /// </summary>
 /// <param name="tolerance">tolerance</param>
 /// <param name="massBinning">mass binning interface</param>
 /// <param name="minCharge">maximum charge to be considered</param>
 /// <param name="maxCharge">minimum charge to be considered</param>
 /// <param name="minMass">minimum mass to be considered</param>
 /// <param name="maxMass">maximum mass to be considered</param>
 public MaxEntDeconvoluter(Spectrum spec, Tolerance tolerance, MzComparerWithBinning massBinning, int minCharge = 1, int maxCharge = 100, double minMass = 10000, double maxMass = 100000)
 {
     _minCharge = minCharge;
     _maxCharge = maxCharge;
     _minMass = minMass;
     _maxMass = maxMass;
     _tolerance = tolerance;
     _massBinning = massBinning;
     _spectrum = spec;
     _deconvolutedSpectrum = null;
 }
Example #5
0
        public void TestFloatBinning()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;
            ShowStarting(methodName);

            const double minMass = 200;
            const double maxMass = 50000;
            const int numBits = 29;

            var comparer = new MzComparerWithBinning(numBits);
            Console.WriteLine(comparer.GetBinNumber(maxMass));
            Console.WriteLine(comparer.GetBinNumber(maxMass) - comparer.GetBinNumber(minMass) + 1);
            Console.WriteLine(LcMsMatchMap.GetBinNumber(maxMass) - LcMsMatchMap.GetBinNumber(minMass) + 1);
        }
Example #6
0
        public void UpdateWithDecoyScore(List<Ms1Spectrum> ms1Spectra, int targetMinCharge, int targetMaxCharge)
        {
            var ms1ScanNumToIndex = _run.GetMs1ScanNumToIndex();
            var ms1ScanNums = _run.GetMs1ScanVector();
            var minCol = ms1ScanNumToIndex[MinScanNum];
            var maxCol = ms1ScanNumToIndex[MaxScanNum];
            MinCharge = targetMinCharge;
            MaxCharge = targetMaxCharge;
            
            var rnd = new Random();
            var comparer = new MzComparerWithBinning(28);
            var mostAbuInternalIndex = TheoreticalEnvelope.IndexOrderByRanking[0];

            var nRows = MaxCharge - MinCharge + 1;
            var nCols = maxCol - minCol + 1;

            Envelopes = new ObservedIsotopeEnvelope[nRows][];
            for (var i = 0; i < nRows; i++) Envelopes[i] = new ObservedIsotopeEnvelope[nCols];

            for (var charge = targetMinCharge; charge <= targetMaxCharge; charge++)
            {
                var mostAbuMz = TheoreticalEnvelope.GetIsotopeMz(charge, mostAbuInternalIndex);
                if (_run.MaxMs1Mz < mostAbuMz || mostAbuMz < _run.MinMs1Mz) continue;

                for (var col = minCol; col <= maxCol; col++)
                {
                    var localWin = ms1Spectra[col].GetLocalMzWindow(mostAbuMz);

                    var numMzBins = comparer.GetBinNumber(localWin.MaxMz) - comparer.GetBinNumber(localWin.MinMz) + 1;
                    var peakSet = new Ms1Peak[TheoreticalEnvelope.Size];

                    for (var k = 0; k < peakSet.Length; k++)
                    {
                        var r = rnd.Next(0, numMzBins);
                        if (r < localWin.PeakCount)
                            peakSet[k] = (Ms1Peak) ms1Spectra[col].Peaks[r + localWin.PeakStartIndex];
                    }

                    var env = new ObservedIsotopeEnvelope(Mass, charge, ms1ScanNums[col], peakSet, TheoreticalEnvelope);
                    //AddObservedEnvelope(env);
                    Envelopes[charge - MinCharge][col - minCol] = env;
                }
            }
            UpdateScore(ms1Spectra, false);
        }
Example #7
0
        public LcMsChargeMap(LcMsRun run, Tolerance tolerance, int maxNumMs2ScansPerMass = MaxNumMs2ScansPerFeature)
        {
            _run = run;
            _scanToIsolationWindow = new Dictionary<int, IsolationWindow>();
            _maxNumMs2ScansPerMass = maxNumMs2ScansPerMass;

            foreach (var ms2ScanNum in _run.GetScanNumbers(2))
            {
                var isoWindow = _run.GetIsolationWindow(ms2ScanNum);
                if (isoWindow != null) _scanToIsolationWindow.Add(ms2ScanNum, isoWindow);
            }

            _tolerance = tolerance;
            _map = new Dictionary<int, BitArray>();
            _comparer = new MzComparerWithBinning(30);  // 2 ppm binning

            _sequenceMassBinToScanNumsMap = new Dictionary<int, IEnumerable<int>>();
            _scanNumToMassBin = new Dictionary<int, List<int>>();
        }
 public ProteinSpectrumMatch FindByFeature(double mass, int minScanNum, int maxScanNum, Tolerance tolerance)
 {
     var massComparerWithBinning = new MzComparerWithBinning(29); // 4ppm
     var massBin = massComparerWithBinning.GetBinNumber(mass);
     ProteinSpectrumMatch ret = null;
     for (var scanNum = minScanNum + 1; scanNum < maxScanNum; scanNum++)
     {
         if (_scanNumToMatchMap[scanNum] == null) continue;
         if (Math.Abs(massBin - massComparerWithBinning.GetBinNumber(_scanNumToMatchMap[scanNum].Mass)) <= 1)
         {
             if (ret == null) ret = _scanNumToMatchMap[scanNum];
             else
             {
                 if (ret.Score < _scanNumToMatchMap[scanNum].Score) ret = _scanNumToMatchMap[scanNum];
             }
         }
     }
     return ret;
 }
        public FilteredProteinMassBinning(AminoAcidSet aaSet, double maxProteinMass = 50000, int numBits = 27)
        {
            _aminoAcidSet = aaSet;
            var terminalModifications = GetTerminalModifications(aaSet);
            var extendedAminoAcidArray = GetExtendedAminoAcidArray(aaSet);

            MaxMass = maxProteinMass;
            MinMass = MaxMass;
            foreach (var aa in extendedAminoAcidArray)
            {
                if (aa.Mass < MinMass) MinMass = aa.Mass;
                foreach (var mod in terminalModifications)
                {
                    var modAa = new ModifiedAminoAcid(aa, mod);
                    if (modAa.Mass < MinMass) MinMass = modAa.Mass;
                }
            }

            _mzComparer = new MzComparerWithBinning(numBits);

            _minMzBinIndex = _mzComparer.GetBinNumber(MinMass);
            _maxMzBinIndex = _mzComparer.GetBinNumber(MaxMass);

            var numberOfMzBins = _maxMzBinIndex - _minMzBinIndex + 2; // pad zero mass bin
            _mzBinToFilteredBinMap = new int[numberOfMzBins];
            for (var i = 0; i < numberOfMzBins; i++) _mzBinToFilteredBinMap[i] = -1;

            var tempMap = new int[numberOfMzBins];
            var fineNodes = new BitArray(Constants.GetBinNumHighPrecision(MaxMass));
            fineNodes[0] = true;

            var effectiveBinCounter = 0;
            for (var fineBinIdx = 0; fineBinIdx < fineNodes.Length; fineBinIdx++)
            {
                if (!fineNodes[fineBinIdx]) continue;

                var fineNodeMass = fineBinIdx / Constants.RescalingConstantHighPrecision;

                foreach (var aa in extendedAminoAcidArray)
                {
                    var validFineNodeIndex = Constants.GetBinNumHighPrecision(fineNodeMass + aa.Mass);
                    if (validFineNodeIndex >= fineNodes.Length) break;
                    fineNodes[validFineNodeIndex] = true;

                    if (fineBinIdx == 0 && !(aa is ModifiedAminoAcid)) // include terminal modifications 
                    {
                        foreach (var terminalMod in terminalModifications)
                        {
                            var modifiedAa = new ModifiedAminoAcid(aa, terminalMod);
                            validFineNodeIndex = Constants.GetBinNumHighPrecision(fineNodeMass + modifiedAa.Mass);
                            if (validFineNodeIndex >= fineNodes.Length) break;
                            fineNodes[validFineNodeIndex] = true;                            
                        }                         
                    }
                }
                
                /*foreach (var m in massList)
                {
                    var validFineNodeIndex = Constants.GetBinNumHighPrecision(fineNodeMass + m);
                    if (validFineNodeIndex >= fineNodes.Length) break;
                    fineNodes[validFineNodeIndex] = true;
                }*/

                var binNum = _mzComparer.GetBinNumber(fineNodeMass);
                if (fineBinIdx == 0 || (binNum >= _minMzBinIndex && binNum <= _maxMzBinIndex && _mzBinToFilteredBinMap[binNum - _minMzBinIndex + 1] < 0))
                {
                    _mzBinToFilteredBinMap[binNum == 0 ? 0 : binNum - _minMzBinIndex + 1] = effectiveBinCounter;
                    tempMap[effectiveBinCounter] = binNum;
                    effectiveBinCounter++;
                }
            }
            _filteredBinToMzBinMap = new int[effectiveBinCounter];
            Array.Copy(tempMap, _filteredBinToMzBinMap, effectiveBinCounter);            
        }
Example #10
0
 static MatchedPeakPostScorer()
 {
     BaseIonTypesCID = new[] { BaseIonType.B, BaseIonType.Y };
     BaseIonTypesETD = new[] { BaseIonType.C, BaseIonType.Z };
     Comparer = new MzComparerWithBinning(28);
 }
Example #11
0
        public void TestId()
        {
            const string rawFilePath = @"H:\Research\QCShew_TopDown\Production\QC_Shew_Intact_26Sep14_Bane_C2Column3.raw";
//            const string fastaFilePath = @"H:\Research\QCShew_TopDown\Production\ID_002216_235ACCEA.icsfldecoy.fasta";
            //const string fastaFilePath = @"H:\Research\QCShew_TopDown\Production\Decoy_SO4280.fasta";
            const string fastaFilePath = @"H:\Research\QCShew_TopDown\Production\SO2312.fasta";
            const string modFilePath = @"H:\Research\QCShew_TopDown\Production\Mods.txt";
            const int numBits = 29; // max error: 4ppm
            const int minCharge = 2;
            const int maxCharge = 20;
            var tolerance = new Tolerance(10);
            const double corrThreshold = 0.7;

            var comparer = new MzComparerWithBinning(numBits);
            const double minFragmentMass = 200.0;
            const double maxFragmentMass = 50000.0;
            var minFragMassBin = comparer.GetBinNumber(minFragmentMass);
            var maxFragMassBin = comparer.GetBinNumber(maxFragmentMass);

            var aminoAcidSet = new AminoAcidSet(modFilePath);

            var run = PbfLcMsRun.GetLcMsRun(rawFilePath);
//            var ms2ScanNumArr = run.GetScanNumbers(2).ToArray();
            //var ms2ScanNumArr = new[] {4130};
            var ms2ScanNumArr = new[] { 5189 };

            var sw = new Stopwatch();

            sw.Start();
            Console.Write("Building Spectrum Arrays...");
            var massVectors = new BitArray[maxFragMassBin - minFragMassBin + 1];
            for (var i = minFragMassBin; i <= maxFragMassBin; i++)
            {
                massVectors[i - minFragMassBin] = new BitArray(run.MaxLcScan + 1);
            }

            foreach (var ms2ScanNum in ms2ScanNumArr)
            {
                var productSpec = run.GetSpectrum(ms2ScanNum) as ProductSpectrum;
                if (productSpec == null) continue;

                productSpec.FilterNoise();
                var deconvolutedPeaks = Deconvoluter.GetDeconvolutedPeaks(productSpec, minCharge, maxCharge, 2, 1.1,
                    tolerance, corrThreshold);

                if (deconvolutedPeaks == null) continue;

                foreach (var p in deconvolutedPeaks)
                {
                    var mass = p.Mass;
                    var deltaMass = tolerance.GetToleranceAsDa(mass, 1);
                    var minMass = mass - deltaMass;
                    var maxMass = mass + deltaMass;

                    var minBinNum = comparer.GetBinNumber(minMass);
                    var maxBinNum = comparer.GetBinNumber(maxMass);
                    for (var binNum = minBinNum; binNum <= maxBinNum; binNum++)
                    {
                        if (binNum >= minFragMassBin && binNum <= maxFragMassBin) massVectors[binNum - minFragMassBin][ms2ScanNum] = true;
                    }
                }
            }
            sw.Stop();
            Console.WriteLine(@"{0:f4} sec.", sw.Elapsed.TotalSeconds);

            sw.Reset();
            sw.Start();
            var fastaDb = new FastaDatabase(fastaFilePath);
            fastaDb.Read();
            var indexedDb = new IndexedDatabase(fastaDb);
            var numProteins = 0;
            var intactProteinAnnotationAndOffsets =
                indexedDb.IntactSequenceAnnotationsAndOffsets(0, int.MaxValue);

            var bestProtein = new string[run.MaxLcScan + 1];
            var bestScore = new int[run.MaxLcScan + 1];
            foreach (var annotationAndOffset in intactProteinAnnotationAndOffsets)
            {
                if (++numProteins % 10 == 0)
                {
                    Console.WriteLine("Processing {0}{1} proteins...", numProteins,
                        numProteins == 1 ? "st" : numProteins == 2 ? "nd" : numProteins == 3 ? "rd" : "th");
                    if (numProteins != 0)
                    {
                        sw.Stop();

                        Console.WriteLine("Elapsed Time: {0:f4} sec", sw.Elapsed.TotalSeconds);
                        sw.Reset();
                        sw.Start();
                    }
                }
                var annotation = annotationAndOffset.Annotation;
                var offset = annotationAndOffset.Offset;

                var protSequence = annotation.Substring(2, annotation.Length - 4);

                // suffix
                var seqGraph = SequenceGraph.CreateGraph(aminoAcidSet, AminoAcid.ProteinNTerm, protSequence,
                    AminoAcid.ProteinCTerm);
                if (seqGraph == null) continue;

                for (var numNTermCleavage = 0; numNTermCleavage <= 0; numNTermCleavage++)
                {
                    if (numNTermCleavage > 0) seqGraph.CleaveNTerm();
                    var allCompositions = seqGraph.GetAllFragmentNodeCompositions().ToArray();

                    var scoreArr = new int[run.MaxLcScan + 1];
                    foreach (var fragComp in allCompositions)
                    {
                        var suffixMass = fragComp.Mass + BaseIonType.Y.OffsetComposition.Mass;
                        var binNum = comparer.GetBinNumber(suffixMass);
                        if (binNum < minFragMassBin || binNum > maxFragMassBin) continue;

                        var vector = massVectors[binNum - minFragMassBin];
                        foreach (var ms2ScanNum in ms2ScanNumArr)
                        {
                            if (vector[ms2ScanNum])
                            {
                                ++scoreArr[ms2ScanNum];
                                Console.WriteLine(suffixMass);
                            }
                        }
                    }
                    foreach (var ms2ScanNum in ms2ScanNumArr)
                    {
                        if (scoreArr[ms2ScanNum] > bestScore[ms2ScanNum])
                        {
                            bestScore[ms2ScanNum] = scoreArr[ms2ScanNum];
                            var proteinName = fastaDb.GetProteinName(offset);
                            bestProtein[ms2ScanNum] = proteinName + (numNTermCleavage == 1 ? "'" : "");
                        }
                    }
                }
                //// prefix
                //var seqGraphPrefix = SequenceGraph.CreateGraph(aminoAcidSet, AminoAcid.ProteinNTerm, protSequence,
                //    AminoAcid.ProteinCTerm);
                //if (seqGraphPrefix == null) continue;

                //{
                //    if (numNTermCleavage > 0) seqGraph.CleaveNTerm();
                //    var allCompositions = seqGraph.GetAllFragmentNodeCompositions();

                //    var scoreArr = new int[run.MaxLcScan + 1];
                //    foreach (var fragComp in allCompositions)
                //    {
                //        var suffixMass = fragComp.Mass + BaseIonType.Y.OffsetComposition.Mass;
                //        var binNum = comparer.GetBinNumber(suffixMass);
                //        if (binNum < minFragMassBin || binNum > maxFragMassBin) continue;

                //        var vector = massVectors[binNum - minFragMassBin];
                //        foreach (var ms2ScanNum in ms2ScanNumArr)
                //        {
                //            if (vector[ms2ScanNum]) ++scoreArr[ms2ScanNum];
                //        }
                //    }
                //    foreach (var ms2ScanNum in ms2ScanNumArr)
                //    {
                //        if (scoreArr[ms2ScanNum] > bestScore[ms2ScanNum])
                //        {
                //            bestScore[ms2ScanNum] = scoreArr[ms2ScanNum];
                //            var proteinName = fastaDb.GetProteinName(offset);
                //            bestProtein[ms2ScanNum] = proteinName + (numNTermCleavage == 1 ? "'" : "");
                //        }
                //    }
                //}
            }

            Console.WriteLine("ScanNum\tBestProtein\tScore");
            foreach (var ms2ScanNum in ms2ScanNumArr)
            {
                Console.WriteLine("{0}\t{1}\t{2}", ms2ScanNum, bestProtein[ms2ScanNum] ?? "", bestScore[ms2ScanNum]);
            }
            //sw.Stop();
            //Console.WriteLine(@"Scoring: {0:f4} sec.", sw.Elapsed.TotalSeconds);
        }
Example #12
0
        public SummedSpectrum GetSummedSpectrum(IList<int> scanNums, int repScanNum = 0)
        {
            var mzComparer = new MzComparerWithBinning();

            var mzDic = new Dictionary<int, List<double>>();
            var intDic = new Dictionary<int, double>();

            foreach (var scanNum in scanNums)
            {
                var spec = GetSpectrum(scanNum);
                if (spec == null) continue;
                foreach (var peak in spec.Peaks)
                {
                    var mzBin = mzComparer.GetBinNumber(peak.Mz);

                    List<double> mzList;
                    if (mzDic.TryGetValue(mzBin, out mzList))
                    {
                        mzList.Add(peak.Mz);
                        intDic[mzBin] += peak.Intensity;
                    }
                    else
                    {
                        mzDic.Add(mzBin, new List<double> { peak.Mz });
                        intDic.Add(mzBin, peak.Intensity);
                    }
                }
            }
            var summedPeakList = new List<Peak>();
            foreach (var entry in mzDic)
            {
                var binNum = entry.Key;
                var mzList = entry.Value;
                var medianMz = mzList.Median();
                var intensity = intDic[binNum];
                summedPeakList.Add(new Peak(medianMz, intensity));
            }
            summedPeakList.Sort();

            var summedSpec = new SummedSpectrum(summedPeakList, repScanNum) {ScanNums = scanNums};
            return summedSpec;
        }
Example #13
0
        public void TestGeneratingXicsOfAllCharges()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;
            TestUtils.ShowStarting(methodName);

            if (!File.Exists(TestRawFilePath))
            {
                Assert.Ignore(@"Skipping test " + methodName + @" since file not found: " + TestRawFilePath);
            }
            
            var run = PbfLcMsRun.GetLcMsRun(TestRawFilePath, 0.0, 0.0);
            var comparer = new MzComparerWithBinning(27);
            const string protSequence =
                "AIPQSVEGQSIPSLAPMLERTTPAVVSVAVSGTHVSKQRVPDVFRYFFGPNAPQEQVQERPFRGLGSGVIIDADKGYIVTNNHVIDGADDIQVGLHDGREVKAKLIGTDSESDIALLQIEAKNLVAIKTSDSDELRVGDFAVAIGNPFGLGQTVTSGIVSALGRSGLGIEMLENFIQTDAAINSGNSGGALVNLKGELIGINTAIVAPNGGNVGIGFAIPANMVKNLIAQIAEHGEVRRGVLGIAGRDLDSQLAQGFGLDTQHGGFVNEVSAGSAAEKAGIKAGDIIVSVDGRAIKSFQELRAKVATMGAGAKVELGLIRDGDKKTVNVTLGEANQTTEKAAGAVHPMLQGASLENASKGVEITDVAQGSPAAMSGLQKGDLIVGINRTAVKDLKSLKELLKDQEGAVALKIVRGKSMLYLVLR";
            //const string annotation = "_." + protSequence + "._";
            var seqGraph = SequenceGraph.CreateGraph(new AminoAcidSet(), AminoAcid.ProteinNTerm, protSequence, AminoAcid.ProteinCTerm);
            if (seqGraph == null) return;
            seqGraph.SetSink(0);
            var neutral = seqGraph.GetSinkSequenceCompositionWithH2O() - Composition.Hydrogen;
            var proteinMass = neutral.Mass;
            var isoEnv = Averagine.GetIsotopomerEnvelope(proteinMass);

            const bool SHOW_ALL_SCANS = false;
            var targetColIndex = 0;

            #pragma warning disable 0162
            if (SHOW_ALL_SCANS)           
                Console.WriteLine("Charge\t" + string.Join("\t", run.GetScanNumbers(1)));
            else
            {
                // Just display data for scan 161
                Console.WriteLine("Charge\t161");
                foreach (var scanNumber in run.GetScanNumbers(1))
                {
                    if (scanNumber == 161)
                        break;
                    targetColIndex++;
                }

            }
            #pragma warning restore 0162

            const int minCharge = 2;
            const int maxCharge = 60;
            for (var charge = minCharge; charge <= maxCharge; charge++)
            {
                var ion = new Ion(neutral, charge);
                var mostAbundantIsotopeMz = ion.GetIsotopeMz(isoEnv.MostAbundantIsotopeIndex);
                //var secondMostAbundantIsotopeMz = ion.GetIsotopeMz(isoEnv.MostAbundantIsotopeIndex + 1);
                var binNum = comparer.GetBinNumber(mostAbundantIsotopeMz);
                var mzStart = comparer.GetMzStart(binNum);
                var mzEnd = comparer.GetMzEnd(binNum);

                var xic = run.GetFullPrecursorIonExtractedIonChromatogram(mzStart, mzEnd);
                Console.Write(charge+"\t");

                #pragma warning disable 0162
                if (SHOW_ALL_SCANS)
                    Console.WriteLine(string.Join("\t", xic.Select(p => p.Intensity)));
                else
                    Console.WriteLine(xic[targetColIndex].Intensity);
                #pragma warning restore 0162
            }
        }
Example #14
0
        public void TestGetNumBins()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;
            TestUtils.ShowStarting(methodName);

            var comparer = new MzComparerWithBinning(26);
            const double minMz = 5000.0; // 600.0
            const double maxMz = 10000.0;    // 2000.0
            var minBinNum = comparer.GetBinNumber(minMz);
            var maxBinNum = comparer.GetBinNumber(maxMz);
            var numBins = maxBinNum - minBinNum;
            Console.WriteLine(@"NumBins: " + numBins);

            Assert.IsTrue(numBins == 16384);
        }        
Example #15
0
        public void TestGettingXicVector()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;
            TestUtils.ShowStarting(methodName);

            if (!File.Exists(TestRawFilePath))
            {
                Assert.Ignore(@"Skipping test " + methodName + @" since file not found: " + TestRawFilePath);
            }

            var run1 = PbfLcMsRun.GetLcMsRun(TestRawFilePath, 0.0, 0.0);
            var run2 = InMemoryLcMsRun.GetLcMsRun(TestRawFilePath, 0.0, 0.0);

            Assert.True(run1 != null && run2 != null);
            var comparer = new MzComparerWithBinning(27);
            const double minMz = 600.0; // 600.0
            const double maxMz = 2000.0;    // 2000.0
            var minBinNum = comparer.GetBinNumber(minMz);
            var maxBinNum = comparer.GetBinNumber(maxMz);
            Console.WriteLine(@"NumBins: " + (maxBinNum - minBinNum));

            var warnCount = 0;

            var sw = new Stopwatch();
            sw.Start();
            for (var binNum = minBinNum; binNum <= maxBinNum; binNum++)
            {
                var mzStart = comparer.GetMzStart(binNum);
                var mzEnd = comparer.GetMzEnd(binNum);

                var vec1 = run1.GetFullPrecursorIonExtractedIonChromatogramVector(mzStart, mzEnd);
                var vec2 = run2.GetFullPrecursorIonExtractedIonChromatogramVector(mzStart, mzEnd);

                Assert.True(vec1.Length == vec2.Length,
                                "Extracted Ion Chromatogram vector length mismatch, {0} vs. {1}", vec1.Length, vec2.Length);

                var matchCount = 0;
                var misMatchCount = 0;
                var positiveCount = 0;

                for (var i = 0; i < vec2.Length; i++)
                {
                    if (vec1[i] > 0 || vec2[i] > 0)
                    {
                        positiveCount++;
                    }

                    if (Math.Abs(vec1[i] - vec2[i]) < float.Epsilon)
                    {
                        matchCount++;
                    }
                    else
                    {
                        misMatchCount++;
                    }
                                               
                }

                if (misMatchCount <= 0 || positiveCount == 0)
                {
                    continue;
                }

                var fractionAgreement = 1 - misMatchCount / (double)positiveCount;

                if (fractionAgreement < 0.80 && misMatchCount > 2)
                {
                    Console.WriteLine(@"{0}/{1} Xic values do not match for bin {2} ({3:0.00} m/z); {4:0.0}% agreement",
                                      misMatchCount, positiveCount, binNum, mzStart, fractionAgreement * 100);
                    warnCount++;
                }
            }
            sw.Stop();

            Console.WriteLine(@"{0:f4} sec", sw.Elapsed.TotalSeconds);

            Assert.IsTrue(warnCount < 10, "Too many Xic mismatch warnings: {0}", warnCount);

        }
Example #16
0
        public void TestGeneringAllXics()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;
            TestUtils.ShowStarting(methodName);

            if (!File.Exists(TestRawFilePath))
            {
                Assert.Ignore(@"Skipping test " + methodName + @" since file not found: " + TestRawFilePath);
            }

            var run = PbfLcMsRun.GetLcMsRun(TestRawFilePath, 0.0, 0.0);

            Assert.True(run != null);

            var ms1Scans = run.GetMs1ScanVector();

            var comparer = new MzComparerWithBinning(27);
            const double minMz = 600.0; // 600.0
            const double maxMz = 2000.0;    // 2000.0
            var minBinNum = comparer.GetBinNumber(minMz);
            var maxBinNum = comparer.GetBinNumber(maxMz);
            var scanCount = run.MaxLcScan - run.MinLcScan + 1;

            var sw = new Stopwatch();
            sw.Start();
            var numBinsProcessed = 0;
            for (var binNum = minBinNum; binNum <= maxBinNum; binNum++)
            {
               
                var mzStart = comparer.GetMzStart(binNum);
                var mzEnd = comparer.GetMzEnd(binNum);
                
                var vec1 = run.GetFullPrecursorIonExtractedIonChromatogramVector(mzStart, mzEnd);

                if (++numBinsProcessed % 2500 == 0)
                {
                    Console.WriteLine(@"{0,5} / {1,5}, {2:0.00} m/z", numBinsProcessed, maxBinNum - minBinNum + 1, mzStart);
                }
                Assert.IsTrue(vec1.Length == ms1Scans.Length);
            }
            sw.Stop();

            Console.WriteLine(@"{0:f4} sec", sw.Elapsed.TotalSeconds);
        }