1616from __future__ import annotations
1717
1818import csv
19- import gzip
2019import logging
2120import re
2221from pathlib import Path
@@ -119,12 +118,8 @@ def __iter__(self) -> Iterable[PSM]:
119118
120119 @staticmethod
121120 def _read_header (filename ):
122- if str (filename ).endswith (".gz" ):
123- with gzip .open (filename , "rt" ) as f :
124- fieldnames = f .readline ().strip ().lower ().split ("\t " )
125- else :
126- with open (filename , "rt" ) as f :
127- fieldnames = f .readline ().strip ().lower ().split ("\t " )
121+ with open (filename , "rt" ) as f :
122+ fieldnames = f .readline ().strip ().lower ().split ("\t " )
128123 return fieldnames
129124
130125 @staticmethod
@@ -378,12 +373,7 @@ def _parse_existing_file(
378373 ) -> Tuple [List [str ], Optional [int ]]:
379374 """Parse existing Percolator Tab file to determine fieldnames and last ScanNr."""
380375 # Get fieldnames
381- if str (filename ).endswith (".gz" ):
382- open_func = gzip .open
383- else :
384- open_func = open
385-
386- with open_func (filename , "rt" ) as open_file :
376+ with open (filename , "rt" ) as open_file :
387377 for line in open_file :
388378 fieldnames = line .strip ().split ("\t " )
389379 break
@@ -398,7 +388,7 @@ def _parse_existing_file(
398388
399389 # Get last ScanNr
400390 last_scannr = None
401- with open_func (filename , "rt" ) as open_file :
391+ with open (filename , "rt" ) as open_file :
402392 # Read last line
403393 open_file .seek (0 )
404394 last_line = None
@@ -425,11 +415,7 @@ def _parse_existing_file(
425415class _PercolatorTabIO :
426416 def __init__ (self , * args , protein_separator = "|||" , ** kwargs ) -> None :
427417 """File reader and writer for Percolator Tab files with fixed Proteins tab."""
428- filename = args [0 ]
429- if str (filename ).endswith (".gz" ):
430- self ._open_file = gzip .open (* args , ** kwargs )
431- else :
432- self ._open_file = open (* args , ** kwargs )
418+ self ._open_file = open (* args , ** kwargs )
433419 self .protein_separator = protein_separator
434420
435421 def __enter__ (self , * args , ** kwargs ) -> _PercolatorTabIO :
0 commit comments