Skip to content

Commit 703edec

Browse files
authored
Oligo fragmentation with null parent (smith-chem-wisc#922)
* can fragment without needing parent * test name change
1 parent 1e3d86c commit 703edec

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

mzLib/Test/Transcriptomics/TestOligoWithSetMods.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using Transcriptomics.Digestion;
1010
using Transcriptomics;
1111
using Omics;
12+
using MassSpectrometry;
13+
using Omics.Fragmentation;
1214

1315
namespace Test.Transcriptomics
1416
{
@@ -171,5 +173,32 @@ public static void TestInequality_SameParentAndDigestionProduct_DifferentRnases(
171173
Assert.That(oligo1, Is.Not.EqualTo((object)oligo2));
172174
Assert.That(oligo1.GetHashCode(), Is.Not.EqualTo(oligo2.GetHashCode()));
173175
}
176+
177+
[Test]
178+
public static void Fragment_WorksWhenParentIsNull()
179+
{
180+
// Arrange: create an OligoWithSetMods with no parent (using the string constructor)
181+
var baseSequence = "GUACUG";
182+
var mod = TestDigestion.PotassiumAdducts[1];
183+
var modDict = new Dictionary<string, Modification> { { mod.IdWithMotif, mod } };
184+
var oligo = new OligoWithSetMods(baseSequence, modDict);
185+
186+
// Confirm parent is null
187+
Assert.That(oligo.Parent == null);
188+
189+
// Act: call Fragment
190+
var products = new List<Product>();
191+
oligo.Fragment(DissociationType.CID, FragmentationTerminus.Both, products);
192+
193+
// Assert: products are generated and not empty
194+
Assert.That(products, Is.Not.Null);
195+
Assert.That(products.Count, Is.GreaterThan(0), "Fragment should generate at least one product when parent is null.");
196+
197+
// Optionally, check that all products are for the correct sequence length
198+
foreach (var product in products)
199+
{
200+
Assert.That(product.NeutralMass, Is.GreaterThan(0), "Product neutral mass should be positive.");
201+
}
202+
}
174203
}
175204
}

mzLib/Transcriptomics/Digestion/OligoWithSetMods.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,15 @@ public void Fragment(DissociationType dissociationType, FragmentationTerminus fr
200200
bool calculateThreePrime =
201201
fragmentationTerminus is FragmentationTerminus.ThreePrime or FragmentationTerminus.Both;
202202

203-
var sequence = (Parent as NucleicAcid)!.NucleicAcidArray[(OneBasedStartResidue - 1)..OneBasedEndResidue];
203+
Nucleotide[] sequence;
204+
if (NucleicAcid is null) // If no parent, construct the nucleotide array ourselves
205+
{
206+
sequence = BaseSequence.Select(p => Nucleotide.TryGetResidue(p, out Nucleotide? nuc) ? nuc : throw new MzLibUtil.MzLibException($"Invalid nucleotide '{p}' in sequence.")).ToArray();
207+
}
208+
else
209+
{
210+
sequence = NucleicAcid.NucleicAcidArray[(OneBasedStartResidue - 1)..OneBasedEndResidue];
211+
}
204212

205213
// intact product ion
206214
if (fragmentationTerminus is FragmentationTerminus.Both or FragmentationTerminus.None)

0 commit comments

Comments
 (0)