Example #1
0
        public static void MassToMzPositiveCharge_plus3()
        {
            ObjectWithMass1000 a  = new ObjectWithMass1000();
            double             mz = (double)ClassExtensions.RoundedDouble(a.ToMz(3), 9);

            Assert.AreEqual(334.340609800, mz);
        }
 public NeutralTerminusFragment(FragmentationTerminus terminus, double neutralMass, int fragmentNumber, int aminoAcidPosition)
 {
     this.Terminus          = terminus;
     this.NeutralMass       = (double)ClassExtensions.RoundedDouble(neutralMass);
     this.FragmentNumber    = fragmentNumber;
     this.AminoAcidPosition = aminoAcidPosition;
 }
        public void CalculateIntensityForThisFeature(bool integrate)
        {
            if (IsotopicEnvelopes.Any())
            {
                double maxIntensity = IsotopicEnvelopes.Max(p => p.Intensity);
                Apex = IsotopicEnvelopes.Where(p => p.Intensity == maxIntensity).First();

                if (integrate)
                {
                    Intensity = IsotopicEnvelopes.Sum(p => p.Intensity);
                }
                else
                {
                    Intensity = Apex.Intensity;
                }

                MassError = Identifications.Min(p => ((ClassExtensions.ToMass(Apex.IndexedPeak.Mz, Apex.ChargeState) - p.monoisotopicMass) / p.monoisotopicMass) * 1e6);
                NumChargeStatesObserved = IsotopicEnvelopes.Select(p => p.ChargeState).Distinct().Count();
            }
            else
            {
                Intensity = 0;
                MassError = double.NaN;
                NumChargeStatesObserved = 0;
                Apex = null;
            }
        }
Example #4
0
 public override Exp_Node Clone()
 {
     return(new Exp_Node_New(
                (Exp_Node_New)left?.Clone(), (Exp_Node_New)right?.Clone(),
                input == null ? null : new List <string>(ClassExtensions.Clone(input)),
                exp_Data, exp_Type, exp_Operator));
 }
        public static IsotopicEnvelope[] GetNeutralExperimentalFragments(MsDataScan scan, CommonParameters commonParam)
        {
            int minZ = 1;
            int maxZ = 10;

            var neutralExperimentalFragmentMasses = scan.MassSpectrum.Deconvolute(scan.MassSpectrum.Range,
                                                                                  minZ, maxZ, commonParam.DeconvolutionMassTolerance.Value, commonParam.DeconvolutionIntensityRatio).ToList();

            if (commonParam.AssumeOrphanPeaksAreZ1Fragments)
            {
                HashSet <double> alreadyClaimedMzs = new HashSet <double>(neutralExperimentalFragmentMasses
                                                                          .SelectMany(p => p.peaks.Select(v => ClassExtensions.RoundedDouble(v.mz).Value)));

                for (int i = 0; i < scan.MassSpectrum.XArray.Length; i++)
                {
                    double mz        = scan.MassSpectrum.XArray[i];
                    double intensity = scan.MassSpectrum.YArray[i];

                    if (!alreadyClaimedMzs.Contains(ClassExtensions.RoundedDouble(mz).Value))
                    {
                        neutralExperimentalFragmentMasses.Add(new IsotopicEnvelope(
                                                                  new List <(double mz, double intensity)> {
                            (mz, intensity)
                        },
                                                                  mz.ToMass(1), 1, intensity, 0, 0));
                    }
                }
            }

            return(neutralExperimentalFragmentMasses.OrderBy(p => p.monoisotopicMass).ToArray());
        }
