Exemplo n.º 1
1
    public void CalculateO18()
    {
      EmassProfileBuilder builder = new EmassProfileBuilder(@"../../../data/ISOTOPE.DAT");

      AtomComposition light = new AtomComposition("C45H73N13O13");
      var res = builder.GetProfile(light, 2, 5);

      Console.WriteLine("nature");
      foreach (var r in res)
      {
        Console.WriteLine("{0:0.0000}\t{1:0.000000}", r.Mz, r.Intensity);
      }

      AtomComposition O181 = new AtomComposition("(O18)1C45H73N13O12");
      var resH = builder.GetProfile(O181, 2, 5);

      Console.WriteLine("O181");
      foreach (var r in resH)
      {
        Console.WriteLine("{0:0.0000}\t{1:0.000000}", r.Mz, r.Intensity);
      }

      AtomComposition O182 = new AtomComposition("(O18)2C45H73N13O11");
      var resH2 = builder.GetProfile(O182, 2, 5);

      Console.WriteLine("O182");
      foreach (var r in resH2)
      {
        Console.WriteLine("{0:0.0000}\t{1:0.000000}", r.Mz, r.Intensity);
      }

      Console.WriteLine(string.Format("O18 - O16 = {0:0.0000}", Atom.O18.MonoMass - Atom.O.MonoMass));
      Console.WriteLine(string.Format("2 * (C13 - C12) = {0:0.0000}", 2 * (Atom.C13.MonoMass - Atom.C.MonoMass)));
      Console.WriteLine(string.Format("O18 - O181, ppm = {0:0.00}ppm", PrecursorUtils.mz2ppm(res[0].Mz, resH[0].Mz - res[2].Mz)));
      Console.WriteLine(string.Format("O18 - O182, ppm = {0:0.00}ppm", PrecursorUtils.mz2ppm(res[0].Mz, resH2[0].Mz - res[4].Mz)));
      Console.WriteLine(string.Format("O181- O182, ppm = {0:0.00}ppm", PrecursorUtils.mz2ppm(resH[0].Mz, resH2[0].Mz - resH[2].Mz)));

    }
Exemplo n.º 2
0
 public void TestConstructionAminoacid()
 {
   AtomComposition ac = new AtomComposition("C5H9NO");
   Assert.AreEqual(5, ac[Atom.C]);
   Assert.AreEqual(9, ac[Atom.H]);
   Assert.AreEqual(1, ac[Atom.N]);
   Assert.AreEqual(1, ac[Atom.O]);
 }
Exemplo n.º 3
0
    public void CalculateO18_charge1()
    {
      EmassProfileBuilder builder = new EmassProfileBuilder(@"../../../data/ISOTOPE.DAT");

      AtomComposition light = new AtomComposition("C45H73N13O13");
      var res = builder.GetProfile(light, 1, 5);

      var max = res.Max(m => m.Intensity);

      Console.WriteLine("nature");
      foreach (var r in res)
      {
        Console.WriteLine("{0:0.0000}\t{1:0.000000}", r.Mz - Atom.H.MonoMass, r.Intensity * 100 / max);
      }
    }
 //[Test]
 public void TestWuyin()
 {
   List<String> lines = FileUtils.ReadFile(@"C:\Documents and Settings\sheng\Desktop\formulas.txt");
   foreach (String line in lines)
   {
     var ac = new AtomComposition(line);
     List<double> profile = this.ip.GetProfile(ac, 10);
     Console.WriteLine(line);
     foreach (double d in profile)
     {
       Console.WriteLine(d);
     }
     Console.WriteLine();
   }
 }
