Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
S
sails
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
analysis
sails
Commits
00b670e6
Commit
00b670e6
authored
May 05, 2020
by
Mark Hymers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow specifying link colours as #rrggbb
Signed-off-by:
Mark Hymers
<
mark.hymers@ynic.york.ac.uk
>
parent
9e2c2fa8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
2 deletions
+91
-2
sails/circular_plots.py
sails/circular_plots.py
+91
-2
No files found.
sails/circular_plots.py
View file @
00b670e6
...
...
@@ -12,6 +12,7 @@ import tempfile
import
numpy
as
np
import
matplotlib.colors
as
mc
import
matplotlib.pyplot
as
plt
# Note that we currently assume the use of 1000 for band widths to make life
...
...
@@ -39,6 +40,8 @@ band_stroke_color = white
band_transparency = 4
</ideogram>
{colors:s}
{ticks:s}
<image>
...
...
@@ -662,7 +665,7 @@ class CircosHandler(object):
if
np
.
isnan
(
val
):
continue
if
isinstance
(
linkcolors
,
tuple
):
if
isinstance
(
linkcolors
,
(
tuple
,
list
)
):
if
val
==
0
:
color
=
linkcolors
[
0
]
elif
val
<
0
:
...
...
@@ -686,6 +689,89 @@ class CircosHandler(object):
return
'
\n
'
.
join
(
s
)
def
parse_colors
(
self
,
linkcolors
,
defaultlinkcolor
):
"""
Parse hex colours into something usable by circos
"""
# Map (r, g, b) tuples to colour names
colour_dict
=
{}
colidx
=
0
if
isinstance
(
linkcolors
,
(
tuple
,
list
)):
lc
=
[]
for
colour
in
linkcolors
:
if
colour
.
startswith
(
'#'
):
# Parse as #RGB and add to colour_dict
r
,
g
,
b
=
mc
.
hex2color
(
colour
)
r
=
int
(
r
*
255
)
g
=
int
(
g
*
255
)
b
=
int
(
b
*
255
)
if
(
r
,
g
,
b
)
not
in
colour_dict
.
keys
():
colour_dict
[(
r
,
g
,
b
)]
=
'customcolor{}'
.
format
(
colidx
)
colidx
+=
1
lc
.
append
(
colour_dict
[(
r
,
g
,
b
)])
else
:
# Leave as it is
lc
.
append
(
colour
)
lc
=
tuple
(
lc
)
elif
isinstance
(
linkcolors
,
np
.
ndarray
):
lc
=
linkcolors
.
copy
()
for
row
in
range
(
lc
.
shape
[
0
]):
for
col
in
range
(
lc
.
shape
[
1
]):
colour
=
lc
[
row
,
col
]
if
colour
is
not
None
and
colour
.
startswith
(
'#'
):
# Parse as #RGB and add to colour_dict
r
,
g
,
b
=
mc
.
hex2color
(
colour
)
r
=
int
(
r
*
255
)
g
=
int
(
g
*
255
)
b
=
int
(
b
*
255
)
if
(
r
,
g
,
b
)
not
in
colour_dict
.
keys
():
colour_dict
[(
r
,
g
,
b
)]
=
'customcolor{}'
.
format
(
colidx
)
colidx
+=
1
lc
[
row
,
col
]
=
colour_dict
[(
r
,
g
,
b
)]
elif
linkcolors
is
None
:
lc
=
None
else
:
raise
Exception
(
"Cannot parse link colors {}"
.
format
(
linkcolors
))
if
defaultlinkcolor
is
None
:
dlc
=
None
elif
defaultlinkcolor
.
startswith
(
"#"
):
# Parse as #RGB and add to colour_dict
r
,
g
,
b
=
mc
.
hex2color
(
defaultlinkcolor
)
r
=
int
(
r
*
255
)
g
=
int
(
g
*
255
)
b
=
int
(
b
*
255
)
if
(
r
,
g
,
b
)
not
in
colour_dict
.
keys
():
colour_dict
[(
r
,
g
,
b
)]
=
'customcolor{}'
.
format
(
colidx
)
colidx
+=
1
dlc
=
colour_dict
[(
r
,
g
,
b
)]
else
:
dlc
=
defaultlinkcolor
# Work out what to put in the colors section (if anything)
colour_text
=
""
if
len
(
colour_dict
)
>
0
:
colour_text
=
"""<colors>
\n
"""
for
k
,
v
in
colour_dict
.
items
():
colour_text
+=
"{} = {},{},{}
\n
"
.
format
(
v
,
k
[
0
],
k
[
1
],
k
[
2
])
colour_text
+=
"""</colors>
\n
"""
return
lc
,
dlc
,
colour_text
def
gen_circos_files
(
self
,
data
,
karyotype_name
,
output_name
,
radius
=
1500
,
circos_path
=
'/etc/circos'
,
...
...
@@ -741,11 +827,13 @@ class CircosHandler(object):
linkcolors
=
kwargs
.
get
(
'linkcolors'
,
None
)
defaultlinkcolor
=
kwargs
.
get
(
'defaultlinkcolor'
,
'black'
)
lc
,
dlc
,
colors
=
self
.
parse_colors
(
linkcolors
,
defaultlinkcolor
)
circle_radius
=
kwargs
.
get
(
'circle_prop'
,
0.85
)
# First of all, create the .txt links file
f
=
open
(
linkspath
,
'w'
)
f
.
write
(
self
.
links
(
data
,
l
inkcolors
,
defaultlinkcolor
))
f
.
write
(
self
.
links
(
data
,
l
c
,
dlc
))
f
.
close
()
# Now the config file - pass all keyword arguments down
...
...
@@ -755,6 +843,7 @@ class CircosHandler(object):
f
.
write
(
CIRCOS_CONF_TEMPLATE
.
format
(
karyotype
=
karyotype_name
,
ticks
=
ticks
,
radius
=
radius
,
colors
=
colors
,
circospath
=
circos_path
,
linksname
=
linksname
,
outputimage
=
imagename
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment