Gurdhhu / bioinf_scripts

10 stars 3 forks source link

write() argument must be str, not bytes #7

Open Truongphi20 opened 2 years ago

Truongphi20 commented 2 years ago

I use this tool on Linux ubuntu 20 and face a problem when I want to launch it with the following command:

python annotate_blast_hits.py blastn_example_input.csv n my_email@.gmail.com The program gives an error like this:

Fetching annotation for 150 accessions from GenBank... Traceback (most recent call last): File "annotate_blast_hits.py", line 104, in <module> raise err File "annotate_blast_hits.py", line 77, in <module> get(ids_to_fetch, step) File "annotate_blast_hits.py", line 55, in get out.write(handle.read()) TypeError: write() argument must be str, not bytes

Can someone tell me what I should do? Thank a lot.

francescapinton commented 2 years ago

Just had the same issue. I put write() argument between double quotation marks and it solved it.

line 55


def get(ids, step):
    handle = Entrez.efetch(db=dbdict[db], id=ids, retmode='xml')
    tmpfile = "".join([file, "_tmp", str(step), ".xml"])
    filelist.append(tmpfile)
    with open(tmpfile, "w") as out:  # Writing a temporary file that will be removed after parsing
        out.write("handle.read()")

I then got other errors I could not solve, so I ran the standalone version instead.