Store path of file that was read in
Closed this issue · 4 comments
Often when maniplating a PDB, I want to create an output PDB using a name that matches the input path with a one/two word description appended to the name. To facilitate this, I wonder your thoughts about storing the path string for an input file as metadata on the PandasPdb
class. Looking at the code called when reading in a PDB, it does not seem this is already done (though I may have missed it).
https://github.com/rasbt/biopandas/blob/master/biopandas/pdb/pandas_pdb.py#L58-L74
This could potentially be added to the __str__
property so when printing the object it returns more helpful info than <biopandas.pdb.pandas_pdb.PandasPdb object at 0x7fe1f5f2a390>
.
Good idea! I agree, attaching the file path can definitely come in handy.
I wouldn't overwrite the __str__
property though, but I was thinking about adding a self.file_path=''
attribute to the __init__
, which then gets set to the actual path when read_pdb
is called (and the file URL if fetch_pdb
was used, e.g., http://www.rcsb.org/pdb/files/xxxx.pdb)
What do you think?
This sounds great. This would be a valuable addition.
Also, perhaps instead of __str__
, do you think it would make sense to have __repr__
include self.file_path
? Here is an example implementation:
def __repr__(self):
return 'Pandas PDB defined by {}'.format(self.file_path)
Just an idea.
Hm, I would actually prefer to return general information about the class instance upon calling print(pandaspdb_obj)
-- I find that more intuitive in context how other object-oriented packages work (e.g,. scikit-learn). Since the PandasPDB
does not have any params for the __init__
method, I'd maybe just return the class name, like
def __repr__(self):
class_name = self.__class__.__name__