LUMC / kPAL

Analysis toolkit and programming library for k-mer profiles
http://kpal.readthedocs.org/
Other
30 stars 6 forks source link

Profile.from_file fails with cryptic TypeErrors #9

Open MatthewRalston opened 6 years ago

MatthewRalston commented 6 years ago

Hi, pretty basic stuff. I found some TypeErrors (code smell) from improper usage of your from_file function. Oddly enough, it looks like you're not type-checking your arguments. And essentially this creates downstream problems with your functions that depend on name being properly instantiated.

>>>from kpal.klib import Profile
>>>p=Profile.from_file("./my_sample.k12")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/.venv/lib/python2.7/site-packages/kpal/klib.py", line 74, in from_file
    name = name or sorted(handle['profiles'].keys())[0]
TypeError: string indices must be integers, not unicode
>>>p=Profile.from_file(open("./my_sample.k12",'r'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/.venv/lib/python2.7/site-packages/kpal/klib.py", line 75, in from_file
    counts = handle["profiles/" + name][:]
TypeError: 'file' object has no attribute '__getitem__'

So, first off, the TypeErrors and then It'd be nice if the documentation were expanded to include something this simple:

>>>from kpal.klib import Profile
>>>import h5py
>>>f = h5py.File("./my_sample.k12", 'r')
>>>p = Profile.from_file(f)