public void RecalcMassDeviations(IPeakList peakList, int scanNumber, SilacType type, double isotopeCorrelationThreshold) { foreach (MascotPeptide mp in peptides.Values) { mp.RecalcMassDeviation(fixedMods, peakList, scanNumber, type, isotopeCorrelationThreshold); } }
public static Modification[] GetModifiedVersions(char aa, SilacType type, SilacLabel[] labels1, SilacLabel[] labels2) { AminoAcid a = AminoAcid.FromLetter(aa); switch (type) { case SilacType.Singlets: return(new Modification[1]); case SilacType.Doublets: Modification[] result = new Modification[2]; if (a.HasFittingLabel(labels1)) { SilacLabel sl = a.GetFittingLabel(labels1); result[1] = Tables.modifications[AminoAcid.GetMascotModificationStringForLabel(sl)]; } return(result); case SilacType.Triplets: result = new Modification[3]; if (a.HasFittingLabel(labels1)) { SilacLabel sl = a.GetFittingLabel(labels1); result[1] = Tables.modifications[AminoAcid.GetMascotModificationStringForLabel(sl)]; } if (a.HasFittingLabel(labels2)) { SilacLabel sl = a.GetFittingLabel(labels2); result[2] = Tables.modifications[AminoAcid.GetMascotModificationStringForLabel(sl)]; } return(result); } throw new Exception("Never get here."); }
private static double GetUncalibratedSilacMass(SilacCluster sc, SilacType type, IsotopeCluster[] isotopeClusters, double[] centerMz, float[] intensities) { return (GetUncalibratedFullIsotopePatternMassEstimate(sc.GetIsotopeClusterIndices(type), sc.GetIsotopePatternStarts(type), sc.GetMassDiffs(type), isotopeClusters, centerMz, intensities)); }
public double GetIntensitySum(SilacType type, int index) { if (index >= 0) { switch (index) { case 0: return(intensity0); case 1: return(intensity1); case 2: return(intensity2); default: throw new Exception("Impossible."); } } switch (type) { case SilacType.Singlets: return(intensity0); case SilacType.Doublets: return(intensity0 + intensity1); case SilacType.Triplets: return(intensity0 + intensity1 + intensity2); default: throw new Exception("Impossible."); } }
public int GetSilacIndex(char[] aas, SilacType type, SilacLabel[] labels1, SilacLabel[] labels2) { foreach (char aa in aas) { int ind = GetSilacIndex(aa, type, labels1, labels2); if (ind != -1) { return(ind); } } return(-1); }
public string GetSilacStatestring(SilacType type1) { if (type1 != SilacType.Singlets && silacIndex != -1) { if (type1 == SilacType.Doublets) { return(silacIndex == 0 ? "Light" : "Heavy"); } return(silacIndex == 0 ? "Light" : (silacIndex == 1 ? "Medium" : "Heavy")); } return(null); }
public int[] GetIsotopeClusterIndices(SilacType type) { if (type == SilacType.Triplets) { return(new int[] { isotopeClusterIndex1, isotopeClusterIndex2, isotopeClusterIndex3 }); } if (type == SilacType.Doublets) { return(new int[] { isotopeClusterIndex1, isotopeClusterIndex2 }); } return(new int[] { isotopeClusterIndex1 }); }
public double[] GetMassDiffs(SilacType type) { if (type == SilacType.Triplets) { return(new double[] { 0, massDiff1, massDiff2 }); } if (type == SilacType.Doublets) { return(new double[] { 0, massDiff1 }); } return(new double[] { 0 }); }
public int[] GetIsotopePatternStarts(SilacType type) { if (type == SilacType.Triplets) { return(new int[] { isotopePatternStart1, isotopePatternStart2, isotopePatternStart3 }); } if (type == SilacType.Doublets) { return(new int[] { isotopePatternStart1, isotopePatternStart2 }); } return(new int[] { isotopePatternStart1 }); }
public int[] GetOffsets(SilacType type) { if (type == SilacType.Triplets) { return(new int[] { offset10, offset20, offset21 }); } if (type == SilacType.Doublets) { return(new int[] { offset10 }); } return(new int[] {}); }
private static double GetCalibratedSilacMassStat(SilacCluster sc, double[,] mzCalibrationPar, double[,] intensityCalibrationPar, SilacType type, IsotopeCluster[] isotopeCluster, IPeakList peakList, float[] intensities) { int dummy; return (GetFullIsotopePatternMassEstimateNoBootstrapStat(sc.GetIsotopeClusterIndices(type), sc.GetIsotopePatternStarts(type), sc.GetMassDiffs(type), mzCalibrationPar, intensityCalibrationPar, true, out dummy, isotopeCluster, peakList, intensities)); }
public static AminoAcid[] CalcAllAas(SilacType type, SilacLabel[] labels1, SilacLabel[] labels2) { switch (type) { case SilacType.Singlets: return(new AminoAcid[0]); case SilacType.Doublets: return(T08ReQuantification.CalcAllAas(labels1)); case SilacType.Triplets: return(T08ReQuantification.CalcAllAas(labels1, labels2)); } throw new Exception("Never get here."); }
public IsotopeMsmsEvidence(int isotopeId, int fileIndex, IsotopeCluster isotopeCluster, double intensity, double calibRT, ReQuantitationResult reQuantitationResult, SilacType type, bool reQuantify) : base( fileIndex, (isotopeCluster != null) ? (float)isotopeCluster.ElutionTime : float.NaN, (float)calibRT, (isotopeCluster != null) ? isotopeCluster.Charge : 0) { this.isotopeId = isotopeId; this.intensity = (float)intensity; if (reQuantify && reQuantitationResult.ContainsIsotopeIndex(isotopeId, type)) { if (type == SilacType.Doublets) { ratio10 = (float)reQuantitationResult.GetDoubletRatio(isotopeId); normalizedRatio10 = (float)reQuantitationResult.GetDoubletNormalizedRatio(isotopeId); ratioSignificanceA10 = (float)Math.Log(reQuantitationResult.GetDoubletRatioSignificanceA(isotopeId)); ratioSignificanceB10 = (float)Math.Log(reQuantitationResult.GetDoubletRatioSignificanceB(isotopeId)); double[] ii = reQuantitationResult.GetDoubletIntensities(isotopeId); intensity0 = (float)ii[0]; intensity1 = (float)ii[1]; } if (type == SilacType.Triplets) { double[] r = reQuantitationResult.GetTripletRatio(isotopeId); ratio10 = (float)r[0]; ratio20 = (float)r[1]; ratio21 = (float)r[2]; double[] rn = reQuantitationResult.GetTripletNormalizedRatio(isotopeId); normalizedRatio10 = (float)rn[0]; normalizedRatio20 = (float)rn[1]; normalizedRatio21 = (float)rn[2]; double[] rsa = reQuantitationResult.GetTripletRatioSignificanceA(isotopeId); ratioSignificanceA10 = (float)Math.Log(rsa[0]); ratioSignificanceA20 = (float)Math.Log(rsa[1]); ratioSignificanceA21 = (float)Math.Log(rsa[2]); double[] rsb = reQuantitationResult.GetTripletRatioSignificanceB(isotopeId); ratioSignificanceB10 = (float)Math.Log(rsb[0]); ratioSignificanceB20 = (float)Math.Log(rsb[1]); ratioSignificanceB21 = (float)Math.Log(rsb[2]); double[] ii = reQuantitationResult.GetTripletIntensities(isotopeId); intensity0 = (float)ii[0]; intensity1 = (float)ii[1]; intensity2 = (float)ii[2]; } } }
public bool ContainsIsotopeIndex(int id, SilacType type) { if (doubletRatioInfo == null) { Read(); } switch (type) { case SilacType.Doublets: return(doubletRatioInfo.ContainsKey(id)); case SilacType.Triplets: return(tripletRatioInfo.ContainsKey(id)); default: throw new Exception("Impossible."); } }
public static int[][] FindChargePairs(int nsilac, SilacType silacType, double matchPpm, double silacTimeCorrelationThreshold, SilacCluster[] silacClusters, IsotopeCluster[] isotopeClusters, IPeakList peakList, float[] intensities, double[] centerMz) { double[] m = new double[nsilac]; for (int i = 0; i < m.Length; i++) { SilacCluster si = silacClusters[i]; m[i] = GetUncalibratedSilacMass(si, silacType, isotopeClusters, centerMz, intensities); } int[] o = ArrayUtil.Order(m); m = ArrayUtil.SubArray(m, o); List <int[]> pairs = new List <int[]>(); for (int i = 0; i < m.Length; i++) { SilacCluster si = silacClusters[o[i]]; int chargei = isotopeClusters[si.IsotopeClusterindex1].Charge; double m1 = m[i]; int ind1 = ArrayUtil.CeilIndex(m, m1 - matchPpm * 1e-6 * m1); for (int j = ind1; j < i; j++) { SilacCluster sj = silacClusters[o[j]]; int chargej = isotopeClusters[sj.IsotopeClusterindex1].Charge; if (chargei == chargej) { continue; } int mini; double[] pi = CalcSilacClusterProfile(si, out mini, silacType, isotopeClusters, peakList, intensities); int minj; double[] pj = CalcSilacClusterProfile(sj, out minj, silacType, isotopeClusters, peakList, intensities); if (T03SilacAssembly.Correlate(pi, mini, pj, minj) > silacTimeCorrelationThreshold) { pairs.Add(new int[] { o[i], o[j] }); } } } return(pairs.ToArray()); }
public static void GetPrecursorInfo(out int charge, out double mz, out double mass, IPeakList peakList, int scanNumber, SilacType type, double isotopeCorrelationThreshold, double simpleMz) { charge = 0; mass = 0; int[] silacInfo = peakList.GetSilacInfoForMsmsScanNumber(scanNumber); if (silacInfo != null) { int silacId = silacInfo[0]; int silacIndex = silacInfo[1]; charge = peakList.GetSilacCharge(silacId); mass = peakList.GetSilacMass(silacId, silacIndex, type); mz = mass / charge + MolUtil.MassProton; } else { int isotopeIndex = peakList.GetIsotopeIndexForMsmsScanNumber(scanNumber); IsotopeCluster ic = null; if (isotopeIndex != -1) { ic = peakList.GetIsotopeCluster(isotopeIndex); } if (isotopeIndex != -1 && ic.IsotopeCorrelation >= isotopeCorrelationThreshold) { charge = ic.Charge; mass = peakList.GetMassEstimate(new int[] { isotopeIndex }, new int[] { ic.IsotopePatternStart }, new double[] { 0 }, false); mz = mass / charge + MolUtil.MassProton; } else { int peakIndex = peakList.GetPeakIndexForMsmsScanNumber(scanNumber); mz = peakIndex >= 0 ? peakList.GetMz(peakIndex) : simpleMz; } } }
private static int CalcSilacIndex(char aa, PeptideModificationState labelMods, string sequence, SilacType type, SilacLabel[] labels1, SilacLabel[] labels2) { for (int i = 0; i < sequence.Length; i++) { if (sequence[i] != aa) { continue; } ushort m = labelMods.GetModificationAt(i); if (type == SilacType.Doublets) { if (m != ushort.MaxValue) { return(1); } return(0); } if (type == SilacType.Triplets) { int ind1 = -1; for (int j = 0; j < labels1.Length; j++) { if (AminoAcid.GetAminoAcidFromLabel(labels1[j]).Letter == aa) { ind1 = j; } } int ind2 = -1; for (int j = 0; j < labels2.Length; j++) { if (AminoAcid.GetAminoAcidFromLabel(labels2[j]).Letter == aa) { ind2 = j; } } if (ind1 == -1 && ind2 == -1) { return(-1); } if (ind1 == -1) { if (m != ushort.MaxValue) { return(2); } return(-1); } if (ind2 == -1) { if (m != ushort.MaxValue) { return(1); } return(-1); } SilacLabel l1 = labels1[ind1]; SilacLabel l2 = labels2[ind2]; if (l1 == l2) { if (m == ushort.MaxValue) { return(0); } return(-1); } if (m == ushort.MaxValue) { return(0); } if (Tables.modifications[AminoAcid.GetMascotModificationStringForLabel(l1)].Index == m) { return(1); } if (Tables.modifications[AminoAcid.GetMascotModificationStringForLabel(l2)].Index == m) { return(2); } throw new Exception("Never get here."); } throw new Exception("Should never happen."); } return(-1); }
public static void ParseMsm(string msmName, string[] silacMsmNames, string isoMsmName, string peakMsmName, string polyMsmName, IPeakList peakList, out int silacCount, out int isoCount, out int peakCount, out int polyCount, SilacType silacType, double isotopeCorrelationThreshold) { HashSet <int> scanNumbers = new HashSet <int>(); StreamReader reader = new StreamReader(msmName); StreamWriter[] silacWriters = new StreamWriter[silacMsmNames.GetLength(0)]; for (int i = 0; i < silacWriters.GetLength(0); i++) { silacWriters[i] = new StreamWriter(silacMsmNames[i]); } StreamWriter isoWriter = new StreamWriter(isoMsmName); StreamWriter peakWriter = new StreamWriter(peakMsmName); StreamWriter polyWriter = new StreamWriter(polyMsmName); string line; List <string> buffer = new List <string>(); string title = null; string mass = null; silacCount = 0; isoCount = 0; peakCount = 0; polyCount = 0; while ((line = reader.ReadLine()) != null) { if (line.IndexOf("BEGIN IONS") != -1) { buffer = new List <string>(); } else if (line.IndexOf("PEPMASS") != -1) { mass = line; } else if (line.IndexOf("CHARGE") != -1) { } else if (line.IndexOf("TITLE") != -1) { title = line; } else if (line.IndexOf("END IONS") != -1) { ProcessMsm(buffer.ToArray(), title, mass, scanNumbers, silacWriters, isoWriter, peakWriter, polyWriter, peakList, isotopeCorrelationThreshold, silacType, ref silacCount, ref isoCount, ref peakCount, ref polyCount); } else { if (line.Length > 0) { buffer.Add(line); } } } reader.Close(); for (int i = 0; i < silacWriters.GetLength(0); i++) { silacWriters[i].Close(); } isoWriter.Close(); peakWriter.Close(); polyWriter.Close(); }
public MsmsHit(MascotPeptide[] peptides, int scanNumber, int fileIndex, MascotQueryType type, int silacIndex, double elutionTime, double mz, double monoisotopicMz, ushort[] fixedMods, HashSet <string> labelModificationSet, SilacType silacType, SilacLabel[] labels1, SilacLabel[] labels2) { rawFileIndex = fileIndex; this.scanNumber = scanNumber; this.silacIndex = silacIndex; this.type = type; pep = peptides[0].Pep; score = peptides[0].MascotScore; altScore = peptides[0].AltScore; charge = (int)Math.Round(peptides[0].Mass / mz); massErrorPpm = peptides[0].MassErrorPpm; if (peptides.Length > 1) { deltaScoreAll = peptides[0].MascotScore - peptides[1].MascotScore; } else { deltaScoreAll = peptides[0].MascotScore; } int ind = -1; for (int i = 1; i < peptides.Length; i++) { if (!peptides[i].Sequence.Equals(peptides[0].Sequence)) { ind = i; break; } } if (ind != -1) { deltaScoreDifferentPep = peptides[0].MascotScore - peptides[ind].MascotScore; } else { deltaScoreDifferentPep = peptides[0].MascotScore; } labelModifications = peptides[0].Modifications.GetLabelModifications(fixedMods, peptides[0].Sequence, labelModificationSet); trueModifications = peptides[0].Modifications.GetTrueModifications(labelModificationSet); this.elutionTime = elutionTime; this.mz = mz; this.monoisotopicMz = monoisotopicMz; if (silacType == SilacType.Singlets) { this.silacIndex = 0; } else if (type != MascotQueryType.Silac) { AminoAcid[] allAas = T07SearchEngineEnhancement.CalcAllAas(silacType, labels1, labels2); char[] allAaLetts = AminoAcid.GetSingleLetters(allAas); for (int i = 0; i < allAaLetts.Length; i++) { this.silacIndex = CalcSilacIndex(allAaLetts[i], labelModifications, peptides[0].Sequence, silacType, labels1, labels2); if (this.silacIndex != -1) { break; } } } }
public static double[] CalcSilacClusterProfile(SilacCluster cl, out int minIndex, SilacType type, IsotopeCluster[] isotopeClusters, IPeakList peakList, float[] intensities) { int[] m = cl.GetIsotopeClusterIndices(type); int n = m.Length; if (n == 1) { return(T03SilacAssembly.CalcIsotopeClusterProfile(isotopeClusters[m[0]], out minIndex, peakList)); } double[][] profiles = new double[n][]; int[] mins = new int[n]; int[] ends = new int[n]; double[] intens = new double[n]; for (int i = 0; i < n; i++) { if (m[i] == -1) { continue; } IsotopeCluster ic = isotopeClusters[m[i]]; profiles[i] = T03SilacAssembly.CalcIsotopeClusterProfile(ic, out mins[i], peakList); intens[i] = T03SilacAssembly.GetIsotopeClusterIntensity(ic, intensities); ends[i] = mins[i] + profiles[i].Length; } minIndex = ArrayUtil.Min(mins); int maxEnd = ArrayUtil.Max(ends); int len = maxEnd - minIndex; double[] result = new double[len]; double norm = 0; for (int i = 0; i < n; i++) { if (m[i] == -1) { continue; } norm += intens[i]; for (int j = 0; j < profiles[i].Length; j++) { result[j + mins[i] - minIndex] += profiles[i][j] * intens[i]; } } for (int i = 0; i < len; i++) { result[i] /= norm; } return(result); }
public static void CalcRatioSignificanceProteinGroups(SilacType type, ICombinedData combinedData, RawFileInfo fileInfo) { if (type == SilacType.Doublets) { { List <double> lNormRatio = new List <double>(); List <double> lRatio = new List <double>(); List <double> lIntensity = new List <double>(); List <int> indices = new List <int>(); for (int i = 0; i < combinedData.GetProteinGroupCount(); i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i); double ratio; double normalizedRatio; int count; double dev; int nOutliers; double pval; group.GetRatio10(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers, out pval); double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData); if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0) { lNormRatio.Add(Math.Log(normalizedRatio)); lRatio.Add(Math.Log(ratio)); lIntensity.Add(Math.Log(intensity)); indices.Add(i); } } double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lNormRatio.ToArray(), lIntensity.ToArray(), 1); double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lNormRatio.ToArray(), lIntensity.ToArray(), -1); for (int i = 0; i < indices.Count; i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]); group.RatioSignificanceA10 = ratioSignificanceA[i]; group.RatioSignificanceB10 = ratioSignificanceB[i]; } } if (fileInfo.HasExperiment) { string[] exps = fileInfo.GetAllExperimentValues(); foreach (string exp in exps) { List <double> lratio = new List <double>(); List <double> lIntensity = new List <double>(); List <int> indices = new List <int>(); for (int i = 0; i < combinedData.GetProteinGroupCount(); i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i); double ratio; double normalizedRatio; int count; double dev; int nOutliers; double pval; group.GetRatio10(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers, fileInfo.GetRawFileIndicesFromExperiment(exp), out pval); double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData); if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0) { lratio.Add(Math.Log(normalizedRatio)); lIntensity.Add(Math.Log(intensity)); indices.Add(i); } } double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1); double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1); for (int i = 0; i < indices.Count; i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]); group.AddRatioSignificanceA10(exp, ratioSignificanceA[i]); group.AddRatioSignificanceB10(exp, ratioSignificanceB[i]); } } } } if (type == SilacType.Triplets) { { List <double> lratio = new List <double>(); List <double> lIntensity = new List <double>(); List <int> indices = new List <int>(); for (int i = 0; i < combinedData.GetProteinGroupCount(); i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i); double ratio; double normalizedRatio; int count; double dev; int nOutliers; double pval; group.GetRatio10(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers, out pval); double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData) + group.GetIntensity2(combinedData); if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0) { lratio.Add(Math.Log(normalizedRatio)); lIntensity.Add(Math.Log(intensity)); indices.Add(i); } } double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1); double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1); for (int i = 0; i < indices.Count; i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]); group.RatioSignificanceA10 = ratioSignificanceA[i]; group.RatioSignificanceB10 = ratioSignificanceB[i]; } } if (fileInfo.HasExperiment) { string[] exps = fileInfo.GetAllExperimentValues(); foreach (string exp in exps) { List <double> lratio = new List <double>(); List <double> lIntensity = new List <double>(); List <int> indices = new List <int>(); for (int i = 0; i < combinedData.GetProteinGroupCount(); i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i); double ratio; double normalizedRatio; int count; double dev; int nOutliers; double pval; group.GetRatio10(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers, fileInfo.GetRawFileIndicesFromExperiment(exp), out pval); double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData) + group.GetIntensity2(combinedData); if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0) { lratio.Add(Math.Log(normalizedRatio)); lIntensity.Add(Math.Log(intensity)); indices.Add(i); } } double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1); double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1); for (int i = 0; i < indices.Count; i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]); group.AddRatioSignificanceA10(exp, ratioSignificanceA[i]); group.AddRatioSignificanceB10(exp, ratioSignificanceB[i]); } } } { List <double> lratio = new List <double>(); List <double> lIntensity = new List <double>(); List <int> indices = new List <int>(); for (int i = 0; i < combinedData.GetProteinGroupCount(); i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i); double ratio; double normalizedRatio; int count; double dev; int nOutliers; double pval; group.GetRatio20(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers, out pval); double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData) + group.GetIntensity2(combinedData); if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0) { lratio.Add(Math.Log(normalizedRatio)); lIntensity.Add(Math.Log(intensity)); indices.Add(i); } } double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1); double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1); for (int i = 0; i < indices.Count; i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]); group.RatioSignificanceA20 = ratioSignificanceA[i]; group.RatioSignificanceB20 = ratioSignificanceB[i]; } } if (fileInfo.HasExperiment) { string[] exps = fileInfo.GetAllExperimentValues(); foreach (string exp in exps) { List <double> lratio = new List <double>(); List <double> lIntensity = new List <double>(); List <int> indices = new List <int>(); for (int i = 0; i < combinedData.GetProteinGroupCount(); i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i); double ratio; double normalizedRatio; int count; double dev; int nOutliers; double pval; group.GetRatio20(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers, fileInfo.GetRawFileIndicesFromExperiment(exp), out pval); double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData) + group.GetIntensity2(combinedData); if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0) { lratio.Add(Math.Log(normalizedRatio)); lIntensity.Add(Math.Log(intensity)); indices.Add(i); } } double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1); double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1); for (int i = 0; i < indices.Count; i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]); group.AddRatioSignificanceA20(exp, ratioSignificanceA[i]); group.AddRatioSignificanceB20(exp, ratioSignificanceB[i]); } } } { List <double> lratio = new List <double>(); List <double> lIntensity = new List <double>(); List <int> indices = new List <int>(); for (int i = 0; i < combinedData.GetProteinGroupCount(); i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i); double ratio; double normalizedRatio; int count; double dev; int nOutliers; double pval; group.GetRatio21(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers, out pval); double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData) + group.GetIntensity2(combinedData); if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0) { lratio.Add(Math.Log(normalizedRatio)); lIntensity.Add(Math.Log(intensity)); indices.Add(i); } } double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1); double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1); for (int i = 0; i < indices.Count; i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]); group.RatioSignificanceA21 = ratioSignificanceA[i]; group.RatioSignificanceB21 = ratioSignificanceB[i]; } } if (fileInfo.HasExperiment) { string[] exps = fileInfo.GetAllExperimentValues(); foreach (string exp in exps) { List <double> lratio = new List <double>(); List <double> lIntensity = new List <double>(); List <int> indices = new List <int>(); for (int i = 0; i < combinedData.GetProteinGroupCount(); i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(i); double ratio; double normalizedRatio; int count; double dev; int nOutliers; double pval; group.GetRatio21(combinedData, out ratio, out normalizedRatio, out count, out dev, out nOutliers, fileInfo.GetRawFileIndicesFromExperiment(exp), out pval); double intensity = group.GetIntensity0(combinedData) + group.GetIntensity1(combinedData) + group.GetIntensity2(combinedData); if (normalizedRatio > 0 && !double.IsInfinity(normalizedRatio) && !double.IsNaN(normalizedRatio) && intensity > 0) { lratio.Add(Math.Log(normalizedRatio)); lIntensity.Add(Math.Log(intensity)); indices.Add(i); } } double[] ratioSignificanceA = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), 1); double[] ratioSignificanceB = NumUtil.MovingBoxPlot(lratio.ToArray(), lIntensity.ToArray(), -1); for (int i = 0; i < indices.Count; i++) { IIdentifiedProteinGroup group = combinedData.GetIProteinGroupAt(indices[i]); group.AddRatioSignificanceA21(exp, ratioSignificanceA[i]); group.AddRatioSignificanceB21(exp, ratioSignificanceB[i]); } } } } }
private static void ProcessMsm(string[] lines, string title, string origMass, HashSet <int> scanNumbers, StreamWriter[] silacWriters, TextWriter isoWriter, TextWriter peakWriter, TextWriter polyWriter, IPeakList peakList, double isotopeCorrelationThreshold, SilacType type, ref int silacCount, ref int isoCount, ref int peakCount, ref int polyCount) { int scanNumber = ExtractScanNumber(title); if (scanNumbers.Contains(scanNumber)) { return; } int[] silacInfo = peakList.GetSilacInfoForMsmsScanNumber(scanNumber); if (silacInfo != null) { scanNumbers.Add(scanNumber); int silacId = silacInfo[0]; int silacIndex = silacInfo[1]; int ch = peakList.GetSilacCharge(silacId); double mass = peakList.GetSilacMass(silacId, silacIndex, type); double mz = mass / ch + MolUtil.MassProton; silacWriters[silacIndex].WriteLine("BEGIN IONS"); silacWriters[silacIndex].WriteLine("PEPMASS=" + mz); silacWriters[silacIndex].WriteLine("CHARGE=" + ch + "+"); silacWriters[silacIndex].WriteLine(title + " _sil_"); for (int i = 0; i < lines.Length; i++) { silacWriters[silacIndex].WriteLine(lines[i]); } silacWriters[silacIndex].WriteLine("END IONS"); silacWriters[silacIndex].WriteLine(); silacCount++; return; } int isotopeIndex = peakList.GetIsotopeIndexForMsmsScanNumber(scanNumber); IsotopeCluster ic = null; if (isotopeIndex != -1) { ic = peakList.GetIsotopeCluster(isotopeIndex); } if (isotopeIndex != -1 && ic.IsotopeCorrelation >= isotopeCorrelationThreshold && ic.PolymerIndex == -1) { scanNumbers.Add(scanNumber); int ch = ic.Charge; double mass = peakList.GetMassEstimate(new int[] { isotopeIndex }, new int[] { ic.IsotopePatternStart }, new double[] { 0 }, false); double mz = mass / ch + MolUtil.MassProton; isoWriter.WriteLine("BEGIN IONS"); isoWriter.WriteLine("PEPMASS=" + mz); isoWriter.WriteLine("CHARGE=" + ch + "+"); isoWriter.WriteLine(title + " _iso_"); for (int i = 0; i < lines.Length; i++) { isoWriter.WriteLine(lines[i]); } isoWriter.WriteLine("END IONS"); isoWriter.WriteLine(); isoCount++; return; } if (isotopeIndex != -1 && ic.PolymerIndex != -1) { scanNumbers.Add(scanNumber); int ch = ic.Charge; double mass = peakList.GetMassEstimate(new int[] { isotopeIndex }, new int[] { ic.IsotopePatternStart }, new double[] { 0 }, false); double mz = mass / ch + MolUtil.MassProton; polyWriter.WriteLine("BEGIN IONS"); polyWriter.WriteLine("PEPMASS=" + mz); polyWriter.WriteLine("CHARGE=" + ch + "+"); polyWriter.WriteLine(title + " _iso_"); for (int i = 0; i < lines.Length; i++) { polyWriter.WriteLine(lines[i]); } polyWriter.WriteLine("END IONS"); polyWriter.WriteLine(); polyCount++; return; } scanNumbers.Add(scanNumber); peakWriter.WriteLine("BEGIN IONS"); peakWriter.WriteLine(origMass); peakWriter.WriteLine("CHARGE=2+ and 3+"); peakWriter.WriteLine(title + " _nix_"); for (int i = 0; i < lines.Length; i++) { peakWriter.WriteLine(lines[i]); } peakWriter.WriteLine("END IONS"); peakWriter.WriteLine(); peakCount++; }
public void RecalcMassDeviation(ushort[] mods, IPeakList peakList, int scanNumber, SilacType type, double isotopeCorrelationThreshold) { Modification[] fixedMods = ArrayUtil.SubArray(Tables.modificationList, mods); double m = CalcMonoisotopicMass(sequence, modifications, fixedMods); int charge; double mz; double mass1; T06MsmsPreparation.GetPrecursorInfo(out charge, out mz, out mass1, peakList, scanNumber, type, isotopeCorrelationThreshold, double.NaN); if (!double.IsNaN(mass1) && mass1 > 0) { float x = (float)(mass1 - m); if (!float.IsNaN(x) && Math.Abs(x / m) < 1e-5) { deltaMass = x; } } }
public static void RecalibrateImpl(SilacType silacType, int nranges, int[] iranges, int[][] chargePairs, SilacCluster[] silacClusters, ref double[,] mzCalibrationParams, ref double[,] intensityCalibrationParams, double massErrorNormalization, IsotopeCluster[] isotopeCluster, IPeakList peakList, float[] intensities) { double[] x = new double[chargePairs.Length]; double[] y = new double[chargePairs.Length]; double[] sig = new double[chargePairs.Length]; for (int i = 0; i < chargePairs.Length; i++) { x[i] = i; int ind1 = chargePairs[i][0]; int ind2 = chargePairs[i][1]; SilacCluster sc1 = silacClusters[ind1]; SilacCluster sc2 = silacClusters[ind2]; sig[i] = Math.Sqrt(sc1.GetMassError(massErrorNormalization) * sc1.GetMassError(massErrorNormalization) + sc2.GetMassError(massErrorNormalization) * sc2.GetMassError(massErrorNormalization)); } intensityCalibrationParams = new double[nranges, nparamsIntensityFit]; double[,] icp = intensityCalibrationParams; Funcs2 f = delegate(double x1, double[] aa) { int ind = (int)Math.Round(x1); int ind1 = chargePairs[ind][0]; int ind2 = chargePairs[ind][1]; double[,] mzAa = new double[nranges, nparamsMzFit]; int c = 0; for (int j = 0; j < iranges.Length; j++) { for (int i = 0; i < nparamsMzFit; i++) { mzAa[iranges[j], i] = aa[c++]; } } double y1 = GetCalibratedSilacMassStat(silacClusters[ind1], mzAa, icp, silacType, isotopeCluster, peakList, intensities); double y2 = GetCalibratedSilacMassStat(silacClusters[ind2], mzAa, icp, silacType, isotopeCluster, peakList, intensities); double yy = y1 - y2; return(yy); }; double chisq; double[] a = new double[nparamsMzFit * iranges.Length]; int county = 0; for (int j = 0; j < iranges.Length; j++) { for (int i = 0; i < nparamsMzFit; i++) { a[county++] = startValsMzFit[i]; } } NumUtil.FitNonlin(x, y, sig, a, out chisq, f); mzCalibrationParams = new double[nranges, nparamsMzFit]; int s = 0; for (int j = 0; j < iranges.Length; j++) { for (int i = 0; i < nparamsMzFit; i++) { mzCalibrationParams[iranges[j], i] = a[s++]; } } double[,] mcp = mzCalibrationParams; f = delegate(double x1, double[] aa) { int ind = (int)Math.Round(x1); int ind1 = chargePairs[ind][0]; int ind2 = chargePairs[ind][1]; double[,] intensityAa = new double[nranges, nparamsIntensityFit]; int c = 0; for (int j = 0; j < iranges.Length; j++) { for (int i = 0; i < nparamsIntensityFit; i++) { intensityAa[iranges[j], i] = aa[c++]; } } double y1 = GetCalibratedSilacMassStat(silacClusters[ind1], mcp, intensityAa, silacType, isotopeCluster, peakList, intensities); double y2 = GetCalibratedSilacMassStat(silacClusters[ind2], mcp, intensityAa, silacType, isotopeCluster, peakList, intensities); double yy = y1 - y2; return(yy); }; a = new double[nparamsIntensityFit * iranges.Length]; NumUtil.FitNonlin(x, y, sig, a, out chisq, f); s = 0; for (int j = 0; j < iranges.Length; j++) { for (int i = 0; i < nparamsIntensityFit; i++) { intensityCalibrationParams[iranges[j], i] = a[s++]; } } icp = intensityCalibrationParams; f = delegate(double x1, double[] aa) { int ind = (int)Math.Round(x1); int ind1 = chargePairs[ind][0]; int ind2 = chargePairs[ind][1]; double[,] mzAa = new double[nranges, nparamsMzFit]; int c = 0; for (int j = 0; j < iranges.Length; j++) { for (int i = 0; i < nparamsMzFit; i++) { mzAa[iranges[j], i] = aa[c++]; } } double y1 = GetCalibratedSilacMassStat(silacClusters[ind1], mzAa, icp, silacType, isotopeCluster, peakList, intensities); double y2 = GetCalibratedSilacMassStat(silacClusters[ind2], mzAa, icp, silacType, isotopeCluster, peakList, intensities); double yy = y1 - y2; return(yy); }; a = new double[nparamsMzFit * iranges.Length]; county = 0; for (int j = 0; j < iranges.Length; j++) { for (int i = 0; i < nparamsMzFit; i++) { a[county++] = mzCalibrationParams[iranges[j], i]; } } NumUtil.FitNonlin(x, y, sig, a, out chisq, f); s = 0; for (int j = 0; j < iranges.Length; j++) { for (int i = 0; i < nparamsMzFit; i++) { mzCalibrationParams[iranges[j], i] = a[s++]; } } }
public static int[] ExtractMsm(string filename, IPeakList peakList, IRawFile rawFile, string msmName, string msmNameBinary, string msmNameIndex, int topx, double isotopeCorrelationThreshold, SilacType type, out long[] pointers) { StreamWriter sw = new StreamWriter(msmName); BinaryWriter writer = FileUtil.GetBinaryWriter(msmNameBinary); List <long> filePointers = new List <long>(); List <int> fileScanNumbers = new List <int>(); long filePos = 0; for (int i = 0; i < rawFile.MS2Count; i++) { Spectrum s = rawFile.GetMS2Spectrum(i); int scanNumber = rawFile.GetScanNumberFromMs2Index(i); double simpleMz = rawFile.GetMS2MonoisotopicMz(i); if (double.IsNaN(simpleMz) || simpleMz < 1) { simpleMz = peakList.GetMs2Mz(i); if (double.IsNaN(simpleMz) || simpleMz < 1) { simpleMz = 1; } } int charge; double mz; double mass; GetPrecursorInfo(out charge, out mz, out mass, peakList, scanNumber, type, isotopeCorrelationThreshold, simpleMz); if (rawFile.GetMS2SignalType(i) != SignalType.Centroid) { double[] specMasses; float[] specIntensities; T01PeakDetection.DetectPeaks(s, false, 3, CentroidPosition.gaussian, out specMasses, out specIntensities); s = new Spectrum(specMasses, specIntensities); } if (topx > 0) { s = s.TopX(topx, 100); } int sn = rawFile.GetScanNumberFromMs2Index(i); if (s.Count == 0) { continue; } StringBuilder sb = new StringBuilder(); writer.Write(s.Count); for (int j = 0; j < s.Count; j++) { sb.AppendFormat("{0:F3}\t{1:F2}\n", s.GetMass(j), s.GetIntensity(j)); writer.Write(s.GetMass(j)); writer.Write(1.0 * s.GetIntensity(j)); } filePointers.Add(filePos); fileScanNumbers.Add(sn); filePos += 16 * s.Count + 4; sw.WriteLine("BEGIN IONS"); sw.WriteLine("PEPMASS={0:F6}", mz); if (charge > 0) { sw.WriteLine("CHARGE={0}+", charge); } else { sw.WriteLine("CHARGE=2+ and 3+"); } sw.WriteLine("TITLE=RawFile: {0} FinneganScanNumber: {1}", filename, sn); sw.Write(sb.ToString()); sw.WriteLine("END IONS"); sw.WriteLine(); } writer.Close(); sw.Close(); pointers = filePointers.ToArray(); return(fileScanNumbers.ToArray()); }
public void ProcessPeptides(int fileIndex, Dictionary <string, int> proteinIdToGroupIndex, IPeakList peakList, MsmsData msmsData, IIdentifiedPeptide[] identifiedPeptides, string[] peptideSequences, ReQuantitationResult reQuantitationResult, bool reQuantify, HashSet <string> labelModificationSet, IProteinSet proteinSet, SilacType silacType, SilacLabel[] labels1, SilacLabel[] labels2, double ms2Tol, string ms2TolUnit, int topx, string[] fixedMods) { if (peptides == null) { Read(); } double[] monoIsoMz = peakList.MS2MonoisotopicMz; for (int i = 0; i < peptides.Length; i++) { MascotPeptide[] p = peptides[i]; int scanNumber = scanNumbers[i]; int ms2ind = peakList.GetMs2IndexFromScanNumber(scanNumber); double mz = peakList.GetMs2Mz(ms2ind); double monotopicMz = monoIsoMz[ms2ind]; double time = peakList.GetMs2Rt(ms2ind); int silacId = -1; int isotopeId = -1; int silacIndex = -1; SilacCluster silacCluster = null; IsotopeCluster isotopeCluster = null; if (type == MascotQueryType.Silac) { int[] silacInfo = peakList.GetSilacInfoForMsmsScanNumber(scanNumber); silacId = silacInfo[0]; silacIndex = silacInfo[1]; silacCluster = peakList.GetSilacCluster(silacId); } else if (type == MascotQueryType.Isotope) { isotopeId = peakList.GetIsotopeIndexForMsmsScanNumber(scanNumber); isotopeCluster = peakList.GetIsotopeCluster(isotopeId); } int index = Array.BinarySearch(peptideSequences, p[0].Sequence); if (index < 0) { continue; } HashSet <int> tmpGroupInds = new HashSet <int>(); foreach (int pi in p[0].ProteinIndex) { string protId = proteinSet.GetName(pi); if (!proteinIdToGroupIndex.ContainsKey(protId)) { continue; } int groupInd = proteinIdToGroupIndex[protId]; if (!tmpGroupInds.Contains(groupInd)) { tmpGroupInds.Add(groupInd); } } double[] specMasses; float[] specIntensities; bool uniqueProtein = (p[0].ProteinIndex.Length == 1); bool uniqueGroup = (tmpGroupInds.Count == 1); msmsData.GetSpectrumFromScanNumber(scanNumber, out specMasses, out specIntensities); identifiedPeptides[index].AddMascotPeptideHit(p, scanNumber, fileIndex, type, silacId, silacIndex, isotopeId, silacCluster, isotopeCluster, time, peakList, mz, monotopicMz, fixedModifications[i], specMasses, specIntensities, reQuantitationResult, reQuantify, labelModificationSet, silacType, labels1, labels2, ms2Tol, ms2TolUnit, topx, fixedMods); identifiedPeptides[index].UniqueProtein = uniqueProtein; identifiedPeptides[index].UniqueGroup = uniqueGroup; } }
private int GetSilacIndex(char aa, SilacType type, SilacLabel[] labels1, SilacLabel[] labels2) { if (type == SilacType.Singlets) { return(0); } int index = -1; string seq = sequence; for (int i = 0; i < seq.Length; i++) { if (seq[i] == aa) { index = i; break; } } if (index == -1) { return(-1); } Modification[] mods = T07SearchEngineEnhancement.GetModifiedVersions(aa, type, labels1, labels2); ushort mod = modifications.GetModificationAt(index); if (mod == ushort.MaxValue) { for (int i = 1; i < mods.Length; i++) { if (mods[i] == null) { return(-1); } } return(0); } if (type == SilacType.Doublets) { if (mods[1] == null) { return(-1); } if (mods[1].Index == mod) { return(1); } return(-1); } if (mods[1] == mods[2]) { return(-1); } if (mods[1] != null && mods[1].Index == mod) { return(1); } if (mods[2] != null && mods[2].Index == mod) { return(2); } return(-1); }