1212
1313def write_read_counts (path : Path , rows : list [tuple [str , int , int , int ]]) -> None :
1414 """Write a tiny CollectReadCounts-style TSV."""
15- lines = ["@RG ID:test" , "CONTIG START END COUNT" ]
16- lines .extend (f"{ contig } { start } { end } { count } " for contig , start , end , count in rows )
17- path .write_text ("
18- " .join (lines ) + "
19- " , encoding = "utf-8" )
15+ lines = ["@RG\t ID:test" , "CONTIG\t START\t END\t COUNT" ]
16+ lines .extend (f"{ contig } \t { start } \t { end } \t { count } " for contig , start , end , count in rows )
17+ path .write_text ("\n " .join (lines ) + "\n " , encoding = "utf-8" )
2018
2119
2220def test_main_version (capsys : pytest .CaptureFixture [str ]) -> None :
2321 with pytest .raises (SystemExit ) as exc_info :
2422 cli .main (["--version" ])
2523
2624 assert exc_info .value .code == 0
27- assert capsys .readouterr ().out == f"gcnvplot { gcnvplot .__version__ }
28- "
25+ assert capsys .readouterr ().out == f"gcnvplot { gcnvplot .__version__ } \n "
2926
3027
3128def test_main_requires_subcommand (capsys : pytest .CaptureFixture [str ]) -> None :
@@ -56,9 +53,7 @@ def test_build_background_writes_expected_summary(
5653 ],
5754 )
5855 paths_file = tmp_path / "background_inputs.txt"
59- paths_file .write_text ("sample_a .tsv
60- sample_b .tsv
61- ", encoding=" utf - 8 ")
56+ paths_file .write_text ("sample_a.tsv\n sample_b.tsv\n " , encoding = "utf-8" )
6257 output_path = tmp_path / "background.tsv"
6358
6459 assert (
@@ -76,25 +71,21 @@ def test_build_background_writes_expected_summary(
7671
7772 background_text = output_path .read_text (encoding = "utf-8" )
7873 assert "# normalization=median" in background_text
79- assert "chr1 100 199 2 0 .66666667 0 .66666667" in background_text
80- assert "chr1 200 299 2 1 .3333333 1 .3333333" in background_text
74+ assert "chr1\t 100 \t 199 \t 2 \t 0 .66666667\t 0 .66666667" in background_text
75+ assert "chr1\t 200 \t 299 \t 2 \t 1 .3333333\t 1 .3333333" in background_text
8176
8277 assert capsys .readouterr ().out == (
83- "Background samples : 2
84- "
85- " Background intervals : 2
86- "
87- f" Wrote : {output_path }
88- "
78+ "Background samples: 2\n "
79+ "Background intervals: 2\n "
80+ f"Wrote: { output_path } \n "
8981 )
9082
9183
9284def test_create_background_requires_output (
9385 tmp_path : Path , capsys : pytest .CaptureFixture [str ]
9486) -> None :
9587 paths_file = tmp_path / "background_inputs.txt"
96- paths_file .write_text ("sample_a .tsv
97- ", encoding=" utf - 8 ")
88+ paths_file .write_text ("sample_a.tsv\n " , encoding = "utf-8" )
9889
9990 with pytest .raises (SystemExit ) as exc_info :
10091 cli .main (["create-background" , "--read-counts-list" , str (paths_file )])
@@ -106,19 +97,17 @@ def test_create_background_requires_output(
10697def test_plot_requires_output (tmp_path : Path , capsys : pytest .CaptureFixture [str ]) -> None :
10798 background_path = tmp_path / "background.tsv"
10899 background_path .write_text (
109- "
110- " .join (
100+ "\n " .join (
111101 [
112102 "# normalization=median" ,
113103 "# samples=2" ,
114104 "# lower_percentile=5" ,
115105 "# upper_percentile=95" ,
116- "CONTIG START END N BG_NORM_MEAN BG_NORM_MEDIAN BG_NORM_SD BG_NORM_P5 BG_NORM_P95 " ,
117- "chr1 100 199 2 1 1 0.1 0.8 1 .2" ,
106+ "CONTIG\t START \t END \t N \t BG_NORM_MEAN \t BG_NORM_MEDIAN \t BG_NORM_SD \t BG_NORM_P5 \t BG_NORM_P95 " ,
107+ "chr1\t 100 \t 199 \t 2 \t 1 \t 1 \t 0.1 \t 0.8 \t 1 .2" ,
118108 ]
119109 )
120- + "
121- " ,
110+ + "\n " ,
122111 encoding = "utf-8" ,
123112 )
124113 sample_path = tmp_path / "sample.tsv"
@@ -144,22 +133,20 @@ def test_plot_log2_ratio_writes_svg_with_zero_centered_axis(
144133) -> None :
145134 background_path = tmp_path / "background.tsv"
146135 background_path .write_text (
147- "
148- " .join (
136+ "\n " .join (
149137 [
150138 "# normalization=median" ,
151139 "# samples=2" ,
152140 "# lower_percentile=5" ,
153141 "# upper_percentile=95" ,
154- "CONTIG START END N BG_NORM_MEAN BG_NORM_MEDIAN BG_NORM_SD BG_NORM_P5 BG_NORM_P95 " ,
155- "chr1 100 199 2 1 1 0.1 0.8 1 .2" ,
156- "chr2 100 199 2 1 1 0.1 0.8 1 .2" ,
157- "chr1 200 299 2 1 1 0.1 0.8 1 .2" ,
158- "chr2 200 299 2 1 1 0.1 0.8 1 .2" ,
142+ "CONTIG\t START \t END \t N \t BG_NORM_MEAN \t BG_NORM_MEDIAN \t BG_NORM_SD \t BG_NORM_P5 \t BG_NORM_P95 " ,
143+ "chr1\t 100 \t 199 \t 2 \t 1 \t 1 \t 0.1 \t 0.8 \t 1 .2" ,
144+ "chr2\t 100 \t 199 \t 2 \t 1 \t 1 \t 0.1 \t 0.8 \t 1 .2" ,
145+ "chr1\t 200 \t 299 \t 2 \t 1 \t 1 \t 0.1 \t 0.8 \t 1 .2" ,
146+ "chr2\t 200 \t 299 \t 2 \t 1 \t 1 \t 0.1 \t 0.8 \t 1 .2" ,
159147 ]
160148 )
161- + "
162- " ,
149+ + "\n " ,
163150 encoding = "utf-8" ,
164151 )
165152 sample_path = tmp_path / "sample.tsv"
@@ -199,8 +186,6 @@ def test_plot_log2_ratio_writes_svg_with_zero_centered_axis(
199186 assert "SIGNAL=0.6727054" in svg
200187
201188 assert capsys .readouterr ().out == (
202- "Plotted intervals : 2
203- "
204- f" Wrote : {output_path }
205- "
189+ "Plotted intervals: 2\n "
190+ f"Wrote: { output_path } \n "
206191 )
0 commit comments