Example #6
0
        public void DeepCopy()
        {
            ClassA original = ClassExtensions.DeepCreate <ClassA>();

            original.IntVal       = 2;
            original.NullIntVal   = 2;
            original.DateTime     = DateTime.Today;
            original.NullDateTime = DateTime.MaxValue;
            original.IntList.Add(2);
            ((List <string>)original.StringEnumerable).Add("Two");
            ((Dictionary <string, int>)original.StringIntDictionary).Add("Two", 2);
            original.ChangeReadonlyInt(2);
            original.CList.Add(new ClassC(1, original));
            original.CList.Add(new ClassC(2, original));
            original.CList.Add(new ClassC(3, original));

            ClassA copy = original.DeepCopy();

            Assert.IsNotNull(copy);
            Assert.AreEqual(copy.IntVal, 2);
            Assert.AreEqual(copy.NullIntVal, 2);
            Assert.AreEqual(copy.DateTime, DateTime.Today);
            Assert.AreEqual(copy.NullDateTime, DateTime.MaxValue);
            Assert.IsNotNull(copy.IntList);
            Assert.AreEqual(copy.IntList.Count, 1);
            Assert.AreEqual(copy.IntList[0], 2);

            Assert.IsNotNull(copy.StringEnumerable);
            Assert.AreEqual(copy.StringEnumerable.Count(), 1);
            Assert.AreEqual(copy.StringEnumerable.First(), "Two");

            Assert.IsNotNull(copy.CList);
            Assert.AreEqual(copy.CList.Count, 3);
            Assert.AreEqual(copy.CList[0].IntVal, 1);
            Assert.AreEqual(copy.CList[0].Owner, copy);
            Assert.AreEqual(copy.CList[1].IntVal, 2);
            Assert.AreEqual(copy.CList[1].Owner, copy);
            Assert.AreEqual(copy.CList[2].IntVal, 3);
            Assert.AreEqual(copy.CList[2].Owner, copy);

            Assert.IsNotNull(copy.StringIntDictionary);
            Assert.AreEqual(copy.StringIntDictionary.Count, 1);
            Assert.AreEqual(copy.StringIntDictionary["Two"], 2);

            Assert.AreEqual(copy.ReadOnlyInt, -1);

            Assert.IsNotNull(copy.B);
            Assert.IsNotNull(copy.B.ClassA);
            Assert.AreSame(copy.B.ClassA, copy);
            Assert.IsNotNull(copy.B.Owner);
            Assert.AreSame(copy.B.Owner, copy);
            Assert.IsNotNull(copy.B.Parent);
            Assert.AreSame(copy.B.Parent, copy);
            Assert.IsNull(copy.B.TheresaMay);
        }
Example #7
0
        public static void TestChemicalFormulaWithIsotopes_DiLeu12plex(string formula, double mass, bool mz)
        {
            ChemicalFormula cf = ChemicalFormula.ParseFormula(formula);

            if (mz)
            {
                Assert.AreEqual(mass, ClassExtensions.RoundedDouble(cf.MonoisotopicMass.ToMz(1), 5));
            }
            else
            {
                Assert.AreEqual(mass, ClassExtensions.RoundedDouble(cf.MonoisotopicMass));
            }
        }
        public static void TestPeptideLabelledWith_DiLeu_4plex(string peptide, double totalMass)
        {
            List <Modification> gptmdModifications = new List <Modification>();

            gptmdModifications.AddRange(GlobalVariables.AllModsKnown);
            List <Modification> itraq4plex = gptmdModifications.Where(m => m.ModificationType == "Multiplex Label" && m.IdWithMotif.Contains("DiLeu-4plex")).ToList();

            Protein          P = new Protein(peptide, "", "", null, null, null, null, null, false, false, null, null, null, null);
            CommonParameters CommonParameters = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 1));
            var p = P.Digest(CommonParameters.DigestionParams, itraq4plex, new List <Modification>()).First();
            var f = p.Fragment(DissociationType.HCD, FragmentationTerminus.Both);

            List <double> productMasses = f.Select(m => m.NeutralMass.ToMz(1)).ToList();

            productMasses.Distinct();
            productMasses.Sort();

            Assert.AreEqual(totalMass, ClassExtensions.RoundedDouble(p.MonoisotopicMass.ToMz(1), 4));
        }
Example #9
0
        public void DeepCreate()
        {
            ClassA classA = ClassExtensions.DeepCreate <ClassA>();

            Assert.IsNotNull(classA);
            Assert.AreEqual(classA.IntVal, 0);
            Assert.IsNull(classA.NullIntVal);
            Assert.AreEqual(classA.DateTime, DateTime.MinValue);
            Assert.IsNull(classA.NullDateTime);
            Assert.IsNotNull(classA.IntList);
            Assert.IsNotNull(classA.StringEnumerable);
            Assert.IsNotNull(classA.StringIntDictionary);
            Assert.AreEqual(classA.ReadOnlyInt, -1);

            Assert.IsNotNull(classA.B);
            Assert.IsNotNull(classA.B.ClassA);
            Assert.IsNotNull(classA.B.Owner);
            Assert.IsNotNull(classA.B.Parent);
            Assert.IsNull(classA.B.TheresaMay);
        }
