33import pytest
44from tacular import ELEMENT_LOOKUP
55
6- from paftacular import PafAnnotation , mzPAFParser
6+ from paftacular import PafAnnotation , parse , parse_single
77from paftacular .comps import (
88 Adduct ,
99 ChemicalFormula ,
@@ -271,8 +271,7 @@ def test_basic_mass(self):
271271 """Test basic mass calculation"""
272272 annotation = PafAnnotation (ion_type = PeptideIon (series = IonSeries .B , position = 2 ))
273273 # Should have some positive mass
274- assert annotation .monoisotopic_mass > 0
275- assert annotation .average_mass > 0
274+ assert annotation .mass () > 0
276275
277276 def test_mass_with_neutral_loss (self ):
278277 """Test mass with neutral loss"""
@@ -282,7 +281,7 @@ def test_mass_with_neutral_loss(self):
282281 neutral_losses = (NeutralLoss (count = - 1 , base_formula = "H2O" ),),
283282 )
284283 # Mass should be reduced by water
285- assert with_loss .monoisotopic_mass < base .monoisotopic_mass
284+ assert with_loss .mass () < base .mass ()
286285
287286 def test_mass_with_charge (self ):
288287 """Test mass calculation includes protonation"""
@@ -291,7 +290,7 @@ def test_mass_with_charge(self):
291290 charge = 2 ,
292291 )
293292 # Should add 2 protons
294- assert annotation .monoisotopic_mass > 0
293+ assert annotation .mass () > 0
295294
296295
297296class TestComposition :
@@ -300,7 +299,7 @@ class TestComposition:
300299 def test_basic_composition (self ):
301300 """Test basic composition calculation"""
302301 annotation = PafAnnotation (ion_type = ChemicalFormula (formula = "C6H12O6" ))
303- comp = annotation .composition
302+ comp = annotation .composition ()
304303 assert isinstance (comp , Counter )
305304 # Should contain C, H, O elements
306305 assert any (elem .symbol == "C" for elem in comp )
@@ -313,7 +312,7 @@ def test_composition_with_charge(self):
313312 ion_type = ChemicalFormula (formula = "C6H12O6" ),
314313 charge = 2 ,
315314 )
316- comp = annotation .composition
315+ comp = annotation .composition ()
317316 # Should have protons added
318317 h_element = ELEMENT_LOOKUP ["H" ]
319318 assert h_element in comp
@@ -324,7 +323,7 @@ def test_composition_with_neutral_loss(self):
324323 ion_type = ChemicalFormula (formula = "C6H12O6" ),
325324 neutral_losses = (NeutralLoss (count = - 1 , base_formula = "H2O" ),),
326325 )
327- comp = annotation .composition
326+ comp = annotation .composition ()
328327 # Composition should be affected by loss
329328 assert isinstance (comp , Counter )
330329
@@ -334,43 +333,37 @@ class TestParsing:
334333
335334 def test_parse_simple (self ):
336335 """Test parsing simple annotation"""
337- parser = mzPAFParser ()
338- annotation = parser .parse_single ("b2" )
336+ annotation = parse_single ("b2" )
339337 assert annotation .ion_type .series == IonSeries .B
340338 assert annotation .ion_type .position == 2
341339
342340 def test_parse_with_sequence (self ):
343341 """Test parsing with sequence"""
344- parser = mzPAFParser ()
345- annotation = parser .parse_single ("y3{PEP}" )
342+ annotation = parse_single ("y3{PEP}" )
346343 assert annotation .ion_type .series == IonSeries .Y
347344 assert annotation .ion_type .position == 3
348345 assert annotation .ion_type .sequence == "PEP"
349346
350347 def test_parse_with_neutral_loss (self ):
351348 """Test parsing with neutral loss"""
352- parser = mzPAFParser ()
353- annotation = parser .parse_single ("b2-H2O" )
349+ annotation = parse_single ("b2-H2O" )
354350 assert len (annotation .neutral_losses ) == 1
355351 assert annotation .neutral_losses [0 ].count == - 1
356352
357353 def test_parse_with_adduct (self ):
358354 """Test parsing with adduct"""
359- parser = mzPAFParser ()
360- annotation = parser .parse_single ("b2[M+Na]" )
355+ annotation = parse_single ("b2[M+Na]" )
361356 assert len (annotation .adducts ) == 1
362357 assert annotation .adducts [0 ].count == 1
363358
364359 def test_parse_with_charge (self ):
365360 """Test parsing with charge"""
366- parser = mzPAFParser ()
367- annotation = parser .parse_single ("b2^2" )
361+ annotation = parse_single ("b2^2" )
368362 assert annotation .charge == 2
369363
370364 def test_parse_multiple_annotations (self ):
371365 """Test parsing comma-separated annotations"""
372- parser = mzPAFParser ()
373- annotations = parser .parse ("b2, y3, a1" )
366+ annotations = parse ("b2, y3, a1" )
374367 assert len (annotations ) == 3
375368 assert annotations [0 ].ion_type .series == IonSeries .B
376369 assert annotations [1 ].ion_type .series == IonSeries .Y
@@ -389,18 +382,16 @@ def test_parse_roundtrip(self):
389382 "r[TMT126]" ,
390383 "f{C6H12O6}" ,
391384 ]
392- parser = mzPAFParser ()
393385 for test_str in test_strings :
394- annotation = parser . parse_single (test_str )
386+ annotation = parse_single (test_str )
395387 serialized = annotation .serialize ()
396- re_parsed = parser . parse_single (serialized )
388+ re_parsed = parse_single (serialized )
397389 assert annotation .ion_type == re_parsed .ion_type
398390
399391 def test_invalid_annotation (self ):
400392 """Test that invalid annotations raise errors"""
401- parser = mzPAFParser ()
402393 with pytest .raises (ValueError , match = "Invalid mzPAF annotation" ):
403- parser . parse_single ("invalid_annotation!" )
394+ parse_single ("invalid_annotation!" )
404395
405396
406397class TestFormulaProperties :
@@ -409,14 +400,14 @@ class TestFormulaProperties:
409400 def test_formula_property (self ):
410401 """Test formula property returns string"""
411402 annotation = PafAnnotation (ion_type = ChemicalFormula (formula = "C6H12O6" ))
412- formula = annotation .formula
403+ formula = annotation .formula ()
413404 assert isinstance (formula , str )
414405 assert len (formula ) > 0
415406
416407 def test_proforma_formula_property (self ):
417408 """Test ProForma formula property"""
418409 annotation = PafAnnotation (ion_type = ChemicalFormula (formula = "C6H12O6" ))
419- formula = annotation .proforma_formula
410+ formula = annotation .proforma_formula ()
420411 assert isinstance (formula , str )
421412 assert len (formula ) > 0
422413
0 commit comments