From 11b79c71f1c121c6556a556721ac658989b2ad1c Mon Sep 17 00:00:00 2001 From: Scott Christley Date: Fri, 18 Oct 2024 12:12:08 -0500 Subject: [PATCH] fix read gzip, add test case --- lang/python/airr/interface.py | 2 +- .../tests/data/good_rearrangement.tsv.gz | Bin 0 -> 1106 bytes lang/python/tests/test_interface.py | 19 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 lang/python/tests/data/good_rearrangement.tsv.gz diff --git a/lang/python/airr/interface.py b/lang/python/airr/interface.py index a8f60298f..b58811dc7 100644 --- a/lang/python/airr/interface.py +++ b/lang/python/airr/interface.py @@ -41,7 +41,7 @@ def read_rearrangement(filename, validate=False, debug=False): airr.io.RearrangementReader: iterable reader class. """ if filename.endswith(".gz"): - handle = gzip.open(filename, 'r') + handle = gzip.open(filename, 'rt') else: handle = open(filename, 'r') diff --git a/lang/python/tests/data/good_rearrangement.tsv.gz b/lang/python/tests/data/good_rearrangement.tsv.gz new file mode 100644 index 0000000000000000000000000000000000000000..c838c584d5e10ba715dd1ebb7fbe1925d847ae23 GIT binary patch literal 1106 zcmV-Y1g-lYiwFpPH)>`817~kil^8C_U(5LsjD3)P1|fK78v5?Paa;Z9}W*y zW=UBl#WK6iitWuRC1p>z&#ZW#{k6-AMb<4t&xf1E-R*{K%DZ&8*sdP3wqvqhEejli zEVJ@7m`r2CukkVainz=8?B9wBB&b^N1#Q}Vzj{&>QIa$TQ{z&hC&=c6X@D0#y}4{ z5{Q^W4;|YcZWbILXS6+R2S_xSKu;5)xs|oEaHB%%$6yC+ zfcDs$*c}@^w_e(TW0GG_$%{b zxXvDd>+6U*n2YeBMrwLC`1tYK`YGo1ndzK|^6`kX2|OGgR+Uk+hagpswLny?DcPKT zk|`vNQg`;rE^snzfa3rht$|ZM;VkHcR-Lo&)6}2#&OR%=JFXWn7d;=VKX&weCv(w0 zbA#4#$zT*d<+yB^#puz1-DkpT{)+&Qe;)QT@g@_e>GFVs0k=GCf5OLoT1*c!{x_2(bya$vOUOmA2nNa#c zAEtbON4{EsB@aGK3EzfM%!X0C3aJ=+CsD;%_L2T!eAW0c8)Nx4#)9C`#aNXe^J_mQ Y152I%RG=m8H>?l;0K5(Ux-J(00KYL1`v3p{ literal 0 HcmV?d00001 diff --git a/lang/python/tests/test_interface.py b/lang/python/tests/test_interface.py index 5fc54060c..0585cac0d 100644 --- a/lang/python/tests/test_interface.py +++ b/lang/python/tests/test_interface.py @@ -23,6 +23,7 @@ def setUp(self): # Test data self.rearrangement_good = os.path.join(data_path, 'good_rearrangement.tsv') + self.rearrangement_good_gz = os.path.join(data_path, 'good_rearrangement.tsv.gz') self.rearrangement_bad = os.path.join(data_path, 'bad_rearrangement.tsv') self.rep_good = os.path.join(data_path, 'good_repertoire.yaml') self.rep_bad = os.path.join(data_path, 'bad_repertoire.yaml') @@ -59,6 +60,24 @@ def test_load_rearrangement(self): result = airr.load_rearrangement(self.rearrangement_bad) self.assertTupleEqual(result.shape, self.shape_bad, 'load(): bad data failed') + # @unittest.skip('-> read_rearrangement(): skipped\n') + def test_read_rearrangement(self): + # Good data + result = [] + reader = airr.read_rearrangement(self.rearrangement_good) + for row in reader: + result.append(row) + reader.close() + self.assertTrue(len(result) == self.shape_good[0], 'read_rearrangement(): good data failed') + + # Good data, gzip + result = [] + reader = airr.read_rearrangement(self.rearrangement_good_gz) + for row in reader: + result.append(row) + reader.close() + self.assertTrue(len(result) == self.shape_good[0], 'read_rearrangement(): good data (gzip) failed') + # @unittest.skip('-> repertoire_template(): skipped\n') def test_repertoire_template(self): try: