From dfc55c1f9aaa71e160c4e8b388d13081073fe063 Mon Sep 17 00:00:00 2001 From: IAlibay Date: Tue, 14 Jul 2020 18:47:10 +0100 Subject: [PATCH] Adds option to read file streams --- propka/input.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/propka/input.py b/propka/input.py index 1cc7d74..2f425fe 100644 --- a/propka/input.py +++ b/propka/input.py @@ -35,18 +35,29 @@ def open_file_for_reading(input_file): return file_ -def read_molecule_file(input_file, mol_container): +def read_molecule_file(input_file, mol_container, filename=None): """Read input file (PDB or PROPKA) for a molecular container Args input_file: input file to read mol_container: MolecularContainer object + filename: str, optional input filename when using a filestream Returns updated MolecularContainer object Raises ValuError if invalid input given """ - input_path = Path(input_file) + try: + input_path = Path(input_file) + except TypeError: + try: + input_path = Path(filename) + except TypeError: + errmsg = ("Path of provided input_file could not be determined " + "if passing a stream-like object, please provide an " + "appropriate string for the filename argument.") + raise TypeError(errmsg) from None + mol_container.name = input_path.stem input_file_extension = input_path.suffix if input_file_extension.lower() == '.pdb':