Skip to content

Commit a814957

Browse files
committed
fixed issue #6 biopython compatability
1 parent 2d923db commit a814957

File tree

5 files changed

+2055
-1228
lines changed

5 files changed

+2055
-1228
lines changed

libpython/biotools.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,30 @@
3434
cDir = os.path.dirname(os.path.abspath(os.sys.argv[0]))
3535
dataDir = os.path.join(cDir, 'data')
3636

37-
import Bio
38-
from Bio import SeqIO
39-
from Bio.Blast import NCBIWWW
37+
try:
38+
import Bio
39+
from Bio import SeqIO
40+
from Bio.Blast import NCBIWWW
41+
except ImportError:
42+
print(
43+
'\n####\nERROR: please install Biopython.\n- conda install biopython\n or\n- pip install biopython\n'
44+
)
45+
os.sys.exit(1)
46+
47+
# Compatible with both pre- and post Biopython 1.78:
48+
oldbiopython = True
49+
try:
50+
from Bio.Alphabet import ProteinAlphabet
51+
52+
print(
53+
'\n####\nINFO: please update your BioPython ({}) to 1.78 or newer.\n- conda update biopython\n or\n- pip update biopython\n'.format(
54+
Bio.__version__
55+
)
56+
)
57+
except ImportError:
58+
oldbiopython = False
59+
print('You are using BioPython {}'.format(Bio.__version__))
60+
4061
import cbmpy
4162

4263
# backwards compatability
@@ -506,13 +527,19 @@ def createSequence(modrefseq, filtered_ids=None, description=None):
506527
if a.startswith('gbank_seq_'):
507528
newName = a.replace('gbank_seq_', '')
508529
if newName not in geneseq:
509-
geneseq[newName] = Bio.SeqRecord.SeqRecord(
510-
Bio.Seq.Seq(
530+
if oldbiopython:
531+
seq = Bio.Seq.Seq(
511532
r_.getAnnotation(a), Bio.Alphabet.ProteinAlphabet()
512-
),
533+
)
534+
else:
535+
seq = Bio.Seq.Seq(r_.getAnnotation(a))
536+
537+
geneseq[newName] = Bio.SeqRecord.SeqRecord(
538+
seq,
513539
id=newName,
514540
name=newName,
515541
description=secDescr,
542+
annotations={"molecule_type": "protein"},
516543
)
517544
# print('Adding {}'.format(a))
518545
print('{} genseqs added'.format(len(geneseq)))

0 commit comments

Comments
 (0)