private IsotopicProfile GetTheorIsotopicProfile(IsosResult saturatedFeature, double lowerIntensityCutoff = 0.0001) { var theorTarget = new PeptideTarget { ChargeState = (short)saturatedFeature.IsotopicProfile.ChargeState, MonoIsotopicMass = saturatedFeature.IsotopicProfile.MonoIsotopicMass }; theorTarget.MZ = (theorTarget.MonoIsotopicMass / theorTarget.ChargeState) + Globals.PROTON_MASS; var averagineFormula = _tomIsotopicPatternGenerator.GetClosestAvnFormula(saturatedFeature.IsotopicProfile.MonoIsotopicMass, false); theorTarget.IsotopicProfile = _tomIsotopicPatternGenerator.GetIsotopePattern(averagineFormula, _tomIsotopicPatternGenerator.aafIsos); theorTarget.EmpiricalFormula = averagineFormula; theorTarget.CalculateMassesForIsotopicProfile(saturatedFeature.IsotopicProfile.ChargeState); //NOTE: This is critical to choosing the optimum peak of the observed isotopic profile //A value of 0.001 will leave more peaks in the theor profile. This //can be bad with co-eluting peptides, so that a peak of the interfering peptide //is used to correct the intensity of our target peptide. //A value of 0.01 helps prevent this (by trimming the peaks of the theor profile, //and reducing the peaks to be considered for peak intensity extrapolation of the target peptide. PeakUtilities.TrimIsotopicProfile(theorTarget.IsotopicProfile, lowerIntensityCutoff); return(theorTarget.IsotopicProfile); }
public static List <PeptideTarget> CreateN14N15TestMassTagList() { var mtList = new List <PeptideTarget>(); var mt1 = new PeptideTarget(); mt1.ID = 23085473; mt1.NormalizedElutionTime = 0.3807834F; mt1.MonoIsotopicMass = 2538.33284203802; mt1.ChargeState = 3; mt1.MZ = mt1.MonoIsotopicMass / mt1.ChargeState + Globals.PROTON_MASS; mt1.Code = "AIHQPAPTFAEQSTTSEILVTGIK"; mt1.EmpiricalFormula = mt1.GetEmpiricalFormulaFromTargetCode(); mtList.Add(mt1); var mt2 = new PeptideTarget(); mt2.ID = 23085470; mt2.NormalizedElutionTime = 0.6053093f; mt2.MonoIsotopicMass = 2329.24291507994; mt2.ChargeState = 3; mt2.MZ = mt2.MonoIsotopicMass / mt2.ChargeState + Globals.PROTON_MASS; mt2.Code = "TAIRDPNPVIFLENEILYGR"; mt1.EmpiricalFormula = mt1.GetEmpiricalFormulaFromTargetCode(); mtList.Add(mt2); return(mtList); }
public void PartialLabelingQuantifierTest1() { // see https://jira.pnnl.gov/jira/browse/OMCS-743 var peptideSeq = "SAMPLERSAMPLER"; var isoCreator = new LabeledIsotopicProfileUtilities(); var elementLabelled = "C"; var lightIsotope = 12; var heavyIsotope = 13; var target = new PeptideTarget(); target.Code = peptideSeq; target.EmpiricalFormula = target.GetEmpiricalFormulaFromTargetCode(); target.ChargeState = 2; target.CalculateMassesForIsotopicProfile(target.ChargeState); target.IsotopicProfile = isoCreator.CreateIsotopicProfileFromEmpiricalFormula(target.EmpiricalFormula, elementLabelled, 12, 13, 0, target.ChargeState); double[] obsMZVals = { 794.4027177, 794.9043951, 795.4060725, 795.9077499, 796.4094273, 796.9111047, 797.4127822, 797.9144596, 798.416137, 798.9178144, 799.4194918, 799.9211693, 800.4228467, 800.9245241, 801.4262015, 801.9278789, 802.4295564, 802.9312338, 803.4329112, 803.9345886, 804.436266, 804.9379435, 805.4396209, 805.9412983, 806.4429757, 806.9446531, 807.4463306, 807.948008, 808.4496854, 808.9513628, 809.4530402, 809.9547176, 810.4563951 }; double[] obsIntensities = { 0.202610146, 0.169786958, 0.10004317, 0.048528412, 0.023649271, 0.01375091, 0.011401505, 0.010165125, 0, 0, 0, 0,0, 0.016295369, 0.02039971, 0.02628524 , 0.034368448, 0.042300575, 0.050392505, 0.057402354, 0.061016738, 0.061990991, 0.059175713, 0.053291295, 0.046892873, 0.037952256, 0.030884989 , 0.024965924, 0.019531111, 0.01613184, 0, 0, 0 }; var peakList = obsMZVals.Select((t, i) => new Peak(t, (float)obsIntensities[i], 0)).ToList(); var partialLabelingQuantifier = new PartialLabelingQuantifier("C", 12, 13); var bestIso = partialLabelingQuantifier.FindBestLabeledProfile(target, peakList, null); var counter = 0; foreach (var currentFitScore in partialLabelingQuantifier.FitScoreData) { Console.WriteLine(currentFitScore.Key + "\t" + currentFitScore.Value); counter++; } }
private void addInfoToResult(IsotopicProfile iso, PeptideTarget mt) { if (iso != null) { iso.ChargeState = mt.ChargeState; iso.MonoIsotopicMass = (iso.GetMZ() - Globals.PROTON_MASS) * mt.ChargeState; iso.IntensityMostAbundant = iso.getMostIntensePeak().Height; // may need to change this to sum the top n peaks. } }
private PeptideTarget convertTextToMassTag(List <string> lineData) { var mt = new PeptideTarget(); mt.ChargeState = (short)parseIntField(getValue(new string[] { "z", "charge_state", "charge" }, lineData, "0")); mt.ID = parseIntField(getValue(new string[] { "id", "targetid", "target_id", "mass_tag_id", "massTagid" }, lineData, "-1")); mt.Code = getValue(new string[] { "peptide", "sequence" }, lineData, ""); var scanNum = parseIntField(getValue(new string[] { "scannum", "scan", "scanNum" }, lineData, "-1")); mt.NormalizedElutionTime = parseFloatField(getValue(new string[] { "net", "avg_ganet", "ElutionTimeTheor" }, lineData, "-1")); var neitherScanOrNETIsProvided = mt.NormalizedElutionTime == -1 && scanNum == -1; if (neitherScanOrNETIsProvided) { mt.ElutionTimeUnit = Globals.ElutionTimeUnit.NormalizedElutionTime; mt.NormalizedElutionTime = 0.5f; // set the NET mid-way between 0 and 1. } var useScanNum = ((int)mt.NormalizedElutionTime == -1 && scanNum != -1); if (useScanNum) { mt.ScanLCTarget = scanNum; //mt.NormalizedElutionTime = scanNum / ; mt.ElutionTimeUnit = Globals.ElutionTimeUnit.ScanNum; } mt.ObsCount = parseIntField(getValue(new string[] { "obs", "obscount" }, lineData, "-1")); mt.MonoIsotopicMass = parseDoubleField(getValue(new string[] { "mass", "monoisotopicmass", "monoisotopic_mass" }, lineData, "0")); mt.EmpiricalFormula = getValue(new string[] { "formula", "empirical_formula", "empiricalformula" }, lineData, ""); mt.ModCount = parseShortField(getValue(new string[] { "modCount", "mod_count" }, lineData, "0")); mt.ModDescription = getValue(new string[] { "mod", "mod_description" }, lineData, ""); if (mt.ChargeState == 0) { } else { mt.MZ = parseDoubleField(getValue(new string[] { "mz" }, lineData, "0")); if (mt.MZ == 0 || mt.MZ == double.NaN) { mt.MZ = mt.MonoIsotopicMass / mt.ChargeState + Globals.PROTON_MASS; } } mt.GeneReference = getValue(new string[] { "reference" }, lineData, ""); mt.RefID = parseIntField(getValue(new string[] { "ref_id" }, lineData, "-1")); mt.ProteinDescription = getValue(new string[] { "description", "protein" }, lineData, ""); return(mt); }
public void initializeFromEmpiricalFormula() { var mt = new PeptideTarget(); mt.Code = "SAMPLER"; mt.EmpiricalFormula = mt.GetEmpiricalFormulaFromTargetCode(); Assert.AreEqual("C33H58N10O11S", mt.EmpiricalFormula); Assert.AreEqual(33, mt.GetAtomCountForElement("C")); }
public N14N15ResultObject(String datasetName, PeptideTarget mt) { this.DatasetName = datasetName; this.MassTag = mt; this.ChromListLabeled = new List <XYData>(); this.ChromListUnlabeled = new List <XYData>(); this.ChromPeakSelectedLabeled = new List <Peak>(); this.ChromPeakSelectedUnlabeled = new List <Peak>(); }
public void test3() { TargetBase target = new PeptideTarget(); target.Code = "TTPSIIAYTDDETIVGQPAKRTTPSIIAYTDDETIVGQPAKRTTPSIIAYTDDETIVGQPAKR"; target.EmpiricalFormula = target.GetEmpiricalFormulaFromTargetCode(); var cluster = _tomIsotopicPatternGenerator.GetIsotopePattern(target.EmpiricalFormula, _tomIsotopicPatternGenerator.aafIsos); TestUtilities.DisplayIsotopicProfileData(cluster); }
public PeptideTarget CreateMT23085904_Z2() { var mt = new PeptideTarget(); mt.ChargeState = 2; mt.Code = "AMPIDLSNLALLDANGK"; mt.EmpiricalFormula = mt.GetEmpiricalFormulaFromTargetCode(); mt.MonoIsotopicMass = 1754.923582420; mt.MZ = 878.4690677; mt.NormalizedElutionTime = 0.4509717f; return(mt); }
public PeptideTarget CreateMT23140708_Z2() { var mt = new PeptideTarget(); mt.ChargeState = 2; mt.Code = "IVKVNVDENPESPAMLGVR"; mt.EmpiricalFormula = mt.GetEmpiricalFormulaFromTargetCode(); mt.MonoIsotopicMass = 2066.08292; mt.MZ = 1034.048737; mt.NormalizedElutionTime = 0.329644f; return(mt); }
private IsotopicProfile getTheorProfile(PeptideTarget massTag, Globals.IsotopicProfileType isotopicProfileType) { switch (isotopicProfileType) { case Globals.IsotopicProfileType.UNLABELLED: return(massTag.IsotopicProfile); case Globals.IsotopicProfileType.LABELLED: return(massTag.IsotopicProfileLabelled); default: return(massTag.IsotopicProfile); } }
protected TargetCollection GetMassTagTargets(string massTagFileName, List <int> targetIDsToFilterOn) { if (String.IsNullOrEmpty(massTagFileName) || !File.Exists(massTagFileName)) { return(new TargetCollection()); } if (massTagFileName.ToLower().Contains("_msgfplus.tsv")) { var iqTargetImporter = new BasicIqTargetImporter(massTagFileName); var iqTargets = iqTargetImporter.Import(); var targetUtilities = new IqTargetUtilities(); var targetCollection = new TargetCollection { TargetList = new List <TargetBase>() }; foreach (var iqTarget in iqTargets) { if (iqTarget.QualityScore > MsgfFdrScoreCutoff) { continue; } targetUtilities.UpdateTargetMissingInfo(iqTarget); TargetBase oldStyleTarget = new PeptideTarget(); oldStyleTarget.ChargeState = (short)iqTarget.ChargeState; oldStyleTarget.Code = iqTarget.Code; oldStyleTarget.EmpiricalFormula = iqTarget.EmpiricalFormula; oldStyleTarget.ID = iqTarget.ID; oldStyleTarget.MZ = iqTarget.MZTheor; oldStyleTarget.MonoIsotopicMass = iqTarget.MonoMassTheor; oldStyleTarget.ScanLCTarget = iqTarget.ScanLC; oldStyleTarget.NormalizedElutionTime = (float)iqTarget.ElutionTimeTheor; oldStyleTarget.ElutionTimeUnit = DeconTools.Backend.Globals.ElutionTimeUnit.ScanNum; targetCollection.TargetList.Add(oldStyleTarget); } return(targetCollection); } var importer = new MassTagFromTextFileImporter(massTagFileName); return(importer.Import(targetIDsToFilterOn)); }
public static List <PeptideTarget> CreateO16O18TestMassTagList1() { var mtList = new List <PeptideTarget>(); var mt = new PeptideTarget(); mt.ID = 1142; mt.MonoIsotopicMass = 921.4807035; mt.ChargeState = 2; mt.MZ = mt.MonoIsotopicMass / mt.ChargeState + Globals.PROTON_MASS; mt.Code = "AEFVEVTK"; mt.EmpiricalFormula = mt.GetEmpiricalFormulaFromTargetCode(); mtList.Add(mt); return(mtList); }
public static List <PeptideTarget> CreateTestMassTagList() { var mtList = new List <PeptideTarget>(); var mt = new PeptideTarget(); mt.ID = 24769; mt.MonoIsotopicMass = 2086.0595; mt.ChargeState = 2; mt.MZ = mt.MonoIsotopicMass / mt.ChargeState + Globals.PROTON_MASS; mt.Code = "DFNEALVHQVVVAYAANAR"; mt.EmpiricalFormula = mt.GetEmpiricalFormulaFromTargetCode(); mtList.Add(mt); return(mtList); }
public static PeptideTarget GetMassTagStandard(int standardNum) { var mt = new PeptideTarget(); mt.ID = 86963986; mt.MonoIsotopicMass = 1516.791851; mt.Code = "AAKEGISCEIIDLR"; mt.EmpiricalFormula = mt.GetEmpiricalFormulaFromTargetCode(); mt.NormalizedElutionTime = 0.2284955f; mt.ChargeState = 2; mt.MZ = mt.MonoIsotopicMass / mt.ChargeState + Globals.PROTON_MASS; return(mt); }
public static List <PeptideTarget> CreateN14N15TestMassTagList() { var mtList = new List <PeptideTarget>(); var mt = new PeptideTarget(); mt.ID = 23085473; mt.NormalizedElutionTime = 0.3807834F; mt.MonoIsotopicMass = 2538.33284203802; mt.ChargeState = 3; mt.MZ = mt.MonoIsotopicMass / mt.ChargeState + Globals.PROTON_MASS; mt.Code = "AIHQPAPTFAEQSTTSEILVTGIK"; mt.EmpiricalFormula = mt.GetEmpiricalFormulaFromTargetCode(); mtList.Add(mt); return(mtList); }
public override void GetFitScores(IEnumerable <IsosResult> isosResults) { foreach (var result in isosResults) { //create a temporary mass tag, as a data object for storing relevant info, and using the CalculateMassesForIsotopicProfile() method. var mt = new PeptideTarget { ChargeState = (short)result.IsotopicProfile.ChargeState, MonoIsotopicMass = result.IsotopicProfile.MonoIsotopicMass }; mt.MZ = (mt.MonoIsotopicMass / mt.ChargeState) + Globals.PROTON_MASS; //TODO: use Josh's isotopicDistribution calculator after confirming averagine formula mt.EmpiricalFormula = _tomIsotopicPatternGenerator.GetClosestAvnFormula(result.IsotopicProfile.MonoIsotopicMass, false); mt.IsotopicProfile = _tomIsotopicPatternGenerator.GetIsotopePattern(mt.EmpiricalFormula, _tomIsotopicPatternGenerator.aafIsos); TheorIsotopicProfile = mt.IsotopicProfile; mt.CalculateMassesForIsotopicProfile(mt.ChargeState); var theorXYData = mt.IsotopicProfile.GetTheoreticalIsotopicProfileXYData(result.IsotopicProfile.GetFWHM()); offsetDistribution(theorXYData, mt.IsotopicProfile, result.IsotopicProfile); // Obsolete Class-wide variable: MercuryDistributionCreator distributionCreator; // //double resolution = result.IsotopicProfile.GetMZofMostAbundantPeak() / result.IsotopicProfile.GetFWHM(); //distributionCreator.CreateDistribution(result.IsotopicProfile.MonoIsotopicMass, result.IsotopicProfile.ChargeState, resolution); //distributionCreator.OffsetDistribution(result.IsotopicProfile); //XYData theorXYData = distributionCreator.Data; var areaFitter = new AreaFitter(); var fitVal = areaFitter.GetFit(theorXYData, result.Run.XYData, 0.1, out _); if (double.IsNaN(fitVal) || fitVal > 1) { result.IsotopicProfile.Score = 1; } else { result.IsotopicProfile.Score = fitVal; } } }
public override TargetCollection Import() { var targetCollection = new TargetCollection(); targetCollection.TargetList.Clear(); GetMassTagDataFromDB(targetCollection, MassTagsToBeRetrieved); GetModDataFromDB(targetCollection, MassTagsToBeRetrieved); var peptideUtils = new PeptideUtils(); var troubleSomePeptides = new List <TargetBase>(); foreach (var targetBase in targetCollection.TargetList) { var peptide = (PeptideTarget)targetBase; var baseEmpiricalFormula = peptideUtils.GetEmpiricalFormulaForPeptideSequence(peptide.Code); if (peptide.ContainsMods) { var peptide1 = peptide; var mods = (from n in _massTagModData where n.Item1 == peptide1.ID select n); foreach (var tuple in mods) { var modString = tuple.Item4; try { baseEmpiricalFormula = EmpiricalFormulaUtilities.AddFormula(baseEmpiricalFormula, modString); } catch { Console.WriteLine("Failed to calculate empirical formula for the Target " + peptide.ID + "; Having trouble with the mod: " + modString + "; This Target was NOT imported!!"); troubleSomePeptides.Add(peptide); } } } try { peptide.EmpiricalFormula = baseEmpiricalFormula; } catch { Console.WriteLine("Failed to calculate empirical formula for the Target " + peptide.ID + "; Cannot parse this formula: " + peptide.EmpiricalFormula + "; This Target was NOT imported!!"); troubleSomePeptides.Add(peptide); } } var cleanTargetList = new List <TargetBase>(); //filter out the bad peptides (the once with errors during empirical formula parsing) foreach (var peptide in targetCollection.TargetList) { if (!troubleSomePeptides.Contains(peptide)) { cleanTargetList.Add(peptide); } } targetCollection.TargetList = cleanTargetList; if (ChargeStateRangeBasedOnDatabase) { targetCollection.ApplyChargeStateFilter(ChargeStateFilterThreshold); } else { var chargeStateTargets = new List <TargetBase>(); foreach (var targetBase in targetCollection.TargetList) { var minCharge = 1; var maxCharge = 100; for (var charge = minCharge; charge <= maxCharge; charge++) { var mz = targetBase.MonoIsotopicMass / charge + Globals.PROTON_MASS; if (mz < MaxMZForChargeStateRange) { if (mz < MinMZForChargeStateRange) { break; } TargetBase chargeStateTarget = new PeptideTarget((PeptideTarget)targetBase); chargeStateTarget.ChargeState = (short)charge; chargeStateTarget.MZ = chargeStateTarget.MonoIsotopicMass / charge + Globals.PROTON_MASS; chargeStateTarget.ObsCount = -1; chargeStateTargets.Add(chargeStateTarget); } } } targetCollection.TargetList = chargeStateTargets.OrderBy(p => p.ID).ThenBy(p => p.ChargeState).ToList(); } return(targetCollection); }
public void CalculateLabelingDistributionTest2() { //mass_tag_id monoisotopic_mass NET obs mod_count mod_description pmt peptide peptideex //355176429 1538.8166126 0.42422 1 0 2.00000 LFLASACLYGAALAGV R.LFLASACLYGAALAGV.C //------------------------load theor data ------------------------------------ var peptideUtils = new PeptideUtils(); var peptide = new PeptideTarget(); peptide.Code = "LFLASACLYGAALAGV"; peptide.EmpiricalFormula = new PeptideUtils().GetEmpiricalFormulaForPeptideSequence(peptide.Code); var theorFeatureGenerator = new JoshTheorFeatureGenerator(); theorFeatureGenerator.GenerateTheorFeature(peptide); var theorProfile = peptide.IsotopicProfile; var theorIntensities = theorProfile.Peaklist.Select(p => (double)p.Height).ToList(); Console.WriteLine("Total carbons = " + peptideUtils.GetNumAtomsForElement("C", peptide.EmpiricalFormula)); var obsIntensities = new List <double>(new[] { 1, 0.8335001, 0.4029815, 0.1846439, 0.1116047, 0.09458135, 0.07157851, 0.04972008, 0.03036686, 0.01545749, 0.008299164, 0.004003931, 0.001711554, 0.000766305, 0.000484514 }); var relexCorrectedIntensities = new List <double>(new[] { 1, 0.84416, 0.4174013, 0.1843375, 0.1073706, 0.09557419, 0.07190877, 0.04823519, 0.02991197, 0.01456759, 0.008299164, 0.004003931, 0.001711554, 0.000766305, 0.000484514 }); /* * * Data for observed profile: * LCMSFeature 8517 from Yellow_C13_070_23Mar10_Griffin_10-01-28 * * * peak mz relIntens width sn * 0 770.418569278349 1 0.008119391 285.256 * 1 770.919748892834 0.8335001 0.008161238 884.9909 * 2 771.421020812818 0.4029815 0.008248929 566.6187 * 3 771.922575912402 0.1846439 0.008058954 703.6938 * 4 772.424544684666 0.1116047 0.007997629 358.0133 * 5 772.926348484216 0.09458135 0.008128829 677.3434 * 6 773.428080290323 0.07157851 0.008151106 100 * 7 773.929769365137 0.04972008 0.008104968 100 * 8 774.431542463583 0.03036686 0.007982519 100 * 9 774.933237566856 0.01545749 0.008024476 100 * 10 775.434950373045 0.008299164 0.008166174 740.9502 * 11 775.936532837365 0.004003931 0.007899459 100 * 12 776.438361528879 0.001711554 0.00877683 44.79652 * 13 776.940072709136 0.0007663054 0.007601836 17.12788 * 14 777.441663634739 0.0004845143 0.007320933 100 * */ var labelDistCalc = new LabelingDistributionCalculator(); double[] solvedXVals; double[] solvedYvals; var d = 0.1; labelDistCalc.CalculateLabelingDistribution(theorIntensities, obsIntensities, d, d, out solvedXVals, out solvedYvals); var xydata = new XYData(); xydata.Xvalues = solvedXVals; xydata.Yvalues = solvedYvals; Console.WriteLine(); Console.WriteLine("threshold= " + d); xydata.Display(); labelDistCalc.CalculateLabelingDistribution(theorIntensities, relexCorrectedIntensities, d, d, out solvedXVals, out solvedYvals); xydata.Xvalues = solvedXVals; xydata.Yvalues = solvedYvals; Console.WriteLine(); Console.WriteLine("Relex-corrected isotopic profile= " + d); xydata.Display(); double fractionUnlabelled, fractionLabelled, averageLabelsIncorporated; labelDistCalc.OutputLabelingInfo(solvedYvals.ToList(), out fractionUnlabelled, out fractionLabelled, out averageLabelsIncorporated); Console.WriteLine(); Console.WriteLine("fractionUnlabelled= " + fractionUnlabelled); Console.WriteLine("fractionLabelled= " + fractionLabelled); Console.WriteLine("averageAmountLabelIncorp= " + averageLabelsIncorporated); //for (double d = 0; d < 2.1; d+=0.1) //{ // labelDistCalc.CalculateLabelingDistribution(theorIntensities, obsIntensities, d, d, out solvedXVals, out solvedYvals); // XYData xydata = new XYData(); // xydata.Xvalues = solvedXVals; // xydata.Yvalues = solvedYvals; // Console.WriteLine(); // Console.WriteLine("threshold= " + d); // xydata.Display(); //} }
public TargetCollection Import(List <int> TargetIDsToFilterOn) { var filterOnTargetIDs = TargetIDsToFilterOn != null && TargetIDsToFilterOn.Count > 0; var data = new TargetCollection(); using (var reader = new StreamReader(m_filename)) { var headerLine = reader.ReadLine(); //first line is the header line. _headers = processLine(headerLine); var lineCounter = 1; while (reader.Peek() != -1) { var line = reader.ReadLine(); lineCounter++; var lineData = processLine(line); PeptideTarget massTag; try { massTag = convertTextToMassTag(lineData); if (filterOnTargetIDs) { if (!TargetIDsToFilterOn.Contains(massTag.ID)) { continue; } } } catch (Exception ex) { var msg = "Importer failed. Error reading line: " + lineCounter.ToString() + "\nDetails: " + ex.Message; throw new Exception(msg); } if (!massTag.ContainsMods && String.IsNullOrEmpty(massTag.EmpiricalFormula)) { massTag.EmpiricalFormula = massTag.GetEmpiricalFormulaFromTargetCode(); } var massTagMassInfoMissing = (Math.Abs(massTag.MonoIsotopicMass - 0) < double.Epsilon); var chargeStateInfoIsAvailable = massTag.ChargeState != 0; if (massTagMassInfoMissing) { if (!String.IsNullOrEmpty(massTag.EmpiricalFormula)) { massTag.MonoIsotopicMass = EmpiricalFormulaUtilities.GetMonoisotopicMassFromEmpiricalFormula( massTag.EmpiricalFormula); if (chargeStateInfoIsAvailable) { massTag.MZ = massTag.MonoIsotopicMass / massTag.ChargeState + Globals.PROTON_MASS; } } } if (!chargeStateInfoIsAvailable) { double minMZToConsider = 400; double maxMZToConsider = 1500; var targetList = new List <PeptideTarget>(); for (var chargeState = 1; chargeState < 100; chargeState++) { var calcMZ = massTag.MonoIsotopicMass / chargeState + Globals.PROTON_MASS; if (calcMZ > minMZToConsider && calcMZ < maxMZToConsider) { var copiedMassTag = new PeptideTarget(massTag); //we need to create multiple mass tags copiedMassTag.ChargeState = (short)chargeState; copiedMassTag.MZ = calcMZ; targetList.Add(copiedMassTag); } } data.TargetList.AddRange(targetList.Take(3)); } else { data.TargetList.Add(massTag); } } } foreach (PeptideTarget peptideTarget in data.TargetList) { //bool noNormalizedElutionTimeInfoAvailable = Math.Abs(peptideTarget.NormalizedElutionTime - -1) < Single.Epsilon; //if (noNormalizedElutionTimeInfoAvailable) //{ // peptideTarget.NormalizedElutionTime = 0.5f; //} } return(data); }
private void GetMassTagDataFromDB(TargetCollection data, IReadOnlyCollection <long> massTagsToBeRetrievedList) { var fact = DbProviderFactories.GetFactory("System.Data.SqlClient"); var currentListPos = 0; using (var cnn = fact.CreateConnection()) { if (cnn == null) { throw new Exception("Factory.CreateConnection returned a null DbConnection object in GetMassTagDataFromDB"); } cnn.ConnectionString = buildConnectionString(); cnn.Open(); var progressCounter = 0; while (currentListPos < massTagsToBeRetrievedList.Count) { var nextGroupOfMassTagIDs = massTagsToBeRetrievedList.Skip(currentListPos).Take(ChunkSize).ToList();// GetRange(currentIndex, 5000); currentListPos += (ChunkSize - 1); var queryString = createQueryString(ImporterMode, nextGroupOfMassTagIDs); //Console.WriteLine(queryString); using (var command = cnn.CreateCommand()) { command.CommandText = queryString; command.CommandTimeout = 120; var reader = command.ExecuteReader(); while (reader.Read()) { var massTag = new PeptideTarget(); progressCounter++; if (!reader["Mass_Tag_ID"].Equals(DBNull.Value)) { massTag.ID = Convert.ToInt32(reader["Mass_Tag_ID"]); } if (!reader["Monoisotopic_Mass"].Equals(DBNull.Value)) { massTag.MonoIsotopicMass = Convert.ToDouble(reader["Monoisotopic_Mass"]); } if (!reader["Peptide"].Equals(DBNull.Value)) { massTag.Code = Convert.ToString(reader["Peptide"]); } if (!reader["Charge_State"].Equals(DBNull.Value)) { massTag.ChargeState = Convert.ToInt16(reader["Charge_State"]); } if (!reader["Mod_Count"].Equals(DBNull.Value)) { massTag.ModCount = Convert.ToInt16(reader["Mod_Count"]); } if (!reader["Mod_Description"].Equals(DBNull.Value)) { massTag.ModDescription = Convert.ToString(reader["Mod_Description"]); } if (!reader["ObsCount"].Equals(DBNull.Value)) { massTag.ObsCount = Convert.ToInt32(reader["ObsCount"]); } if (massTag.ChargeState != 0) { massTag.MZ = massTag.MonoIsotopicMass / massTag.ChargeState + Globals.PROTON_MASS; } if (!reader["Avg_GANET"].Equals(DBNull.Value)) { massTag.NormalizedElutionTime = Convert.ToSingle(reader["Avg_GANET"]); } if (!reader["Ref_ID"].Equals(DBNull.Value)) { massTag.RefID = Convert.ToInt32(reader["Ref_ID"]); } if (!reader["Reference"].Equals(DBNull.Value)) { massTag.GeneReference = Convert.ToString(reader["Reference"]); } if (!reader["Description"].Equals(DBNull.Value)) { massTag.ProteinDescription = Convert.ToString(reader["Description"]); } data.TargetList.Add(massTag); if (progressCounter % 100 == 0) { Console.WriteLine(progressCounter + " records loaded; " + reader[0]); } } reader.Close(); } } } }
public override void Deconvolute(ResultCollection resultList) { float[] xvals = new float[1]; float[] yvals = new float[1]; resultList.Run.XYData.GetXYValuesAsSingles(ref xvals, ref yvals); int sizeOfRapidArray = 10000; int[] chargeResults = new int[sizeOfRapidArray]; double[] intensityResults = new double[sizeOfRapidArray]; double[] mzResults = new double[sizeOfRapidArray]; double[] scoreResults = new double[sizeOfRapidArray]; double[] avgmassResults = new double[sizeOfRapidArray]; double[] massResults = new double[sizeOfRapidArray]; double[] mostAbundantMassResults = new double[sizeOfRapidArray]; if (resultList.Run.PeakList == null || resultList.Run.PeakList.Count == 0) { return; } rapidPeakList = ConvertPeakListToRapidPeakList(resultList.Run.PeakList); if (rapidPeakList == null || rapidPeakList.Length == 0) { return; } double rapidsBackgroundIntensityParameter = (resultList.Run.CurrentBackgroundIntensity * minPeptideToBackgroundRatio); Transformer.PerformTransform_cluster(Convert.ToSingle(rapidsBackgroundIntensityParameter), ref xvals, ref yvals, ref rapidPeakList, ref chargeResults, ref intensityResults, ref mzResults, ref scoreResults, ref avgmassResults, ref massResults, ref mostAbundantMassResults); GenerateResults(resultList, ref chargeResults, ref intensityResults, ref mzResults, ref scoreResults, ref avgmassResults, ref massResults, ref mostAbundantMassResults, this.resultCombiningMode); if (this.IsNewFitCalculationPerformed) { //HACK: RAPID doesn't return the peaks of the isotopic profile. And it's score is meaningless. So will iterate over //the results and 1) get the peaks of the isotopic profile and 2) get a least-squares fit of the isotopic profile. foreach (IsosResult result in resultList.IsosResultBin) { //create a temporary mass tag, as a data object for storing relevent info, and using the CalculateMassesForIsotopicProfile() method. PeptideTarget mt = new PeptideTarget(); mt.ChargeState = (short)result.IsotopicProfile.ChargeState; mt.MonoIsotopicMass = result.IsotopicProfile.MonoIsotopicMass; mt.MZ = (mt.MonoIsotopicMass / mt.ChargeState) + Globals.PROTON_MASS; mt.EmpiricalFormula = _TomIsotopicPatternCreator.GetClosestAvnFormula(result.IsotopicProfile.MonoIsotopicMass, false); mt.IsotopicProfile = _TomIsotopicPatternCreator.GetIsotopePattern(mt.EmpiricalFormula, _TomIsotopicPatternCreator.aafIsos); mt.CalculateMassesForIsotopicProfile(mt.ChargeState); double toleranceInPPM = calcToleranceInPPMFromIsotopicProfile(result.IsotopicProfile); //this finds the isotopic profile based on the theor. isotopic profile. BasicTFF bff = new BasicTFF(toleranceInPPM, false); IsotopicProfile iso = bff.FindMSFeature(resultList.Run.PeakList, mt.IsotopicProfile); if (iso != null && iso.Peaklist != null && iso.Peaklist.Count > 1) { //start at the second peak... and add the newly found peaks for (int i = 1; i < iso.Peaklist.Count; i++) { result.IsotopicProfile.Peaklist.Add(iso.Peaklist[i]); } //now that we have the peaks, we can get info for MonoPlusTwoAbundance result.IsotopicProfile.MonoPlusTwoAbundance = result.IsotopicProfile.GetMonoPlusTwoAbundance(); } XYData theorXYData = mt.IsotopicProfile.GetTheoreticalIsotopicProfileXYData(result.IsotopicProfile.GetFWHM()); //offset the theor isotopic profile offsetDistribution(theorXYData, mt.IsotopicProfile, result.IsotopicProfile); AreaFitter areafitter = new AreaFitter(); int ionCountUsed; double fitval = areafitter.GetFit(theorXYData, result.Run.XYData, 0.1, out ionCountUsed); if (fitval == double.NaN || fitval > 1) { fitval = 1; } result.IsotopicProfile.Score = fitval; } } }
public void GetUnsummedIntensitiesAndDetectSaturation(Run run, IEnumerable <IsosResult> resultList) { Check.Require(run != null, "SaturationDetector failed. Run is null"); if (run == null) { return; } if (_msGenerator == null) { _msGenerator = MSGeneratorFactory.CreateMSGenerator(run.MSFileType); } if (run is UIMFRun uimfRun) { if (uimfRun.CurrentScanSet == null) { throw new NullReferenceException("CurrentScanSet is null. You need to set it."); } if (uimfRun.CurrentIMSScanSet == null) { throw new NullReferenceException("CurrentIMSScanSet is null. You need to set it."); } //this creates a FrameSet containing only the primary frame. Therefore no summing will occur var lcScanSet = new ScanSet(uimfRun.CurrentScanSet.PrimaryScanNumber); //this creates a ScanSet containing only the primary scan. Therefore no summing will occur var imsScanSet = new IMSScanSet(uimfRun.CurrentIMSScanSet.PrimaryScanNumber); //get the mass spectrum +/- 5 da from the range of the isotopicProfile uimfRun.CurrentScanSet = lcScanSet; uimfRun.CurrentIMSScanSet = imsScanSet; _msGenerator.Execute(run.ResultCollection); } else { if (run.CurrentScanSet == null) { throw new NullReferenceException("CurrentScanSet is null. You need to set it."); } //this creates a ScanSet containing only the primary scan. Therefore no summing will occur var scanSet = new ScanSet(run.CurrentScanSet.PrimaryScanNumber); run.CurrentScanSet = scanSet; _msGenerator.Execute(run.ResultCollection); } foreach (var result in resultList) { var indexOfObsMostAbundant = result.IsotopicProfile.GetIndexOfMostIntensePeak(); var mzOfMostAbundant = result.IsotopicProfile.Peaklist[indexOfObsMostAbundant].XValue; var indexOfUnsummedMostAbundantMZ = run.XYData.GetClosestXVal(mzOfMostAbundant); if (indexOfUnsummedMostAbundantMZ >= 0) { result.IsotopicProfile.OriginalIntensity = run.XYData.Yvalues[indexOfUnsummedMostAbundantMZ]; result.IsotopicProfile.IsSaturated = (result.IsotopicProfile.OriginalIntensity >= SaturationThreshold); if (result.IsotopicProfile.IsSaturated) { //problem is that with these saturated profiles, they are often truncated because another //isotopic profile was falsely assigned to the back end of it. So we need to find more peaks that should //belong to the saturated profile. var theorTarget = new PeptideTarget { ChargeState = (short)result.IsotopicProfile.ChargeState, MonoIsotopicMass = result.IsotopicProfile.MonoIsotopicMass }; theorTarget.MZ = (theorTarget.MonoIsotopicMass / theorTarget.ChargeState) + Globals.PROTON_MASS; var averagineFormula = _tomIsotopicPatternGenerator.GetClosestAvnFormula(result.IsotopicProfile.MonoIsotopicMass, false); theorTarget.IsotopicProfile = _tomIsotopicPatternGenerator.GetIsotopePattern(averagineFormula, _tomIsotopicPatternGenerator.aafIsos); theorTarget.EmpiricalFormula = averagineFormula; theorTarget.CalculateMassesForIsotopicProfile(result.IsotopicProfile.ChargeState); AssignMissingPeaksToSaturatedProfile(run.PeakList, result.IsotopicProfile, theorTarget.IsotopicProfile); //goal is to find the index of the isotopic profile peaks of a peak that is not saturated var indexOfGoodUnsaturatedPeak = -1; for (var i = indexOfObsMostAbundant + 1; i < result.IsotopicProfile.Peaklist.Count; i++) { var indexUnsummedData = run.XYData.GetClosestXVal(result.IsotopicProfile.Peaklist[i].XValue); var unsummedIntensity = run.XYData.Yvalues[indexUnsummedData]; if (unsummedIntensity < _minRelIntTheorProfile * SaturationThreshold) { indexOfGoodUnsaturatedPeak = i; break; } } AdjustSaturatedIsotopicProfile(result.IsotopicProfile, theorTarget.IsotopicProfile, indexOfGoodUnsaturatedPeak); } } //double summedIntensity = 0; //foreach (MSPeak peak in result.IsotopicProfile.Peaklist) //{ // int indexOfMZ = result.Run.XYData.GetClosestXVal(peak.XValue); // if (indexOfMZ >= 0) // { // summedIntensity += result.Run.XYData.Yvalues[indexOfMZ]; // } //} //result.IsotopicProfile.OriginalTotalIsotopicAbundance = summedIntensity; } }