Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
plotting_scripts
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Blaise LI
plotting_scripts
Commits
e332b282
Commit
e332b282
authored
6 years ago
by
Blaise Li
Browse files
Options
Downloads
Patches
Plain Diff
Moved optional plotting to static methods.
parent
3ddac00d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
plot_scatterplot.py
+90
-58
90 additions, 58 deletions
plot_scatterplot.py
with
90 additions
and
58 deletions
plot_scatterplot.py
+
90
−
58
View file @
e332b282
...
...
@@ -83,6 +83,85 @@ class Scatterplot:
Intended to be used with *DataFrame.apply*.
"""
return
"
_
"
.
join
(
map
(
str
,
row
.
values
))
@staticmethod
def
put_quadrants
(
axis
,
x_annot_loc
,
y_annot_loc
,
line_style
):
"""
Delineate quadrants of absolute fold changes over 2.
*axis* is the :class:`matplotlib.axes.Axes` on which to work.
*x_annot_loc* and *y_annot_loc* are the position at which to annotate
the lines delineating the quadrants.
This works through side effects on *axis*.
"""
axis
.
axhline
(
y
=
1
,
**
line_style
)
axis
.
annotate
(
f
"
y = 1
"
,
xy
=
(
x_annot_loc
,
1
),
xycoords
=
"
data
"
,
horizontalalignment
=
'
left
'
,
verticalalignment
=
'
bottom
'
,
size
=
"
x-small
"
,
color
=
line_style
[
"
color
"
])
axis
.
axhline
(
y
=-
1
,
**
line_style
)
axis
.
annotate
(
f
"
y = -1
"
,
xy
=
(
x_annot_loc
,
-
1
),
xycoords
=
"
data
"
,
horizontalalignment
=
'
left
'
,
verticalalignment
=
'
top
'
,
size
=
"
x-small
"
,
color
=
line_style
[
"
color
"
])
axis
.
axvline
(
x
=
1
,
**
line_style
)
axis
.
annotate
(
f
"
x = -1
"
,
xy
=
(
-
1
,
y_annot_loc
),
xycoords
=
"
data
"
,
horizontalalignment
=
'
right
'
,
verticalalignment
=
'
bottom
'
,
rotation
=
90
,
size
=
"
x-small
"
,
color
=
line_style
[
"
color
"
])
axis
.
axvline
(
x
=-
1
,
**
line_style
)
axis
.
annotate
(
f
"
x = 1
"
,
xy
=
(
1
,
y_annot_loc
),
xycoords
=
"
data
"
,
horizontalalignment
=
'
left
'
,
verticalalignment
=
'
bottom
'
,
rotation
=
90
,
size
=
"
x-small
"
,
color
=
line_style
[
"
color
"
])
@staticmethod
def
write_quadrant_counts
(
axis
,
annot_up_up
,
annot_up_down
,
annot_down_up
,
annot_down_down
,
text_color
):
"""
Annotate quadrants of absolute fold changes over 2.
*axis* is the :class:`matplotlib.axes.Axes` on which to work.
*annot_up_up*, *annot_up_down*, *annot_down_up* and *annot_down_down*
are the annotations to put in each quadrant.
This works through side effects on *axis*.
"""
axis
.
annotate
(
annot_up_up
,
xy
=
(
0.95
,
0.95
),
xycoords
=
"
axes fraction
"
,
size
=
"
x-small
"
,
color
=
text_color
,
horizontalalignment
=
"
right
"
,
verticalalignment
=
"
top
"
)
axis
.
annotate
(
annot_up_down
,
xy
=
(
0.95
,
0.05
),
xycoords
=
"
axes fraction
"
,
size
=
"
x-small
"
,
color
=
text_color
,
horizontalalignment
=
"
right
"
,
verticalalignment
=
"
bottom
"
)
axis
.
annotate
(
annot_down_up
,
xy
=
(
0.05
,
0.95
),
xycoords
=
"
axes fraction
"
,
size
=
"
x-small
"
,
color
=
text_color
,
horizontalalignment
=
"
left
"
,
verticalalignment
=
"
top
"
)
axis
.
annotate
(
annot_down_down
,
xy
=
(
0.05
,
0.05
),
xycoords
=
"
axes fraction
"
,
size
=
"
x-small
"
,
color
=
text_color
,
horizontalalignment
=
"
left
"
,
verticalalignment
=
"
bottom
"
)
def
__init__
(
self
,
x_input_file
,
y_input_file
,
...
...
@@ -152,7 +231,11 @@ class Scatterplot:
if
gene_id
in
chose_from
]
return
[
gene_id
for
gene_id
in
self
.
data
.
query
(
selector
).
index
]
def
plot_maker
(
self
,
annotate_folds
=
True
,
grouping
=
None
,
group2colour
=
None
,
**
kwargs
):
def
plot_maker
(
self
,
annotate_folds
=
True
,
grouping
=
None
,
group2colour
=
None
,
**
kwargs
):
"""
Builds a plotting function that can colour dots based on them
belonging to a group defined by *grouping*.
If *annotate_folds* is True, lines indicating 2-fold thresholds
...
...
@@ -188,43 +271,9 @@ class Scatterplot:
(
y_annot_loc
,
_
)
=
kwargs
[
"
y_range
"
]
else
:
y_annot_loc
=
min
(
self
.
data
.
y
)
axis
.
axhline
(
y
=
1
,
**
line_style
)
axis
.
annotate
(
f
"
y = 1
"
,
xy
=
(
x_annot_loc
,
1
),
xycoords
=
"
data
"
,
horizontalalignment
=
'
left
'
,
verticalalignment
=
'
bottom
'
,
size
=
"
x-small
"
,
color
=
line_style
[
"
color
"
])
axis
.
axhline
(
y
=-
1
,
**
line_style
)
axis
.
annotate
(
f
"
y = -1
"
,
xy
=
(
x_annot_loc
,
-
1
),
xycoords
=
"
data
"
,
horizontalalignment
=
'
left
'
,
verticalalignment
=
'
top
'
,
size
=
"
x-small
"
,
color
=
line_style
[
"
color
"
])
axis
.
axvline
(
x
=
1
,
**
line_style
)
axis
.
annotate
(
f
"
x = -1
"
,
xy
=
(
-
1
,
y_annot_loc
),
xycoords
=
"
data
"
,
horizontalalignment
=
'
right
'
,
verticalalignment
=
'
bottom
'
,
rotation
=
90
,
size
=
"
x-small
"
,
color
=
line_style
[
"
color
"
])
axis
.
axvline
(
x
=-
1
,
**
line_style
)
axis
.
annotate
(
f
"
x = 1
"
,
xy
=
(
1
,
y_annot_loc
),
xycoords
=
"
data
"
,
horizontalalignment
=
'
left
'
,
verticalalignment
=
'
bottom
'
,
rotation
=
90
,
size
=
"
x-small
"
,
color
=
line_style
[
"
color
"
])
# Number of genes beyond lfc thresholds, in each quadrant
# up_up = 100 * len(self.data.query(
# f"x > 1 & y > 1")) / len(self.data)
# up_down = 100 * len(self.data.query(
# f"x > 1 & y < 1")) / len(self.data)
# down_up = 100 * len(self.data.query(
# f"x < 1 & y > 1")) / len(self.data)
# down_down = 100 * len(self.data.query(
# f"x < 1 & y < 1")) / len(self.data)
Scatterplot
.
put_quadrants
(
axis
,
x_annot_loc
,
y_annot_loc
,
line_style
)
# Genes beyond lfc thresholds, in each quadrant
up_up
=
self
.
data
.
query
(
"
x > 1 & y > 1
"
)
up_down
=
self
.
data
.
query
(
...
...
@@ -256,30 +305,13 @@ class Scatterplot:
ingroup_up_down
=
""
ingroup_down_up
=
""
ingroup_down_down
=
""
axis
.
annotate
(
Scatterplot
.
write_quadrant_counts
(
axis
,
f
"
{
len
(
up_up
)
}{
ingroup_up_up
}
"
,
xy
=
(
0.95
,
0.95
),
xycoords
=
"
axes fraction
"
,
size
=
"
x-small
"
,
color
=
line_style
[
"
color
"
],
horizontalalignment
=
"
right
"
,
verticalalignment
=
"
top
"
)
axis
.
annotate
(
f
"
{
len
(
up_down
)
}{
ingroup_up_down
}
"
,
xy
=
(
0.95
,
0.05
),
xycoords
=
"
axes fraction
"
,
size
=
"
x-small
"
,
color
=
line_style
[
"
color
"
],
horizontalalignment
=
"
right
"
,
verticalalignment
=
"
bottom
"
)
axis
.
annotate
(
f
"
{
len
(
down_up
)
}{
ingroup_down_up
}
"
,
xy
=
(
0.05
,
0.95
),
xycoords
=
"
axes fraction
"
,
size
=
"
x-small
"
,
color
=
line_style
[
"
color
"
],
horizontalalignment
=
"
left
"
,
verticalalignment
=
"
top
"
)
axis
.
annotate
(
f
"
{
len
(
down_down
)
}{
ingroup_down_down
}
"
,
xy
=
(
0.05
,
0.05
),
xycoords
=
"
axes fraction
"
,
size
=
"
x-small
"
,
color
=
line_style
[
"
color
"
],
horizontalalignment
=
"
left
"
,
verticalalignment
=
"
bottom
"
)
line_style
[
"
color
"
])
axis
.
set_xlabel
(
self
.
x_label
,
fontsize
=
17
)
axis
.
set_ylabel
(
self
.
y_label
,
fontsize
=
17
)
# This doesn't work with plt.axis("equal")
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment