/// <summary> /// 根据给定的中性丢失类型候选者,以及给定的组合数,得到该组合数的所有组合方式 /// </summary> /// <param name="nlTypes"></param> /// <param name="numberOfCombination"></param> /// <returns></returns> public List <INeutralLossType> GetCombinationValues(IEnumerable <INeutralLossType> nlTypes, int numberOfCombination) { List <INeutralLossType> result = new List <INeutralLossType>(); if (nlTypes.Count() >= numberOfCombination) { if (numberOfCombination == 1) { return(nlTypes.Distinct().ToList()); } var subTypes = nlTypes.Skip(1); INeutralLossType firstType = nlTypes.First(); List <INeutralLossType> subs = GetCombinationValues(subTypes, numberOfCombination - 1); foreach (INeutralLossType aType in subs) { CombinedNeutralLossType curType = new CombinedNeutralLossType(aType); if (curType.InsertNeutralLossType(firstType)) { AddToDistinctList(result, curType); } } List <INeutralLossType> combinedSubTypes = GetCombinationValues(subTypes, numberOfCombination); foreach (INeutralLossType aType in combinedSubTypes) { AddToDistinctList(result, aType); } } return(result); }
public void TestGetPrecursorNeutralLossPeaks() { List<INeutralLossType> nls = new INeutralLossType[] { NeutralLossConstants.NL_H3PO4 }.ToList(); MatchedPeak precursor = new MatchedPeak(1000, 0, 2); List<MatchedPeak> pkls = matcher.GetNeutralLossPeaks(IonType.PRECURSOR_NEUTRAL_LOSS_PHOSPHO, precursor, nls, (m => m.IsPhosphoNeutralLossType())); Assert.AreEqual("[MH2-H3PO4]", pkls[0].DisplayName); Assert.AreEqual(1000 - NeutralLossConstants.NL_H3PO4.Mass / 2, pkls[0].Mz, 0.01); precursor.Charge = 1; pkls = matcher.GetNeutralLossPeaks(IonType.PRECURSOR_NEUTRAL_LOSS_PHOSPHO, precursor, nls, (m => m.IsPhosphoNeutralLossType())); Assert.AreEqual("[MH-H3PO4]", pkls[0].DisplayName); Assert.AreEqual(1000 - NeutralLossConstants.NL_H3PO4.Mass, pkls[0].Mz, 0.01); }
public void TestGetPrecursorNeutralLossPeaks() { List <INeutralLossType> nls = new INeutralLossType[] { NeutralLossConstants.NL_H3PO4 }.ToList(); MatchedPeak precursor = new MatchedPeak(1000, 0, 2); List <MatchedPeak> pkls = matcher.GetNeutralLossPeaks(IonType.PRECURSOR_NEUTRAL_LOSS_PHOSPHO, precursor, nls, (m => m.IsPhosphoNeutralLossType())); Assert.AreEqual("[MH2-H3PO4]", pkls[0].DisplayName); Assert.AreEqual(1000 - NeutralLossConstants.NL_H3PO4.Mass / 2, pkls[0].Mz, 0.01); precursor.Charge = 1; pkls = matcher.GetNeutralLossPeaks(IonType.PRECURSOR_NEUTRAL_LOSS_PHOSPHO, precursor, nls, (m => m.IsPhosphoNeutralLossType())); Assert.AreEqual("[MH-H3PO4]", pkls[0].DisplayName); Assert.AreEqual(1000 - NeutralLossConstants.NL_H3PO4.Mass, pkls[0].Mz, 0.01); }
/// <summary> /// 添加到列表中,如果质量一样就保留组合类型最少的那个 /// </summary> /// <param name="nlTypes">中性丢失类型列表</param> /// <param name="aType">添加的类型</param> public void AddToDistinctList(List <INeutralLossType> nlTypes, INeutralLossType aType) { INeutralLossType findType = nlTypes.Find(t => Math.Abs(t.Mass - aType.Mass) < 0.0001); if (null != findType) { if (findType.Count > aType.Count) { nlTypes.Remove(findType); nlTypes.Add(aType); } } else { nlTypes.Add(aType); } }
public bool InsertNeutralLossType(INeutralLossType aType) { if (!aType.CanMultipleLoss) { foreach (INeutralLossType oldType in combinedTypes) { if (oldType.Equals(aType)) { return(false); } } } combinedTypes.Insert(0, aType); Initialize(); return(true); }
public static bool IsPhosphoNeutralLossType(this INeutralLossType aType) { return(aType.Name.Contains("PO")); }
public CombinedNeutralLossType(INeutralLossType aType) : this(new[] { aType }) { }
public static string GetBYIonDisplayName(INeutralLossType nlType, MatchedPeak sourcePeak, MatchedPeak targetPeak) { return(MyConvert.Format("[{0}{1}-{2}]", sourcePeak.PeakType.GetDisplayName(), sourcePeak.PeakIndex, nlType.Name)); }
public static string GetPrecursorDisplayName(INeutralLossType nlType, MatchedPeak sourcePeak, MatchedPeak targetPeak) { return(MyConvert.Format("[MH{0}-{1}]", targetPeak.Charge == 1 ? "" : targetPeak.Charge.ToString(), nlType.Name)); }