protected void AppendScan(List <IsobaricItem> result, int scan, string mode, double isolationWidth) { IsobaricItem item = new IsobaricItem(); PeakList <Peak> pkl = RawReader.GetPeakList(scan, MinMz, MaxMz); if (pkl.Count < MinPeakCount) { return; } var recordScan = GetIdentificationScan(scan); if (pkl.ScanTimes.Count == 0) { pkl.ScanTimes.Add(RawReader.GetScanTime(recordScan)); } item.ScanMode = mode; item.RawPeaks = pkl; item.PeakInIsolationWindow = RawReader.GetPeakInIsolationWindow(scan, isolationWidth); item.PlexType = this.PlexType; result.Add(item); }
public override void SetProperty(T t, string value) { var item = t.FindIsobaricItem(); if (string.IsNullOrEmpty(value)) { if (null != item) { t.RemoveIsobaricItem(); } return; } if (item == null) { item = new IsobaricItem(); if (setPlexType) { item.PlexType = this.plexType; } t.SetIsobaricItem(item); } SetValue(item, value); }
public bool Valid(IsobaricItem item) { if (null != Validator) { return(Validator(item)); } return(true); }
private void AssignItraqItem(IsobaricItem pkl, List <Peak> peaks) { pkl.Scan = pkl.RawPeaks.ScanTimes[0]; pkl.PlexType = Definition.PlexType; for (int i = 0; i < Definition.Items.Length; i++) { pkl[Definition.Items[i].Index] = GetPeakIntensity(peaks[i]); } }
public static void ReadChannels(XmlReader reader, IsobaricItem item) { reader.MoveToElement("Ions"); reader.ReadStartElement("Ions"); foreach (var def in item.Definition.Items) { item[def.Index] = reader.ReadElementAsDouble(def.Name); } }
/// <summary> /// source和当前对象将共享rawpeaks和peakinisolationwindow /// </summary> /// <param name="source"></param> public IsobaricItem(IsobaricItem source) { this.PlexType = source.PlexType; this.ScanMode = source.ScanMode; this.RawPeaks = source.RawPeaks; this.PeakInIsolationWindow = source.PeakInIsolationWindow; this.Valid = source.Valid; this.ValidProbability = source.ValidProbability; this.PrecursorPercentage = source.PrecursorPercentage; }
public IsobaricItemImpl(IsobaricItem parent, IsobaricDefinition definition) { this._parent = parent; this._definition = definition; this._baseIndex = definition.Items.Min(m => m.Index); var totalLength = definition.Items.Max(m => m.Index) - _baseIndex + 1; _ions = new double[totalLength]; }
public static void WriteChannels(XmlWriter xw, IsobaricItem item) { xw.WriteStartElement("Ions"); var refItems = item.Definition.Items; foreach (var refItem in refItems) { xw.WriteElementFormat(refItem.Name, "{0:0.0}", item[refItem.Index]); } xw.WriteEndElement(); }
private void CheckPlexType(IsobaricType plexType, string expectHeader, string expectValue) { var ann = new IdentifiedSpectrum(); var pqr = new IsobaricItem() { PlexType = plexType, Valid = true, ValidProbability = 0.0005 }; var refItems = plexType.GetDefinition().Items; foreach (var item in refItems) { pqr[item.Index] = item.Mass; } ann.SetIsobaricItem(pqr); //从实例构建converter var converter = new ITraqItemPlexConverter <IAnnotation>(); List <IPropertyConverter <IAnnotation> > converters = new List <IPropertyConverter <IAnnotation> >(); converters.Add(converter); converters.AddRange(converter.GetRelativeConverter(new IAnnotation[] { ann }.ToList())); CompositePropertyConverter <IAnnotation> finalConverter = new CompositePropertyConverter <IAnnotation>(converters, ','); if (exportToConsole) { Console.WriteLine(finalConverter.Name); } Assert.AreEqual(expectHeader, finalConverter.Name); var line1 = finalConverter.GetProperty(ann); if (exportToConsole) { Console.WriteLine(line1); } Assert.AreEqual(expectValue, line1); var protein2 = new IdentifiedSpectrum(); //从factory根据header构建converter var finalC = IdentifiedSpectrumPropertyConverterFactory.GetInstance().GetConverters(finalConverter.Name, ','); finalC.SetProperty(protein2, line1); var line2 = finalConverter.GetProperty(protein2); Assert.AreEqual(line1, line2); }
public static IsobaricItem FindOrCreateITsobaricItem(this IAnnotation ann) { if (ann.Annotations.ContainsKey(ITraqConsts.ITRAQ_TYPE)) { return(ann.Annotations[ITraqConsts.ITRAQ_TYPE] as IsobaricItem); } else { var result = new IsobaricItem(); ann.Annotations[ITraqConsts.ITRAQ_TYPE] = result; return(result); } }
public void Correct(IsobaricItem item) { if (item.PlexType != this.PlexType) { throw new ArgumentException(string.Format("Argument item should be {0}. Check your parameters!", this.PlexType)); } var observed = item.ObservedIons(); var x = Correct(observed); for (int i = 0; i < item.Definition.Items.Length; i++) { item[item.Definition.Items[i].Index] = Math.Max(ITraqConsts.NULL_INTENSITY, x[i]); } }
public override IsobaricResult ReadFromFile(string fileName) { XElement root = XElement.Load(fileName); IsobaricResult result = new IsobaricResult(); foreach (var ele in root.Elements("ITraqScan")) { var item = new IsobaricItem(); item.PlexType = EnumUtils.StringToEnum(ele.Element("PlexType").Value, IsobaricType.PLEX4); item.Experimental = ele.Element("Experimental").Value; item.ScanMode = ele.Element("ScanMode").Value; item.Scan = new ScanTime(Convert.ToInt32(ele.Element("Scan").Value), MyConvert.ToDouble(ele.Element("RetentionTime").Value)); item.Scan.IonInjectionTime = MyConvert.ToDouble(ele.Element("IonInjectionTime").Value); var ppEle = ele.Element("PrecursorPercentage"); if (null != ppEle) { item.PrecursorPercentage = MyConvert.ToDouble(ppEle.Value); } if (!Accept(item)) { continue; } var ions = ele.Element("Ions"); var defs = item.Definition.Items; foreach (var def in defs) { item[def.Index] = MyConvert.ToDouble(ions.Element(def.Name).Value); } if (ReadPeaks) { item.RawPeaks = ElementToPeakList(ele, "RawPeaks", false); item.PeakInIsolationWindow = ElementToPeakList(ele, "PeakInIsolationWindow", true); } result.Add(item); } return(result); }
/// <summary> /// 从XmlReader中读取ITraqItem信息。 /// </summary> /// <param name="reader">XmlReader</param> /// <param name="readPeaks">是否读取Peak信息</param> /// <param name="accept">在读取Peak前,对ITraqItem进行筛选</param> /// <param name="untilSucceed">如果筛选失败,是否进行读取下一个ITraqItem</param> /// <returns></returns> public static IsobaricItem Parse(XmlReader reader, bool readPeaks, Predicate <IsobaricItem> accept, bool untilSucceed = false) { IsobaricItem result = null; while (reader.MoveToElement("ITraqScan")) { reader.ReadStartElement(); result = new IsobaricItem(); result.PlexType = EnumUtils.StringToEnum(reader.ReadElementAsString("PlexType"), IsobaricType.PLEX4); result.Experimental = reader.ReadElementAsString("Experimental"); result.ScanMode = reader.ReadElementAsString("ScanMode"); result.Scan = new ScanTime(reader.ReadElementAsInt("Scan"), reader.ReadElementAsDouble("RetentionTime")); result.Scan.IonInjectionTime = reader.ReadElementAsDouble("IonInjectionTime"); result.PrecursorPercentage = reader.ReadElementAsDouble("PrecursorPercentage"); if (null != accept && !accept(result)) { result = null; if (untilSucceed) { continue; } else { break; } } ReadChannels(reader, result); if (readPeaks) { result.RawPeaks = ReadElementPeakList(reader, "RawPeaks", false); result.PeakInIsolationWindow = ReadElementPeakList(reader, "PeakInIsolationWindow", true); } break; } return(result); }
public static void WriteIsobaricItem(XmlTextWriter w, IsobaricItem item) { w.WriteStartElement("ITraqScan"); w.WriteElement("PlexType", item.PlexType.ToString()); w.WriteElement("Experimental", item.Experimental); w.WriteElement("ScanMode", item.ScanMode); w.WriteElement("Scan", item.Scan.Scan); w.WriteElementFormat("RetentionTime", "{0:0.0}", item.Scan.RetentionTime); w.WriteElementFormat("IonInjectionTime", "{0:0.000}", item.Scan.IonInjectionTime); w.WriteElementFormat("PrecursorPercentage", "{0:0.000}", item.PrecursorPercentage); WriteChannels(w, item); WriteElementPeakList(w, item.RawPeaks, "RawPeaks", false); WriteElementPeakList(w, item.PeakInIsolationWindow, "PeakInIsolationWindow", true); w.WriteEndElement(); w.Flush(); }
public bool Valid(IsobaricItem m) { return(m[phospho1] != ITraqConsts.NULL_INTENSITY && m[phospho2] != ITraqConsts.NULL_INTENSITY); }
public virtual string GetRatioValue(IsobaricItem item) { return(MyConvert.Format("{0:0.0000}", 1 - (item[phospho1] + item[phospho2]) / (item[normal1] + item[normal2]))); }
public double GetReference(IsobaricItem item) { return((from f in References select f.GetValue(item)).Average()); }
public static IsobaricItemImpl CreateItem(this IsobaricType plexType, IsobaricItem parent) { return(new IsobaricItemImpl(parent, plexType.GetDefinition())); }
public override List <IsobaricItem> ReadFromFile(string fileName) { var result = new List <IsobaricItem>(); RawReader.Open(fileName); try { int startScan = RawReader.GetFirstSpectrumNumber(); int endScan = RawReader.GetLastSpectrumNumber(); Progress.SetRange(startScan, endScan); for (int scan = startScan; scan <= endScan; scan++) { if (Progress.IsCancellationPending()) { throw new UserTerminatedException(); } Progress.SetPosition(scan); if (2 == RawReader.GetMsLevel(scan)) { string scanMode = RawReader.GetScanMode(scan); if (string.IsNullOrEmpty(scanMode)) { AppendScan(result, scan, "UNKNOWN"); continue; } scanMode = scanMode.ToLower(); if (scanMode.Equals("pqd")) { AppendScan(result, scan, "PQD"); } else if (scanMode.Equals("cid")) { //如果上一个scan是pqd,那么,现在这个cid的结果从该pqd读取。 if (result.Count > 0 && result[result.Count - 1].RawPeaks.ScanTimes[0].Scan == scan - 1 && result[result.Count - 1].RawPeaks.ScanMode == "PQD") { var lastItem = result[result.Count - 1]; var item = new IsobaricItem(lastItem); item.Scan = RawReader.GetScanTime(scan); item.ScanMode = "CID"; result.Add(item); } else//否则,从自己的peaklist中读取。 { AppendScan(result, scan, "CID"); } } else { Console.WriteLine("Scan {0} is skipped with mode {1}", scan, scanMode); } } } } finally { RawReader.Close(); } return(result); }
protected virtual double GetRatio2(IsobaricItem item) { return(ratio2func1(item) / ratio2func2(item)); }
public static void SetIsobaricItem(this IAnnotation ann, IsobaricItem item) { ann.Annotations[ITraqConsts.ITRAQ_TYPE] = item; }
private double GetRsd(IsobaricItem item, int index1, int index2) { var acc = new MeanStandardDeviation(new double[] { item[index1], item[index2] }); return(acc.StdDev / acc.Mean); }
public virtual string GetRatioValue(IsobaricItem item) { return(MyConvert.Format("{0:0.0000}\t{1:0.0000}", GetRatio1(item), GetRatio2(item))); }
public virtual bool Valid(IsobaricItem item) { return(validator(item)); }
protected override double GetRatio2(IsobaricItem item) { return(Math.Log(base.GetRatio2(item))); }
public string GetRatioValue(IsobaricItem item) { return(MyConvert.Format("{0:0.00}", (item[sample1] + item[sample2]) / (item[reference1] + item[reference2]))); }
public double GetValue(IsobaricItem item) { return(item[Index]); }
private double GetReference(IsobaricItem item) { return((from f in refFuncs select f.GetValue(item)).Average()); }
public void Setup() { t1 = new IsobaricItem() { Experimental = "S1", ScanMode = "HCD", PlexType = IsobaricType.PLEX4, PrecursorPercentage = 0.85, Scan = new ScanTime(255, 3.4), RawPeaks = new PeakList <Peak>(new Peak[] { new Peak(114.1, 114.1), new Peak(115.1, 115.1), new Peak(116.1, 116.1), new Peak(117.1, 117.1) }.ToList()), PeakInIsolationWindow = new PeakList <Peak>(new Peak[] { new Peak(214.1, 114.1), new Peak(215.1, 115.1), new Peak(216.1, 116.1), new Peak(217.1, 117.1) }.ToList()) { Precursor = new PrecursorPeak() { MasterScan = 1, Charge = 2, Intensity = 3.0, IsolationMass = 1800.1, IsolationWidth = 2.0, MonoIsotopicMass = 1879.1 } } }; t1[114] = 4.5; t1[115] = 5.5; t1[116] = 6.5; t1[117] = 7.5; t2 = new IsobaricItem() { Experimental = "S2", ScanMode = "ETD", PlexType = IsobaricType.PLEX8, PrecursorPercentage = 0.33, Scan = new ScanTime(355, 4.4), RawPeaks = new PeakList <Peak>(new Peak[] { new Peak(114.1, 1114.1), new Peak(115.1, 1115.1), new Peak(116.1, 1116.1), new Peak(117.1, 1117.1) }.ToList()), PeakInIsolationWindow = new PeakList <Peak>(new Peak[] { new Peak(1214.1, 114.1), new Peak(1215.1, 115.1), new Peak(1216.1, 116.1), new Peak(1217.1, 117.1) }.ToList()) { Precursor = new PrecursorPeak() { MasterScan = 3, Charge = 3, Intensity = 4.0, IsolationMass = 2800.1, IsolationWidth = 3.0, MonoIsotopicMass = 2879.1 } } }; t2[113] = 3.5; t2[114] = 4.5; t2[115] = 5.5; t2[116] = 6.5; t2[117] = 7.5; t2[118] = 8.5; t2[119] = 9.5; t2[121] = 11.5; tr = new IsobaricResult(); tr.Mode = "PQD"; tr.Add(t1); tr.Add(t2); }