@@ -52,6 +52,48 @@ def test_only_sentinel_modification_columns_leave_none(tmp_path):
5252 assert run ["modification_parameters" ] is None
5353
5454
55+ def test_zero_padded_source_names_are_preserved_in_sample_and_run_outputs (tmp_path ):
56+ """Source names remain distinct text identifiers, while biological replicates are integers."""
57+ sdrf = tmp_path / "zero_padded.sdrf.tsv"
58+ sdrf .write_text (
59+ "source name\t characteristics[organism]\t characteristics[organism part]\t "
60+ "characteristics[biological replicate]\t comment[fraction identifier]\t "
61+ "comment[data file]\t comment[label]\n "
62+ "001\t Homo sapiens\t liver\t 1\t 01\t A_001.raw\t label free sample\n "
63+ "01\t Homo sapiens\t liver\t 2\t 02\t A_002.raw\t label free sample\n " ,
64+ encoding = "utf-8" ,
65+ )
66+ sample_path = tmp_path / "sample.parquet"
67+ run_path = tmp_path / "run.parquet"
68+
69+ with SdrfConverter () as converter :
70+ converter .convert (str (sdrf ), sample_output = str (sample_path ), run_output = str (run_path ))
71+
72+ samples = pq .read_table (sample_path ).to_pylist ()
73+ runs = pq .read_table (run_path ).to_pylist ()
74+ assert {sample ["sample_accession" ] for sample in samples } == {"001" , "01" }
75+ assert [(run ["samples" ][0 ]["sample_accession" ], run ["samples" ][0 ]["biological_replicate" ]) for run in runs ] == [
76+ ("001" , 1 ),
77+ ("01" , 2 ),
78+ ]
79+ assert [run ["fraction" ] for run in runs ] == ["01" , "02" ]
80+
81+
82+ @pytest .mark .parametrize (("value" , "expected" ), [("1" , 1 ), ("1.0" , 1 ), ("2.5" , None ), ("x" , None )])
83+ def test_replicates_written_as_whole_decimals_are_integers (tmp_path , value , expected ):
84+ """A spreadsheet export writes replicate 1 as 1.0; a fraction or text is no replicate number."""
85+ columns = [
86+ "source name" ,
87+ "comment[data file]" ,
88+ "comment[label]" ,
89+ "characteristics[biological replicate]" ,
90+ "comment[technical replicate]" ,
91+ ]
92+ runs , _ = _convert_sdrf (tmp_path , columns , [["S1" , "run_01.raw" , "label free sample" , value , value ]])
93+ sample = runs [0 ]["samples" ][0 ]
94+ assert (sample ["biological_replicate" ], sample ["technical_replicate" ]) == (expected , expected )
95+
96+
5597@pytest .mark .parametrize (
5698 ("sdrf_value" , "expected" ),
5799 [
0 commit comments