Exemplo n.º 5
0
        private void ReadAtomMap(StreamReader filein, out AtomComposition leftMap, out AtomComposition rightMap)
        {
            leftMap  = new AtomComposition("");
            rightMap = new AtomComposition("");
            string line;

            while ((line = filein.ReadLine()) != null)
            {
                if (line.Trim().Length == 0)
                {
                    break;
                }
                Match atomMatch = Regex.Match(line, @"(\d*)(\S+)\s(\d+)\s(\d+)");
                if (!atomMatch.Success)
                {
                    throw new Exception("Cannot parse atom information from " + line);
                }

                string atomSymbol;
                if (atomMatch.Groups[1].Length > 0)
                {
                    atomSymbol = "(" + atomMatch.Groups[2].Value + atomMatch.Groups[1].Value + ")";
                }
                else
                {
                    atomSymbol = atomMatch.Groups[2].Value;
                }

                int leftCount  = int.Parse(atomMatch.Groups[3].Value);
                int rightCount = int.Parse(atomMatch.Groups[4].Value);

                Atom atom = Atom.ValueOf(atomSymbol);
                if (0 != leftCount)
                {
                    leftMap[atom] = leftCount;
                }

                if (0 != rightCount)
                {
                    rightMap[atom] = rightCount;
                }
            }
        }
Exemplo n.º 6
0
        //[Test]
        public void TestWuyinPeptide()
        {
            List <String> lines = FileUtils.ReadFile(@"C:\Documents and Settings\sheng\Desktop\sequences.txt");
            var           aas   = new Aminoacids();

            foreach (String line in lines)
            {
                AtomComposition ac = aas.GetPeptideAtomComposition(line);
                ac.Add(new AtomComposition("H2O"));
                List <double> profile = this.ip.GetProfile(ac, 10);
                Console.WriteLine(line);
                Console.WriteLine(ac);
                foreach (double d in profile)
                {
                    Console.WriteLine(d);
                }
                Console.WriteLine();
            }
        }
        protected override void DoRealGo()
        {
            MassCalculator averageCalc = new MassCalculator(Atom.AverageMassFunction);
            MassCalculator monoCalc    = new MassCalculator(Atom.MonoMassFunction);

            Aminoacids aas = new Aminoacids();

            aas['C'].ResetMass(aas['C'].MonoMass + 57.0215, aas['C'].AverageMass + 57.0215);

            StringBuilder sb = new StringBuilder();

            double totalMass = 0.0;

            if (peptideSequence.Text.Length > 0)
            {
                double averageMass = aas.AveragePeptideMass(peptideSequence.Text);
                sb.Append(MyConvert.Format("PeptideMass={0:0.0000}; ", averageMass));

                totalMass = averageMass;
            }

            if (glycanStructure.Text.Length > 0)
            {
                AtomComposition ac          = new AtomComposition(glycanStructure.Text);
                double          averageMass = averageCalc.GetMass(ac);
                sb.Append(MyConvert.Format("GlycanMass={0:0.0000}; ", averageMass));

                if (totalMass > 0)
                {
                    totalMass += averageMass - 18.0;
                    sb.Append(MyConvert.Format("TotalMass={0:0.0000}; ", totalMass));

                    for (int charge = 2; charge <= 4; charge++)
                    {
                        sb.Append(MyConvert.Format("Charge{0}={1:0.0000}; ", charge, (totalMass + charge) / charge));
                    }
                }
            }

            txtResultInfo.Text = sb.ToString();
        }
        public SilacCompoundInfo Build(IPeptideInfo peptideInfo)
        {
            var cis = new List <CompoundInfo>();

            double sampleMz = this.silacFile.SampleCalculator.GetMz(peptideInfo.Sequence, peptideInfo.Charge);

            AtomComposition sampleAtomComposition = this.silacFile.SampleAtomCompositionCalculator.GetAtomComposition(peptideInfo);

            cis.Add(new CompoundInfo(true, sampleMz, sampleAtomComposition, peptideInfo.Charge));

            double refMz = this.silacFile.ReferenceCalculator.GetMz(peptideInfo.Sequence, peptideInfo.Charge);

            AtomComposition refAtomComposition = this.silacFile.ReferenceAtomCompositionCalculator.GetAtomComposition(peptideInfo);

            cis.Add(new CompoundInfo(false, refMz, refAtomComposition, peptideInfo.Charge));

            //sort by ascending compoundMz
            cis.Sort();

            return(new SilacCompoundInfo(cis[0], cis[1]));
        }
        public List <double> GetProfile(AtomComposition ac)
        {
            List <double> result;

            for (int iLength = 10;; iLength *= 2)
            {
                result = GetProfile(ac, iLength);
                if (result[result.Count - 1] < result[result.Count - 2] &&
                    result[result.Count - 1] < PERCENT_TOLERANCE)
                {
                    break;
                }
            }

            while (result.Count > 1 && result[result.Count - 2] < PERCENT_TOLERANCE)
            {
                result.RemoveAt(result.Count - 1);
            }

            return(result);
        }
        public double[] ParseOffsets()
        {
            var acs    = this.NeutralLoss.Split(new char[] { ',', ';', ' ', '\t' }, System.StringSplitOptions.RemoveEmptyEntries);
            var masses = new List <double>();

            foreach (var acStr in acs)
            {
                double mass;
                if (double.TryParse(acStr, out mass))
                {
                    masses.Add(mass);
                }
                else
                {
                    var ac = new AtomComposition(acStr);
                    masses.Add(-Atom.GetMonoMass(ac));
                }
            }

            return(masses.ToArray());
        }
    public void TestPeptideAtomCompositionCalculator()
    {
      AtomComposition nterm = new AtomComposition("H");
      AtomComposition cterm = new AtomComposition("OH");
      Aminoacids aas = new Aminoacids();
      PeptideAtomCompositionCalculator calc = new PeptideAtomCompositionCalculator(nterm, cterm, aas);

      //Terminal only
      IPeptideInfo terminalInfo = new IdentifiedPeptideInfo("",0.0,0);
      AtomComposition terminalActual = calc.GetAtomComposition(terminalInfo);
      Assert.AreEqual(2, terminalActual[Atom.H]);
      Assert.AreEqual(1, terminalActual[Atom.O]);

      //A:C3H5NO
      IPeptideInfo peptideInfo = new IdentifiedPeptideInfo("A", 0.0, 0);
      AtomComposition peptideActual = calc.GetAtomComposition(peptideInfo);
      Assert.AreEqual(3, peptideActual[Atom.C]);
      Assert.AreEqual(7, peptideActual[Atom.H]);
      Assert.AreEqual(1, peptideActual[Atom.N]);
      Assert.AreEqual(2, peptideActual[Atom.O]);
    }
