Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ONT_pilot_gitlab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Contributor 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
ESB
ONT_pilot_gitlab
Commits
25b450c3
Commit
25b450c3
authored
4 years ago
by
Valentina Galata
Browse files
Options
Downloads
Patches
Plain Diff
crispr fig: num of spacers/arrays per assembly; contig intersections (issue
#19
)
parent
1990f776
No related branches found
No related tags found
2 merge requests
!71
Master
,
!70
Add latest figure updates
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
figures/src/fig_crispr.R
+75
-6
75 additions, 6 deletions
figures/src/fig_crispr.R
figures/src/utils.R
+1
-0
1 addition, 0 deletions
figures/src/utils.R
with
76 additions
and
6 deletions
figures/src/fig_crispr.R
+
75
−
6
View file @
25b450c3
...
...
@@ -8,7 +8,7 @@ sink(file=file(snakemake@log[[1]], open="wt"), type="message")
## IMPORT
suppressMessages
(
library
(
testit
))
suppressMessages
(
library
(
UpSetR
))
#
suppressMessages(library(UpSetR))
suppressMessages
(
library
(
ggplot2
))
# custom
source
(
snakemake
@
params
$
utils
)
...
...
@@ -24,23 +24,92 @@ stats <- read.csv(
# change names
stats
$
crispr_tool
<-
CRISPR_TOOL_NAMES
[
stats
$
crispr_tool
]
stats
$
asm_tool
<-
ASM_TOOL_NAMES
[
stats
$
asm_tool
]
# aggregate: spacers per contig
# stats_aggr_sc <- aggregate(
# x=stats$spacers,
# by=list(seq_id=stats$seq_id, crispr_tool=stats$crispr_tool, asm_tool=stats$asm_tool),
# FUN=sum
# )
# aggregate: spacers per assembly
stats_aggr_sa
<-
aggregate
(
x
=
stats
$
spacers
,
by
=
list
(
crispr_tool
=
stats
$
crispr_tool
,
asm_tool
=
stats
$
asm_tool
),
FUN
=
sum
)
# aggregate: arrays per assembly
stats_aggr_aa
<-
aggregate
(
x
=
stats
$
seq_id
,
by
=
list
(
crispr_tool
=
stats
$
crispr_tool
,
asm_tool
=
stats
$
asm_tool
),
FUN
=
length
)
## PLOT: UpSetR + PDF
## PLOTS
# UpSetR plotting function
plot_upsetr
<-
function
(
df
,
asm_tool
){
asm_sets
<-
lapply
(
CRISPR_TOOL_NAMES
,
function
(
x
){
unique
(
unlist
(
df
[
df
$
asm_tool
==
asm_tool
&
df
$
crispr_tool
==
x
,
"seq_id"
]))
}
)
names
(
asm_sets
)
<-
CRISPR_TOOL_NAMES
[
names
(
asm_sets
)]
UpSetR
::
upset
(
data
=
UpSetR
::
fromList
(
asm_sets
),
order.by
=
"degree"
,
decreasing
=
FALSE
)
UpSetR
::
upset
(
data
=
UpSetR
::
fromList
(
asm_sets
),
order.by
=
"degree"
,
decreasing
=
FALSE
,
mainbar.y.label
=
sprintf
(
"Contig intersection size (%s)"
,
asm_tool
),
sets.x.label
=
"Contigs w/ CRISPR array(s)"
)
}
# Custom ggplot2 theme
my_theme
<-
theme_bw
()
+
theme
(
# legend
legend.title
=
element_blank
(),
# grid
panel.grid
=
element_blank
(),
# strip
strip.background
=
element_rect
(
fill
=
"white"
),
strip.text
=
element_text
(
size
=
12
,
color
=
"black"
),
# axes
axis.title
=
element_text
(
size
=
12
,
color
=
"black"
),
axis.text.y
=
element_text
(
size
=
9
,
color
=
"black"
),
axis.text.x
=
element_text
(
size
=
9
,
color
=
"black"
,
angle
=
90
,
vjust
=
0.5
,
hjust
=
1
)
)
# List of ggplot plots
plots
<-
list
()
# Plot: Number of spacers per tool/assembly
plots
$
spacers_asm
<-
ggplot
(
data
=
stats_aggr_sa
,
aes
(
x
=
crispr_tool
,
y
=
x
,
fill
=
asm_tool
))
+
geom_col
(
position
=
"dodge"
)
+
scale_fill_manual
(
values
=
ASM_TOOL_COLORS
$
notmeth
,
guide
=
"legend"
)
+
labs
(
x
=
""
,
y
=
"Number of spacers"
)
+
my_theme
# Plot: Number of arrays per tool/assembly
plots
$
arrays_asm
<-
ggplot
(
data
=
stats_aggr_aa
,
aes
(
x
=
crispr_tool
,
y
=
x
,
fill
=
asm_tool
))
+
geom_col
(
position
=
"dodge"
)
+
scale_fill_manual
(
values
=
ASM_TOOL_COLORS
$
notmeth
,
guide
=
"legend"
)
+
labs
(
x
=
""
,
y
=
"Number of CRISPR arrays"
)
+
my_theme
# Plot: UpSetR (+ PDF)
# NOTE:
# For an unknown reason creating and saving multiple plots using a for-loop or sapply d
id
not work - the PDF
wa
s empty.
# Creating a PDF per plot in a for-loop or using sapply d
id
not work either - each PDF
wa
s empty.
# For an unknown reason creating and saving multiple plots using a for-loop or sapply d
oes
not work - the PDF
i
s empty.
# Creating a PDF per plot in a for-loop or using sapply d
oes
not work either - each PDF
i
s empty.
pdf
(
snakemake
@
output
$
pdf
,
width
=
snakemake
@
params
$
width
,
height
=
snakemake
@
params
$
height
)
for
(
pp
in
plots
){
print
(
pp
)
}
plot_upsetr
(
stats
,
"Flye"
)
plot_upsetr
(
stats
,
"MEGAHIT"
)
plot_upsetr
(
stats
,
"metaSPAdes"
)
plot_upsetr
(
stats
,
"metaSPAdes (H)"
)
dev.off
()
\ No newline at end of file
dev.off
()
This diff is collapsed.
Click to expand it.
figures/src/utils.R
+
1
−
0
View file @
25b450c3
...
...
@@ -90,6 +90,7 @@ PLASFLOW_COLORS <- list(
)
names
(
PLASFLOW_COLORS
$
class
)
<-
c
(
"chromosome"
,
"plasmid"
,
"unclassified"
)
##############################
# RGI
RGI_NAMES
<-
list
(
col
=
c
(
...
...
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