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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Blaise LI
plotting_scripts
Commits
34c5af35
Commit
34c5af35
authored
6 years ago
by
Blaise Li
Browse files
Options
Downloads
Patches
Plain Diff
Renaming function, commenting.
parent
443b2dfe
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plot_scatterplot.py
+14
-5
14 additions, 5 deletions
plot_scatterplot.py
with
14 additions
and
5 deletions
plot_scatterplot.py
+
14
−
5
View file @
34c5af35
#!/usr/bin/env python3
#!/usr/bin/env python3
# vim: set fileencoding=<utf-8> :
# vim: set fileencoding=<utf-8> :
"""
This script reads data from
"
tidy
"
files and makes plots out of
"""
This script reads data from
"
tidy
"
files and makes a scatter plot out of it.
it, at the same scale.
It also outputs a table containing the plotted data points.
"""
It also outputs a table containing the plotted data points.
"""
import
argparse
import
argparse
...
@@ -91,12 +90,19 @@ class Scatterplot:
...
@@ -91,12 +90,19 @@ class Scatterplot:
y_column
,
y_column
,
labels
,
labels
,
extra_cols
=
None
):
extra_cols
=
None
):
# usecols can be a callable to filter column names:
# If callable, the callable function will be evaluated against the
# column names, returning names where the callable function evaluates
# to True.
if
extra_cols
is
None
:
if
extra_cols
is
None
:
x_usecols
=
[
"
gene
"
,
x_column
].
__contains__
x_usecols
=
[
"
gene
"
,
x_column
].
__contains__
y_usecols
=
[
"
gene
"
,
y_column
].
__contains__
y_usecols
=
[
"
gene
"
,
y_column
].
__contains__
else
:
else
:
x_usecols
=
[
"
gene
"
,
x_column
,
*
extra_cols
].
__contains__
x_usecols
=
[
"
gene
"
,
x_column
,
*
extra_cols
].
__contains__
y_usecols
=
[
"
gene
"
,
y_column
,
*
extra_cols
].
__contains__
y_usecols
=
[
"
gene
"
,
y_column
,
*
extra_cols
].
__contains__
# The columns containing the data to plot might have the same name
# in the two tables.
# We rename them to x and y for simplicity.
x_data
=
pd
.
read_csv
(
x_data
=
pd
.
read_csv
(
x_input_file
,
sep
=
"
\t
"
,
index_col
=
"
gene
"
,
usecols
=
x_usecols
).
rename
(
x_input_file
,
sep
=
"
\t
"
,
index_col
=
"
gene
"
,
usecols
=
x_usecols
).
rename
(
columns
=
{
x_column
:
"
x
"
})
columns
=
{
x_column
:
"
x
"
})
...
@@ -115,6 +121,7 @@ class Scatterplot:
...
@@ -115,6 +121,7 @@ class Scatterplot:
self
.
data
=
pd
.
merge
(
self
.
data
=
pd
.
merge
(
x_data
,
y_data
,
x_data
,
y_data
,
left_index
=
True
,
right_index
=
True
,
validate
=
"
one_to_one
"
)
left_index
=
True
,
right_index
=
True
,
validate
=
"
one_to_one
"
)
# Compute a classifier column (to be used to colour points)
if
extra_cols
is
not
None
:
if
extra_cols
is
not
None
:
extra_cols
=
list
(
concat
((
extra_cols
=
list
(
concat
((
[
colname
]
if
colname
in
self
.
data
.
columns
[
colname
]
if
colname
in
self
.
data
.
columns
...
@@ -148,7 +155,7 @@ class Scatterplot:
...
@@ -148,7 +155,7 @@ class Scatterplot:
def
plot_maker
(
self
,
grouping
=
None
,
group2colour
=
None
,
**
kwargs
):
def
plot_maker
(
self
,
grouping
=
None
,
group2colour
=
None
,
**
kwargs
):
"""
Builds a plotting function that can colour dots based on them
"""
Builds a plotting function that can colour dots based on them
belonging to a group defined by *grouping*.
"""
belonging to a group defined by *grouping*.
"""
def
plot
_lfclfc_scatter
():
def
plot
ting_function
():
"""
Generates the scatterplot, returns its legend so that
"""
Generates the scatterplot, returns its legend so that
*save_plot* can include it in the bounding box.
"""
*save_plot* can include it in the bounding box.
"""
# fig, axis = plot_scatter(
# fig, axis = plot_scatter(
...
@@ -297,9 +304,11 @@ class Scatterplot:
...
@@ -297,9 +304,11 @@ class Scatterplot:
# TODO: force ticks to be integers
# TODO: force ticks to be integers
# Return a tuple of "extra artists",
# Return a tuple of "extra artists",
# to correctly define the bounding box
# to correctly define the bounding box
return
plot
_lfclfc_scatter
return
plot
ting_function
def
save_plot
(
self
,
outfile
,
grouping
=
None
,
group2colour
=
None
,
**
kwargs
):
def
save_plot
(
self
,
outfile
,
grouping
=
None
,
group2colour
=
None
,
**
kwargs
):
"""
Creates the plotting function and transmits it for execution
"""
Creates the plotting function and transmits it for execution
to the function that really does the saving.
"""
to the function that really does the saving.
"""
if
grouping
is
None
and
self
.
grouping_col
is
not
None
:
if
grouping
is
None
and
self
.
grouping_col
is
not
None
:
...
...
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