Exemplo n.º 12
0
        public void CalculateO18()
        {
            EmassProfileBuilder builder = new EmassProfileBuilder(@TestContext.CurrentContext.TestDirectory + "/../../../data//ISOTOPE.DAT");

            AtomComposition light = new AtomComposition("C45H73N13O13");
            var             res   = builder.GetProfile(light, 2, 5);

            Console.WriteLine("nature");
            foreach (var r in res)
            {
                Console.WriteLine("{0:0.0000}\t{1:0.000000}", r.Mz, r.Intensity);
            }

            AtomComposition O181 = new AtomComposition("(O18)1C45H73N13O12");
            var             resH = builder.GetProfile(O181, 2, 5);

            Console.WriteLine("O181");
            foreach (var r in resH)
            {
                Console.WriteLine("{0:0.0000}\t{1:0.000000}", r.Mz, r.Intensity);
            }

            AtomComposition O182  = new AtomComposition("(O18)2C45H73N13O11");
            var             resH2 = builder.GetProfile(O182, 2, 5);

            Console.WriteLine("O182");
            foreach (var r in resH2)
            {
                Console.WriteLine("{0:0.0000}\t{1:0.000000}", r.Mz, r.Intensity);
            }

            Console.WriteLine(string.Format("O18 - O16 = {0:0.0000}", Atom.O18.MonoMass - Atom.O.MonoMass));
            Console.WriteLine(string.Format("2 * (C13 - C12) = {0:0.0000}", 2 * (Atom.C13.MonoMass - Atom.C.MonoMass)));
            Console.WriteLine(string.Format("O18 - O181, ppm = {0:0.00}ppm", PrecursorUtils.mz2ppm(res[0].Mz, resH[0].Mz - res[2].Mz)));
            Console.WriteLine(string.Format("O18 - O182, ppm = {0:0.00}ppm", PrecursorUtils.mz2ppm(res[0].Mz, resH2[0].Mz - res[4].Mz)));
            Console.WriteLine(string.Format("O181- O182, ppm = {0:0.00}ppm", PrecursorUtils.mz2ppm(resH[0].Mz, resH2[0].Mz - resH[2].Mz)));
        }
