Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skyline: Raised the peak truncation threshold #3361

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,9 @@
<data name="ProductNeutralMass">
<value>Product Neutral Mass</value>
</data>
<data name="ProportionTruncated">
<value>Proportion Truncated</value>
</data>
<data name="Protein">
<value>Protein</value>
</data>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ appeared on the heavy transitions.</value>
<value>If true, then Skyline will automatically add or remove transitions from the precursor depending on the Transition Settings Filter, spectral library, etc.</value>
</data>
<data name="AverageMassErrorPPM">
<value>Average Mass Error PPM</value>
<value>The area weighted mean for all transitions of the difference between the expected and measured m/z values expressed in parts per million (PPM)</value>
</data>
<data name="AverageMasses">
<value>The modified sequence which specifies modifications with their average masses, e.g. "C[+57.05162]".</value>
Expand Down Expand Up @@ -319,7 +319,7 @@ specific default collision energy equation within Skyline</value>
<data name="CountTruncated">
<value>The number of transitions for a precursor that integrate a peak with a
boundary at either end of the acquisition time range, where intensity at the end is
greater than 1% of the entire peak height higher than the other extent.</value>
greater than 25% of the background-subtracted peak height higher than the other extent.</value>
</data>
<data name="Cv">
<value>Cv</value>
Expand Down Expand Up @@ -1246,6 +1246,11 @@ the decoy m/z.</value>
<data name="ProductNeutralMass">
<value>Neutral mass of the product ion peptide fragment in Daltons.</value>
</data>
<data name="ProportionTruncated">
<value>The area weighted mean (0 to 1.0) of transitions for a precursor that integrate a peak with a
boundary at either end of the acquisition time range, where intensity at the end is
greater than 25% of the background-subtracted peak height higher than the other extent.</value>
</data>
<data name="Protein">
<value>Protein</value>
</data>
Expand Down Expand Up @@ -1651,8 +1656,8 @@ using the Results Grid.</value>
<value>Transitions</value>
</data>
<data name="Truncated">
<value>True if the integrated a peak has a boundary at either end of the acquisition
time range, where intensity at the end is greater than 1% of the entire peak height
<value>True if the integrate peak has a boundary at either end of the acquisition
time range, where intensity at the end is greater than 25% of the background-subtracted peak height
higher than the other extent.</value>
</data>
<data name="TurningPoint">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public double? RatioDotProduct {
public double? AverageMassErrorPPM { get { return ChromInfo.MassError; } }
[Format(NullValue = TextUtil.EXCEL_NA)]
public int? CountTruncated { get { return ChromInfo.Truncated; } }
[Format(Formats.STANDARD_RATIO, NullValue = TextUtil.EXCEL_NA)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to use Formats.Percent here instead of Formats.STANDARD_RATIO.
(There is also Formats.PEAK_AREA_NORMALIZED which is a percent with up to four decimal places)

public double? ProportionTruncated { get { return ChromInfo.TruncatedProportion; } }
public PeakIdentification Identified { get { return ChromInfo.Identified; } }
[Format(Formats.STANDARD_RATIO, NullValue = TextUtil.EXCEL_NA)]
public double? LibraryDotProduct { get { return ChromInfo.LibraryDotProduct; } }
Expand Down
2 changes: 1 addition & 1 deletion pwiz_tools/Skyline/Model/Results/ChromHeaderInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ public ChromPeak(IPeakFinder finder,
// recorded values, where the intensity is higher than the other extent
// by more than 1% of the peak height.
_flagValues |= FlagValues.peak_truncation_known;
const double truncationTolerance = 0.01;
const double truncationTolerance = 0.25;
double deltaIntensityExtents = (intensities[peak.EndIndex] - intensities[peak.StartIndex]) / Height;
if ((peak.StartIndex == 0 && deltaIntensityExtents < -truncationTolerance) ||
(peak.EndIndex == times.Count - 1 && deltaIntensityExtents > truncationTolerance))
Expand Down
44 changes: 28 additions & 16 deletions pwiz_tools/Skyline/Model/Results/DocNodeChromInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,23 @@ public sealed class TransitionGroupChromInfo : ChromInfo
[Flags]
private enum Flags
{
HasRetentionTime = 1,
HasStartRetentionTime = 2,
HasEndRetentionTime = 4,
HasFwhm = 8,
HasArea = 16,
HasAreaMs1 = 32,
HasAreaFragment = 64,
HasBackgroundArea = 128,
HasBackgroundAreaMs1 = 256,
HasBackgroundAreaFragment = 512,
HasHeight = 1024,
HasMassError = 2048,
HasLibraryDotProduct = 4096,
HasIsotopeDotProduct = 8192,
HasQValue = 16384,
HasZScore = 32768,
HasRetentionTime = 0x00000001,
HasStartRetentionTime = 0x00000002,
HasEndRetentionTime = 0x00000004,
HasFwhm = 0x00000008,
HasArea = 0x00000010,
HasAreaMs1 = 0x00000020,
HasAreaFragment = 0x00000040,
HasBackgroundArea = 0x00000080,
HasBackgroundAreaMs1 = 0x00000100,
HasBackgroundAreaFragment = 0x00000200,
HasHeight = 0x00000400,
HasMassError = 0x00000800,
HasLibraryDotProduct = 0x00001000,
HasIsotopeDotProduct = 0x00002000,
HasQValue = 0x00004000,
HasZScore = 0x00008000,
HasTruncatedProportion = 0x00010000,
}

private Flags _flags;
Expand All @@ -209,6 +210,7 @@ public TransitionGroupChromInfo(ChromFileInfoId fileId,
float? height,
float? massError,
int? truncated,
float? truncatedProportion,
PeakIdentification identified,
float? libraryDotProduct,
float? isotopeDotProduct,
Expand All @@ -234,6 +236,7 @@ public TransitionGroupChromInfo(ChromFileInfoId fileId,
Height = height;
MassError = massError;
Truncated = truncated;
TruncatedProportion = truncatedProportion;
Identified = identified;
LibraryDotProduct = libraryDotProduct;
IsotopeDotProduct = isotopeDotProduct;
Expand Down Expand Up @@ -340,6 +343,13 @@ public int? Truncated
private set { _truncated = value ?? -1; }
}

private float _truncatedProportion;
public float? TruncatedProportion
{
get { return GetOptional(_truncatedProportion, Flags.HasTruncatedProportion); }
private set { _truncatedProportion = SetOptional(value, Flags.HasTruncatedProportion); }
}

public PeakIdentification Identified { get; private set; }
public bool IsIdentified { get { return Identified != PeakIdentification.FALSE; } }

Expand Down Expand Up @@ -455,6 +465,7 @@ public bool Equals(TransitionGroupChromInfo other)
other.BackgroundAreaFragment.Equals(BackgroundAreaFragment) &&
other.Height.Equals(Height) &&
other.Truncated.Equals(Truncated) &&
other.TruncatedProportion.Equals(TruncatedProportion) &&
other.Identified.Equals(Identified) &&
other.LibraryDotProduct.Equals(LibraryDotProduct) &&
other.IsotopeDotProduct.Equals(IsotopeDotProduct) &&
Expand Down Expand Up @@ -493,6 +504,7 @@ public override int GetHashCode()
result = (result*397) ^ (BackgroundAreaFragment.HasValue ? BackgroundAreaFragment.Value.GetHashCode() : 0);
result = (result*397) ^ (Height.HasValue ? Height.Value.GetHashCode() : 0);
result = (result*397) ^ (Truncated.HasValue ? Truncated.Value.GetHashCode() : 0);
result = (result*397) ^ (TruncatedProportion.HasValue ? TruncatedProportion.Value.GetHashCode() : 0);
result = (result*397) ^ Identified.GetHashCode();
result = (result*397) ^ (LibraryDotProduct.HasValue ? LibraryDotProduct.Value.GetHashCode() : 0);
result = (result*397) ^ (IsotopeDotProduct.HasValue ? IsotopeDotProduct.Value.GetHashCode() : 0);
Expand Down
3 changes: 2 additions & 1 deletion pwiz_tools/Skyline/Model/Serialization/DocumentFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public struct DocumentFormat : IComparable<DocumentFormat>
public static readonly DocumentFormat VERSION_23_13 = new DocumentFormat(23.13); // Relative abundance formatting
public static readonly DocumentFormat VERSION_24_1 = new DocumentFormat(24.1); // Release format
public static readonly DocumentFormat VERSION_24_11 = new DocumentFormat(24.11); // Global spectrum filters
public static readonly DocumentFormat CURRENT = VERSION_24_11;
public static readonly DocumentFormat VERSION_24_12 = new DocumentFormat(24.12); // truncated_proportion
public static readonly DocumentFormat CURRENT = VERSION_24_12;

private readonly double _versionNumber;
public DocumentFormat(double versionNumber)
Expand Down
5 changes: 5 additions & 0 deletions pwiz_tools/Skyline/Model/Serialization/DocumentReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ private TransitionGroupChromInfo ReadTransitionGroupChromInfo(XmlReader reader,
float? height = reader.GetNullableFloatAttribute(ATTR.height);
float? massError = reader.GetNullableFloatAttribute(ATTR.mass_error_ppm);
int? truncated = reader.GetNullableIntAttribute(ATTR.truncated);
float? truncatedProportion = reader.GetNullableFloatAttribute(ATTR.truncated_proportion);
// When truncated count is zero, truncate proportion is known to be zero
if (truncated is 0 && !truncatedProportion.HasValue)
truncatedProportion = 0;
PeakIdentification identified = reader.GetEnumAttribute(ATTR.identified, PeakIdentificationFastLookup.Dict,
PeakIdentification.FALSE, XmlUtil.EnumCase.upper);
float? libraryDotProduct = reader.GetNullableFloatAttribute(ATTR.library_dotp);
Expand Down Expand Up @@ -158,6 +162,7 @@ private TransitionGroupChromInfo ReadTransitionGroupChromInfo(XmlReader reader,
height,
massError,
truncated,
truncatedProportion,
identified,
libraryDotProduct,
isotopeDotProduct,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public static class ATTR
public const string fwhm = "fwhm";
public const string fwhm_degenerate = "fwhm_degenerate";
public const string truncated = "truncated";
public const string truncated_proportion = "truncated_proportion";
public const string identified = "identified";
public const string user_set = "user_set";
public const string peak_count_ratio = "peak_count_ratio";
Expand Down
3 changes: 3 additions & 0 deletions pwiz_tools/Skyline/Model/Serialization/DocumentWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@ private static void WriteTransitionGroupChromInfo(XmlWriter writer, TransitionGr
writer.WriteAttributeNullable(ATTR.height, chromInfo.Height);
writer.WriteAttributeNullable(ATTR.mass_error_ppm, chromInfo.MassError);
writer.WriteAttributeNullable(ATTR.truncated, chromInfo.Truncated);
// Writing truncated proportion 0 for peaks with a truncated count of zero is redundant
if ((chromInfo.Truncated ?? 0) != 0)
writer.WriteAttributeNullable(ATTR.truncated_proportion, chromInfo.TruncatedProportion);
writer.WriteAttribute(ATTR.identified, chromInfo.Identified.ToString().ToLowerInvariant());
writer.WriteAttributeNullable(ATTR.library_dotp, chromInfo.LibraryDotProduct);
writer.WriteAttributeNullable(ATTR.isotope_dotp, chromInfo.IsotopeDotProduct);
Expand Down
7 changes: 7 additions & 0 deletions pwiz_tools/Skyline/Model/TransitionGroupDocNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,7 @@ public TransitionGroupChromInfoCalculator(SrmSettings settings,
private float? BackgroundAreaFragment { get; set; }
private float? MassError { get; set; }
private int? Truncated { get; set; }
private float? TruncatedProportion { get; set; }
private PeakIdentification Identified { get; set; }
private float? LibraryDotProduct { get; set; }
private float? IsotopeDotProduct { get; set; }
Expand Down Expand Up @@ -2625,6 +2626,11 @@ public void AddChromInfo(TransitionDocNode nodeTran, TransitionChromInfo info)
Truncated = 0;
if (info.IsTruncated.Value)
Truncated++;

// Weighted mean value for truncation
double truncatedProportion = TruncatedProportion ?? 1;
truncatedProportion += ((info.IsTruncated.Value ? 1 : 0) - truncatedProportion) * info.Area / Area.Value;
TruncatedProportion = (float)truncatedProportion;
}
switch (Settings.GetChromSource(nodeTran))
{
Expand Down Expand Up @@ -2713,6 +2719,7 @@ public TransitionGroupChromInfo CalcChromInfo()
(float?) BestRetentionTimes?.Height,
MassError,
Truncated,
TruncatedProportion,
Identified,
LibraryDotProduct,
IsotopeDotProduct,
Expand Down
10 changes: 9 additions & 1 deletion pwiz_tools/Skyline/Test/MProphetResultsHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,15 @@ public void TestMProphetResultsHandler()
AssertEx.FileEquals(mProphetExpected, mProphetActual);

// 4. Export mProphet -> Import Peak Boundaries leads to same result as reintegrate
var resultsHandlerQAll = new MProphetResultsHandler(docOriginal, peakScoringModel) { QValueCutoff = 1.0 };

// Remove RWSSIPLSQLHLI because its truncation values change between 24.11 and 24.12
// That is the ChromPeak.Truncated value stored in the .skyd file is different from
// what gets recalculated during peak boundary import.
var pepRemovePath = docOriginal.EnumeratePathsAtLevel(IdentityPath.ROOT, SrmDocument.Level.Molecules)
.First(path => path.Child is Peptide { Sequence: @"RWSSIPLSQLHLI" });
var docRemoved = (SrmDocument) docOriginal.RemoveChild(pepRemovePath.Parent, docOriginal.FindNode(pepRemovePath));

var resultsHandlerQAll = new MProphetResultsHandler(docRemoved, peakScoringModel) { QValueCutoff = 1.0 };
resultsHandlerQAll.ScoreFeatures();
var docNewQAll = resultsHandlerQAll.ChangePeaks();
var peakBoundaryImporter = new PeakBoundaryImporter(docNewQAll);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private void ExploreTopPeptides()
OkDialog(findDlg, findDlg.Close);

var findView = WaitForOpenForm<FindResultsForm>();
int expectedItems = IsFullData ? 454 : 290;
int expectedItems = IsFullData ? 228 : 151;
try
{
WaitForConditionUI(1000, () => findView.ItemCount == expectedItems);
Expand Down Expand Up @@ -610,9 +610,9 @@ private void AddTruncatedPrecursorsView(DocumentGridForm documentGrid, bool init
OkDialog(viewEditor, viewEditor.OkDialog);

var pathTruncated = PropertyPath.Parse("Results!*.Value.CountTruncated");
int expectedItems = 148;
int expectedItems = 86;
if (IsFullData)
expectedItems = 221; // initialTestExecution ? 223 : 221;
expectedItems = 129;
try
{
WaitForConditionUI(1000, () => documentGrid.RowCount == expectedItems &&
Expand Down Expand Up @@ -1155,7 +1155,7 @@ private void PrepareForStatistics()

PauseForScreenShot<DocumentGridForm>("Document Grid with MissingData field");

int expectedRows = IsFullData ? 222 : 149;
int expectedRows = IsFullData ? 133 : 89;
const int expectedRowsAbbreviated = 221; // When not all of the tests are run
RunUI(() =>
{
Expand Down
Loading