Skip to content

Commit

Permalink
update API Framework WebServices for Python3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardsnj committed Nov 1, 2024
1 parent 91cb280 commit 1a0803c
Show file tree
Hide file tree
Showing 16 changed files with 53,247 additions and 48,867 deletions.
20 changes: 10 additions & 10 deletions src/APIFramework.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import werkzeug
import atexit
import hashlib
import urllib2
import urllib.request
import random
import string
import datetime
Expand Down Expand Up @@ -191,7 +191,7 @@ def google_analytics_tag_id(self):
return self._google_analytics_tag_id

def set_google_analytics_tag_id(self, tag):
assert type(tag) in [str, unicode]
assert type(tag) == str
self._google_analytics_tag_id = tag

def input_file_folder(self):
Expand Down Expand Up @@ -293,7 +293,7 @@ def find_config(self, config_file_name):
def parse_config(self, config_file_name):

config = configparser.ConfigParser()
if hasattr(config,"read_file"):
if hasattr(config,"read_file"):
config.read_file(open(config_file_name))
else:
config.readfp(open(config_file_name))
Expand Down Expand Up @@ -465,7 +465,7 @@ def random_str(l=20):

@staticmethod
def str2hash(s):
return hashlib.md5(s).hexdigest()
return hashlib.md5(s.encode('utf8')).hexdigest()

def submit(self):
if flask.request.method in ['GET', 'POST']:
Expand Down Expand Up @@ -738,14 +738,14 @@ def download_file(self):
# FLASK helper functions
def form_task(self, params):
task = {}
task_str = ""
for par in self.task_params:
task_str = ""
for par in self.task_params:
if par in params:
task[par] = params[par].strip()
task[par] = params[par].strip()
elif self.task_params[par] != None:
task[par] = self.task_params[par].strip()
task_str += "_" + task[par]
task["id"] = self.str2hash(task_str.encode("utf-8"))
task["id"] = self.str2hash(task_str)
return task

# @staticmethod
Expand Down Expand Up @@ -981,7 +981,7 @@ def task_queue_get(self, task_queue, pid, suicide_queue):
def get_queue_length(self):
url = "http://%s:%s/queue_length" % (self.host(), self.port())

req = urllib2.urlopen(url)
req = urllib.request.urlopen(url)
x = req.read()

return int(x)
Expand Down Expand Up @@ -1046,7 +1046,7 @@ def cleanup(self):


def terminate_all(self):
for i, p in self._deamon_process_pool.items():
for i, p in list(self._deamon_process_pool.items()):
self.output(0, "Worker-%s is terminated" % (i))
p.terminate()
del self._deamon_process_pool[i]
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Converter/Converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def form_task(self, p):

p["seq"] = p["seq"].strip()
p["format"] = p["format"].strip()
task_str = p["seq"].encode("utf-8") +"_"+ p["format"].encode("utf-8")
task_str = p["seq"] +"_"+ p["format"]
list_id = self.str2hash(task_str)

res["id"] = list_id
Expand Down
2 changes: 1 addition & 1 deletion src/Application/GlyLookup/GlyLookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def form_task(self, p):
res = {}

p["seq"] = p["seq"].strip()
task_str = p["seq"].encode("utf-8")
task_str = p["seq"]
list_id = self.str2hash(task_str)

res["id"] = list_id
Expand Down
7 changes: 3 additions & 4 deletions src/Application/Glymage/Glymage.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,15 +583,14 @@ def getimage():
elif flask.request.method == "POST":
para = flask.request.form
else:
raise RuntimeError
return self.error_image(), 404

p = {}
for k in dict(para).keys():
v = para.get(k)
if v:
p[k] = str(v)

print >>sys.stderr, p
query, query_type = "", ""
if "seq" in p:
query = p["seq"].strip()
Expand All @@ -617,7 +616,7 @@ def getimage():
except pygly.GlycanFormatter.GlycanParseError:
pass
if not newquery:
raise RuntimeError
return self.error_image(), 404
query = newquery

if "acc" in p:
Expand All @@ -634,7 +633,7 @@ def getimage():
query_type = "task"

if query == "" or query_type == "":
raise RuntimeError
return self.error_image(), 404

p["notation"] = p.get("notation","snfg").lower()
if p["notation"] not in ("snfg",):
Expand Down
14 changes: 7 additions & 7 deletions src/Application/Glymage/image2hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ def s2h(s):

for seqtype in ("wurcs","glycoct"):
for dirpath, dirnames, filenames in os.walk("./"+seqtype):
for f in filenames:
for f in filenames:
acc,extn = f.rsplit('.',1)
if extn != 'txt':
continue
if extn != 'txt':
continue
if not re.search(r'^G[0-9]{5}[A-Z]{2}$',acc):
continue
continue
# print f,acc,extn
s = open(os.path.join(dirpath,f)).read()
if seqtype == "wurcs":
acc_to_cannonseq[acc] = s
h = s2h(s)
h = s2h(s.encode())
seq_hash_to_acc[h] = acc
if acc not in acc_to_seq_hash:
acc_to_seq_hash[acc] = []
Expand All @@ -59,11 +59,11 @@ def s2h(s):
continue

acc,ext = fn.split('.',1)
print acc,ext
print(acc,ext)

fp = os.path.join(dirpath, fn)

imgstr = open(fp).read()
imgstr = open(fp,'rb').read()
imgh = s2h(imgstr)


Expand Down
6 changes: 3 additions & 3 deletions src/Application/Glymage/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
except:
continue

print src_abs
print dst_abs
print
print(src_abs)
print(dst_abs)
print()


# print shash, notation, display
Expand Down
6 changes: 3 additions & 3 deletions src/Application/Glymage/makeimages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function dockerrun() {
# docker wait $CID
}

PYSCR="python2 pygly-scripts"
PYSCR="python3 pygly-scripts"
SHSCR="pygly-scripts"
DUMPSEQ="$PYSCR/dumpgtcseq.py"
ALLIMG="$SHSCR/allimg.sh"
Expand Down Expand Up @@ -52,7 +52,7 @@ dockerrun $JSONMOTIF /work/snfg/compact

CURDIR=`pwd`
rm -rf image/hash
( cd work; python2 $CURDIR/image2hash.py ../image/hash )
( cd work; python3.12 $CURDIR/image2hash.py ../image/hash )
rm -rf image/snfg
python2 $CURDIR/link.py
python3.12 $CURDIR/link.py
( cd image; tar czf image.tgz hash snfg error.png error.json imageinfo.tsv shash2acc.tsv cannonseq.tsv )
2 changes: 1 addition & 1 deletion src/Application/MotifMatch/MotifMatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def pre_start(self, worker_para):
site = worker_para["glycomotif_version"]
assert site in ["", "dev", "test"]

gm = pygly.GlycanResource.GlycoMotif()
gm = pygly.GlycanResource.GlycoMotif(usecache=False)
gm.endpt = "https://glycomotif.glyomics.org/glycomotif"+site+"/sparql/query"

wp = WURCS20Format()
Expand Down
Loading

0 comments on commit 1a0803c

Please sign in to comment.