Skip to content

Commit

Permalink
Fix Audit Log error when copy/pasting protein groups (#2758)
Browse files Browse the repository at this point in the history
Fixed unhandled error copying and pasting protein groups (reported by Philip)

Fix "LogException" when copying and pasting protein groups.
The audit log code was choking on the fact that ProteinGroupMetadata overrides the "Name" property which is marked with the "[Track]" attribute. The audit log code was calling using the accessor from the subclass instead of the accessor from the base class.
  • Loading branch information
nickshulman authored Oct 28, 2023
1 parent 53ce871 commit 4fd35e2
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pwiz_tools/Skyline/Model/AuditLog/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,14 @@ public PropertyInfoWrapper(PropertyInfo propertyInfo) : this(propertyInfo.Name,
var accessors = propertyInfo.GetAccessors(true);
if (accessors.Length > 0)
{
var baseDef = accessors[0].GetBaseDefinition();
var firstAccessor = accessors[0];
var baseDef = firstAccessor.GetBaseDefinition();
if (baseDef.DeclaringType != null)
DeclaringType = baseDef.DeclaringType;
{
DeclaringType = baseDef.DeclaringType;
GetValue = o => baseDef.Invoke(o, Array.Empty<object>());
}

}

PropertyInfo = propertyInfo;
Expand Down
94 changes: 94 additions & 0 deletions pwiz_tools/Skyline/TestFunctional/CopyProteinGroupTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Original author: Nicholas Shulman <nicksh .at. u.washington.edu>,
* MacCoss Lab, Department of Genome Sciences, UW
*
* Copyright 2023 University of Washington - Seattle, WA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using pwiz.Common.SystemUtil;
using pwiz.ProteomeDatabase.API;
using pwiz.Skyline.EditUI;
using pwiz.Skyline.Model;
using pwiz.Skyline.Model.AuditLog;
using pwiz.Skyline.Model.Proteome;
using pwiz.SkylineTestUtil;

namespace pwiz.SkylineTestFunctional
{
[TestClass]
public class CopyProteinGroupTest : AbstractFunctionalTest
{
[TestMethod]
public void TestProteinGroupCopy()
{
TestFilesZip = @"TestFunctional\CopyProteinGroupTest.zip";
RunFunctionalTest();
}

protected override void DoTest()
{
SetClipboardText("ELVIS");
RunUI(()=>SkylineWindow.Paste());
var associateProteinsDlg = ShowDialog<AssociateProteinsDlg>(SkylineWindow.ShowAssociateProteinsDlg);
RunUI(()=>
{
associateProteinsDlg.FastaFileName = TestFilesDir.GetTestPath("elvis.fasta");
associateProteinsDlg.GroupProteins = true;
});
WaitForConditionUI(() => associateProteinsDlg.IsOkEnabled);
OkDialog(associateProteinsDlg, associateProteinsDlg.OkDialog);
RunUI(() =>
{
SkylineWindow.SelectAll();
SkylineWindow.Copy();
SkylineWindow.EditDelete();
SkylineWindow.Paste();
});

// Verify that the "ProteinMetadata_Name" entry in the audit log has the correct
// name of the protein group
// This is to make sure that the ProteinGroupMetadata override of the Name property
// was the one whose value got recorded in the audit log
var document = SkylineWindow.Document;
var firstProteinGroup = document.MoleculeGroups.First();
Assert.IsInstanceOfType(firstProteinGroup.PeptideGroup, typeof(FastaSequenceGroup));
Assert.IsInstanceOfType(firstProteinGroup.ProteinMetadata, typeof(ProteinGroupMetadata));
var proteinGroupName = firstProteinGroup.ProteinMetadata.Name;
Assert.IsNotNull(document.AuditLog);
var lastAuditLogEntry = document.AuditLog.AuditLogEntries;
Assert.AreEqual(MessageType.pasted_targets, lastAuditLogEntry.UndoRedo.MessageInfo.Type);

// Construct a PropertyName corresponding to "{0:Targets}{2:PropertySeparator}Protein1 / Protein2{2:PropertySeparator}{0:ProteinMetadata_Name}" which is the first "Name" entry of the detail line
var propertyName =
new PropertyName(
new PropertyName(
new PropertyName(
AuditLogParseHelper.GetParseString(ParseStringType.property_names, nameof(Targets))),
proteinGroupName),
AuditLogParseHelper.GetParseString(ParseStringType.property_names, nameof(ProteinMetadata) + "_" + nameof(ProteinMetadata.Name)));

var proteinMetadataNameDetails = lastAuditLogEntry.AllInfo.Where(detailLogMessage => detailLogMessage.Names.FirstOrDefault() == propertyName.ToString()).ToList();
Assert.AreEqual(1, proteinMetadataNameDetails.Count);

var proteinMetadataNameDetail = proteinMetadataNameDetails[0];
Assert.AreEqual(MessageType.is_, proteinMetadataNameDetail.Type);
Assert.AreEqual(2, proteinMetadataNameDetail.Names.Count);

// Verify that the second "Name" value of the detail item is the quoted string "Protein1 / Protein2", so
Assert.AreEqual(LogMessage.Quote(proteinGroupName), proteinMetadataNameDetail.Names[1]);
}
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
>Protein1
ELVIS
>Protein2
KELVIS
1 change: 1 addition & 0 deletions pwiz_tools/Skyline/TestFunctional/TestFunctional.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
<Compile Include="CantReadSkydTest.cs" />
<Compile Include="CleavableCrosslinkTest.cs" />
<Compile Include="ConstrainNormalizationMethodTest.cs" />
<Compile Include="CopyProteinGroupTest.cs" />
<Compile Include="CrosslinkImsTest.cs" />
<Compile Include="DdaPeakIntegrationTest.cs" />
<Compile Include="DdaScoringTest.cs" />
Expand Down

0 comments on commit 4fd35e2

Please sign in to comment.