From 52a1910318c870d1897d4ada70fd51e5b9ce1072 Mon Sep 17 00:00:00 2001 From: deliaBlue Date: Sat, 2 Dec 2023 22:05:21 +0100 Subject: [PATCH] style: correct style with black --- scripts/tests/test_filter_multimappers.py | 128 ++++--- scripts/tests/test_iso_name_tagging.py | 162 +++++---- scripts/tests/test_mirna_extension.py | 165 +++++---- scripts/tests/test_mirna_quantification.py | 326 +++++++++++------- ...test_oligomap_output_to_sam_nh_filtered.py | 280 ++++++++++----- scripts/tests/test_primir_quantification.py | 187 +++++----- 6 files changed, 764 insertions(+), 484 deletions(-) diff --git a/scripts/tests/test_filter_multimappers.py b/scripts/tests/test_filter_multimappers.py index bb38337..3dc96ac 100755 --- a/scripts/tests/test_filter_multimappers.py +++ b/scripts/tests/test_filter_multimappers.py @@ -12,7 +12,7 @@ find_best_alignments, main, parse_arguments, - write_output + write_output, ) @@ -143,10 +143,7 @@ class TestParseArguments: def test_no_input(self, monkeypatch): """Call without input file.""" with pytest.raises(SystemExit) as sysex: - monkeypatch.setattr( - sys, 'argv', - ['filter_multimappers'] - ) + monkeypatch.setattr(sys, "argv", ["filter_multimappers"]) parse_arguments().parse_args() assert sysex.value.code == 2 @@ -154,10 +151,12 @@ def test_correct_input(self, monkeypatch, sam_no_multimappers_file): """Call with a single input file.""" sam_1 = sam_no_multimappers_file monkeypatch.setattr( - sys, 'argv', - ['filter_multimappers', - str(sam_1), - ] + sys, + "argv", + [ + "filter_multimappers", + str(sam_1), + ], ) args = parse_arguments().parse_args() assert isinstance(args, argparse.Namespace) @@ -166,11 +165,13 @@ def test_all_input_options(self, monkeypatch, sam_no_multimappers_file): """Call with a single input file and the --nh option.""" sam_1 = sam_no_multimappers_file monkeypatch.setattr( - sys, 'argv', - ['filter_multimappers', - str(sam_1), - '--nh', - ] + sys, + "argv", + [ + "filter_multimappers", + str(sam_1), + "--nh", + ], ) args = parse_arguments().parse_args() assert isinstance(args, argparse.Namespace) @@ -179,10 +180,13 @@ def test_too_many_inputs(self, monkeypatch, sam_multimappers_files): """Call with too many input files.""" sam_1, sam_2 = sam_multimappers_files monkeypatch.setattr( - sys, 'argv', - ['filter_multimappers', - str(sam_1), str(sam_2), - ] + sys, + "argv", + [ + "filter_multimappers", + str(sam_1), + str(sam_2), + ], ) with pytest.raises(SystemExit) as sysex: parse_arguments().parse_args() @@ -270,16 +274,16 @@ def test_write_output_one_alignment(self, capsys, sam_multimappers_files): """Test funciton with a single alignment.""" in_sam, out_sam = sam_multimappers_files - with pysam.AlignmentFile(in_sam, 'r') as in_file: + with pysam.AlignmentFile(in_sam, "r") as in_file: alignment = next(in_file) write_output([alignment]) captured = capsys.readouterr() - with pysam.AlignmentFile(out_sam, 'r') as out_file: + with pysam.AlignmentFile(out_sam, "r") as out_file: out_alignment = next(out_file) - assert captured.out == out_alignment.to_string() + '\n' + assert captured.out == out_alignment.to_string() + "\n" class TestMain: @@ -290,87 +294,101 @@ def test_main_empty_file(self, capsys, monkeypatch, sam_empty_file): empty_file = sam_empty_file monkeypatch.setattr( - sys, 'argv', - ['filter_multimappers', - str(empty_file), - ] + sys, + "argv", + [ + "filter_multimappers", + str(empty_file), + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(empty_file, 'r') as out_file: + with open(empty_file, "r") as out_file: assert captured.out == out_file.read() - def test_main_multimappers(self, capsys, monkeypatch, - sam_multimappers_files): + def test_main_multimappers( + self, capsys, monkeypatch, sam_multimappers_files + ): """Test main function with multimappers.""" in_sam, out_sam = sam_multimappers_files monkeypatch.setattr( - sys, 'argv', - ['filter_multimappers', - str(in_sam), - ] + sys, + "argv", + [ + "filter_multimappers", + str(in_sam), + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(out_sam, 'r') as out_file: + with open(out_sam, "r") as out_file: assert captured.out == out_file.read() - def test_main_multimappers_nh(self, capsys, monkeypatch, - sam_multimappers_nh_files): + def test_main_multimappers_nh( + self, capsys, monkeypatch, sam_multimappers_nh_files + ): """Test main function with multimappers with nh argument.""" in_sam, out_sam = sam_multimappers_nh_files monkeypatch.setattr( - sys, 'argv', - ['filter_multimappers', - str(in_sam), - '--nh', - ] + sys, + "argv", + [ + "filter_multimappers", + str(in_sam), + "--nh", + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(out_sam, 'r') as out_file: + with open(out_sam, "r") as out_file: assert captured.out == out_file.read() - def test_main_no_multimappers(self, capsys, monkeypatch, - sam_no_multimappers_file): + def test_main_no_multimappers( + self, capsys, monkeypatch, sam_no_multimappers_file + ): """Test main function with no multimappers.""" sam_file = sam_no_multimappers_file monkeypatch.setattr( - sys, 'argv', - ['filter_multimappers', - str(sam_file), - ] + sys, + "argv", + [ + "filter_multimappers", + str(sam_file), + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(sam_file, 'r') as out_file: + with open(sam_file, "r") as out_file: assert captured.out == out_file.read() - def test_main_secondary_supplementary(self, capsys, monkeypatch, - sam_sec_sup_files): + def test_main_secondary_supplementary( + self, capsys, monkeypatch, sam_sec_sup_files + ): """Test main function with secondary and supplementary alignments.""" in_sam, out_sam = sam_sec_sup_files monkeypatch.setattr( - sys, 'argv', - ['filter_multimappers', - str(in_sam), - ] + sys, + "argv", + [ + "filter_multimappers", + str(in_sam), + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(out_sam, 'r') as out_file: + with open(out_sam, "r") as out_file: assert captured.out == out_file.read() diff --git a/scripts/tests/test_iso_name_tagging.py b/scripts/tests/test_iso_name_tagging.py index de2c5ba..ef1881c 100644 --- a/scripts/tests/test_iso_name_tagging.py +++ b/scripts/tests/test_iso_name_tagging.py @@ -6,10 +6,7 @@ import pytest -from ..iso_name_tagging import ( - main, - parse_arguments -) +from ..iso_name_tagging import main, parse_arguments @pytest.fixture @@ -60,10 +57,13 @@ def test_no_bed(self, monkeypatch, bed_sam): with pytest.raises(SystemExit) as sysex: monkeypatch.setattr( - sys, 'argv', - ['iso_name_tagging', - '--sam', str(in_sam), - ] + sys, + "argv", + [ + "iso_name_tagging", + "--sam", + str(in_sam), + ], ) parse_arguments().parse_args() assert sysex.value.code == 2 @@ -74,10 +74,13 @@ def test_no_sam(self, monkeypatch, bed_sam): with pytest.raises(SystemExit) as sysex: monkeypatch.setattr( - sys, 'argv', - ['iso_name_tagging', - '--bed', str(in_bed), - ] + sys, + "argv", + [ + "iso_name_tagging", + "--bed", + str(in_bed), + ], ) parse_arguments().parse_args() assert sysex.value.code == 2 @@ -87,11 +90,15 @@ def test_correct_input(self, monkeypatch, bed_sam): in_bed, in_sam, output = bed_sam monkeypatch.setattr( - sys, 'argv', - ['iso_name_tagging', - '--bed', str(in_bed), - '--sam', str(in_sam), - ] + sys, + "argv", + [ + "iso_name_tagging", + "--bed", + str(in_bed), + "--sam", + str(in_sam), + ], ) args = parse_arguments().parse_args() assert isinstance(args, argparse.Namespace) @@ -101,13 +108,19 @@ def test_all_input(self, monkeypatch, bed_sam): in_bed, in_sam, output = bed_sam monkeypatch.setattr( - sys, 'argv', - ['iso_name_tagging', - '--bed', str(in_bed), - '--sam', str(in_sam), - '--id', "alias", - '--extension', '6', - ] + sys, + "argv", + [ + "iso_name_tagging", + "--bed", + str(in_bed), + "--sam", + str(in_sam), + "--id", + "alias", + "--extension", + "6", + ], ) args = parse_arguments().parse_args() assert isinstance(args, argparse.Namespace) @@ -116,43 +129,53 @@ def test_all_input(self, monkeypatch, bed_sam): class TestMain: """Test 'main()' function.""" - def test_main_empty_bed_file(self, monkeypatch, capsys, empty_files, - bed_sam): + def test_main_empty_bed_file( + self, monkeypatch, capsys, empty_files, bed_sam + ): """Test main function with an empty bed file.""" empty_bed, empty_sam = empty_files monkeypatch.setattr( - sys, 'argv', - ['iso_name_tagging', - '--bed', str(empty_bed), - '--sam', str(empty_sam), - ] + sys, + "argv", + [ + "iso_name_tagging", + "--bed", + str(empty_bed), + "--sam", + str(empty_sam), + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(empty_sam, 'r') as out_file: + with open(empty_sam, "r") as out_file: assert captured.out == out_file.read() - def test_main_empty_sam_file(self, monkeypatch, capsys, empty_files, - bed_sam): + def test_main_empty_sam_file( + self, monkeypatch, capsys, empty_files, bed_sam + ): """Test main function with an empty sam file.""" empty_bed, empty_sam = empty_files in_bed, in_sam, output = bed_sam monkeypatch.setattr( - sys, 'argv', - ['iso_name_tagging', - '--bed', str(in_bed), - '--sam', str(empty_sam), - ] + sys, + "argv", + [ + "iso_name_tagging", + "--bed", + str(in_bed), + "--sam", + str(empty_sam), + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(empty_sam, 'r') as out_file: + with open(empty_sam, "r") as out_file: assert captured.out == out_file.read() def test_main_bed_sam_file(self, monkeypatch, capsys, bed_sam): @@ -160,37 +183,47 @@ def test_main_bed_sam_file(self, monkeypatch, capsys, bed_sam): in_bed, in_sam, output = bed_sam monkeypatch.setattr( - sys, 'argv', - ['iso_name_tagging', - '--bed', str(in_bed), - '--sam', str(in_sam), - ] + sys, + "argv", + [ + "iso_name_tagging", + "--bed", + str(in_bed), + "--sam", + str(in_sam), + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(output, 'r') as out_file: + with open(output, "r") as out_file: assert captured.out == out_file.read() - def test_main_bed_sam_extension_file(self, monkeypatch, capsys, - bed_sam_extension): + def test_main_bed_sam_extension_file( + self, monkeypatch, capsys, bed_sam_extension + ): """Test main function with extension equals 6.""" in_bed, in_sam, output = bed_sam_extension monkeypatch.setattr( - sys, 'argv', - ['iso_name_tagging', - '--bed', str(in_bed), - '--sam', str(in_sam), - '--extension', '6', - ] + sys, + "argv", + [ + "iso_name_tagging", + "--bed", + str(in_bed), + "--sam", + str(in_sam), + "--extension", + "6", + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(output, 'r') as out_file: + with open(output, "r") as out_file: assert captured.out == out_file.read() def test_main_bed_sam_file_id(self, monkeypatch, capsys, bed_sam_id): @@ -198,16 +231,21 @@ def test_main_bed_sam_file_id(self, monkeypatch, capsys, bed_sam_id): in_bed, in_sam, output = bed_sam_id monkeypatch.setattr( - sys, 'argv', - ['iso_name_tagging', - '--bed', str(in_bed), - '--sam', str(in_sam), - '--id', 'id' - ] + sys, + "argv", + [ + "iso_name_tagging", + "--bed", + str(in_bed), + "--sam", + str(in_sam), + "--id", + "id", + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(output, 'r') as out_file: + with open(output, "r") as out_file: assert captured.out == out_file.read() diff --git a/scripts/tests/test_mirna_extension.py b/scripts/tests/test_mirna_extension.py index 07f14db..16f8309 100644 --- a/scripts/tests/test_mirna_extension.py +++ b/scripts/tests/test_mirna_extension.py @@ -7,11 +7,7 @@ import gffutils import pytest -from ..mirna_extension import ( - main, - MirnaExtension, - parse_arguments -) +from ..mirna_extension import main, MirnaExtension, parse_arguments @pytest.fixture @@ -59,10 +55,7 @@ class TestParseArguments: def test_no_files(self, monkeypatch): """Call without input nor output files.""" with pytest.raises(SystemExit) as sysex: - monkeypatch.setattr( - sys, 'argv', - ['mirna_extension'] - ) + monkeypatch.setattr(sys, "argv", ["mirna_extension"]) parse_arguments().parse_args() assert sysex.value.code == 2 @@ -71,11 +64,14 @@ def test_in_files(self, monkeypatch, gff_empty, tmp_path): gff_in = gff_empty monkeypatch.setattr( - sys, 'argv', - ['mirna_extension', - str(gff_in), - '--outdir', str(tmp_path), - ] + sys, + "argv", + [ + "mirna_extension", + str(gff_in), + "--outdir", + str(tmp_path), + ], ) args = parse_arguments().parse_args() @@ -86,13 +82,18 @@ def test_all_arguments(self, monkeypatch, gff_extremes_chr, tmp_path): chr_size, gff_in, gff_pre_out, gff_mir_out = gff_extremes_chr monkeypatch.setattr( - sys, 'argv', - ['mirna_extension', - str(gff_in), - '--outdir', str(tmp_path), - '--chr', str(chr_size), - '--extension', '6', - ] + sys, + "argv", + [ + "mirna_extension", + str(gff_in), + "--outdir", + str(tmp_path), + "--chr", + str(chr_size), + "--extension", + "6", + ], ) args = parse_arguments().parse_args() @@ -110,23 +111,27 @@ def test_main_empty_file(self, monkeypatch, gff_empty, tmp_path): mir_out = tmp_path / "extended_mirna_annotation_6_nt.gff3" monkeypatch.setattr( - sys, 'argv', - ['mirna_extension', - str(gff_empty), - '--outdir', str(tmp_path), - ] + sys, + "argv", + [ + "mirna_extension", + str(gff_empty), + "--outdir", + str(tmp_path), + ], ) args = parse_arguments().parse_args() main(args) - with open(gff_empty, 'r') as expected, open(primir_out, 'r') as output: + with open(gff_empty, "r") as expected, open(primir_out, "r") as output: assert output.read() == expected.read() - with open(gff_empty, 'r') as expected, open(mir_out, 'r') as output: + with open(gff_empty, "r") as expected, open(mir_out, "r") as output: assert output.read() == expected.read() - def test_main_no_extreme_coords(self, monkeypatch, tmp_path, - gff_no_extremes): + def test_main_no_extreme_coords( + self, monkeypatch, tmp_path, gff_no_extremes + ): """Test main function with no extreme coords.""" in_gff, pre_gff, mir_gff = gff_no_extremes @@ -134,19 +139,17 @@ def test_main_no_extreme_coords(self, monkeypatch, tmp_path, mir_out = tmp_path / "extended_mirna_annotation_6_nt.gff3" monkeypatch.setattr( - sys, 'argv', - ['mirna_extension', - str(in_gff), - '--outdir', str(tmp_path) - ] + sys, + "argv", + ["mirna_extension", str(in_gff), "--outdir", str(tmp_path)], ) args = parse_arguments().parse_args() main(args) - with open(pre_gff, 'r') as expected, open(primir_out, 'r') as output: + with open(pre_gff, "r") as expected, open(primir_out, "r") as output: assert output.read() == expected.read() - with open(mir_gff, 'r') as expected, open(mir_out, 'r') as output: + with open(mir_gff, "r") as expected, open(mir_out, "r") as output: assert output.read() == expected.read() def test_main_extreme_coords(self, monkeypatch, tmp_path, gff_extremes): @@ -157,23 +160,22 @@ def test_main_extreme_coords(self, monkeypatch, tmp_path, gff_extremes): mir_out = tmp_path / "extended_mirna_annotation_6_nt.gff3" monkeypatch.setattr( - sys, 'argv', - ['mirna_extension', - str(in_gff), - '--outdir', str(tmp_path) - ] + sys, + "argv", + ["mirna_extension", str(in_gff), "--outdir", str(tmp_path)], ) args = parse_arguments().parse_args() main(args) - with open(pre_gff, 'r') as expected, open(primir_out, 'r') as output: + with open(pre_gff, "r") as expected, open(primir_out, "r") as output: assert output.read() == expected.read() - with open(mir_gff, 'r') as expected, open(mir_out, 'r') as output: + with open(mir_gff, "r") as expected, open(mir_out, "r") as output: assert output.read() == expected.read() - def test_main_extreme_coords_limit_size(self, monkeypatch, tmp_path, - gff_extremes_chr): + def test_main_extreme_coords_limit_size( + self, monkeypatch, tmp_path, gff_extremes_chr + ): """Test main function with extreme coords and limited by chr size.""" chr_size, in_gff, pre_gff, mir_gff = gff_extremes_chr @@ -181,24 +183,28 @@ def test_main_extreme_coords_limit_size(self, monkeypatch, tmp_path, mir_out = tmp_path / "extended_mirna_annotation_6_nt.gff3" monkeypatch.setattr( - sys, 'argv', - ['mirna_extension', - str(in_gff), - '--outdir', str(tmp_path), - '--chr', str(chr_size) - ] + sys, + "argv", + [ + "mirna_extension", + str(in_gff), + "--outdir", + str(tmp_path), + "--chr", + str(chr_size), + ], ) args = parse_arguments().parse_args() main(args) - with open(pre_gff, 'r') as expected, open(primir_out, 'r') as output: + with open(pre_gff, "r") as expected, open(primir_out, "r") as output: assert output.read() == expected.read() - with open(mir_gff, 'r') as expected, open(mir_out, 'r') as output: + with open(mir_gff, "r") as expected, open(mir_out, "r") as output: assert output.read() == expected.read() -class TestLoadGffFile(): +class TestLoadGffFile: """Test for the 'load_gff_file' method.""" def test_load_gff_file(self, gff_no_extremes): @@ -210,22 +216,34 @@ def test_load_gff_file(self, gff_no_extremes): assert mirnaObject is not None assert isinstance(mirnaObject.db, gffutils.FeatureDB) - assert len(list( - mirnaObject.db.features_of_type("miRNA_primary_transcript"))) == 2 + assert ( + len( + list( + mirnaObject.db.features_of_type("miRNA_primary_transcript") + ) + ) + == 2 + ) assert len(list(mirnaObject.db.features_of_type("miRNA"))) == 3 def test_load_gff_file_std(self, monkeypatch, gff_no_extremes): """Test input loading from standard input.""" in_file, pre_exp, mir_exp = gff_no_extremes - monkeypatch.setattr(sys, 'stdin', str(in_file)) + monkeypatch.setattr(sys, "stdin", str(in_file)) mirnaObject = MirnaExtension() mirnaObject.load_gff_file() assert mirnaObject is not None assert isinstance(mirnaObject.db, gffutils.FeatureDB) - assert len(list( - mirnaObject.db.features_of_type("miRNA_primary_transcript"))) == 2 + assert ( + len( + list( + mirnaObject.db.features_of_type("miRNA_primary_transcript") + ) + ) + == 2 + ) assert len(list(mirnaObject.db.features_of_type("miRNA"))) == 3 @@ -243,10 +261,10 @@ def test_extend_mirnas_no_extreme_coords(self, tmp_path, gff_no_extremes): mirnaObject.load_gff_file(str(in_file)) mirnaObject.extend_mirnas(primir_out=primir_out, mir_out=mir_out) - with open(primir_out, 'r') as output, open(pre_exp, 'r') as expected: + with open(primir_out, "r") as output, open(pre_exp, "r") as expected: assert output.read() == expected.read() - with open(mir_out, 'r') as output, open(mir_exp, 'r') as expected: + with open(mir_out, "r") as output, open(mir_exp, "r") as expected: assert output.read() == expected.read() def test_extend_mirnas_extreme_coords(self, tmp_path, gff_extremes): @@ -260,14 +278,15 @@ def test_extend_mirnas_extreme_coords(self, tmp_path, gff_extremes): mirnaObject.load_gff_file(str(in_file)) mirnaObject.extend_mirnas(primir_out=primir_out, mir_out=mir_out) - with open(primir_out, 'r') as output, open(pre_exp, 'r') as expected: + with open(primir_out, "r") as output, open(pre_exp, "r") as expected: assert output.read() == expected.read() - with open(mir_out, 'r') as output, open(mir_exp, 'r') as expected: + with open(mir_out, "r") as output, open(mir_exp, "r") as expected: assert output.read() == expected.read() - def test_extend_mirnas_extreme_coords_chr_boundaries(self, tmp_path, - gff_extremes_chr): + def test_extend_mirnas_extreme_coords_chr_boundaries( + self, tmp_path, gff_extremes_chr + ): """Test miRNA extension with extreme coordinates and chr boundaries.""" chr_size, in_file, pre_exp, mir_exp = gff_extremes_chr @@ -275,19 +294,19 @@ def test_extend_mirnas_extreme_coords_chr_boundaries(self, tmp_path, mir_out = tmp_path / "extended_mirna_annotation_6_nt.gff3" len_dict = {} - with open(chr_size, 'r') as f: + with open(chr_size, "r") as f: for line in f: - line = line.strip().split('\t') + line = line.strip().split("\t") len_dict[line[0]] = int(line[1]) mirnaObject = MirnaExtension() mirnaObject.load_gff_file(str(in_file)) - mirnaObject.extend_mirnas(primir_out=primir_out, - mir_out=mir_out, - seq_lengths=len_dict) + mirnaObject.extend_mirnas( + primir_out=primir_out, mir_out=mir_out, seq_lengths=len_dict + ) - with open(primir_out, 'r') as output, open(pre_exp, 'r') as expected: + with open(primir_out, "r") as output, open(pre_exp, "r") as expected: assert output.read() == expected.read() - with open(mir_out, 'r') as output, open(mir_exp, 'r') as expected: + with open(mir_out, "r") as output, open(mir_exp, "r") as expected: assert output.read() == expected.read() diff --git a/scripts/tests/test_mirna_quantification.py b/scripts/tests/test_mirna_quantification.py index 6103527..cc044b1 100644 --- a/scripts/tests/test_mirna_quantification.py +++ b/scripts/tests/test_mirna_quantification.py @@ -13,7 +13,7 @@ contribution, get_name, main, - parse_arguments + parse_arguments, ) @@ -158,9 +158,11 @@ def test_no_input(self, monkeypatch): """Call without input file.""" with pytest.raises(SystemExit) as sysex: monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - ] + sys, + "argv", + [ + "mirna_quantification", + ], ) parse_arguments().parse_args() assert sysex.value.code == 2 @@ -170,11 +172,14 @@ def test_correct_input(self, monkeypatch, empty_file): in_sam = empty_file monkeypatch.setattr( - sys, 'argv', - ['mirna__quantification', - str(in_sam), - '--lib', 'test_lib', - ] + sys, + "argv", + [ + "mirna__quantification", + str(in_sam), + "--lib", + "test_lib", + ], ) args = parse_arguments().parse_args() assert isinstance(args, argparse.Namespace) @@ -185,10 +190,13 @@ def test_too_many_input_files(self, monkeypatch, empty_file): with pytest.raises(SystemExit) as sysex: monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - str(in_sam), str(in_sam), - ] + sys, + "argv", + [ + "mirna_quantification", + str(in_sam), + str(in_sam), + ], ) parse_arguments().parse_args() assert sysex.value.code == 2 @@ -198,25 +206,31 @@ def test_all_input(self, monkeypatch, empty_file): in_sam = empty_file monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - str(in_sam), - '--count', - '--len', - '--read-ids', - '--collapsed', - '--nh', - '--tag', 'YW', - '--outdir', 'Path.cwd()', - '--lib', 'test_lib', - '--mir-list', '[mirna, isomir]' - ] + sys, + "argv", + [ + "mirna_quantification", + str(in_sam), + "--count", + "--len", + "--read-ids", + "--collapsed", + "--nh", + "--tag", + "YW", + "--outdir", + "Path.cwd()", + "--lib", + "test_lib", + "--mir-list", + "[mirna, isomir]", + ], ) args = parse_arguments().parse_args() assert isinstance(args, argparse.Namespace) -class TestGetContribution(): +class TestGetContribution: """Test 'get_contribution()' function.""" def test_collapsed_nh(self, alns): @@ -268,16 +282,19 @@ def test_main_empty_sam_file(self, monkeypatch, tmp_path, empty_file): output = tmp_path / "mirna_counts_lib" monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - str(empty_in), - '--outdir', str(tmp_path), - ] + sys, + "argv", + [ + "mirna_quantification", + str(empty_in), + "--outdir", + str(tmp_path), + ], ) args = parse_arguments().parse_args() main(args) - with open(empty_out, 'r') as expected, open(output, 'r') as out_file: + with open(empty_out, "r") as expected, open(output, "r") as out_file: assert out_file.read() == expected.read() def test_main_isomir_mirna_sam_file(self, monkeypatch, tmp_path, sam_file): @@ -286,106 +303,131 @@ def test_main_isomir_mirna_sam_file(self, monkeypatch, tmp_path, sam_file): output = tmp_path / "mirna_counts_lib" monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - str(infile), - '--collapsed', - '--nh', - '--outdir', str(tmp_path), - ] + sys, + "argv", + [ + "mirna_quantification", + str(infile), + "--collapsed", + "--nh", + "--outdir", + str(tmp_path), + ], ) args = parse_arguments().parse_args() main(args) - with open(out_table, 'r') as expected, open(output, 'r') as out_file: + with open(out_table, "r") as expected, open(output, "r") as out_file: assert out_file.read() == expected.read() - def test_main_iso_sam_file(self, monkeypatch, tmp_path, - iso_mirna_sam_file): + def test_main_iso_sam_file( + self, monkeypatch, tmp_path, iso_mirna_sam_file + ): """Test main function tabulating only isomiRs.""" infile, iso_out_table, mirna_out_table = iso_mirna_sam_file mirna_output = tmp_path / "mirna_counts_lib" monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - str(infile), - '--collapsed', - '--nh', - '--outdir', str(tmp_path), - '--mir-list', "isomir", - ] + sys, + "argv", + [ + "mirna_quantification", + str(infile), + "--collapsed", + "--nh", + "--outdir", + str(tmp_path), + "--mir-list", + "isomir", + ], ) args = parse_arguments().parse_args() main(args) - with (open(iso_out_table, 'r') as expected, - open(mirna_output, 'r') as out_file): + with open(iso_out_table, "r") as expected, open( + mirna_output, "r" + ) as out_file: assert out_file.read() == expected.read() - def test_main_mirna_sam_file(self, monkeypatch, tmp_path, - iso_mirna_sam_file): + def test_main_mirna_sam_file( + self, monkeypatch, tmp_path, iso_mirna_sam_file + ): """Test main function tabulating only canonical miRNA.""" infile, iso_out_table, mirna_out_table = iso_mirna_sam_file mirna_output = tmp_path / "mirna_counts_lib" monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - str(infile), - '--collapsed', - '--nh', - '--outdir', str(tmp_path), - '--mir-list', "mirna" - ] + sys, + "argv", + [ + "mirna_quantification", + str(infile), + "--collapsed", + "--nh", + "--outdir", + str(tmp_path), + "--mir-list", + "mirna", + ], ) args = parse_arguments().parse_args() main(args) - with (open(mirna_out_table, 'r') as expected, - open(mirna_output, 'r') as out_file): + with ( + open(mirna_out_table, "r") as expected, + open(mirna_output, "r") as out_file, + ): assert out_file.read() == expected.read() - def test_main_xn_tag_sam_file(self, monkeypatch, tmp_path, - xn_tag_sam_file): + def test_main_xn_tag_sam_file( + self, monkeypatch, tmp_path, xn_tag_sam_file + ): """Test main function with feature name in the XN tag.""" infile, out_table = xn_tag_sam_file output = tmp_path / "mirna_counts_lib" monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - str(infile), - '--collapsed', - '--nh', - '--tag', 'XN', - '--outdir', str(tmp_path), - ] + sys, + "argv", + [ + "mirna_quantification", + str(infile), + "--collapsed", + "--nh", + "--tag", + "XN", + "--outdir", + str(tmp_path), + ], ) args = parse_arguments().parse_args() main(args) - with open(out_table, 'r') as expected, open(output, 'r') as out_file: + with open(out_table, "r") as expected, open(output, "r") as out_file: assert out_file.read() == expected.read() - def test_main_nh_missing_sam_file(self, monkeypatch, tmp_path, - nh_missing_sam_file): + def test_main_nh_missing_sam_file( + self, monkeypatch, tmp_path, nh_missing_sam_file + ): """Test main function with some missing NH tag in SAM file.""" infile, out_table = nh_missing_sam_file output = tmp_path / "mirna_counts_lib" monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - str(infile), - '--collapsed', - '--outdir', str(tmp_path), - ] + sys, + "argv", + [ + "mirna_quantification", + str(infile), + "--collapsed", + "--outdir", + str(tmp_path), + ], ) args = parse_arguments().parse_args() main(args) - with open(out_table, 'r') as expected, open(output, 'r') as out_file: + with open(out_table, "r") as expected, open(output, "r") as out_file: assert out_file.read() == expected.read() def test_main_seq_len_sam_file(self, monkeypatch, tmp_path, len_sam_file): @@ -394,19 +436,22 @@ def test_main_seq_len_sam_file(self, monkeypatch, tmp_path, len_sam_file): output = tmp_path / "mirna_counts_lib" monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - str(infile), - '--collapsed', - '--nh', - '--len', - '--outdir', str(tmp_path), - ] + sys, + "argv", + [ + "mirna_quantification", + str(infile), + "--collapsed", + "--nh", + "--len", + "--outdir", + str(tmp_path), + ], ) args = parse_arguments().parse_args() main(args) - with open(out_table, 'r') as expected, open(output, 'r') as out_file: + with open(out_table, "r") as expected, open(output, "r") as out_file: assert out_file.read() == expected.read() def test_main_read_sam_file(self, monkeypatch, tmp_path, read_sam_file): @@ -415,80 +460,95 @@ def test_main_read_sam_file(self, monkeypatch, tmp_path, read_sam_file): output = tmp_path / "mirna_counts_lib" monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - str(infile), - '--collapsed', - '--nh', - '--read-ids', - '--outdir', str(tmp_path), - ] + sys, + "argv", + [ + "mirna_quantification", + str(infile), + "--collapsed", + "--nh", + "--read-ids", + "--outdir", + str(tmp_path), + ], ) args = parse_arguments().parse_args() main(args) - with open(out_table, 'r') as expected, open(output, 'r') as out_file: + with open(out_table, "r") as expected, open(output, "r") as out_file: assert out_file.read() == expected.read() - def test_main_read_len_sam_file(self, monkeypatch, tmp_path, - read_len_sam_file): + def test_main_read_len_sam_file( + self, monkeypatch, tmp_path, read_len_sam_file + ): """Test main function with read IDs and feature length im output.""" infile, out_table = read_len_sam_file output = tmp_path / "mirna_counts_lib" monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - str(infile), - '--collapsed', - '--nh', - '--len', - '--read-ids', - '--outdir', str(tmp_path), - ] + sys, + "argv", + [ + "mirna_quantification", + str(infile), + "--collapsed", + "--nh", + "--len", + "--read-ids", + "--outdir", + str(tmp_path), + ], ) args = parse_arguments().parse_args() main(args) - with open(out_table, 'r') as expected, open(output, 'r') as out_file: + with open(out_table, "r") as expected, open(output, "r") as out_file: assert out_file.read() == expected.read() - def test_main_uncollpased_sam_file(self, monkeypatch, tmp_path, - uncollapsed_sam_file): + def test_main_uncollpased_sam_file( + self, monkeypatch, tmp_path, uncollapsed_sam_file + ): """Test main function with uncollapsed SAM file.""" infile, out_table = uncollapsed_sam_file output = tmp_path / "mirna_counts_lib" monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - str(infile), - '--nh', - '--outdir', str(tmp_path), - ] + sys, + "argv", + [ + "mirna_quantification", + str(infile), + "--nh", + "--outdir", + str(tmp_path), + ], ) args = parse_arguments().parse_args() main(args) - with open(out_table, 'r') as expected, open(output, 'r') as out_file: + with open(out_table, "r") as expected, open(output, "r") as out_file: assert out_file.read() == expected.read() - def test_main_uncollap_miss_nh_sam_file(self, monkeypatch, tmp_path, - uncollapsed_missing_nh_sam_file): + def test_main_uncollap_miss_nh_sam_file( + self, monkeypatch, tmp_path, uncollapsed_missing_nh_sam_file + ): """Test main function with uncollapsed SAM file and missing NH tags.""" infile, out_table = uncollapsed_missing_nh_sam_file output = tmp_path / "mirna_counts_lib" monkeypatch.setattr( - sys, 'argv', - ['mirna_quantification', - str(infile), - '--count', - '--outdir', str(tmp_path), - ] + sys, + "argv", + [ + "mirna_quantification", + str(infile), + "--count", + "--outdir", + str(tmp_path), + ], ) args = parse_arguments().parse_args() main(args) - with open(out_table, 'r') as expected, open(output, 'r') as out_file: + with open(out_table, "r") as expected, open(output, "r") as out_file: assert out_file.read() == expected.read() diff --git a/scripts/tests/test_oligomap_output_to_sam_nh_filtered.py b/scripts/tests/test_oligomap_output_to_sam_nh_filtered.py index b4ae339..ac63559 100644 --- a/scripts/tests/test_oligomap_output_to_sam_nh_filtered.py +++ b/scripts/tests/test_oligomap_output_to_sam_nh_filtered.py @@ -12,7 +12,7 @@ get_cigar_md, get_sam_fields, main, - parse_arguments + parse_arguments, ) @@ -54,28 +54,106 @@ def single_read(): def aln_fields(): """Create sample alignment as a Fields class NamedTuple.""" # Perfect alignment - field_1 = Fields("read_1", "0", "19", "44377", "255", "19M", '*', '0', '0', - "CTACAAAGGGAAGCACTTT", '*', "NM:i:0", "MD:Z:19") + field_1 = Fields( + "read_1", + "0", + "19", + "44377", + "255", + "19M", + "*", + "0", + "0", + "CTACAAAGGGAAGCACTTT", + "*", + "NM:i:0", + "MD:Z:19", + ) # Alignment with a mismatch in the first position - field_2 = Fields("read_1", '0', "19", "53471", "255", "19M", '*', '0', '0', - "CTACAAAGGGAAGCACTTT", '*', "NM:i:1", "MD:Z:G18") + field_2 = Fields( + "read_1", + "0", + "19", + "53471", + "255", + "19M", + "*", + "0", + "0", + "CTACAAAGGGAAGCACTTT", + "*", + "NM:i:1", + "MD:Z:G18", + ) # Alignment with a mismatch in the last position - field_3 = Fields("read_1", "0", "19", "44278", "255", "19M", '*', '0', '0', - "CTACAAAGGGAAGCACTTT", '*', "NM:i:1", "MD:Z:18C") + field_3 = Fields( + "read_1", + "0", + "19", + "44278", + "255", + "19M", + "*", + "0", + "0", + "CTACAAAGGGAAGCACTTT", + "*", + "NM:i:1", + "MD:Z:18C", + ) # Alignment with a mismatch in the middle of the read sequence - field_4 = Fields("read_1", "0", "19", "50971", "255", "19M", '*', '0', '0', - "CTACAAAGGGAAGCACTTT", '*', "NM:i:1", "MD:Z:14C4") + field_4 = Fields( + "read_1", + "0", + "19", + "50971", + "255", + "19M", + "*", + "0", + "0", + "CTACAAAGGGAAGCACTTT", + "*", + "NM:i:1", + "MD:Z:14C4", + ) # Alignment with an insertion at read's first position - field_5 = Fields("read_2", "16", "19", "7627", "255", "1I22M", '*', '0', - '0', "AAAGCACCTCCAGAGCTTGAAGC", '*', "NM:i:1", "MD:Z:23") + field_5 = Fields( + "read_2", + "16", + "19", + "7627", + "255", + "1I22M", + "*", + "0", + "0", + "AAAGCACCTCCAGAGCTTGAAGC", + "*", + "NM:i:1", + "MD:Z:23", + ) # Alignment with an insertion in the middle of the read sequence - field_6 = Fields("read_2", "16", "19", "7886", "255", "9M1I12M", '*', '0', - '0', "AAAGCACCTCCAGAGCTTGAAGC", '*', "NM:i:1", "MD:Z:23") + field_6 = Fields( + "read_2", + "16", + "19", + "7886", + "255", + "9M1I12M", + "*", + "0", + "0", + "AAAGCACCTCCAGAGCTTGAAGC", + "*", + "NM:i:1", + "MD:Z:23", + ) return [field_1, field_2, field_3, field_4, field_5, field_6] @@ -168,8 +246,7 @@ def test_no_files(self, monkeypatch): """Call without input nor output files.""" with pytest.raises(SystemExit) as sysex: monkeypatch.setattr( - sys, 'argv', - ['oligomap_output_to_sam_nh_filtered'] + sys, "argv", ["oligomap_output_to_sam_nh_filtered"] ) parse_arguments().parse_args() assert sysex.value.code == 2 @@ -179,10 +256,12 @@ def test_in_files(self, monkeypatch, empty_file): empty_in = empty_file monkeypatch.setattr( - sys, 'argv', - ['oligomap_output_to_sam_nh_filtered', - str(empty_in), - ] + sys, + "argv", + [ + "oligomap_output_to_sam_nh_filtered", + str(empty_in), + ], ) args = parse_arguments().parse_args() @@ -193,11 +272,14 @@ def test_all_arguments(self, monkeypatch, genome_nh_2): fa_in, sam_out = genome_nh_2 monkeypatch.setattr( - sys, 'argv', - ['oligomap_output_to_sam_nh_filtered', - str(fa_in), - '-n', '100', - ] + sys, + "argv", + [ + "oligomap_output_to_sam_nh_filtered", + str(fa_in), + "-n", + "100", + ], ) args = parse_arguments().parse_args() @@ -211,74 +293,94 @@ def test_perfect_aln(self, alns): """Test perfect alignment.""" result = ("19M", "MD:Z:19") - assert get_cigar_md(alns[0][0], alns[0][1], - alns[0][2], alns[0][3]) == result + assert ( + get_cigar_md(alns[0][0], alns[0][1], alns[0][2], alns[0][3]) + == result + ) def test_mm_first_pos_aln(self, alns): """Test mismatch at read's first position.""" result = ("19M", "MD:Z:G18") - assert get_cigar_md(alns[1][0], alns[1][1], - alns[1][2], alns[1][3]) == result + assert ( + get_cigar_md(alns[1][0], alns[1][1], alns[1][2], alns[1][3]) + == result + ) def test_mm_last_pos_aln(self, alns): """Test mismatch at read's last position.""" result = ("19M", "MD:Z:18C") - assert get_cigar_md(alns[2][0], alns[2][1], - alns[2][2], alns[2][3]) == result + assert ( + get_cigar_md(alns[2][0], alns[2][1], alns[2][2], alns[2][3]) + == result + ) def test_mm_middle_aln(self, alns): """Test mismatch in the middle of the read.""" result = ("19M", "MD:Z:14C4") - assert get_cigar_md(alns[3][0], alns[3][1], - alns[3][2], alns[3][3]) == result + assert ( + get_cigar_md(alns[3][0], alns[3][1], alns[3][2], alns[3][3]) + == result + ) def test_in_first_pos_aln(self, alns): """Test insertion at read's first position.""" result = ("1I22M", "MD:Z:23") - assert get_cigar_md(alns[4][0], alns[4][1], - alns[4][2], alns[4][3]) == result + assert ( + get_cigar_md(alns[4][0], alns[4][1], alns[4][2], alns[4][3]) + == result + ) def test_in_last_pos_aln(self, alns): """Test insertion at read's last position.""" result = ("22M1I", "MD:Z:23") - assert get_cigar_md(alns[5][0], alns[5][1], - alns[5][2], alns[5][3]) == result + assert ( + get_cigar_md(alns[5][0], alns[5][1], alns[5][2], alns[5][3]) + == result + ) def test_in_middle_aln(self, alns): """Test insertion in the middle of the read.""" result = ("9M1I13M", "MD:Z:23") - assert get_cigar_md(alns[6][0], alns[6][1], - alns[6][2], alns[6][3]) == result + assert ( + get_cigar_md(alns[6][0], alns[6][1], alns[6][2], alns[6][3]) + == result + ) def test_del_first_pos_aln(self, alns): """Test deletion at read's first position.""" result = ("1D22M", "MD:Z:^T22") - assert get_cigar_md(alns[7][0], alns[7][1], - alns[7][2], alns[7][3]) == result + assert ( + get_cigar_md(alns[7][0], alns[7][1], alns[7][2], alns[7][3]) + == result + ) def test_del_last_pos_aln(self, alns): """Test deletion at read's last position.""" result = ("22M1D", "MD:Z:22^A0") - assert get_cigar_md(alns[8][0], alns[8][1], - alns[8][2], alns[8][3]) == result + assert ( + get_cigar_md(alns[8][0], alns[8][1], alns[8][2], alns[8][3]) + == result + ) def test_del_middle_aln(self, alns): """Test deletion in the middle of the read.""" result = ("11M1D10M", "MD:Z:11^A10") - assert get_cigar_md(alns[9][0], alns[9][1], - alns[9][2], alns[9][3]) == result + assert ( + get_cigar_md(alns[9][0], alns[9][1], alns[9][2], alns[9][3]) + == result + ) -class TestGetSAMFields(): +class TestGetSAMFields: """Test 'get_sam_fields()' function.""" def test_pos_strand_no_err(self, alns, aln_fields): @@ -287,8 +389,12 @@ def test_pos_strand_no_err(self, alns, aln_fields): line2 = "19" line3 = "errors: 0 orientation: +" - assert get_sam_fields([line1, line2, line3, alns[0][1], - alns[0][2], alns[0][3]]) == aln_fields[0] + assert ( + get_sam_fields( + [line1, line2, line3, alns[0][1], alns[0][2], alns[0][3]] + ) + == aln_fields[0] + ) def test_neg_strand_one_err(self, alns, aln_fields): """Test alignment with an insertion in the negative strand.""" @@ -296,8 +402,12 @@ def test_neg_strand_one_err(self, alns, aln_fields): line2 = "19" line3 = "errors: 1 orientation: -" - assert get_sam_fields([line1, line2, line3, alns[6][1], - alns[6][2], alns[6][3]]) == aln_fields[5] + assert ( + get_sam_fields( + [line1, line2, line3, alns[6][1], alns[6][2], alns[6][3]] + ) + == aln_fields[5] + ) class TestEvalAln: @@ -306,43 +416,43 @@ class TestEvalAln: def test_eval_empty_dict_new_read(self, aln_fields): """Test evaluation with a new read and an empty dictionary.""" d = dict() - minerr_nh = {"read_0": ['0', 1]} + minerr_nh = {"read_0": ["0", 1]} aln = aln_fields[0] nhfilter = None eval_aln(nhfilter, d, minerr_nh, aln) assert list(d.keys())[0] == aln.read_name - assert minerr_nh[aln.read_name] == ['0', 1] + assert minerr_nh[aln.read_name] == ["0", 1] def test_eval_empty_dict_smaller_error(self, aln_fields): """Test evaluation with a smaller error and an empty dictionary.""" d = dict() - minerr_nh = {"read_1": ['1', 1]} + minerr_nh = {"read_1": ["1", 1]} aln = aln_fields[0] nhfilter = None eval_aln(nhfilter, d, minerr_nh, aln) assert list(d.keys())[0] == aln.read_name - assert minerr_nh[aln.read_name] == ['0', 1] + assert minerr_nh[aln.read_name] == ["0", 1] def test_increase_nh_no_filter(self, aln_fields): """Test evaluation when increasing NH without a maximum value.""" d = {"read_1": [aln_fields[1], aln_fields[2]]} - minerr_nh = {"read_1": ['1', 2]} + minerr_nh = {"read_1": ["1", 2]} aln = aln_fields[3] nhfilter = None eval_aln(nhfilter, d, minerr_nh, aln) assert len(d[aln.read_name]) == 3 - assert minerr_nh[aln.read_name] == ['1', 3] + assert minerr_nh[aln.read_name] == ["1", 3] def test_exceed_nh_filter_2(self, capsys, aln_fields): """Test evaluation when exceeding the maximum NH set to 2.""" d = {"read_1": [aln_fields[1], aln_fields[2]]} - minerr_nh = {"read_1": ['1', 2]} + minerr_nh = {"read_1": ["1", 2]} aln = aln_fields[3] nhfilter = 2 @@ -350,25 +460,25 @@ def test_exceed_nh_filter_2(self, capsys, aln_fields): captured = capsys.readouterr() assert len(d) == 0 - assert minerr_nh[aln.read_name] == ['1', 3] + assert minerr_nh[aln.read_name] == ["1", 3] assert captured.err == "Filtered by NH | Read read_1 | Errors = 1\n" def test_no_exceed_nh_filter_2(self, aln_fields): """Test evaluation when increasing NH with maximum value of 2.""" d = {"read_1": [aln_fields[1]]} - minerr_nh = {"read_1": ['1', 1]} + minerr_nh = {"read_1": ["1", 1]} aln = aln_fields[2] nhfilter = 2 eval_aln(nhfilter, d, minerr_nh, aln) assert len(d[aln.read_name]) == 2 - assert minerr_nh[aln.read_name] == ['1', 2] + assert minerr_nh[aln.read_name] == ["1", 2] def test_smaller_min_error(self, capsys, aln_fields): """Test evaluation when having a smaller minimumm error.""" d = {"read_1": [aln_fields[1], aln_fields[2]]} - minerr_nh = {"read_1": ['1', 2]} + minerr_nh = {"read_1": ["1", 2]} aln = aln_fields[0] nhfilter = None @@ -376,7 +486,7 @@ def test_smaller_min_error(self, capsys, aln_fields): captured = capsys.readouterr() assert len(d[aln.read_name]) == 1 - assert minerr_nh[aln.read_name] == ['0', 1] + assert minerr_nh[aln.read_name] == ["0", 1] assert captured.err == "Filtered by ERROR | Read read_1 | Errors = 1\n" def test_different_read(self, capsys, tmp_path, aln_fields, single_read): @@ -384,7 +494,7 @@ def test_different_read(self, capsys, tmp_path, aln_fields, single_read): out_file = single_read d = {"read_1": [aln_fields[1], aln_fields[2]]} - minerr_nh = {"read_1": ['1', 2]} + minerr_nh = {"read_1": ["1", 2]} aln = aln_fields[4] nhfilter = None @@ -395,7 +505,7 @@ def test_different_read(self, capsys, tmp_path, aln_fields, single_read): assert len(minerr_nh) == 1 assert captured.err == "Written read read_1 | Errors = 1 | NH = 2\n" - with open(out_file, 'r') as expected: + with open(out_file, "r") as expected: assert captured.out == expected.read() @@ -407,16 +517,18 @@ def test_main_empty_file(self, monkeypatch, capsys, empty_file): empty_in = empty_file monkeypatch.setattr( - sys, 'argv', - ['oligomap_output_to_sam_nh_filtered', - str(empty_in), - ] + sys, + "argv", + [ + "oligomap_output_to_sam_nh_filtered", + str(empty_in), + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(empty_in, 'r') as expected: + with open(empty_in, "r") as expected: assert captured.out == expected.read() def test_main_max_nh_2(self, monkeypatch, capsys, genome_nh_2): @@ -424,33 +536,39 @@ def test_main_max_nh_2(self, monkeypatch, capsys, genome_nh_2): in_file, out_file = genome_nh_2 monkeypatch.setattr( - sys, 'argv', - ['oligomap_output_to_sam_nh_filtered', - str(in_file), - '-n', '2', - ] + sys, + "argv", + [ + "oligomap_output_to_sam_nh_filtered", + str(in_file), + "-n", + "2", + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(out_file, 'r') as expected: + with open(out_file, "r") as expected: assert captured.out == expected.read() - def test_main_no_nh_transcriptome(self, monkeypatch, capsys, - transcriptome_no_nh): + def test_main_no_nh_transcriptome( + self, monkeypatch, capsys, transcriptome_no_nh + ): """Test main function with no NH set for transcriptome mappings.""" in_file, out_file = transcriptome_no_nh monkeypatch.setattr( - sys, 'argv', - ['oligomap_output_to_sam_nh_filtered', - str(in_file), - ] + sys, + "argv", + [ + "oligomap_output_to_sam_nh_filtered", + str(in_file), + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(out_file, 'r') as expected: + with open(out_file, "r") as expected: assert captured.out == expected.read() diff --git a/scripts/tests/test_primir_quantification.py b/scripts/tests/test_primir_quantification.py index 51d12f5..55c6502 100644 --- a/scripts/tests/test_primir_quantification.py +++ b/scripts/tests/test_primir_quantification.py @@ -6,10 +6,7 @@ import pytest -from ..primir_quantification import ( - main, - parse_arguments -) +from ..primir_quantification import main, parse_arguments @pytest.fixture @@ -90,9 +87,11 @@ def test_no_input(self, monkeypatch): """Call without input file.""" with pytest.raises(SystemExit) as sysex: monkeypatch.setattr( - sys, 'argv', - ['primir_quantification', - ] + sys, + "argv", + [ + "primir_quantification", + ], ) parse_arguments().parse_args() assert sysex.value.code == 2 @@ -102,10 +101,12 @@ def test_correct_input(self, monkeypatch, bed_file): in_bed, out_table = bed_file monkeypatch.setattr( - sys, 'argv', - ['primir_quantification', - str(in_bed), - ] + sys, + "argv", + [ + "primir_quantification", + str(in_bed), + ], ) args = parse_arguments().parse_args() assert isinstance(args, argparse.Namespace) @@ -116,10 +117,13 @@ def test_too_many_input_files(self, monkeypatch, bed_file): with pytest.raises(SystemExit) as sysex: monkeypatch.setattr( - sys, 'argv', - ['primir_quantification', - str(in_bed), str(in_bed), - ] + sys, + "argv", + [ + "primir_quantification", + str(in_bed), + str(in_bed), + ], ) parse_arguments().parse_args() assert sysex.value.code == 2 @@ -129,15 +133,18 @@ def test_all_input(self, monkeypatch, bed_file): in_bed, out_table = bed_file monkeypatch.setattr( - sys, 'argv', - ['primir_quantification', - str(in_bed), - '--id', "name", - '--feat-extension', - '--read-ids', - '--collapsed', - '--nh' - ] + sys, + "argv", + [ + "primir_quantification", + str(in_bed), + "--id", + "name", + "--feat-extension", + "--read-ids", + "--collapsed", + "--nh", + ], ) args = parse_arguments().parse_args() assert isinstance(args, argparse.Namespace) @@ -151,54 +158,62 @@ def test_main_empty_bed_file(self, monkeypatch, capsys, empty_file): empty_file = empty_file monkeypatch.setattr( - sys, 'argv', - ['primir_quantification', - str(empty_file), - ] + sys, + "argv", + [ + "primir_quantification", + str(empty_file), + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(empty_file, 'r') as out_file: + with open(empty_file, "r") as out_file: assert captured.out == out_file.read() - def test_main_no_extension(self, monkeypatch, capsys, - bed_no_extension_files): + def test_main_no_extension( + self, monkeypatch, capsys, bed_no_extension_files + ): """Test main function with no extension in features names.""" in_bed, expected_out = bed_no_extension_files monkeypatch.setattr( - sys, 'argv', - ['primir_quantification', - str(in_bed), - ] + sys, + "argv", + [ + "primir_quantification", + str(in_bed), + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(expected_out, 'r') as out_file: + with open(expected_out, "r") as out_file: assert captured.out == out_file.read() - def test_main_id_extension(self, monkeypatch, capsys, - bed_extension_id_files): + def test_main_id_extension( + self, monkeypatch, capsys, bed_extension_id_files + ): """Test main function with extension in feature name and read names.""" in_bed, expected_out = bed_extension_id_files monkeypatch.setattr( - sys, 'argv', - ['primir_quantification', - str(in_bed), - '--feat-extension', - '--read-ids', - ] + sys, + "argv", + [ + "primir_quantification", + str(in_bed), + "--feat-extension", + "--read-ids", + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(expected_out, 'r') as out_file: + with open(expected_out, "r") as out_file: assert captured.out == out_file.read() def test_main_id(self, monkeypatch, capsys, bed_id_files): @@ -206,36 +221,41 @@ def test_main_id(self, monkeypatch, capsys, bed_id_files): in_bed, expected_out = bed_id_files monkeypatch.setattr( - sys, 'argv', - ['primir_quantification', - str(in_bed), - '--read-ids', - ] + sys, + "argv", + [ + "primir_quantification", + str(in_bed), + "--read-ids", + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(expected_out, 'r') as out_file: + with open(expected_out, "r") as out_file: assert captured.out == out_file.read() - def test_main_some_extension_file(self, monkeypatch, capsys, - bed_some_extension_files): + def test_main_some_extension_file( + self, monkeypatch, capsys, bed_some_extension_files + ): """Test main function with read names.""" in_bed, expected_out = bed_some_extension_files monkeypatch.setattr( - sys, 'argv', - ['primir_quantification', - str(in_bed), - '--feat-extension', - ] + sys, + "argv", + [ + "primir_quantification", + str(in_bed), + "--feat-extension", + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(expected_out, 'r') as out_file: + with open(expected_out, "r") as out_file: assert captured.out == out_file.read() def test_main_collpased_nh_file(self, monkeypatch, capsys, bed_file): @@ -243,37 +263,42 @@ def test_main_collpased_nh_file(self, monkeypatch, capsys, bed_file): in_bed, expected_out = bed_file monkeypatch.setattr( - sys, 'argv', - ['primir_quantification', - str(in_bed), - '--collapsed', - '--nh', - ] + sys, + "argv", + [ + "primir_quantification", + str(in_bed), + "--collapsed", + "--nh", + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(expected_out, 'r') as out_file: + with open(expected_out, "r") as out_file: assert captured.out == out_file.read() - def test_main_collpased_file(self, monkeypatch, capsys, - bed_collapsed_file): + def test_main_collpased_file( + self, monkeypatch, capsys, bed_collapsed_file + ): """Test main function with collapsed alignments.""" in_bed, expected_out = bed_collapsed_file monkeypatch.setattr( - sys, 'argv', - ['primir_quantification', - str(in_bed), - '--collapsed', - ] + sys, + "argv", + [ + "primir_quantification", + str(in_bed), + "--collapsed", + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(expected_out, 'r') as out_file: + with open(expected_out, "r") as out_file: assert captured.out == out_file.read() def test_main_nh_file(self, monkeypatch, capsys, bed_nh_file): @@ -281,15 +306,17 @@ def test_main_nh_file(self, monkeypatch, capsys, bed_nh_file): in_bed, expected_out = bed_nh_file monkeypatch.setattr( - sys, 'argv', - ['primir_quantification', - str(in_bed), - '--nh', - ] + sys, + "argv", + [ + "primir_quantification", + str(in_bed), + "--nh", + ], ) args = parse_arguments().parse_args() main(args) captured = capsys.readouterr() - with open(expected_out, 'r') as out_file: + with open(expected_out, "r") as out_file: assert captured.out == out_file.read()