public override int GetHashCode() { unchecked { return((Mz.GetHashCode() * 397) ^ RetentionTime.GetHashCode()); } }
/* * Determines if a peptide's retention time is in the past, future, or present * Returns PAST(-1) if the retention window has passed, PRESENT(0) if the * retention window is in the future, FUTURE(1) if the retention window is * active. */ public String retentionTense(Peptide pep) { RetentionTime rt = pep.getRetentionTime(); bool isObserved = !rt.IsPredicted(); double rtStart = rt.getRetentionTimeStart(); double rtEnd = rt.getRetentionTimeEnd(); if (isObserved) { if (pep.isExcluded(currentTime)) { return(CURRENT_OBSERVED); } else { return(PAST_OBSERVED); } } else if (pep.isExcluded(currentTime)) { return(PRESENT); } else if (rtStart > currentTime) { return(FUTURE); } else if (rtEnd < currentTime) { return(PAST); } return(ERROR); }
public static string GetDoubleValueText(RetentionTime retentionTime) { if (retentionTime == null) { return("Null"); } return(retentionTime.Minutes.ToString("F3")); }
public override int GetHashCode() { var hashCode = StringComparer.OrdinalIgnoreCase.GetHashCode(Name); hashCode = (hashCode * 397) ^ RetentionTime.GetHashCode(); hashCode = (hashCode * 397) ^ AggregationTime.GetHashCode(); return(hashCode); }
protected internal override LibraryKeyProto ToLibraryKeyProto() { return(new LibraryKeyProto() { KeyType = LibraryKeyProto.Types.KeyType.PrecursorMz, PrecursorMz = Mz, RetentionTime = RetentionTime.GetValueOrDefault(), }); }
public Peptide(String _sequence, double _mass, bool _fromFasta) { // peptideEvidence = _peptideEvidence; fromFasta = _fromFasta; sequence = _sequence; mass = _mass; retentionTime = new RetentionTime(); parentProteins = new Dictionary <String, Protein>(); scores = new List <Double>(); dCNs = new List <Double>(); }
/* * These are from the experiment and will be removed if you call reset on the * graph */ public Peptide addPeptideFromIdentification(IDs id, double currentTime) { String peptideSequence = id.getPeptideSequence(); double peptideMass = id.getPeptideMass(); HashSet <String> parentProteinAccessions = id.getParentProteinAccessions(); Peptide pep; if (containsPeptide(peptideSequence)) { return(getPeptide(peptideSequence)); } else { // Adds the peptide from the identification into the database pep = new Peptide(peptideSequence, peptideMass, false); // these peptides will be removed if reset() is called SequenceToPeptide.Add(peptideSequence, pep); peptides.Add(pep); if (includeRetentionTime) { // TODO right now this takes the current time as the peak retention time... // should we run it through RTCalc so we can better estimate our RT alignment? // 2019-04-29 No, do not. Observed times are better than predicted // pep.setRetentionTime(RetentionTimeUtil.convertDoubleToRetentionTime(rt, // retentionTimeWindow, // retentionTimeWindow)); RetentionTime rt = new RetentionTime(currentTime + retentionTimeWindow, retentionTimeWindow, retentionTimeWindow, false); pep.setRetentionTime(rt); } } // update its parent proteins foreach (String acc in parentProteinAccessions) { Protein parentProtein = AccesstionToProtein[acc]; if (parentProtein != null) { pep.addProtein(parentProtein); } else if (acc.Contains(GlobalVar.DecoyPrefix)) { log.Info("WARNINGin Decoy parent protein for this peptide was not found!!"); log.Info(acc); } else { log.Warn("WARNINGin Non-decoy parent protein for this peptide was not found!!"); log.Warn(acc); } } return(pep); }
public void observedPeptide(Peptide pep, double time, double rt_window) { // set a new RT RetentionTime newRT = new RetentionTime(time + rt_window, rt_window, rt_window, false); // excludes it for 2*rt_window time pep.setRetentionTime(newRT); //addPeptide(pep); //personally i dont think this line is necessary, since the peptide would have already be added in //MachineLearningGuidedExclusion EvaluateIdentification() //Note that in the last line when re-setting the retention time of the peptide, isPredicted will be set to false }
public override string ToString() { var precursor = Mz.ToString(@"0.000", CultureInfo.CurrentCulture); if (!RetentionTime.HasValue) { return(precursor); } var rt = RetentionTime.GetValueOrDefault().ToString(@"0.00", CultureInfo.CurrentCulture); return(string.Format(@"{0} ({1})", precursor, rt)); }
private string RetentionToString(RetentionTime time) { if (time.Initial) { return("{Initial Time}"); } else { String result = String.Format(CultureInfo.InvariantCulture, "{0:F3} min", time.Minutes); return(result); } }
/// <summary> /// Generates a hash code. /// </summary> /// <returns>Hash code based on stored data.</returns> public override int GetHashCode() { var hashCode = PrecursorMz.GetHashCode() ^ PrecursorChargeState.GetHashCode() ^ Scan.GetHashCode() ^ Id.GetHashCode() ^ GroupId.GetHashCode() ^ TotalIonCurrent.GetHashCode() ^ RetentionTime.GetHashCode(); return(hashCode); }
public override int GetHashCode() { unchecked { var result = base.GetHashCode(); result = (result * 397) ^ ResultsFile.GetHashCode(); result = (result * 397) ^ PrecursorMz.GetHashCode(); result = (result * 397) ^ MatchedPrecursorMz.GetHashCode(); result = (result * 397) ^ RetentionTime.GetHashCode(); result = (result * 397) ^ MzBytes.GetHashCode(); result = (result * 397) ^ IntensityBytes.GetHashCode(); return(result); } }
public override int GetHashCode() { unchecked { var result = base.GetHashCode(); result = (result * 397) ^ ResultsFile.GetHashCode(); result = (result * 397) ^ PrecursorMz.GetHashCode(); result = (result * 397) ^ MatchedPrecursorMz.GetHashCode(); result = (result * 397) ^ (DocumentPeptide == null ? 0 : DocumentPeptide.GetHashCode()); result = (result * 397) ^ DocumentPrecursorCharge.GetHashCode(); result = (result * 397) ^ RetentionTime.GetHashCode(); result = (result * 397) ^ MzBytes.GetHashCode(); result = (result * 397) ^ IntensityBytes.GetHashCode(); return(result); } }
protected void evaluateIdentification(IDs id) { log.Debug("NoExclusion. Scores added, but nothing added to the exclusion list"); // check if the peptide is identified or not if (id == null) { performanceEvaluator.countMS2UnidentifiedAnalyzed(); return; } Peptide pep = getPeptideFromIdentification(id); // if it was going to be null, it already returned // is fragmented // add decoy or non-existent protein connections // database.addProteinFromIdentification(pep, id.getParentProteinAccessions()); Double xCorr = id.getXCorr(); Double dCN = id.getDeltaCN(); pep.addScore(xCorr, 0.0, dCN); performanceEvaluator.evaluateAnalysis(exclusionList, pep); RetentionTime rt = pep.getRetentionTime(); if (!rtCalcPredictedRT.Keys.Contains(pep.getSequence())) { rtCalcPredictedRT.Add(pep.getSequence(), rt.getRetentionTimePeak()); } ObservedPeptideRtTrackerObject observedPep = new ObservedPeptideRtTrackerObject(pep.getSequence(), id.getScanTime(), id.getXCorr(), rt.getRetentionTimePeak(), rt.getRetentionTimeStart() + GlobalVar.retentionTimeWindowSize, RetentionTime.getRetentionTimeOffset(), rtCalcPredictedRT[pep.getSequence()], (rt.IsPredicted() ? 1 : 0)); if ((xCorr > 2.5)) { // calibrates our retention time alignment if the observed time is different // from the predicted only if it passes this threshold calibrateRetentionTime(pep); } observedPep.offset = RetentionTime.getRetentionTimeOffset(); peptideIDRT.Add(observedPep); }
private void OnDevicePreflightEnd(PreflightEventArgs args) { Log.WriteLine(Id, "ProgramTime.Minutes = " + args.RunContext.ProgramTime.Minutes.ToString()); // Check everything foreach (IProgramStep step in args.RunContext.ProgramSteps) { IRampStep rampStep = step as IRampStep; if (rampStep == null) { continue; } m_IsRamped = true; RetentionTime duration = rampStep.Duration; IDoublePropertyValue startValue = rampStep.StartValue as IDoublePropertyValue; IDoublePropertyValue endValue = rampStep.EndValue as IDoublePropertyValue; } }
//actual experiment hooked up to the mass spec public static void RunRealTimeExperiment() { PreExperimentSetUp(); Console.WriteLine("Running real time experiment"); double startTime = getCurrentTime(); GlobalVar.ppmTolerance = 5.0 / 1000000.0; GlobalVar.retentionTimeWindowSize = 1.0; GlobalVar.AccordThreshold = 0.5; Console.WriteLine("Creating exclusion profile"); ExclusionProfile exclusionProfile = new MachineLearningGuidedExclusion(InputFileOrganizer.AccordNet_LogisticRegressionClassifier_WeightAndInterceptSavedFile, database, GlobalVar.ppmTolerance, GlobalVar.retentionTimeWindowSize); String experimentName = GlobalVar.experimentName + String.Format("_MLGE:ppmTol_{0}_rtWin_{1}_prThr_{2}", GlobalVar.ppmTolerance, GlobalVar.retentionTimeWindowSize, GlobalVar.AccordThreshold); Experiment experiment = new Experiment(exclusionProfile, experimentName, 1, ExclusionProfileEnum.MACHINE_LEARNING_GUIDED_EXCLUSION_PROFILE, startTime); new DataReceiver().DoJob(exclusionProfile); double analysisTime = getCurrentTime() - startTime; try { WriteUnusedSpectra(experiment); WriteScanArrivalProcessedTime(DataProcessor.scanArrivalAndProcessedTimeList); WriteScanArrivalProcessedTime(DataProcessor.spectraNotAdded); WriteUsedSpectra(experiment); WriterClass.writeln("ExclusionList size: " + exclusionProfile.getExclusionList().getExclusionList().Count); WriterClass.writeln("Number of exclusion: " + exclusionProfile.getUnusedSpectra().Count); WriterClass.writeln("Final rtoffset: " + RetentionTime.getRetentionTimeOffset()); } catch (Exception e) { Console.WriteLine("Writing exception catched at end of experiment"); } finally { WriterClass.CloseWriter(); } exclusionProfile.reset(); reset(); }
private void OnTransferPreflightToRun(PreflightEventArgs args) { // We use the IProgramStep interface to walk the list of events in the instrument method. // In a real driver we would need to build some kind of time table and send it to the hardware. // In this example we create a list instead and write it to the audit trail. // Note that the property is not updated, as this would be done asynchronously during the run. StringBuilder sb = new StringBuilder("Table of timed events:\n"); foreach (IProgramStep step in args.RunContext.ProgramSteps) { IRampStep rampStep = step as IRampStep; if (rampStep != null) { RetentionTime duration = rampStep.Duration; IDoublePropertyValue startValue = rampStep.StartValue as IDoublePropertyValue; IDoublePropertyValue endValue = rampStep.EndValue as IDoublePropertyValue; sb.Append("Retention "); sb.Append(step.Retention.Minutes.ToString("F3")); sb.Append(": "); sb.Append(startValue.Property.Owner.Name); sb.Append("."); sb.Append(startValue.Property.Name); sb.Append("="); sb.Append(startValue.Value.Value.ToString("F3")); sb.Append(", "); sb.Append(endValue.Property.Owner.Name); sb.Append("."); sb.Append(endValue.Property.Name); sb.Append("="); sb.Append(endValue.Value.Value.ToString("F3")); sb.Append(", Duration="); sb.Append(duration.Minutes.ToString("F3")); sb.Append("\n"); } } m_Device.AuditMessage(AuditLevel.Message, sb.ToString()); }
/* * Computes the difference between the predicted retention time and when we * actually observed this peptide. This difference is then used to calibrate the * retention time using the RetentionTimeCalibrator class by calculating a * retention time offset. This offset will shift all retention time windows by * this value. */ protected void calibrateRetentionTime(Peptide pep) //called when we observe a peptide that passes the xcorr threshold { bool isPredictedRT = pep.getRetentionTime().IsPredicted(); // if isPredictedRT is true, then that means this is the first time you observed it // if false, then you already have observed it and would have already // readjusted the offset, so no need to to it again. // isPredictedRT is false means that you have observed it before, excluded it, but then //it shows up again if (isPredictedRT) { // only calibrate RT prediction if it was a predicted peptide... // peptides which were observed should not affect RT prediction calibration double predictedRT = pep.getRetentionTime().getRetentionTimePeak(); double rtPredictionError = currentTime - predictedRT; double newOffset = RetentionTimeUtil.computeRTOffset(rtPredictionError, currentTime); RetentionTime.setRetentionTimeOffset(newOffset); performanceEvaluator.countPeptideCalibration(); } //changes the status of the peptide from isPredicted = true to false, because now you have observed it exclusionList.observedPeptide(pep, currentTime, database.getRetentionTimeWindow()); }
public override int GetHashCode() { unchecked { int result = base.GetHashCode(); result = (result * 397) ^ (MassError.HasValue ? MassError.Value.GetHashCode() : 0); result = (result * 397) ^ RetentionTime.GetHashCode(); result = (result * 397) ^ StartRetentionTime.GetHashCode(); result = (result * 397) ^ EndRetentionTime.GetHashCode(); result = (result * 397) ^ Area.GetHashCode(); result = (result * 397) ^ BackgroundArea.GetHashCode(); result = (result * 397) ^ Height.GetHashCode(); result = (result * 397) ^ Fwhm.GetHashCode(); result = (result * 397) ^ IsFwhmDegenerate.GetHashCode(); result = (result * 397) ^ Identified.GetHashCode(); result = (result * 397) ^ (IsTruncated.HasValue ? IsTruncated.Value.GetHashCode() : 0); result = (result * 397) ^ Rank; result = (result * 397) ^ Ratios.GetHashCodeDeep(); result = (result * 397) ^ OptimizationStep.GetHashCode(); result = (result * 397) ^ Annotations.GetHashCode(); result = (result * 397) ^ UserSet.GetHashCode(); return(result); } }
/// <summary> /// Serialize to a JSON object /// </summary> public new void SerializeJson(Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } ((fhirCsR4.Models.BackboneElement) this).SerializeJson(writer, options, false); if (IsDerived != null) { writer.WriteBoolean("isDerived", (bool)IsDerived !); } if (Type != null) { writer.WritePropertyName("type"); Type.SerializeJson(writer, options); } if (!string.IsNullOrEmpty(Preference)) { writer.WriteString("preference", (string)Preference !); } if (_Preference != null) { writer.WritePropertyName("_preference"); _Preference.SerializeJson(writer, options); } if (Container != null) { writer.WritePropertyName("container"); Container.SerializeJson(writer, options); } if (!string.IsNullOrEmpty(Requirement)) { writer.WriteString("requirement", (string)Requirement !); } if (_Requirement != null) { writer.WritePropertyName("_requirement"); _Requirement.SerializeJson(writer, options); } if (RetentionTime != null) { writer.WritePropertyName("retentionTime"); RetentionTime.SerializeJson(writer, options); } if ((RejectionCriterion != null) && (RejectionCriterion.Count != 0)) { writer.WritePropertyName("rejectionCriterion"); writer.WriteStartArray(); foreach (CodeableConcept valRejectionCriterion in RejectionCriterion) { valRejectionCriterion.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if ((Handling != null) && (Handling.Count != 0)) { writer.WritePropertyName("handling"); writer.WriteStartArray(); foreach (SpecimenDefinitionTypeTestedHandling valHandling in Handling) { valHandling.SerializeJson(writer, options, true); } writer.WriteEndArray(); } if (includeStartObject) { writer.WriteEndObject(); } }
public void setRetentionTime(RetentionTime _retentionTime) { retentionTime = _retentionTime; }
//Called by DataProcessor, entry point to Alex's program public bool evaluate(Spectra spec) { currentTime = spec.getStartTime(); updateExclusionList(spec); if (spec.getMSLevel() == 1) { log.Debug("Evaluating ms1 scan"); processMS1(spec); } else if (spec.getMSLevel() == 2) { log.Debug("evaluating ms2 scan"); if (spec.getIndex() % GlobalVar.ScansPerOutput == 0) { #if SIMULATION double progressPercent = spec.getIndex() / GlobalVar.ExperimentTotalScans * 100; log.Info("Progress: {0:F2}% Processing ID: {1}\t ScanNum: {2} \t Excluded: {3}", progressPercent, spec.getIndex(), spec.getScanNum(), excludedSpectra.Count); #else log.Info("Progress: {0}\t{1} excluded------------------------", spec.getIndex(), excludedSpectra.Count); log.Info("ExclusionListSize: {0}\tRTOffset: {1}", exclusionList.getExclusionList().Count, RetentionTime.getRetentionTimeOffset()); #endif } return(processMS2(spec)); } else { log.Debug("unrecognized msScan"); } return(true); }
protected bool Equals(PrecursorLibraryKey other) { return(Mz.Equals(other.Mz) && RetentionTime.Equals(other.RetentionTime)); }
private void OnDeviceTransferPreflightToRun(PreflightEventArgs args) { Log.WriteLine(Id, "ProgramTime.Minutes = " + args.RunContext.ProgramTime.Minutes.ToString()); m_IsRamped = false; // Iterate through each IProgramStep from the instrument method bool isIsocratic = false; foreach (IProgramStep step in args.RunContext.ProgramSteps) { IPropertyAssignmentStep propertyAssignmentStep = step as IPropertyAssignmentStep; if (propertyAssignmentStep == null) { continue; } if (propertyAssignmentStep.Property == m_FlowHandler.FlowNominalProperty) { isIsocratic = true; FlowRequested = (propertyAssignmentStep.Value as IDoublePropertyValue).Value.GetValueOrDefault(); } else if (propertyAssignmentStep.Property == m_FlowHandler.ComponentProperties[1]) { isIsocratic = true; m_EluentPercentB = (propertyAssignmentStep.Value as IDoublePropertyValue).Value.GetValueOrDefault(); } else if (propertyAssignmentStep.Property == m_FlowHandler.ComponentProperties[2]) { isIsocratic = true; m_EluentPercentC = (propertyAssignmentStep.Value as IDoublePropertyValue).Value.GetValueOrDefault(); } else if (propertyAssignmentStep.Property == m_FlowHandler.ComponentProperties[3]) { isIsocratic = true; m_EluentPercentD = (propertyAssignmentStep.Value as IDoublePropertyValue).Value.GetValueOrDefault(); } } if (isIsocratic) { Log.WriteLine(Id, "Isocratic - FlowRequested = " + FlowRequested.ToString()); UpdateEluents(); FlowNominal = FlowRequested; if (IsSimulated) { Flow = FlowRequested; } return; } // In a real driver we would need to build some kind of time table and send it to the hardware. // In this example we create a list instead and write it to the audit trail. // Note that the property is not updated, as this would be done asynchronously during the run. StringBuilder sb = new StringBuilder(); sb.AppendLine("Table of timed events:"); foreach (IProgramStep step in args.RunContext.ProgramSteps) { IRampStep rampStep = step as IRampStep; if (rampStep == null) { continue; } m_IsRamped = true; RetentionTime duration = rampStep.Duration; IDoublePropertyValue startValue = rampStep.StartValue as IDoublePropertyValue; IDoublePropertyValue endValue = rampStep.EndValue as IDoublePropertyValue; const string sprt = "\t"; sb.Append("Retention " + step.Retention.Minutes.ToString("F3") + sprt); sb.Append(startValue.Property.Owner.Name + "." + startValue.Property.Name + " = " + startValue.Value.Value.ToString("F3") + ", "); sb.Append(endValue.Property.Owner.Name + "." + endValue.Property.Name + " = " + endValue.Value.Value.ToString("F3") + ", "); sb.AppendLine("Duration = " + duration.Minutes.ToString("F3")); } if (m_IsRamped) { string text = "Table of timed events:" + Environment.NewLine + sb.ToString(); Log.WriteLine(Id, "Gradient - " + text); // SendTimeTableCommand if (args.RunContext.IsManual) { // SendStartCommand(); } } else { string text = "Table of timed events: None"; Log.WriteLine(Id, "Gradient - " + text); } }
/// <summary> /// We use OnTransferPreflightToRun to find out the end time of the instrument method. /// Usually our run should end shortly after that time. /// </summary> /// <param name="args"></param> void m_MyCmDevice_OnTransferPreflightToRun(PreflightEventArgs args) { m_EndTime = args.RunContext.ProgramTime; }