obiconvert TypeError: a bytes-like object is required, not 'str'
2
0
Entering edit mode
2.5 years ago

Hello everyone! Being completely new to OBItools, I am trying to build an ecoPCR database in order to design species-specific primers within a metabarcoding fragment. For this I would like to convert my "manually" created alignment in fasta format to an ecoPCR database. My fasta file looks like this:

>Acinonyx_jubatus_AF344830_1
GGGTTGGTAAATTTCGTGCCAGCCACCGCGGTCATACGATTAACCCAAACTAATAGACCCACGGCGTAAAGCGTGTTATAGAGAAAAAAATTACTAAAGTTAAACCTTAACTAGGCCGTAAAAAGCTATAGTTAACATGAAAATACAGCACGAAAGTAACTTTAATACCTCCAACTGCACGATAGCTAAGACCCAAACTGGGATTAGATACCCCACTATG
>Acinonyx_jubatus_AY463959_1
GGGTTGGTAAATTTCGTGCCAGCCACCGCGGTCATACGATTAACCCAAACTAATAGACCCACGGCGTAAAGCGTGTTATAGAGAAAAAAATTACTAAAGTTAAACCTTAACTAGGCCGTAAAAAGCTATAGTTAACATGAAAATACAGCACGAAAGTAACTTTAATACCTCCAACTGCACGATAGCTAAGACCCAAACTGGGATTAGATACCCCACTATG
>Acinonyx_jubatus_KP202271_1
GGGTTGGTAAATTTCGTGCCAGCCACCGCGGTCATACGATTAACCCAAACTAATAGACCCACGGCGTAAAGCGTGTTATAGAGAAAAAAATTACTAAAGTTAAACCTTAACTAGGCCGTAAAAAGCTACAGTTAACATGAAAATACAGCACGAAAGTAACTTTAATACCTCCAACTGCACGATAGCTAAGACCCAAACTGGGATTAGATACCCCACTATG
>....`

and I am trying to run the command:

obiconvert --fasta --ecopcrdb-output=sequencesdb 12S_MiMammal_August2022.fas 

Unfortunately, I keep getting this error message:

 Traceback (most recent call last):
  File "/usr/bin/obiconvert", line 52, in <module>
    writer(entry)
  File "/usr/lib/python3/dist-packages/obitools/format/options.py", line 371, in sequenceWriter
    writer.put(sequence)
  File "/usr/lib/python3/dist-packages/obitools/ecopcr/sequence.py", line 173, in put
    self._file.write(self._ecoSeqPacker(sequence))
  File "/usr/lib/python3/dist-packages/obitools/ecopcr/sequence.py", line 115, in _ecoSeqPacker
    compactseq = gzip.zlib.compress(str(seq).upper(),9)
TypeError: a bytes-like object is required, not 'str'

When I convert it from fasta to OBITools extended fasta format, the command runs fine. I suspect that it is related to the prefix-filename that I am entering?

Any suggestions what I am missing here? Any help will be highly appreciated!

Thanks!

fasta ecopcr obitools obiconvert • 1.1k views
ADD COMMENT
2
Entering edit mode
2.5 years ago
tim.booth ▴ 110

Hi,

I don't know anything about OBITools but I do recognise the error message. It's something you often see when trying to run code that was written for Python2 in Python3. Looking on bioconda, there are packages for this software and all of them use Python2 so I think that confirms my suspicion. See:

https://anaconda.org/bioconda/obitools/files

Unfortunately this sort of thing often happens with code that is no longer maintained, as seems to be the case with the OBITools package. Your best bet will be to install a version into a conda environment which will supply a compatible Python for you.

If you've not used conda before then the basic steps are:

1 ) Get miniconda from https://docs.conda.io/en/latest/miniconda.html

(don't worry that miniconda comes with Python3 - it can still manage a Py2 environment for you)

2 ) Configure miniconda to use Bioconda packages - see https://bioconda.github.io/ for the commands

3 ) Once conda is active, install the package in a new env:

$ conda create -n obitools obitools
$ conda activate obitools

Hopefully that sorts you out. Good luck.

TIM

ADD COMMENT
1
Entering edit mode
2.5 years ago

Dear Tim,

thank you very much for your response. It was indeed an issue with python2 versus python3. I've installed the python2 environment and now the program runs fine.

Celine, the author of obitools gave me also very similar instructions to yours which I am sharing here, as well.

As you said, first you need to install git and miniconda ( https://docs.conda.io/en/latest/miniconda.html)

Then you can install obitools via the activated environment via:

git clone https://git.metabarcoding.org/obitools/obitools.git
cd obitools
conda create --name obi-py2 python=2.7
conda activate obi-py2
pip install jinja2
pip install -U setuptools
pip install sphinx
python setup.py build
python setup.py install

Cheers, Tamara

ADD COMMENT

Login before adding your answer.

Traffic: 1801 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6