Example #10
0
        public void CalculateIntensityForThisFeature(bool integrate)
        {
            if (IsotopicEnvelopes.Any())
            {
                double maxIntensity = IsotopicEnvelopes.Max(p => p.Intensity);
                Apex = IsotopicEnvelopes.First(p => p.Intensity == maxIntensity);

                if (integrate)
                {
                    Intensity = IsotopicEnvelopes.Sum(p => p.Intensity);
                }
                else
                {
                    Intensity = Apex.Intensity;
                }

                MassError = double.NaN;

                foreach (Identification id in Identifications)
                {
                    double massErrorForId = ((ClassExtensions.ToMass(Apex.IndexedPeak.Mz, Apex.ChargeState) - id.PeakfindingMass) / id.PeakfindingMass) * 1e6;

                    if (double.IsNaN(MassError) || Math.Abs(massErrorForId) < Math.Abs(MassError))
                    {
                        MassError = massErrorForId;
                    }
                }

                NumChargeStatesObserved = IsotopicEnvelopes.Select(p => p.ChargeState).Distinct().Count();
            }
            else
            {
                Intensity = 0;
                MassError = double.NaN;
                NumChargeStatesObserved = 0;
                Apex = null;
            }
        }
        public void CalculateIntensityForThisFeature(bool integrate)
        {
            if (isotopeClusters.Any())
            {
                apexPeak = isotopeClusters.Where(p => p.isotopeClusterIntensity == isotopeClusters.Max(v => v.isotopeClusterIntensity)).FirstOrDefault();

                if (integrate)
                {
                    intensity = isotopeClusters.Select(p => p.isotopeClusterIntensity).Sum();
                }
                else
                {
                    intensity = apexPeak.isotopeClusterIntensity;
                }

                massError = ((ClassExtensions.ToMass(apexPeak.peakWithScan.mainPeak.Mz, apexPeak.chargeState) - identifyingScans.First().monoisotopicMass) / identifyingScans.First().monoisotopicMass) * 1e6;
                numChargeStatesObserved = isotopeClusters.Select(p => p.chargeState).Distinct().Count();
            }
            else
            {
                apexPeak = null;
            }
        }
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(ClassExtensions.FormatFileSize((long)value));
 }
