def test_is_seekable(self): "It tests wether the fhands are seekable or not" # StringIO fhand = StringIO("hola") assert fhand_is_seekable(fhand) # standard file fhand = NamedTemporaryFile() fhand.seek(0) assert fhand_is_seekable(fhand) # a wrapped BufferedReader fhand2 = wrap_in_buffered_reader(fhand) assert fhand_is_seekable(fhand2) # pylint: disable=R0903 # pylint: disable=C0111 class NonSeekable(object): "Just for testing" pass assert not fhand_is_seekable(NonSeekable()) class NonSeekable2(object): def seek(self): pass def seekable(self): return False assert not fhand_is_seekable(NonSeekable2())
def test_is_seekable(self): 'It tests wether the fhands are seekable or not' # StringIO fhand = StringIO('hola') assert fhand_is_seekable(fhand) # standard file fhand = NamedTemporaryFile() fhand.seek(0) assert fhand_is_seekable(fhand) # a wrapped BufferedReader fhand2 = wrap_in_buffered_reader(fhand) assert fhand_is_seekable(fhand2) # pylint: disable=R0903 # pylint: disable=C0111 class NonSeekable(object): 'Just for testing' pass assert not fhand_is_seekable(NonSeekable()) class NonSeekable2(object): def seek(self): pass def seekable(self): return False assert not fhand_is_seekable(NonSeekable2())
def parse_basic_args(parser): 'It parses the command line and it returns a dict with the arguments.' parsed_args = parser.parse_args() # we have to wrap the file in a BufferedReader to allow peeking into stdin wrapped_fhands = [] # if input is stdin it will be a fhand not a list of fhands. # we have to convert to a list in_fhands = parsed_args.input if not isinstance(in_fhands, list): in_fhands = [in_fhands] for fhand in in_fhands: fhand = wrap_in_buffered_reader(fhand) fhand = uncompress_if_required(fhand) wrapped_fhands.append(fhand) in_format = parsed_args.in_format out_fhand = getattr(parsed_args, OUTFILE) comp_kind = get_requested_compression(parsed_args) if isinstance(out_fhand, list): new_out_fhands = [] for out_f in out_fhand: try: out_f = compress_fhand(out_f, compression_kind=comp_kind) except RuntimeError, error: print 'hello', error parser.error(error) new_out_fhands.append(out_f) out_fhand = new_out_fhands
def test_io_open(self): 'It checks the file wrapping in ReaderBuffers' # a standard file fhand = NamedTemporaryFile() fhand.write('hola') fhand.flush() fhand2 = open(fhand.name) fhand3 = wrap_in_buffered_reader(fhand2, force_wrap=True) assert fhand3.peek(10) == 'hola'
def parse_basic_args(parser): 'It parses the command line and it returns a dict with the arguments.' parsed_args = parser.parse_args() # we have to wrap the file in a BufferedReader to allow peeking into stdin wrapped_fhands = [] # if input is stdin it will be a fhand not a list of fhands. # we have to convert to a list in_fhands = parsed_args.input if not isinstance(in_fhands, list): in_fhands = [in_fhands] for fhand in in_fhands: fhand = wrap_in_buffered_reader(fhand) fhand = uncompress_if_required(fhand) wrapped_fhands.append(fhand) # We have to add the one_line to the fastq files in order to get the # speed improvements of the seqitems in_format = parsed_args.in_format if in_format == GUESS_FORMAT: for wrapped_fhand in wrapped_fhands: get_format(wrapped_fhand) else: if in_format != get_format(wrapped_fhands[0]): msg = 'The given input format does not correspond to the input' msg += ' file' raise WrongFormatError(msg) if 'fastq' in in_format: for wrapped_fhand in wrapped_fhands: get_format(wrapped_fhand) else: # we dont set the first one because already did in the previous # checking for wrapped_fhand in wrapped_fhands[1:]: set_format(wrapped_fhand, in_format) out_fhand = getattr(parsed_args, OUTFILE) comp_kind = get_requested_compression(parsed_args) if isinstance(out_fhand, list): new_out_fhands = [] for out_f in out_fhand: try: out_f = compress_fhand(out_f, compression_kind=comp_kind) except RuntimeError, error: parser.error(error) new_out_fhands.append(out_f) out_fhand = new_out_fhands
def get_input_fhand(in_fhand): in_fhand = wrap_in_buffered_reader(in_fhand, buffering=DEF_FILE_BUFFER) in_compressed = _vcf_is_gz(in_fhand) if in_compressed and not _fhand_is_tellable(in_fhand): msg = 'The given input has no tell member and it is compressed. ' msg += 'You cannot use gzip file through stdin, try to pipe it ' msg += 'uncompressed with zcat |' raise RuntimeError(msg) if in_compressed: mod_in_fhand = gzip.GzipFile(fileobj=in_fhand) else: mod_in_fhand = in_fhand return mod_in_fhand
def parse_basic_args(parser): 'It parses the command line and it returns a dict with the arguments.' parsed_args = parser.parse_args() # we have to wrap the file in a BufferedReader to allow peeking into stdin wrapped_fhands = [] # if input is stdin it will be a fhand not a list of fhands. # we have to convert to a list in_fhands = parsed_args.input if not isinstance(in_fhands, list): in_fhands = [in_fhands] for fhand in in_fhands: fhand = wrap_in_buffered_reader(fhand) fhand = uncompress_if_required(fhand) wrapped_fhands.append(fhand) # We have to add the one_line to the fastq files in order to get the # speed improvements of the seqitems in_format = parsed_args.in_format if 'fastq' in in_format: guessed_in_format = guess_format(wrapped_fhands[0]) if '-one_line' in guessed_in_format: in_format += '-one_line' else: guessed_in_format = None out_fhand = getattr(parsed_args, OUTFILE) comp_kind = get_requested_compression(parsed_args) if isinstance(out_fhand, list): new_out_fhands = [] for out_f in out_fhand: try: out_f = compress_fhand(out_f, compression_kind=comp_kind) except RuntimeError, error: parser.error(error) new_out_fhands.append(out_f) out_fhand = new_out_fhands