Exemplo n.º 13
0
    public void Calculate()
    {
      var calc = new EmassCalculator(@"../../../data/ISOTOPE.DAT");

      EmassProfileBuilder builder = new EmassProfileBuilder();

      AtomComposition light = new AtomComposition("C45H73N13O13");
      var res = builder.GetProfile(light, 2, 4);

      Console.WriteLine("light");
      foreach (var r in res)
      {
        Console.WriteLine("{0:0.0000}\t{1:0.000000}", r.Mz, r.Intensity);
      }

      AtomComposition heavy = new AtomComposition("(C13)6(N15)4C39H73N9O13");
      var resH = builder.GetProfile(heavy, 2, 4);

      Console.WriteLine("heavy");
      foreach (var r in resH)
      {
        Console.WriteLine("{0:0.0000}\t{1:0.000000}", r.Mz, r.Intensity);
      }
    }
Exemplo n.º 14
0
        public void Calculate()
        {
            var calc = new EmassCalculator(@TestContext.CurrentContext.TestDirectory + "/../../../data//ISOTOPE.DAT");

            EmassProfileBuilder builder = new EmassProfileBuilder();

            AtomComposition light = new AtomComposition("C45H73N13O13");
            var             res   = builder.GetProfile(light, 2, 4);

            Console.WriteLine("light");
            foreach (var r in res)
            {
                Console.WriteLine("{0:0.0000}\t{1:0.000000}", r.Mz, r.Intensity);
            }

            AtomComposition heavy = new AtomComposition("(C13)6(N15)4C39H73N9O13");
            var             resH  = builder.GetProfile(heavy, 2, 4);

            Console.WriteLine("heavy");
            foreach (var r in resH)
            {
                Console.WriteLine("{0:0.0000}\t{1:0.000000}", r.Mz, r.Intensity);
            }
        }
Exemplo n.º 15
0
        public O18QuantificationPeptideProcessor(IFileFormat <O18QuantificationSummaryItem> fileFormat,
                                                 bool isPostDigestionLabelling, string rawFilename, string peptide,
                                                 double purityOfO18Water, List <O18QuanEnvelope> envelopes, double mzTolerance,
                                                 string additionalFormula, double scanPercentageStart, double scanPercentageEnd)
        {
            _fileFormat = fileFormat;
            _isPostDigestionLabelling = isPostDigestionLabelling;
            _rawFilename       = new FileInfo(rawFilename).FullName;
            _peptide           = peptide;
            _additionalFormula = additionalFormula;

            _atomComposition = _aas.GetPeptideAtomComposition(peptide);
            if (!string.IsNullOrEmpty(additionalFormula))
            {
                var additionalAtomComposition = new AtomComposition(additionalFormula);
                _atomComposition.Add(additionalAtomComposition);
            }
            _profile          = _cp.GetProfile(_atomComposition, 0, 10);
            _purityOfO18Water = purityOfO18Water;
            _envelopes        = envelopes;

            _scanPercentageStart = scanPercentageStart;
            _scanPercentageEnd   = scanPercentageEnd;
        }
        public override List <double> GetProfile(AtomComposition ac, int profileLength)
        {
            int countC = ac.GetAtomCount(Atom.C);
            int countH = ac.GetAtomCount(Atom.H);
            int countO = ac.GetAtomCount(Atom.O);
            int countN = ac.GetAtomCount(Atom.N);
            int countS = ac.GetAtomCount(Atom.S);
            int maxC13 = Math.Min(profileLength, countC);
            int maxH2  = Math.Min(profileLength, countH);
            int maxO18 = Math.Min(profileLength / 2, countO);
            int maxN15 = Math.Min(profileLength, countN);
            int maxS34 = Math.Min(profileLength / 2, countS);

            var profile = new double[profileLength];

            for (int countC13 = 0; countC13 <= maxC13; countC13++)
            {
                int    pcLength = countC13;
                double combC    = StatisticsUtils.GetCombinationProbability(countC13, countC, C13, C12);
                for (int countH2 = 0; countH2 <= maxH2; countH2++)
                {
                    int phLength = pcLength + countH2;
                    if (phLength >= profileLength)
                    {
                        break;
                    }
                    double combH = StatisticsUtils.GetCombinationProbability(countH2, countH, H2, H);
                    for (int countN15 = 0; countN15 <= maxN15; countN15++)
                    {
                        int pnLength = phLength + countN15;
                        if (pnLength >= profileLength)
                        {
                            break;
                        }
                        double combN = StatisticsUtils.GetCombinationProbability(countN15, countN, N15, N14);
                        for (int countO18 = 0; countO18 <= maxO18; countO18++)
                        {
                            int poLength = pnLength + countO18 * 2;
                            if (poLength >= profileLength)
                            {
                                break;
                            }
                            double combO = StatisticsUtils.GetCombinationProbability(countO18, countO, O18, O16);

                            for (int countS34 = 0; countS34 <= maxS34; countS34++)
                            {
                                int psLength = poLength + countS34 * 2;
                                if (psLength >= profileLength)
                                {
                                    break;
                                }
                                double combS            = StatisticsUtils.GetCombinationProbability(countS34, countS, S34, S32);
                                double totalProbability = combC * combH * combN * combO * combS;
                                profile[psLength] += totalProbability;
                            }
                        }
                    }
                }
            }
            var result = new List <double>();

            foreach (double value in profile)
            {
                result.Add(value);
            }

            return(result);
        }
