Skip to content

Commit 23f9809

Browse files
authored
Merge pull request #39 from KatyBrown/CI_testing
Minor changes prior to publication
2 parents 364da94 + 0729275 commit 23f9809

16 files changed

Lines changed: 21151 additions & 20980 deletions

CIAlign/miniAlignments.py

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ def drawMarkUp(a, markupdict, nams, ali_width, ali_height):
9898
-------
9999
100100
'''
101+
colD = utilityFunctions.getMarkupColours()
102+
lineweight_h = 5 / ali_height
101103
# removes single positions
102104
if "crop_ends" in markupdict:
103-
colour = "black"
105+
colour = colD['crop_ends']
104106
for nam, boundary in markupdict['crop_ends'].items():
105107
y = len(nams) - nams.index(nam) - 1
106108
# left end of the sequence
@@ -109,51 +111,80 @@ def drawMarkUp(a, markupdict, nams, ali_width, ali_height):
109111
matplotlib.patches.Rectangle(
110112
[boundary[0][0]-0.5, y-0.5],
111113
(boundary[0][-1] - boundary[0][0]) + 1,
112-
1, color='black', lw=0, zorder=50))
113-
114+
1, color=colour, lw=0, zorder=50))
115+
a.hlines(y, boundary[0][0]-0.5, boundary[0][-1]+0.5, zorder=51, color='black',
116+
lw=lineweight_h)
117+
# a.plot([boundary[0][0]-0.5, boundary[0][-1]+0.5], [y-0.5, y+0.5], zorder=51, color='black',
118+
# lw=lineweight_h, solid_capstyle='butt')
114119
# right end of the sequence
115120
if boundary[1].shape[0] > 0:
116121
a.add_patch(
117122
matplotlib.patches.Rectangle(
118123
[boundary[1][0]-0.5, y-0.5],
119124
(boundary[1][-1] - boundary[1][0]) + 1,
120-
1, color='black', lw=0, zorder=50))
125+
1, color=colour, lw=0, zorder=50))
126+
a.hlines(y, boundary[1][0]-0.5, boundary[1][-1]+0.5, zorder=51, color='black',
127+
lw=lineweight_h )
128+
# a.plot([boundary[1][0]-0.5, boundary[1][-1]+0.5], [y-0.5, y+0.5], zorder=51, color='black',
129+
# lw=lineweight_h, solid_capstyle='butt')
121130

122131
# removes whole rows
123132
if "remove_divergent" in markupdict:
124-
colour = '#f434c5'
133+
colour = colD['remove_divergent']
125134
for row in markupdict['remove_divergent']:
126135
y = len(nams) - nams.index(row) - 1.5
127136
a.add_patch(matplotlib.patches.Rectangle(
128137
(-0.5, y), ali_width, 1,
129-
color=colour, zorder=49, lw=0))
138+
color=colour, zorder=48, lw=0))
139+
a.hlines(y+0.5, -0.5, ali_width-0.5, zorder=49, color='black',
140+
lw=lineweight_h)
141+
# a.plot([-0.5, ali_width-0.5], [y+0.1, y+0.9], zorder=49, color='black',
142+
# lw=lineweight_h, solid_capstyle='butt')
130143

131144
# removes whole columns
132145
if "remove_insertions" in markupdict:
133-
colour = "#7bc5ff"
146+
colour = colD['remove_insertions']
147+
start = list(markupdict['remove_insertions'])[0]
148+
# p = start
149+
# x = False
134150
for col in markupdict['remove_insertions']:
151+
#if x:
152+
# start = p
153+
# x = False
135154
a.add_patch(matplotlib.patches.Rectangle(
136-
(col-0.5, -0.5), 1, ali_height, color=colour, zorder=48,
137-
lw=0))
138-
155+
(col-0.5, -0.5), 1, ali_height, color=colour, zorder=46,
156+
lw=0 ))
157+
for row in np.arange(ali_height):
158+
a.hlines(row, col-0.5, col+0.5, zorder=47, color='black',
159+
lw=lineweight_h )
160+
# if p != col - 1 and p != start:
161+
# a.plot([start, col+0.5], [-0.5, ali_height], zorder=47, color='black',
162+
# lw=lineweight_h, solid_capstyle='butt')
163+
# x = True
164+
# p = col
165+
# a.plot([start, col+0.5], [-0.5, ali_height], zorder=47, color='black',
166+
# lw=lineweight_h, solid_capstyle='butt')
139167
# removes whole rows
140168
if "remove_short" in markupdict:
141-
colour = '#fff6b3'
169+
colour = colD['remove_short']
142170
for row in markupdict['remove_short']:
143171
y = len(nams) - nams.index(row) - 1.5
144172
a.add_patch(matplotlib.patches.Rectangle(
145173
(-0.5, y), ali_width, 1,
146-
color=colour, zorder=47, lw=0))
147-
174+
color=colour, zorder=44, lw=0))
175+
a.hlines(y+0.5, -0.5, ali_width-0.5, zorder=45, color='black',
176+
lw=lineweight_h )
148177
# removes whole columns
149178
if "remove_gaponly" in markupdict:
150-
colour = "#f57700"
179+
colour = colD['remove_gaponly']
151180
for col in markupdict['remove_gaponly']:
152181
a.add_patch(matplotlib.patches.Rectangle((col-0.5, -0.5), 1,
153182
ali_height,
154183
color=colour,
155-
zorder=46, lw=0))
156-
184+
zorder=42, lw=0))
185+
for row in np.arange(ali_height):
186+
a.hlines(row, col-0.5, col+0.5, zorder=43, color='black',
187+
lw=lineweight_h )
157188

158189
def drawMarkUpLegend(outfile):
159190
'''
@@ -174,12 +205,16 @@ def drawMarkUpLegend(outfile):
174205
'''
175206
legend = plt.figure(figsize=(2, 2), dpi=100)
176207
leg = legend.add_subplot(1, 1, 1)
177-
colours = ['black', '#f434c5', "#7bc5ff", '#fff6b3', "#f57700"]
178-
functions = ['Cropped Ends', 'Too Divergent', 'Insertions',
179-
'Too Short', 'Gap Only']
180-
for i, c in enumerate(colours):
181-
leg.plot(1, 5-i, marker='.', color=c, markersize=20)
182-
leg.text(2, 5-i, functions[i])
208+
colours = utilityFunctions.getMarkupColours()
209+
210+
functions = {'crop_ends': 'Cropped Ends',
211+
'remove_divergent': 'Too Divergent',
212+
'remove_insertions': 'Insertions',
213+
'remove_short': 'Too Short',
214+
'remove_gaponly': 'Gap Only'}
215+
for i, (func, txt) in enumerate(functions.items()):
216+
leg.plot(1, 5-i, marker='.', color=colours[func], markersize=20)
217+
leg.text(2, 5-i, txt)
183218
leg.set_xlim(0.5, 3)
184219
leg.set_ylim(-1, 6)
185220
leg.set_axis_off()

CIAlign/palettes.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python3
2+
3+
def base():
4+
'''
5+
Returns the hexadecimal values for black and white
6+
7+
Parameters
8+
----------
9+
None
10+
11+
Returns
12+
-------
13+
dict
14+
A dictionary containing the hexadecimal values for black and white
15+
'''
16+
17+
return {'black': '#000000',
18+
'white': '#FFFFFF'}
19+
20+
def CBSafe():
21+
'''
22+
Returns the hexadecimal values for a colour blind safe colour palette
23+
24+
Parameters
25+
----------
26+
None
27+
28+
Returns
29+
-------
30+
dict
31+
A dictionary containing the hexadecimal values for the colours used
32+
in the CIAlign mini alignments
33+
'''
34+
35+
b = base()
36+
b.update({'yellow_nt': "#c9c433",
37+
'green_nt': "#56ae6c",
38+
'red_nt': "#a22c49",
39+
'blue_nt': "#0038a2",
40+
'grey_nt': "#6979d3",
41+
'red_aa': "#a22c49",
42+
'yellow_aa': "#c9c433",
43+
'blue_aa': "#0038a2",
44+
'orange_aa': "#e57700",
45+
'midblue_aa': "#589aab",
46+
'cyan_aa': "#50d3cb",
47+
'lightgrey_aa': '#eae2ea',
48+
'green_aa': "#56ae6c",
49+
'darkgrey_aa': "#888988",
50+
'purple_aa': '#89236a',
51+
'paleblue_aa': '#e669ca',
52+
'peach_aa': "#ffc4a9",
53+
'tan_aa': "#936e23",
54+
'remove_insertions': "#9db341",
55+
'remove_divergent': "#7066bc",
56+
'crop_ends': '#020545',
57+
'remove_gaponly': '#f9c1d2',
58+
'remove_short': "#c85133"})
59+
return (b)
60+

CIAlign/utilityFunctions.py

Lines changed: 108 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import warnings
66
import matplotlib.font_manager
77
import sys
8+
try:
9+
import CIAlign.palettes as palettes
10+
except ImportError:
11+
import palettes
812
matplotlib.use('Agg')
913

1014

@@ -95,86 +99,139 @@ def FastaToArray(infile, log=None, outfile_stem=None):
9599
return (arr, nams[1:])
96100

97101

98-
def getAAColours():
102+
def getPalette(palette='CBS'):
103+
'''
104+
Generates a dictionary which assigns a name to each colour using a colour
105+
blindness safe palette, generated using
106+
https://medialab.github.io/iwanthue/
107+
Parameters
108+
----------
109+
palette: str
110+
The ID of the palette to be used, currently only colour blind safe
111+
(CBS) is implemented.
112+
113+
Returns
114+
-------
115+
dict
116+
Dictionary where keys are names of colours and
117+
values are hexadecimal codes for colours
118+
'''
119+
if palette.lower() == 'cbs':
120+
p = palettes.CBSafe()
121+
122+
return (p)
123+
124+
125+
def getAAColours(pal='CBS'):
99126
'''
100127
Generates a dictionary which assigns a colour to each amino acid.
101128
Based on the "RasmMol" amino colour scheme and the table here:
102129
http://acces.ens-lyon.fr/biotic/rastop/help/colour.htm
103-
(plus grey for "X" and white for "-")
130+
approximated using a CB safe palette generated using
131+
https://medialab.github.io/iwanthue/
104132
105133
Parameters
106134
----------
107-
None
135+
pal: str
136+
A string designating which palette to use, currently only colour blind
137+
safe (CBS) is implemented.
108138
109139
Returns
110140
-------
111141
dict
112142
Dictionary where keys are single letter amino acid codes and
113143
values are hexadecimal codes for colours
114144
'''
115-
return {'D': '#E60A0A',
116-
'E': '#E60A0A',
117-
'C': '#E6E600',
118-
'M': '#E6E600',
119-
'K': '#145AFF',
120-
'R': '#145AFF',
121-
'S': '#FA9600',
122-
'T': '#FA9600',
123-
'F': '#3232AA',
124-
'Y': '#3232AA',
125-
'N': '#00DCDC',
126-
'Q': '#00DCDC',
127-
'G': '#EBEBEB',
128-
'L': '#0F820F',
129-
'V': '#0F820F',
130-
'I': '#0F820F',
131-
'A': '#C8C8C8',
132-
'W': '#B45AB4',
133-
'H': '#8282D2',
134-
'P': '#DC9682',
135-
'X': '#b2b2b2',
136-
'-': '#FFFFFF00',
137-
'B': '#b2b2b2',
138-
'Z': '#b2b2b2',
139-
'J': '#b2b2b2',
140-
'*': '#FFFFFF00',
141-
'U': '#b2b2b2',
142-
'O': '#b2b2b2'
145+
pal = getPalette(palette=pal)
146+
return {'D': pal['red_aa'],
147+
'E': pal['red_aa'],
148+
'C': pal['yellow_aa'],
149+
'M': pal['yellow_aa'],
150+
'K': pal['blue_aa'],
151+
'R': pal['blue_aa'],
152+
'S': pal['orange_aa'],
153+
'T': pal['orange_aa'],
154+
'F': pal['midblue_aa'],
155+
'Y': pal['midblue_aa'],
156+
'N': pal['cyan_aa'],
157+
'Q': pal['cyan_aa'],
158+
'G': pal['lightgrey_aa'],
159+
'L': pal['green_aa'],
160+
'V': pal['green_aa'],
161+
'I': pal['green_aa'],
162+
'A': pal['darkgrey_aa'],
163+
'W': pal['purple_aa'],
164+
'H': pal['paleblue_aa'],
165+
'P': pal['peach_aa'],
166+
'X': pal['black'],
167+
'-': pal['white'],
168+
'B': pal['tan_aa'],
169+
'Z': pal['tan_aa'],
170+
'J': pal['tan_aa'],
171+
'*': pal['white'],
172+
'U': pal['tan_aa'],
173+
'O': pal['tan_aa']
143174
}
144175

145176

146-
def getNtColours():
177+
def getNtColours(pal='CBS'):
147178
'''
148179
Generates a dictionary which assigns a colour to each nucleotide (plus grey
149180
for "N" and white for "-")
150181
Parameters
151182
----------
152-
None
183+
pal: str
184+
A string designating which palette to use, currently only colour blind
185+
safe (CBS) is implemented.
153186
154187
Returns
155188
-------
156189
dict
157190
Dictionary where keys are single letter nucleotide codes and
158191
values are hexadecimal codes for colours
159192
'''
160-
return {'A': '#1ed30f',
161-
'G': '#f4d931',
162-
'T': '#f43131',
163-
'C': '#315af4',
164-
'N': '#b2b2b2',
165-
"-": '#FFFFFF',
166-
"U": '#f43131',
167-
"R": '#b2b2b2',
168-
"Y": '#b2b2b2',
169-
"S": '#b2b2b2',
170-
"W": '#b2b2b2',
171-
"K": '#b2b2b2',
172-
"M": '#b2b2b2',
173-
"B": '#b2b2b2',
174-
"D": '#b2b2b2',
175-
"H": '#b2b2b2',
176-
"V": '#b2b2b2',
177-
"X": '#b2b2b2'}
193+
pal = getPalette(palette=pal)
194+
return {'A': pal['green_nt'],
195+
'G': pal['yellow_nt'],
196+
'T': pal['red_nt'],
197+
'C': pal['blue_nt'],
198+
'N': pal['grey_nt'],
199+
"-": pal['white'],
200+
"U": pal['red_nt'],
201+
"R": pal['grey_nt'],
202+
"Y": pal['grey_nt'],
203+
"S": pal['grey_nt'],
204+
"W": pal['grey_nt'],
205+
"K": pal['grey_nt'],
206+
"M": pal['grey_nt'],
207+
"B": pal['grey_nt'],
208+
"D": pal['grey_nt'],
209+
"H": pal['grey_nt'],
210+
"V": pal['grey_nt'],
211+
"X": pal['grey_nt']}
212+
213+
214+
def getMarkupColours(pal='CBS'):
215+
'''
216+
Generates a dictionary which assigns a colour to each markup type
217+
Parameters
218+
----------
219+
pal: str
220+
A string designating which palette to use, currently only colour blind
221+
safe (CBS) is implemented.
222+
223+
Returns
224+
-------
225+
dict
226+
Dictionary where keys are CIAlign cleaning function names and
227+
values are hexadecimal codes for colours
228+
'''
229+
pal = getPalette(palette=pal)
230+
return {'remove_insertions': pal['remove_insertions'],
231+
'crop_ends': pal['crop_ends'],
232+
'remove_gaponly': pal['remove_gaponly'],
233+
'remove_short': pal['remove_short'],
234+
'remove_divergent': pal['remove_divergent']}
178235

179236

180237
def writeOutfile(outfile, arr, nams, removed, rmfile=None):
-178 KB
Loading
-118 KB
Loading
694 KB
Loading
628 KB
Loading
796 KB
Loading
760 KB
Loading

0 commit comments

Comments
 (0)