Skip to content

Commit c2a2001

Browse files
committed
feat: formatted all R code with 'styler'
1 parent a156490 commit c2a2001

27 files changed

+476
-340
lines changed

R/ConsensusPeak.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
GetConsensusPeak <- function(peak.file, peak.folder = NULL, mspc.path = NULL, rep.type = c("bio", "tec"), stringency.threshold = 1e-8,
2727
weak.threshold = 1e-4, gamma = 1e-8, alpha = 0.05, min.overlap.num = 1,
2828
multiple.intersections = c("Lowest", "Highest"), parallelism.degree = 1) {
29-
3029
# check parameters
3130
rep.type <- match.arg(arg = rep.type)
3231
multiple.intersections <- match.arg(arg = multiple.intersections)

R/LoadTrack.R

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,16 @@
5656
#' meta.info = sample.meta
5757
#' )
5858
LoadTrackFile <- function(
59-
track.file, track.folder = NULL,
60-
format = c("bam", "wig", "bw", "bedgraph", "txt"),
61-
region = NULL, extend = 2000,
62-
gtf.gr = NULL, gene.name = "HNRNPC",
63-
gene.name.type = c("gene_name", "gene_id"),
64-
meta.info = NULL, meta.file = "",
65-
bamcoverage.path = NULL,
66-
norm.method = c("RPKM", "CPM", "BPM", "RPGC", "None"),
67-
single.nuc = FALSE, single.nuc.region = NULL,
68-
bin.size = 10, bc.extra.para = NULL, n.cores = 1
69-
) {
59+
track.file, track.folder = NULL,
60+
format = c("bam", "wig", "bw", "bedgraph", "txt"),
61+
region = NULL, extend = 2000,
62+
gtf.gr = NULL, gene.name = "HNRNPC",
63+
gene.name.type = c("gene_name", "gene_id"),
64+
meta.info = NULL, meta.file = "",
65+
bamcoverage.path = NULL,
66+
norm.method = c("RPKM", "CPM", "BPM", "RPGC", "None"),
67+
single.nuc = FALSE, single.nuc.region = NULL,
68+
bin.size = 10, bc.extra.para = NULL, n.cores = 1) {
7069
# check parameters
7170
format <- match.arg(arg = format)
7271
gene.name.type <- match.arg(arg = gene.name.type)
@@ -83,8 +82,8 @@ LoadTrackFile <- function(
8382
if (format == "bam") {
8483
seqnames <- Rsamtools::scanBamHeader(track.file[1]) %>%
8584
lapply(function(x) x$targets) %>%
86-
unname %>%
87-
unlist
85+
unname() %>%
86+
unlist()
8887
gr <- GenomicRanges::GRanges(
8988
seqnames = names(seqnames[1]),
9089
IRanges(start = 1, end = min(100000, seqnames[1]))
@@ -128,20 +127,20 @@ LoadTrackFile <- function(
128127
BiocParallel::bplapply(track.file, BPPARAM = BiocParallel::MulticoreParam(), FUN = index_bam)
129128
}
130129
if (single.nuc) {
131-
if (is.null(n.cores) || n.cores == 1) {
132-
track.list <- lapply(
133-
track.file,
134-
single_nuc_cov,
135-
single.nuc.region
136-
)
137-
} else {
138-
track.list <- BiocParallel::bplapply(
139-
track.file,
140-
BPPARAM = BiocParallel::MulticoreParam(),
141-
FUN = single_nuc_cov,
142-
single.nuc.region
143-
)
144-
}
130+
if (is.null(n.cores) || n.cores == 1) {
131+
track.list <- lapply(
132+
track.file,
133+
single_nuc_cov,
134+
single.nuc.region
135+
)
136+
} else {
137+
track.list <- BiocParallel::bplapply(
138+
track.file,
139+
BPPARAM = BiocParallel::MulticoreParam(),
140+
FUN = single_nuc_cov,
141+
single.nuc.region
142+
)
143+
}
145144
} else {
146145
if (norm.method == "None") {
147146
message("Calculating coverage with GenomicAlignments when 'norm.method = None'")
@@ -310,8 +309,7 @@ single_nuc_cov <- function(x, single.nuc.region) {
310309
}
311310

312311
bam_coverage <- function(
313-
x, bamcoverage.path, bin.size, norm.method, bc.extra.para, gr
314-
) {
312+
x, bamcoverage.path, bin.size, norm.method, bc.extra.para, gr) {
315313
# bigwig file
316314
out.bw.file <- tempfile(fileext = c(".bw"))
317315
# prepare bamCoverage cmd

R/geom_base.R

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@
7676
#' single.nuc = TRUE,
7777
#' rect.color = "white"
7878
#' ) +
79-
#' geom_base(bam.file = bam.file,
80-
#' bs.fa.seq = BSgenome.Hsapiens.UCSC.hg19)
79+
#' geom_base(
80+
#' bam.file = bam.file,
81+
#' bs.fa.seq = BSgenome.Hsapiens.UCSC.hg19
82+
#' )
8183
#'
8284
geom_base <- function(bam.file, fa.file = NULL, bs.fa.seq = NULL, chr.split = "[[:space:]]",
8385
nuc.offset = -0.1, nuc.size = 4, nuc.padding = 0.05, nuc.padding.r = 0,
@@ -93,16 +95,17 @@ geom_base <- function(bam.file, fa.file = NULL, bs.fa.seq = NULL, chr.split = "[
9395
"*" = "#FFC0CB"
9496
), aa.border.color = "white", aa.size = 4, aa.margin = 2, aa.height = 0.4,
9597
plot.space = 2.5, plot.height = 0.5) {
96-
structure(list(
97-
bam.file = bam.file, fa.file = fa.file, bs.fa.seq = bs.fa.seq, chr.split = chr.split,
98-
nuc.offset = nuc.offset, nuc.size = nuc.size, nuc.padding = nuc.padding, nuc.padding.r = nuc.padding.r,
99-
nuc.color = nuc.color, guide.line = guide.line, guide.line.color = guide.line.color, guide.line.type = guide.line.type,
100-
mark.type = mark.type, star.size = star.size,
101-
show.aa = show.aa, sens = sens, numcode = numcode, NAstring = NAstring, ambiguous = ambiguous,
102-
aa.color = aa.color, aa.border.color = aa.border.color, aa.size = aa.size, aa.margin = aa.margin, aa.height = aa.height,
103-
plot.space = plot.space, plot.height = plot.height
104-
),
105-
class = "base"
98+
structure(
99+
list(
100+
bam.file = bam.file, fa.file = fa.file, bs.fa.seq = bs.fa.seq, chr.split = chr.split,
101+
nuc.offset = nuc.offset, nuc.size = nuc.size, nuc.padding = nuc.padding, nuc.padding.r = nuc.padding.r,
102+
nuc.color = nuc.color, guide.line = guide.line, guide.line.color = guide.line.color, guide.line.type = guide.line.type,
103+
mark.type = mark.type, star.size = star.size,
104+
show.aa = show.aa, sens = sens, numcode = numcode, NAstring = NAstring, ambiguous = ambiguous,
105+
aa.color = aa.color, aa.border.color = aa.border.color, aa.size = aa.size, aa.margin = aa.margin, aa.height = aa.height,
106+
plot.space = plot.space, plot.height = plot.height
107+
),
108+
class = "base"
106109
)
107110
}
108111

@@ -122,8 +125,10 @@ ggplot_add.base <- function(object, plot, object_name) {
122125
# plot.region.end <- plot.data[nrow(plot.data), "start"]
123126
plot.region.end <- max(plot.data[, "start"])
124127
region <-
125-
GenomicRanges::GRanges(plot.chr,
126-
IRanges::IRanges(plot.region.start, plot.region.end))
128+
GenomicRanges::GRanges(
129+
plot.chr,
130+
IRanges::IRanges(plot.region.start, plot.region.end)
131+
)
127132

128133
# get parameters
129134
bam.file <- object$bam.file
@@ -155,9 +160,11 @@ ggplot_add.base <- function(object, plot, object_name) {
155160

156161
# get position AGCT frequency
157162
pos.nuc.freq <-
158-
GenomicAlignments::alphabetFrequencyFromBam(bam.file,
159-
param = region,
160-
baseOnly = TRUE)
163+
GenomicAlignments::alphabetFrequencyFromBam(
164+
bam.file,
165+
param = region,
166+
baseOnly = TRUE
167+
)
161168
# filter out others
162169
pos.nuc.freq <-
163170
pos.nuc.freq[, c("A", "G", "C", "T")] %>% as.data.frame()
@@ -202,15 +209,15 @@ ggplot_add.base <- function(object, plot, object_name) {
202209
# get position with alt
203210
alt.pos <- pos.nuc.freq.long %>%
204211
dplyr::filter(.data$Ref == .data$Base &
205-
.data$Total != .data$Freq) %>%
212+
.data$Total != .data$Freq) %>%
206213
dplyr::pull(.data$Pos) %>%
207214
unique()
208215
alt.pos.nuc.freq.long <-
209216
pos.nuc.freq.long %>% dplyr::filter(.data$Pos %in% c(alt.pos))
210217
# get position without alt
211218
ref.pos <- pos.nuc.freq.long %>%
212219
dplyr::filter(.data$Ref == .data$Base &
213-
.data$Total == .data$Freq) %>%
220+
.data$Total == .data$Freq) %>%
214221
dplyr::pull(.data$Pos) %>%
215222
unique()
216223
ref.pos.nuc.freq.long <-
@@ -336,9 +343,11 @@ ggplot_add.base <- function(object, plot, object_name) {
336343
label.r = unit(nuc.padding.r, "lines")
337344
) +
338345
labs(y = "Base") +
339-
geom_hline(yintercept = guide.line,
340-
color = guide.line.color,
341-
linetype = guide.line.type)
346+
geom_hline(
347+
yintercept = guide.line,
348+
color = guide.line.color,
349+
linetype = guide.line.type
350+
)
342351

343352
# make final AA plot
344353
options(digits = nchar(max(list_translated[[1]]$Pos)) + 1)
@@ -358,17 +367,20 @@ ggplot_add.base <- function(object, plot, object_name) {
358367
),
359368
color = aa.border.color
360369
) +
361-
geom_text(data = list_translated[[reading_frame]],
362-
aes_string(x = "Pos", y = "y", label = "anno"))
370+
geom_text(
371+
data = list_translated[[reading_frame]],
372+
aes_string(x = "Pos", y = "y", label = "anno")
373+
)
363374
}
364375
aa_plot <- aa_plot +
365376
labs(y = "AA") +
366377
theme_aa(margin.len = aa.margin, fill.color = aa.color)
367378
final.plot <-
368379
patchwork::wrap_plots(base.plot,
369-
aa_plot,
370-
ncol = 1,
371-
heights = c(1, aa.height))
380+
aa_plot,
381+
ncol = 1,
382+
heights = c(1, aa.height)
383+
)
372384
} else {
373385
# create plot without amino acid
374386
final.plot <- base.plot +
@@ -387,9 +399,11 @@ ggplot_add.base <- function(object, plot, object_name) {
387399
label.r = unit(nuc.padding.r, "lines")
388400
) +
389401
labs(y = "Base") +
390-
geom_hline(yintercept = guide.line,
391-
color = guide.line.color,
392-
linetype = guide.line.type)
402+
geom_hline(
403+
yintercept = guide.line,
404+
color = guide.line.color,
405+
linetype = guide.line.type
406+
)
393407
}
394408

395409
# assemble plot

R/geom_cnv.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@
4242
geom_cnv <- function(cnv.df, bin.col = 3, cn.col = 4, ref.cn = 2,
4343
bin.point.color = "grey", bin.point.alpha = 0.6, cn.line.color = "red",
4444
ref.line.color = "black", plot.space = 0.1, plot.height = 0.2) {
45-
structure(list(
46-
cnv.df = cnv.df, bin.col = bin.col, cn.col = cn.col, ref.cn = ref.cn,
47-
bin.point.color = bin.point.color, bin.point.alpha = bin.point.alpha, cn.line.color = cn.line.color,
48-
ref.line.color = ref.line.color, plot.space = plot.space, plot.height = plot.height
49-
),
50-
class = "cnv"
45+
structure(
46+
list(
47+
cnv.df = cnv.df, bin.col = bin.col, cn.col = cn.col, ref.cn = ref.cn,
48+
bin.point.color = bin.point.color, bin.point.alpha = bin.point.alpha, cn.line.color = cn.line.color,
49+
ref.line.color = ref.line.color, plot.space = plot.space, plot.height = plot.height
50+
),
51+
class = "cnv"
5152
)
5253
}
5354

R/geom_coverage.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@
8888
#' geom_coverage(
8989
#' data = track.df, facet.key = "Type",
9090
#' mark.region = data.frame(
91-
#' start = c(21678900,21732001,21737590),
92-
#' end = c(21679900,21732400,21737650),
93-
#' label=c("M1", "M2", "M3")),
91+
#' start = c(21678900, 21732001, 21737590),
92+
#' end = c(21679900, 21732400, 21737650),
93+
#' label = c("M1", "M2", "M3")
94+
#' ),
9495
#' mark.color = grey(0.4)
9596
#' )
9697
#'
@@ -112,7 +113,8 @@ geom_coverage <- function(data, mapping = NULL, color = NULL, rect.color = NA,
112113
if (!is.null(color)) {
113114
testcolors <- sapply(color, function(x) {
114115
tryCatch(is.matrix(col2rgb(x)),
115-
error = function(e) FALSE)
116+
error = function(e) FALSE
117+
)
116118
})
117119
if (length(color) < length(unique(data[, group.key]))) {
118120
warning("Fewer colors provided than there are groups in ", group.key, " variable, falling back to default colors")
@@ -259,9 +261,10 @@ geom_coverage <- function(data, mapping = NULL, color = NULL, rect.color = NA,
259261

260262
if (range.position == "in") {
261263
data.range <- data.range %>%
262-
dplyr::summarise(.groups = "drop_last",
263-
min_score = pretty(.data[[ymax.str]])[1],
264-
max_score = tail(pretty(.data[[ymax.str]]), 1)
264+
dplyr::summarise(
265+
.groups = "drop_last",
266+
min_score = pretty(.data[[ymax.str]])[1],
267+
max_score = tail(pretty(.data[[ymax.str]]), 1)
265268
)
266269
data.range$label <- paste0("[", data.range$min_score, ", ", data.range$max_score, "]")
267270
region.range <- geom_text(

R/geom_feature.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@
4242
#' # )
4343
geom_feature <- function(feature.file = NULL, feature.df = NULL, feature.color = "black", feature.size = 5,
4444
plot.space = 0.1, plot.height = 0.1) {
45-
structure(list(
46-
feature.file = feature.file, feature.df = feature.df, feature.color = feature.color, feature.size = feature.size,
47-
plot.space = plot.space, plot.height = plot.height
48-
),
49-
class = "feature"
45+
structure(
46+
list(
47+
feature.file = feature.file, feature.df = feature.df, feature.color = feature.color, feature.size = feature.size,
48+
plot.space = plot.space, plot.height = plot.height
49+
),
50+
class = "feature"
5051
)
5152
}
5253

R/geom_gc.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737
geom_gc <- function(fa.file = NULL, bs.fa.seq = NULL, chr.split = "[[:space:]]", guide.line = NULL,
3838
line.color = "black", guide.line.color = "red", guide.line.type = "dashed",
3939
plot.space = 0.1, plot.height = 0.2) {
40-
structure(list(
41-
fa.file = fa.file, bs.fa.seq = bs.fa.seq, chr.split = chr.split, guide.line = guide.line,
42-
line.color = line.color, guide.line.color = guide.line.color, guide.line.type = guide.line.type,
43-
plot.space = plot.space, plot.height = plot.height
44-
),
45-
class = "gc"
40+
structure(
41+
list(
42+
fa.file = fa.file, bs.fa.seq = bs.fa.seq, chr.split = chr.split, guide.line = guide.line,
43+
line.color = line.color, guide.line.color = guide.line.color, guide.line.type = guide.line.type,
44+
plot.space = plot.space, plot.height = plot.height
45+
),
46+
class = "gc"
4647
)
4748
}
4849

R/geom_gene.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ geom_gene <- function(gtf.gr,
7171
arrow.gap = NULL,
7272
arrow.num = 50,
7373
color.by = "strand",
74-
fill.color = c("-" = "cornflowerblue",
75-
"+" = "darkolivegreen3"),
74+
fill.color = c(
75+
"-" = "cornflowerblue",
76+
"+" = "darkolivegreen3"
77+
),
7678
show.utr = FALSE,
7779
label.size = 3,
7880
label.vjust = 2,

R/geom_ideogram.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ geom_ideogram <- function(genome = "hg19", mark.color = "red", mark.alpha = 0.7,
7878
highlight.centromere = FALSE, highlight.color = "green", highlight.alpha = 0.7, highlight.line.size = 1,
7979
highlight.shadow.color = "black", highlight.shadow.alpha = 0.7, highlight.shadow.line.size = 1,
8080
plot.space = 0.1, plot.height = 0.1) {
81-
8281
# test if suggested package is installed
8382
requireNamespace("ggbio", quietly = TRUE)
8483

85-
structure(list(
86-
genome = genome, mark.color = mark.color, mark.alpha = mark.alpha, mark.line.size = mark.line.size,
87-
add.shadow = add.shadow, shadow.color = shadow.color, shadow.alpha = shadow.alpha, shadow.line.size = shadow.line.size,
88-
highlight.centromere = highlight.centromere, highlight.color = highlight.color, highlight.alpha = highlight.alpha,
89-
highlight.line.size = highlight.line.size, highlight.shadow.color = highlight.shadow.color, highlight.shadow.alpha = highlight.shadow.alpha,
90-
highlight.shadow.line.size = highlight.shadow.line.size, plot.space = plot.space, plot.height = plot.height
91-
),
92-
class = "ideogram"
84+
structure(
85+
list(
86+
genome = genome, mark.color = mark.color, mark.alpha = mark.alpha, mark.line.size = mark.line.size,
87+
add.shadow = add.shadow, shadow.color = shadow.color, shadow.alpha = shadow.alpha, shadow.line.size = shadow.line.size,
88+
highlight.centromere = highlight.centromere, highlight.color = highlight.color, highlight.alpha = highlight.alpha,
89+
highlight.line.size = highlight.line.size, highlight.shadow.color = highlight.shadow.color, highlight.shadow.alpha = highlight.shadow.alpha,
90+
highlight.shadow.line.size = highlight.shadow.line.size, plot.space = plot.space, plot.height = plot.height
91+
),
92+
class = "ideogram"
9393
)
9494
}
9595

0 commit comments

Comments
 (0)