Exemplo n.º 17
0
 public PeptideAtomCompositionCalculator(AtomComposition nTerm, AtomComposition cTerm, Aminoacids aas)
 {
     this.nTerm = nTerm;
     this.cTerm = cTerm;
     this.aas   = aas;
 }
        public Pattern Calculate(string formula, double limit, long charge)
        {
            AtomComposition ac = new AtomComposition(formula);

            return(Calculate(ac, limit, charge));
        }
Exemplo n.º 19
0
 public override List <double> GetProfile(AtomComposition ac, int profileLength)
 {
     return(GetProfile(ac.GetAtomCount(Atom.C), profileLength));
 }
 public abstract List <double> GetProfile(AtomComposition ac, int profileLength);
Exemplo n.º 21
0
        public SilacQuantificationSummaryItem ReadFromFile(string filename)
        {
            XElement root = XElement.Load(filename);

            var result = new SilacQuantificationSummaryItem(root.GetChildValue("SampleIsLight", true));

            result.RawFilename              = root.GetChildValue("RawFilename", "");
            result.SoftwareVersion          = root.GetChildValue("SoftwareVersion", "");
            result.PeptideSequence          = root.GetChildValue("PeptideSequence");
            result.Charge                   = root.GetChildValue("Charge", 2);
            result.SampleAtomComposition    = root.GetChildValue("SampleAtomComposition");
            result.ReferenceAtomComposition = root.GetChildValue("ReferenceAtomComposition");
            result.Ratio = root.GetChildValue("Ratio", 0.0);
            result.RegressionCorrelation = root.GetChildValue("Correlation", 0.0);
            result.SampleAbundance       = root.GetChildValue("SampleAbundance", 0.0);
            result.ReferenceAbundance    = root.GetChildValue("ReferenceAbundance", 0.0);

            result.SampleProfile = new List <Peak>();
            ReadProfile(root, "SampleProfile", result.SampleProfile);

            result.ReferenceProfile = new List <Peak>();
            ReadProfile(root, "ReferenceProfile", result.ReferenceProfile);

            var observed = root.Element("ObservedEnvelopes");

            result.ObservedEnvelopes = new SilacEnvelopes();
            foreach (var pkl in observed.Elements())
            {
                var    peakList      = new SilacPeakListPair();
                int    scan          = Convert.ToInt32(pkl.Attribute("Scan").Value);
                double retentiontime = MyConvert.ToDouble(pkl.Attribute("Retentiontime").Value);
                peakList.Enabled      = Convert.ToBoolean(pkl.Attribute("Enabled").Value);
                peakList.IsIdentified = Convert.ToBoolean(pkl.Attribute("Identified").Value);

                var extended = pkl.Attribute("ExtendedIdentification");
                if (extended != null)
                {
                    peakList.IsExtendedIdentification = Convert.ToBoolean(pkl.Attribute("ExtendedIdentification").Value);
                }
                else
                {
                    peakList.IsExtendedIdentification = false;
                }

                peakList.LightIntensity = MyConvert.ToDouble(pkl.Attribute("LightIntensity").Value);
                peakList.HeavyIntensity = MyConvert.ToDouble(pkl.Attribute("HeavyIntensity").Value);

                peakList.Light = new PeakList <Peak>();
                peakList.Light.ScanTimes.Add(new ScanTime(scan, retentiontime));

                peakList.Heavy = new PeakList <Peak>();
                peakList.Heavy.ScanTimes.Add(new ScanTime(scan, retentiontime));

                ReadPeakList(pkl, "LightPeakList", peakList.Light);
                ReadPeakList(pkl, "HeavyPeakList", peakList.Heavy);

                result.ObservedEnvelopes.Add(peakList);
            }

            if (result.LightProfile[0].Mz == 0.0)
            {
                EmassProfileBuilder builder = new EmassProfileBuilder();

                double minPercentage = 0.0001;

                AtomComposition acSample = new AtomComposition(result.SampleAtomComposition);
                result.SampleProfile = builder.GetProfile(acSample, result.Charge, minPercentage);

                AtomComposition acRef = new AtomComposition(result.ReferenceAtomComposition);
                result.ReferenceProfile = builder.GetProfile(acRef, result.Charge, minPercentage);
            }

            result.CalculateCorrelation();

            return(result);
        }
        public override IEnumerable <string> Process(string filename)
        {
            string resultFile = filename + ".profile";

            using (StreamWriter sw = new StreamWriter(resultFile))
            {
                sw.WriteLine("Name\tFormula\tAtomComposition\tProfile");
                using (StreamReader sr = new StreamReader(filename))
                {
                    bool bProcess = sr.BaseStream.Length > 0;

                    if (bProcess)
                    {
                        Progress.SetRange(0, sr.BaseStream.Length);
                    }

                    string line;
                    sr.ReadLine();

                    Dictionary <string, List <Peak> > formulaProfileMap = new Dictionary <string, List <Peak> >();

                    while ((line = sr.ReadLine()) != null)
                    {
                        if (bProcess)
                        {
                            Progress.SetPosition(sr.BaseStream.Position);
                        }

                        if (Progress.IsCancellationPending())
                        {
                            throw new UserTerminatedException();
                        }

                        if (line.Trim().Length == 0)
                        {
                            break;
                        }

                        string[] parts = line.Split(new char[] { '\t' });
                        if (parts.Length < 3)
                        {
                            throw new Exception("It's not atom composition : " + line);
                        }

                        List <Peak> profile;
                        if (formulaProfileMap.ContainsKey(parts[2]))
                        {
                            profile = formulaProfileMap[parts[2]];
                        }
                        else
                        {
                            AtomComposition ac = new AtomComposition(parts[2]);
                            profile = builder.GetProfile(ac, 0, 0.00001);
                            formulaProfileMap[parts[2]] = profile;
                        }

                        sw.Write("{0}\t{1}\t{2}", parts[0], parts[1], parts[2]);
                        foreach (var value in profile)
                        {
                            sw.Write("\t{0:0.00000}:{1:0.00000}", value.Mz, value.Intensity);
                        }
                        sw.WriteLine();
                    }
                }
            }

            return(new[] { resultFile });
        }
Exemplo n.º 23
0
 public void TestCompositionToString() {
   AtomComposition ac = new AtomComposition("C5H9NO");
   Assert.AreEqual("C5H9NO", ac.ToString());
 }
Exemplo n.º 24
0
 public void TestConstructionCompound()
 {
   AtomComposition ac = new AtomComposition("CaCl2");
   Assert.AreEqual(1, ac[Atom.Ca]);
   Assert.AreEqual(2, ac[Atom.Cl]);
 }
Exemplo n.º 25
0
 public void TestIsotopic()
 {
   AtomComposition ac = new AtomComposition("C5(C13)6");
   Assert.AreEqual(5, ac[Atom.C]);
   Assert.AreEqual(6, ac[Atom.C13]);
 }