19
19
20
20
Author: Brett G. Olivier
21
21
Contact email: bgoli@users.sourceforge.net
22
- Last edit: $Author: bgoli $ ($Id: CBModel.py 625 2017-10-20 12:00:53Z bgoli $)
22
+ Last edit: $Author: bgoli $ ($Id: CBModel.py 629 2017-10-24 22:01:14Z bgoli $)
23
23
24
24
"""
25
25
## gets rid of "invalid variable name" info
34
34
from __future__ import absolute_import
35
35
#from __future__ import unicode_literals
36
36
37
- import numpy , re , time , weakref , copy , json , urllib2 , ast
37
+ import numpy , re , time , weakref , copy , json , ast
38
+
39
+ try :
40
+ from urllib2 import quote as urlquote
41
+ from urllib2 import unquote as urlunquote
42
+ except ImportError :
43
+ from urllib .parse import quote as urlquote
44
+ from urllib .parse import unquote as urlunquote
38
45
39
46
global GENE_CNTR
40
47
GENE_CNTR = 0
@@ -218,7 +225,10 @@ def setNotes(self, notes):
218
225
219
226
"""
220
227
#self.notes = self.__urlEncode(notes)
221
- self .notes = notes .decode (errors = 'ignore' )
228
+ try :
229
+ self .notes = notes .decode (errors = 'ignore' )
230
+ except AttributeError :
231
+ self .notes = notes
222
232
223
233
def setAnnotation (self , key , value ):
224
234
"""
@@ -347,7 +357,7 @@ def serializeToDisk(self, filename, protocol=2):
347
357
# Reimplemented in Model
348
358
349
359
"""
350
- F = file (filename , 'wb' )
360
+ F = open (filename , 'wb' )
351
361
pickle .dump (self , F , protocol = protocol )
352
362
F .close ()
353
363
@@ -440,7 +450,7 @@ def __urlEncode(self, txt):
440
450
441
451
"""
442
452
try :
443
- txt = urllib2 . quote (txt .encode (self .__text_encoding__ , errors = 'replace' ), safe = '' )
453
+ txt = urlquote (txt .encode (self .__text_encoding__ , errors = 'replace' ), safe = '' )
444
454
except UnicodeDecodeError as why :
445
455
pass
446
456
#print(txt)
@@ -451,7 +461,7 @@ def __urlDecode(self, txt):
451
461
Decodes a URL encoded string
452
462
453
463
"""
454
- return urllib2 . unquote (txt )
464
+ return urlunquote (txt )
455
465
456
466
class Model (Fbase ):
457
467
"""
@@ -716,7 +726,7 @@ def serializeToDisk(self, filename, protocol=2):
716
726
# overloaded in CBModel
717
727
718
728
"""
719
- F = file (filename , 'wb' )
729
+ F = open (filename , 'wb' )
720
730
pickle .dump (self , F , protocol = protocol )
721
731
F .close ()
722
732
self .__setGlobalIdStore__ ()
@@ -4584,7 +4594,7 @@ def addAssociation(self, assoc):
4584
4594
4585
4595
"""
4586
4596
#self.assoc = assoc
4587
- raise RuntimeError , '\n This method has ceased to exist'
4597
+ raise RuntimeError ( '\n This method has ceased to exist' )
4588
4598
4589
4599
def createAssociationAndGeneRefsFromTree (self , gprtree , altlabels = None ):
4590
4600
"""
@@ -4633,7 +4643,7 @@ def createAssociationAndGeneRefsFromTree(self, gprtree, altlabels=None):
4633
4643
self .buildEvalFunc ()
4634
4644
4635
4645
def createAssociationAndGeneRefs (self ):
4636
- raise RuntimeError , "\n \n DEPRECATED CHANGE NOW!"
4646
+ raise RuntimeError ( "\n \n DEPRECATED CHANGE NOW!" )
4637
4647
4638
4648
def createAssociationAndGeneRefsFromString (self , assoc , altlabels = None ):
4639
4649
"""
@@ -4688,7 +4698,7 @@ def createAssociationAndGeneRefsFromString(self, assoc, altlabels=None):
4688
4698
except SyntaxError :
4689
4699
err = '\n Error in Gene Association String: {}\n ' .format (assoc )
4690
4700
#print(err)
4691
- raise SyntaxError , err
4701
+ raise SyntaxError ( err )
4692
4702
self .setTree (newtree )
4693
4703
genes = self .__getGeneRefsfromGPRDict__ (newtree , [])
4694
4704
genes .sort ()
@@ -4788,7 +4798,7 @@ def getAssociationStr(self, use_labels=False):
4788
4798
keymap = {}
4789
4799
for g in self .generefs :
4790
4800
keymap [g ] = self .__objref__ ().getGene (g ).getLabel ()
4791
- keys = keymap .keys ()
4801
+ keys = list ( keymap .keys () )
4792
4802
keys .sort (reverse = True )
4793
4803
for k in keys :
4794
4804
out = out .replace (k , keymap [k ])
0 commit comments