Adds option to read file streams

This commit is contained in:
IAlibay
2020-07-14 18:47:10 +01:00
parent 8b371bfc27
commit dfc55c1f9a

View File

@@ -35,18 +35,29 @@ def open_file_for_reading(input_file):
return 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 """Read input file (PDB or PROPKA) for a molecular container
Args Args
input_file: input file to read input_file: input file to read
mol_container: MolecularContainer object mol_container: MolecularContainer object
filename: str, optional input filename when using a filestream
Returns Returns
updated MolecularContainer object updated MolecularContainer object
Raises Raises
ValuError if invalid input given ValuError if invalid input given
""" """
try:
input_path = Path(input_file) 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 mol_container.name = input_path.stem
input_file_extension = input_path.suffix input_file_extension = input_path.suffix
if input_file_extension.lower() == '.pdb': if input_file_extension.lower() == '.pdb':