diriano / ploidyNGS

Explore ploidy levels from NGS data alone
GNU General Public License v3.0
38 stars 14 forks source link

Mistake in ploidyNGS.py #4

Closed SRodenburg closed 7 years ago

SRodenburg commented 7 years ago

When I'm trying out either the test or one of my own files, I'm getting the following error:

Traceback (most recent call last):
  File "./ploidyNGS.py", line 98, in <module>
...
TypeError: expected string or Unicode object, file found

I pinpointed the mistake to be in ploidyNGS.py, at line 59 There the BAM file is opened, while at line 85 the file handle is parsed to pysam. This should be the file name as a string only. To solve I simply changed line 59; bamOBJ = open(args.bam,"r") to bamOBJ = args.bam

The solution seems trivial, but it's not reflected in the traceback

diriano commented 7 years ago

Dear Users,

thanks a lot for your interest in ploidyNGS.

Unfortunately I have not been able to reproduce the error you reported.

pysam.AlingmentFile can either receive a file or an object. See (http://pysam.readthedocs.io/en/latest/api.html):

class pysam.AlignmentFile AlignmentFile(filepath_or_object, mode=None, template=None, reference_names=None, reference_lengths=None, text=NULL, header=None, add_sq_text=False, check_header=True, check_sq=True, reference_filename=None, filename=None, duplicate_filehandle=True)

Which version of pysam and of python are you using?

Thanks, Diego

SRodenburg commented 7 years ago

Indeed, according to the documentation it seems to accept a string or a filehandle. I am using pysam 0.10.0 from inside the virtualenv as described in the installation docs of ploidyNGS. For now it doesn't complain.

Regards, Sander Rodenburg

diriano commented 7 years ago

Dear Sander,

I am not sure I understood correctly.

With pysam 0.10.0 it does not complain? Does it generate the PDF and tab files?

Diego

SRodenburg commented 7 years ago

It does, but only after I change the code as described above. I don't understand why it doesn't work when pysam get a file handle instead of a filename string. Anyway, it correctly generates the pdf and table now.

Regards, Sander

brkldj commented 7 years ago

I have the same problem as @SRodenburg , and his solution (with the addition of commenting out the line with bamOBJ.close() ) works for me.

diriano commented 7 years ago

Thanks for your comments. Yes, this is related to pysam 0.10, it should accept an object as per their documentation. I have updated the code so that the name of the BAM file passes directly as bamOBJ. I am closing this issue.