This repository has been archived by the owner on Apr 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.py
158 lines (128 loc) · 4.5 KB
/
setup.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"""
This is the setup.py for ToeholdTools.
If you wish to use the app demo, you must also run ./src/thtools/app/build.sh
"""
import os
import shutil
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
def mkdir(path):
"""Force the clearing and creation of a directory."""
try:
os.mkdir(path)
except FileExistsError:
shutil.rmtree(path, ignore_errors=True)
os.mkdir(path)
#######################################################################
# save miRBase
import gzip
import re
import urllib.request
print("Downloading miRBase...")
mkdir("src/thtools/miRBase/")
with urllib.request.urlopen(
"https://mirbase.org/ftp/CURRENT/mature.fa.gz"
) as miRBase_url:
with gzip.GzipFile(fileobj=miRBase_url, mode="rb") as gzipped_f:
txt = gzipped_f.read()
lines = txt.splitlines()
chunks = [b"\n".join(lines[n : n + 2]) for n in range(0, len(lines), 2)]
sorted_chunks = sorted(
chunks,
key=lambda x: [
int(group) if group.isdigit() else group for group in re.split(rb"([0-9]+)", x)
],
) # https://stackoverflow.com/a/2669120/13712044
miRNA_by_species = {}
for chunk in sorted_chunks:
species = b" ".join(chunk.split()[2:4])
if species in miRNA_by_species:
miRNA_by_species[species].append(chunk)
else:
miRNA_by_species[species] = [chunk]
for species, species_chunks in miRNA_by_species.items():
with open(b"src/thtools/miRBase/" + species + b".fa", "wb") as f:
f.write(b"\n".join(species_chunks))
#######################################################################
# make pygments.css for docs
import datetime
from pygments.style import Style
from pygments.formatters import HtmlFormatter
from pygments.token import Token
class CustomStyle(Style):
default_style = ""
bg = "#f8f8f2"
fore = "#282a36"
comment = "#adb6cf"
error = "#8b080b"
# color names from https://coolors.co/
flickr_pink = "#f72585"
purple = "#7209b7"
trypan_blue = "#834cff"
absolute_zero = "#0048d0"
styles = {
Token.Text.Whitespace: fore,
Token.Comment: "italic " + comment,
Token.Comment.Preproc: "noitalic " + flickr_pink,
Token.Keyword: flickr_pink,
Token.Keyword.Pseudo: flickr_pink,
Token.Keyword.Type: fore,
Token.Operator: fore,
Token.Operator.Word: flickr_pink,
Token.Name.Builtin: absolute_zero,
Token.Name.Function: trypan_blue,
Token.Name.Class: absolute_zero,
Token.Name.Namespace: fore,
Token.Name.Exception: flickr_pink,
Token.Name.Variable: "italic " + absolute_zero,
Token.Name.Constant: flickr_pink,
Token.Name.Label: purple,
Token.Name.Entity: fore,
Token.Name.Attribute: absolute_zero,
Token.Name.Tag: flickr_pink,
Token.Name.Decorator: fore,
Token.Literal.String: purple,
Token.Literal.String.Doc: "italic " + purple,
Token.Literal.String.Interpol: "bold " + purple,
Token.Literal.String.Escape: "bold " + purple,
Token.Literal.String.Regex: purple,
Token.Literal.String.Symbol: purple,
Token.Literal.String.Other: purple,
Token.Literal.Number: trypan_blue,
Token.Generic.Heading: fore,
Token.Generic.Subheading: fore,
Token.Generic.Deleted: error,
Token.Generic.Inserted: "bg:#50fa7b",
Token.Generic.Error: flickr_pink,
Token.Generic.Emph: "italic",
Token.Generic.Strong: "bold",
Token.Generic.Prompt: "bold " + error,
Token.Generic.Output: fore,
Token.Generic.Traceback: error,
Token.Error: "border:" + error,
}
css = HtmlFormatter(style=CustomStyle).get_style_defs()
with open("docs/source/_static/pygments.css", "w") as f:
f.write(
datetime.datetime.now().strftime(
"/* Created on %b %d %Y at %H:%M:%S by make_pygments.py */"
)
+ "\n"
+ css
)
#######################################################################
# package app requirements
if shutil.which("npm"):
print("npm detected: getting app requirements...")
os.system("src/thtools/app/build.sh")
#######################################################################
# build package
from setuptools import setup, Extension
from Cython.Distutils.build_ext import new_build_ext
import numpy
print("Building with Cython...")
setup(
ext_modules=[Extension("*", ["src/thtools/*.pyx"])],
cmdclass={"build_ext": new_build_ext},
include_dirs=numpy.get_include(),
)