Example #13
0
        protected List <int> GetBinsToSearch(Ms2ScanWithSpecificMass scan)
        {
            int        obsPreviousFragmentCeilingMz = 0;
            List <int> binsToSearch = new List <int>();

            if (commonParameters.DissociationType == DissociationType.LowCID)
            {
                double[] masses      = scan.TheScan.MassSpectrum.XArray;
                double[] intensities = scan.TheScan.MassSpectrum.YArray;

                for (int i = 0; i < masses.Length; i++)
                {
                    //convert to an int since we're in discreet 1.0005...
                    int fragmentBin = (int)(Math.Round(masses[i].ToMass(1) / 1.0005079) * 1.0005079 * FragmentBinsPerDalton);

                    if (FragmentIndex[fragmentBin] != null)
                    {
                        binsToSearch.Add(fragmentBin);
                    }

                    // add complementary ions
                    if (commonParameters.AddCompIons)
                    {
                        if (complementaryIonConversionDictionary.TryGetValue(commonParameters.DissociationType, out double protonMassShift)) //TODO: this is broken for EThcD because that method needs two conversions
                        {
                            protonMassShift = ClassExtensions.ToMass(protonMassShift, 1);
                            fragmentBin     = (int)Math.Round((scan.PrecursorMass + protonMassShift - masses[i]) / 1.0005079);

                            if (FragmentIndex[fragmentBin] != null)
                            {
                                binsToSearch.Add(fragmentBin);
                            }
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                }
            }
            else
            {
                foreach (var envelope in scan.ExperimentalFragments)
                {
                    // assume charge state 1 to calculate mass tolerance
                    double experimentalFragmentMass = envelope.monoisotopicMass;

                    // get theoretical fragment bins within mass tolerance
                    int obsFragmentFloorMass   = (int)Math.Floor((commonParameters.ProductMassTolerance.GetMinimumValue(experimentalFragmentMass)) * FragmentBinsPerDalton);
                    int obsFragmentCeilingMass = (int)Math.Ceiling((commonParameters.ProductMassTolerance.GetMaximumValue(experimentalFragmentMass)) * FragmentBinsPerDalton);

                    // prevents double-counting peaks close in m/z and lower-bound out of range exceptions
                    if (obsFragmentFloorMass < obsPreviousFragmentCeilingMz)
                    {
                        obsFragmentFloorMass = obsPreviousFragmentCeilingMz;
                    }
                    obsPreviousFragmentCeilingMz = obsFragmentCeilingMass + 1;

                    // prevent upper-bound index out of bounds errors;
                    // lower-bound is handled by the previous "if (obsFragmentFloorMass < obsPreviousFragmentCeilingMz)" statement
                    if (obsFragmentCeilingMass >= FragmentIndex.Length)
                    {
                        obsFragmentCeilingMass = FragmentIndex.Length - 1;

                        if (obsFragmentFloorMass >= FragmentIndex.Length)
                        {
                            obsFragmentFloorMass = FragmentIndex.Length - 1;
                        }
                    }

                    // search mass bins within a tolerance
                    for (int fragmentBin = obsFragmentFloorMass; fragmentBin <= obsFragmentCeilingMass; fragmentBin++)
                    {
                        if (FragmentIndex[fragmentBin] != null)
                        {
                            binsToSearch.Add(fragmentBin);
                        }
                    }

                    // add complementary ions
                    if (commonParameters.AddCompIons)
                    {
                        //okay, we're not actually adding in complementary m/z peaks, we're doing a shortcut and just straight up adding the bins assuming that they're z=1

                        if (complementaryIonConversionDictionary.TryGetValue(commonParameters.DissociationType, out double protonMassShift)) //TODO: this is broken for EThcD because that method needs two conversions
                        {
                            protonMassShift = ClassExtensions.ToMass(protonMassShift, 1);
                            int compFragmentFloorMass   = (int)Math.Round(((scan.PrecursorMass + protonMassShift) * FragmentBinsPerDalton)) - obsFragmentCeilingMass;
                            int compFragmentCeilingMass = (int)Math.Round(((scan.PrecursorMass + protonMassShift) * FragmentBinsPerDalton)) - obsFragmentFloorMass;

                            // prevent index out of bounds errors
                            if (compFragmentCeilingMass >= FragmentIndex.Length)
                            {
                                compFragmentCeilingMass = FragmentIndex.Length - 1;

                                if (compFragmentFloorMass >= FragmentIndex.Length)
                                {
                                    compFragmentFloorMass = FragmentIndex.Length - 1;
                                }
                            }
                            if (compFragmentFloorMass < 0)
                            {
                                compFragmentFloorMass = 0;
                            }

                            for (int fragmentBin = compFragmentFloorMass; fragmentBin <= compFragmentCeilingMass; fragmentBin++)
                            {
                                if (FragmentIndex[fragmentBin] != null)
                                {
                                    binsToSearch.Add(fragmentBin);
                                }
                            }
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                }
            }
            return(binsToSearch);
        }
Example #14
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            if (this.IdWithMotif != null)
            {
                sb.AppendLine("ID   " + this.IdWithMotif);
            }
            if (this.Accession != null)
            {
                sb.AppendLine("AC   " + this.Accession);
            }
            if (this.ModificationType != null)
            {
                sb.AppendLine("MT   " + this.ModificationType);
            }
            if (this.FeatureType != null)
            {
                sb.AppendLine("FT   " + this.FeatureType);
            }
            if (this.Target != null)
            {
                sb.AppendLine("TG   " + this.Target);
            }                                         // at this stage, each mod has only one target though many may have the same Id
            if (this.LocationRestriction != null)
            {
                sb.AppendLine("PP   " + this.LocationRestriction);
            }
            if (this.ChemicalFormula != null)
            {
                sb.AppendLine("CF   " + this.ChemicalFormula.Formula);
            }
            if (this.MonoisotopicMass != null)
            {
                sb.AppendLine("MM   " + this.MonoisotopicMass);
            }
            if (this.DatabaseReference != null)
            {
                if (this.DatabaseReference.Count != 0)
                {
                    List <string> myKeys = new List <string>(this.DatabaseReference.Keys);
                    myKeys.Sort();
                    foreach (string myKey in myKeys)
                    {
                        List <string> myValues = new List <string>(this.DatabaseReference[myKey]);
                        myValues.Sort();
                        foreach (string myValue in myValues)
                        {
                            sb.AppendLine("DR   " + myKey + "; " + myValue);
                        }
                    }
                }
            }
            if (this.TaxonomicRange != null)
            {
                if (this.TaxonomicRange.Count != 0)
                {
                    List <string> myKeys = new List <string>(this.TaxonomicRange.Keys);
                    myKeys.Sort();
                    foreach (string myKey in myKeys)
                    {
                        List <string> myValues = new List <string>(this.TaxonomicRange[myKey]);
                        myValues.Sort();
                        foreach (string myValue in myValues)
                        {
                            sb.AppendLine("TR   " + myKey + "; " + myValue);
                        }
                    }
                }
            }
            if (this.NeutralLosses != null)
            {
                if (this.NeutralLosses.Count != 0)
                {
                    List <DissociationType> allDissociationTypes = this.NeutralLosses.Keys.ToList();
                    allDissociationTypes.Sort();

                    foreach (DissociationType dissociationType in allDissociationTypes)
                    {
                        StringBuilder myLine = new StringBuilder();
                        myLine.Append("NL   ");

                        List <double> myValues = new List <double>(this.NeutralLosses[dissociationType]);
                        myValues.Sort();
                        for (int i = 0; i < myValues.Count; i++)
                        {
                            myLine.Append(dissociationType + ":" + ClassExtensions.RoundedDouble(myValues[i]));
                            if (i < myValues.Count - 1)
                            {
                                myLine.Append(" or ");
                            }
                        }

                        sb.AppendLine(myLine.ToString());
                    }
                }
            }
            if (this.DiagnosticIons != null)
            {
                if (this.DiagnosticIons.Count != 0)
                {
                    List <DissociationType> allDissociationTypes = this.DiagnosticIons.Keys.ToList();
                    allDissociationTypes.Sort();

                    foreach (DissociationType dissociationType in allDissociationTypes)
                    {
                        StringBuilder myLine = new StringBuilder();
                        myLine.Append("DI   ");

                        List <double> myValues = new List <double>(this.DiagnosticIons[dissociationType]);
                        myValues.Sort();
                        for (int i = 0; i < myValues.Count; i++)
                        {
                            myLine.Append(dissociationType + ":" + ClassExtensions.RoundedDouble(myValues[i]));
                            if (i < myValues.Count - 1)
                            {
                                myLine.Append(" or ");
                            }
                        }

                        sb.AppendLine(myLine.ToString());
                    }
                }
            }

            if (this.Keywords != null)
            {
                if (this.Keywords.Count != 0)
                {
                    sb.AppendLine("KW   " + String.Join(" or ", this.Keywords.ToList().OrderBy(b => b)));
                }
            }

            return(sb.ToString());
        }
Example #15
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(SpectraFileInfo.FilenameWithoutExtension + "\t");
            sb.Append(string.Join("|", Identifications.Select(p => p.BaseSequence).Distinct()) + '\t');
            sb.Append(string.Join("|", Identifications.Select(p => p.ModifiedSequence).Distinct()) + '\t');

            var t = Identifications.SelectMany(p => p.ProteinGroups.Select(v => v.ProteinGroupName)).Distinct().OrderBy(p => p);

            if (t.Any())
            {
                sb.Append(string.Join(";", t) + '\t');
            }
            else
            {
                sb.Append("" + '\t');
            }

            sb.Append("" + Identifications.First().MonoisotopicMass + '\t');
            if (!IsMbrPeak)
            {
                sb.Append("" + Identifications.First().Ms2RetentionTimeInMinutes + '\t');
            }
            else
            {
                sb.Append("" + '\t');
            }

            sb.Append("" + Identifications.First().PrecursorChargeState + '\t');
            sb.Append("" + ClassExtensions.ToMz(Identifications.First().MonoisotopicMass, Identifications.First().PrecursorChargeState) + '\t');
            sb.Append("" + Intensity + "\t");

            if (Apex != null)
            {
                sb.Append("" + IsotopicEnvelopes.Min(p => p.IndexedPeak.RetentionTime) + "\t");
                sb.Append("" + Apex.IndexedPeak.RetentionTime + "\t");
                sb.Append("" + IsotopicEnvelopes.Max(p => p.IndexedPeak.RetentionTime) + "\t");

                sb.Append("" + Apex.IndexedPeak.Mz + "\t");
                sb.Append("" + Apex.ChargeState + "\t");
            }
            else
            {
                sb.Append("" + "-" + "\t");
                sb.Append("" + "-" + "\t");
                sb.Append("" + "-" + "\t");

                sb.Append("" + "-" + "\t");
                sb.Append("" + "-" + "\t");
            }

            sb.Append("" + NumChargeStatesObserved + "\t");

            if (IsMbrPeak)
            {
                sb.Append("" + "MBR" + "\t");
            }
            else
            {
                sb.Append("" + "MSMS" + "\t");
            }

            sb.Append("" + (IsMbrPeak ? MbrScore.ToString() : "") + "\t");

            sb.Append("" + Identifications.Count + "\t");
            sb.Append("" + NumIdentificationsByBaseSeq + "\t");
            sb.Append("" + NumIdentificationsByFullSeq + "\t");
            sb.Append("" + SplitRT + "\t");
            sb.Append("" + MassError + "\t");

            return(sb.ToString());
        }
        override public string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(fileName + "\t");
            sb.Append(string.Join("|", identifyingScans.Select(p => p.BaseSequence).Distinct()) + '\t');
            sb.Append(string.Join("|", identifyingScans.Select(p => p.FullSequence).Distinct()) + '\t');

            var t = identifyingScans.SelectMany(p => p.proteinGroups).Distinct().Select(p => p.proteinGroupName).OrderBy(p => p);

            if (t.Any())
            {
                sb.Append(string.Join(";", t) + '\t');
            }
            else
            {
                sb.Append("" + '\t');
            }

            sb.Append("" + identifyingScans.First().monoisotopicMass + '\t');
            if (!isMbrFeature)
            {
                sb.Append("" + identifyingScans.First().ms2RetentionTime + '\t');
            }
            else
            {
                sb.Append("" + '\t');
            }
            sb.Append("" + identifyingScans.First().chargeState + '\t');
            sb.Append("" + ClassExtensions.ToMz(identifyingScans.First().monoisotopicMass, identifyingScans.First().chargeState) + '\t');
            sb.Append("" + intensity + "\t");

            if (apexPeak != null)
            {
                sb.Append("" + isotopeClusters.Select(p => p.peakWithScan.retentionTime).Min() + "\t");
                sb.Append("" + apexPeak.peakWithScan.retentionTime + "\t");
                sb.Append("" + isotopeClusters.Select(p => p.peakWithScan.retentionTime).Max() + "\t");

                sb.Append("" + apexPeak.peakWithScan.mainPeak.Mz + "\t");
                sb.Append("" + apexPeak.chargeState + "\t");
            }
            else
            {
                sb.Append("" + "-" + "\t");
                sb.Append("" + "-" + "\t");
                sb.Append("" + "-" + "\t");

                sb.Append("" + "-" + "\t");
                sb.Append("" + "-" + "\t");
            }

            sb.Append("" + numChargeStatesObserved + "\t");

            if (isMbrFeature)
            {
                sb.Append("" + "MBR" + "\t");
            }
            else
            {
                sb.Append("" + "MSMS" + "\t");
            }

            sb.Append("" + identifyingScans.Count + "\t");
            sb.Append("" + numIdentificationsByBaseSeq + "\t");
            sb.Append("" + numIdentificationsByFullSeq + "\t");
            sb.Append("" + splitRT + "\t");
            sb.Append("" + massError);

            return(sb.ToString());
        }
Example #17
0
        public EntityDataLog Logs(T entity)
        {
            EntityDataLog entityDataLog = new EntityDataLog();
            Type          type          = typeof(T);

            entityDataLog.FullName = type.FullName;
            DisplayNameAttribute[] customAttributes1 = ReflectionExtensions.GetCustomAttributes <DisplayNameAttribute>(type);
            DisplayAttribute[]     customAttributes2 = ReflectionExtensions.GetCustomAttributes <DisplayAttribute>(type);
            if (customAttributes1 != null && customAttributes1.Length > 0)
            {
                entityDataLog.DisplayName = customAttributes1[0].DisplayName;
            }
            else if (customAttributes2 != null && customAttributes2.Length > 0)
            {
                entityDataLog.DisplayName = customAttributes2[0].Name;
            }
            // ISSUE: reference to a compiler-generated method
            DbEntityEntry <T> dbEntityEntry = this.DataContext.Entry <T>(entity);

            if (dbEntityEntry.State == EntityState.Modified)
            {
                foreach (string propertyName in dbEntityEntry.OriginalValues.PropertyNames)
                {
                    EntityPropertyData entityPropertyData = new EntityPropertyData();
                    entityPropertyData.Name = propertyName;
                    DisplayNameAttribute displayAttribute1 = ClassExtensions <T> .GetDisplayAttribute <DisplayNameAttribute>(propertyName);

                    DisplayAttribute displayAttribute2 = ClassExtensions <T> .GetDisplayAttribute(propertyName);

                    if (!string.IsNullOrEmpty(displayAttribute1.DisplayName))
                    {
                        entityPropertyData.DisplayName = displayAttribute1.DisplayName;
                    }
                    else if (!string.IsNullOrEmpty(displayAttribute2.Name))
                    {
                        entityPropertyData.DisplayName = displayAttribute2.Name;
                    }
                    entityPropertyData.OldValue = dbEntityEntry.OriginalValues[propertyName];
                    entityPropertyData.NewValue = dbEntityEntry.CurrentValues[propertyName];
                    entityDataLog.ChangedProperties.Add(entityPropertyData);
                }
            }
            else
            {
                foreach (PropertyInfo property in typeof(T).GetProperties())
                {
                    EntityPropertyData entityPropertyData = new EntityPropertyData();
                    entityPropertyData.Name = property.Name;
                    DisplayNameAttribute displayAttribute1 = ClassExtensions <T> .GetDisplayAttribute <DisplayNameAttribute>(entityPropertyData.Name);

                    DisplayAttribute displayAttribute2 = ClassExtensions <T> .GetDisplayAttribute(entityPropertyData.Name);

                    if (!string.IsNullOrEmpty(displayAttribute1.DisplayName))
                    {
                        entityPropertyData.DisplayName = displayAttribute1.DisplayName;
                    }
                    else if (!string.IsNullOrEmpty(displayAttribute2.Name))
                    {
                        entityPropertyData.DisplayName = displayAttribute2.Name;
                    }
                    entityPropertyData.OldValue = property.GetValue((object)entity, (object[])null);
                    entityDataLog.ChangedProperties.Add(entityPropertyData);
                }
            }
            return(entityDataLog);
        }
        protected List <int> GetBinsToSearch(Ms2ScanWithSpecificMass scan)
        {
            int        obsPreviousFragmentCeilingMz = 0;
            List <int> binsToSearch = new List <int>();

            foreach (var peakMz in scan.TheScan.MassSpectrum.XArray)
            {
                // assume charge state 1 to calculate mass tolerance
                double experimentalFragmentMass = ClassExtensions.ToMass(peakMz, 1);

                // get theoretical fragment bins within mass tolerance
                int obsFragmentFloorMass   = (int)Math.Floor((commonParameters.ProductMassTolerance.GetMinimumValue(experimentalFragmentMass)) * FragmentBinsPerDalton);
                int obsFragmentCeilingMass = (int)Math.Ceiling((commonParameters.ProductMassTolerance.GetMaximumValue(experimentalFragmentMass)) * FragmentBinsPerDalton);

                // prevents double-counting peaks close in m/z and lower-bound out of range exceptions
                if (obsFragmentFloorMass < obsPreviousFragmentCeilingMz)
                {
                    obsFragmentFloorMass = obsPreviousFragmentCeilingMz;
                }
                obsPreviousFragmentCeilingMz = obsFragmentCeilingMass + 1;

                // prevent upper-bound index out of bounds errors;
                // lower-bound is handled by the previous "if (obsFragmentFloorMass < obsPreviousFragmentCeilingMz)" statement
                if (obsFragmentCeilingMass >= FragmentIndex.Length)
                {
                    obsFragmentCeilingMass = FragmentIndex.Length - 1;

                    if (obsFragmentFloorMass >= FragmentIndex.Length)
                    {
                        obsFragmentFloorMass = FragmentIndex.Length - 1;
                    }
                }

                // search mass bins within a tolerance
                for (int fragmentBin = obsFragmentFloorMass; fragmentBin <= obsFragmentCeilingMass; fragmentBin++)
                {
                    if (FragmentIndex[fragmentBin] != null)
                    {
                        binsToSearch.Add(fragmentBin);
                    }
                }

                // add complementary ions
                if (commonParameters.AddCompIons)
                {
                    //okay, we're not actually adding in complementary m/z peaks, we're doing a shortcut and just straight up adding the bins assuming that they're z=1
                    foreach (DissociationType dissociationType in DissociationTypes)
                    {
                        if (complementaryIonConversionDictionary.TryGetValue(dissociationType, out double protonMassShift))
                        {
                            protonMassShift = ClassExtensions.ToMass(protonMassShift, 1);
                            int compFragmentFloorMass   = (int)Math.Round(((scan.PrecursorMass + protonMassShift) * FragmentBinsPerDalton)) - obsFragmentCeilingMass;
                            int compFragmentCeilingMass = (int)Math.Round(((scan.PrecursorMass + protonMassShift) * FragmentBinsPerDalton)) - obsFragmentFloorMass;

                            // prevent index out of bounds errors
                            if (compFragmentCeilingMass >= FragmentIndex.Length)
                            {
                                compFragmentCeilingMass = FragmentIndex.Length - 1;

                                if (compFragmentFloorMass >= FragmentIndex.Length)
                                {
                                    compFragmentFloorMass = FragmentIndex.Length - 1;
                                }
                            }
                            if (compFragmentFloorMass < 0)
                            {
                                compFragmentFloorMass = 0;
                            }

                            for (int fragmentBin = compFragmentFloorMass; fragmentBin <= compFragmentCeilingMass; fragmentBin++)
                            {
                                if (FragmentIndex[fragmentBin] != null)
                                {
                                    binsToSearch.Add(fragmentBin);
                                }
                            }
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                }
            }
            return(binsToSearch);
        }
Example #19
0
        public static void TestChemicalFormulaWithIsotopesTMT(string formula, double mass)
        {
            ChemicalFormula cf = ChemicalFormula.ParseFormula(formula);

            Assert.AreEqual(mass, ClassExtensions.RoundedDouble(cf.MonoisotopicMass));
        }
Example #20
0
 public static double ProductTypeSpecificFragmentNeutralMass(double mass, ProductType p)
 {
     return((double)ClassExtensions.RoundedDouble(mass + GetMassShiftFromProductType(p), 9));
 }
Example #21
0
        private void DrawHeatmapThing(ChromatographicPeak peak, Canvas canvas)
        {
            var allPeaks = peak.isotopicEnvelopes.SelectMany(p => p.peaks).ToList();
            List <Tuple <double, int, double> > datapoints = new List <Tuple <double, int, double> >();

            double xAxisLowerbound = peak.isotopicEnvelopes.Min(p => p.retentionTime);
            double xAxisUpperbound = peak.isotopicEnvelopes.Max(p => p.retentionTime);
            double yAxisLowerbound = -1;
            double yAxisUpperbound = 20;
            double xAxisStep       = (xAxisUpperbound - xAxisLowerbound) / 5;
            double yAxisStep       = 1;

            if (xAxisLowerbound == xAxisUpperbound)
            {
                xAxisLowerbound--;
                xAxisUpperbound++;
            }

            canvas.Children.Clear();
            DrawGraphAxes(canvas, xAxisLowerbound, xAxisUpperbound, xAxisStep, yAxisLowerbound, yAxisUpperbound, yAxisStep, 20, "{0:0.00}", "F0");


            foreach (var env in peak.isotopicEnvelopes)
            {
                foreach (var msPeak in env.peaks)
                {
                    double peakMass = ClassExtensions.ToMass(msPeak.mz, env.charge);
                    int    massDiff = (int)Math.Round(peakMass - peak.mass, 0);

                    datapoints.Add(new Tuple <double, int, double>(env.retentionTime, massDiff, msPeak.intensity / env.charge));
                }
            }

            if (intensityToColor == null)
            {
                intensityToColor = new Dictionary <double, SolidColorBrush>();
                intensityToColor.Add(0.0, Brushes.Blue);
                intensityToColor.Add(0.2, Brushes.Violet);
                intensityToColor.Add(0.4, Brushes.Green);
                intensityToColor.Add(0.6, Brushes.Gold);
                intensityToColor.Add(0.8, Brushes.Orange);
                intensityToColor.Add(1.0, Brushes.Red);
            }

            // Make some data sets.
            PointCollection points = new PointCollection();
            List <Tuple <double, double, double> > xyz = new List <Tuple <double, double, double> >();

            var dataGroupedByMassDiff = datapoints.GroupBy(p => p.Item2);

            foreach (var massDiff in dataGroupedByMassDiff)
            {
                var group = massDiff.ToList().GroupBy(v => v.Item1);

                foreach (var g in group)
                {
                    var h = g.ToList();

                    double intensityHere = h.Sum(v => v.Item3);

                    xyz.Add(new Tuple <double, double, double>(h.First().Item1, h.First().Item2, intensityHere));
                }
            }

            double maxIntensity = xyz.Max(p => p.Item3);

            var timepoints = xyz.GroupBy(p => p.Item1).OrderBy(v => v.Key);

            double diff                    = (timepoints.Last().First().Item1 - timepoints.First().First().Item1);
            int    numtimepoints           = timepoints.Count();
            Point  tick1W                  = WtoD(new Point(0, 0));
            Point  tick2W                  = WtoD(new Point(diff / numtimepoints, 0));
            double widthOfHeatmapRectangle = tick2W.X - tick1W.X;

            double summedMaxColumn = timepoints.Max(p => p.Sum(v => v.Item3));

            foreach (var timepointIsotopes in timepoints)
            {
                var list = timepointIsotopes.ToList();

                double maxOfColumn = list.Max(p => p.Item3);

                foreach (var point in timepointIsotopes)
                {
                    Point p = new Point(point.Item1, point.Item2);
                    var   transformedPoint = WtoD(p);
                    points.Add(transformedPoint);

                    var rectangle = new Rectangle();

                    var dfg = GetHeatmapColor(point.Item3 / maxOfColumn);
                    //double opacity = (byte)(255 * (list.Sum(g => g.Item3) / summedMaxColumn));

                    SolidColorBrush brush = new SolidColorBrush(Color.FromArgb(255, (byte)dfg.Item1, (byte)dfg.Item2, (byte)dfg.Item3));

                    rectangle.Stroke = brush;
                    rectangle.Fill   = brush;
                    rectangle.Height = 4;
                    rectangle.Width  = widthOfHeatmapRectangle;
                    Canvas.SetLeft(rectangle, transformedPoint.X - rectangle.Width / 2);
                    Canvas.SetTop(rectangle, transformedPoint.Y - rectangle.Height / 2);
                    canvas.Children.Add(rectangle);

                    //TextBlock ratio = new TextBlock();
                    //ratio.Text = ((point.Item3 / maxOfColumn) * 100).ToString("F0");
                    //ratio.FontSize = 8;
                    //Canvas.SetLeft(ratio, transformedPoint.X - rectangle.Width / 2);
                    //Canvas.SetTop(ratio, transformedPoint.Y - rectangle.Height / 2 - 2);
                    //canvas.Children.Add(ratio);
                }
            }
        }