-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
72 lines (67 loc) · 1.7 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import sys
import subprocess
import requests
# https://molbiol-tools.ca/Amino_acid_abbreviations.htm
protein_conversion = {
"Ala": "A",
"Arg": "R",
"Asn": "N",
"Asp": "D",
"Asx": "B",
"Cys": "C",
"Glu": "E",
"Gln": "Q",
"Glx": "Z",
"Gly": "G",
"His": "H",
"Ile": "I",
"Leu": "L",
"Lys": "K",
"Met": "M",
"Phe": "F",
"Pro": "P",
"Ser": "S",
"Thr": "T",
"Trp": "W",
"Tyr": "Y",
"Val": "V",
"Ter": "*",
}
def get_pdot_abbreviation(pdot: str):
for full, abbr in protein_conversion.items():
pdot = pdot.replace(full, abbr)
return pdot
rev_compl_dic = {
"c": "g",
"C": "G",
"g": "c",
"G": "C",
"t": "a",
"T": "A",
"A": "T",
"a": "t",
}
def reverse_complement(input: str):
return "".join([rev_compl_dic[c] for c in input])
def relative_path(path: str) -> str:
"""
Paths are different from within a PyInstaller package, this function figures that out
https://pyinstaller.org/en/stable/runtime-information.html#run-time-information
"""
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, path)
else:
return os.path.join(".", path)
def get_release_tag() -> str:
tag = ""
try:
result = subprocess.run(['git', 'describe', '--tags'], stdout=subprocess.PIPE)
tag = result.stdout.decode().strip()
except FileNotFoundError:
url = "https://api.github.com/repos/ErasmusMC-Bioinformatics/molclass/releases/latest"
resp = requests.get(url)
resp.raise_for_status()
json = resp.json()
tag = json["tag_name"]
return tag