annotate small_rna_maps.r @ 29:8b5695592784 draft

"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c3d728b98db4987821feae40952d9797c97eaf5a"
author artbio
date Fri, 04 Oct 2019 04:33:53 -0400
parents fe1a9cfaf5c3
children 183bf49fe77c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
1 ## Setup R error handling to go to stderr
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
2 options( show.error.messages=F,
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
3 error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
7
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
4 options(warn = -1)
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
5 library(RColorBrewer)
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
6 library(lattice)
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
7 library(latticeExtra)
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
8 library(grid)
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
9 library(gridExtra)
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
10 library(optparse)
2
507383cce5a8 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents: 0
diff changeset
11
7
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
12
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
13 option_list <- list(
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
14 make_option(c("-i", "--ymin"), type="double", help="set min ylimit. e.g. '-100.0'"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
15 make_option(c("-a", "--ymax"), type="double", help="set max ylimit. e.g. '100.0'"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
16 make_option(c("-f", "--first_dataframe"), type="character", help="path to first dataframe"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
17 make_option(c("-e", "--extra_dataframe"), type="character", help="path to additional dataframe"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
18 make_option(c("-n", "--normalization"), type="character", help="space-separated normalization/size factors"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
19 make_option("--first_plot_method", type = "character", help="How additional data should be plotted"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
20 make_option("--extra_plot_method", type = "character", help="How additional data should be plotted"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
21 make_option("--global", type = "character", help="data should be plotted as global size distribution"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
22 make_option("--output_pdf", type = "character", help="path to the pdf file with plots")
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
23 )
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
24
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
25 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list)
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
26 args = parse_args(parser)
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
27
2
507383cce5a8 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents: 0
diff changeset
28 # data frames implementation
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
29 ## first table
2
507383cce5a8 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents: 0
diff changeset
30 Table = read.delim(args$first_dataframe, header=T, row.names=NULL)
27
fe1a9cfaf5c3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d234ef45deb84f70c85b3372b8e0137df0be4e29
artbio
parents: 21
diff changeset
31 colnames(Table)[1] <- "Dataset"
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
32 if (args$first_plot_method == "Counts" | args$first_plot_method == "Size") {
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
33 Table <- within(Table, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-1))
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
34 }
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
35 n_samples=length(unique(Table$Dataset))
6
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
36 samples = unique(Table$Dataset)
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
37 if (args$normalization != "") {
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
38 norm_factors = as.numeric(unlist(strsplit(args$normalization, " ")))
6
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
39 } else {
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
40 norm_factors = rep(1, n_samples)
6
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
41 }
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
42 if (args$first_plot_method == "Counts" | args$first_plot_method == "Size" | args$first_plot_method == "Coverage") {
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
43 i = 1
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
44 for (sample in samples) {
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
45 Table[, length(Table)][Table$Dataset==sample] <- Table[, length(Table)][Table$Dataset==sample]*norm_factors[i]
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
46 i = i + 1
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
47 }
6
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
48 }
11
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
49 genes=unique(Table$Chromosome)
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
50 per_gene_readmap=lapply(genes, function(x) subset(Table, Chromosome==x))
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
51 per_gene_limit=lapply(genes, function(x) c(1, unique(subset(Table, Chromosome==x)$Chrom_length)) )
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
52 n_genes=length(per_gene_readmap)
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
53 # second table
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
54 if (args$extra_plot_method != '') {
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
55 ExtraTable=read.delim(args$extra_dataframe, header=T, row.names=NULL)
27
fe1a9cfaf5c3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d234ef45deb84f70c85b3372b8e0137df0be4e29
artbio
parents: 21
diff changeset
56 colnames(ExtraTable)[1] <- "Dataset"
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
57 if (args$extra_plot_method == "Counts" | args$extra_plot_method=='Size') {
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
58 ExtraTable <- within(ExtraTable, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-1))
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
59 }
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
60 if (args$extra_plot_method == "Counts" | args$extra_plot_method == "Size" | args$extra_plot_method == "Coverage") {
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
61 i = 1
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
62 for (sample in samples) {
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
63 ExtraTable[, length(ExtraTable)][ExtraTable$Dataset==sample] <- ExtraTable[, length(ExtraTable)][ExtraTable$Dataset==sample]*norm_factors[i]
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
64 i = i + 1
6
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
65 }
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
66 }
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
67 per_gene_size=lapply(genes, function(x) subset(ExtraTable, Chromosome==x))
6
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
68 }
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
69
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
70 ## functions
7
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
71 globalbc = function(df, global="", ...) {
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
72 if (global == "yes") {
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
73 bc <- barchart(Counts~as.factor(Size)|factor(Dataset, levels=unique(Dataset)),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
74 data = df, origin = 0,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
75 horizontal=FALSE,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
76 col=c("darkblue"),
21
b585cb347a26 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit bbcc21562b752860dc28945ccc69ff1ef29dec5b
artbio
parents: 14
diff changeset
77 scales=list(y=list(tick.number=4, rot=90, relation="same", cex=0.5, alternating=T), x=list(rot=0, cex=0.6, tck=0.5, alternating=c(3,3))),
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
78 xlab=list(label=bottom_first_method[[args$first_plot_method]], cex=.85),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
79 ylab=list(label=legend_first_method[[args$first_plot_method]], cex=.85),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
80 main=title_first_method[[args$first_plot_method]],
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
81 layout = c(2, 6), newpage=T,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
82 as.table=TRUE,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
83 aspect=0.5,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
84 strip = strip.custom(par.strip.text = list(cex = 1), which.given=1, bg="lightblue"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
85 ...
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
86 )
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
87 } else {
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
88 bc <- barchart(Counts~as.factor(Size)|factor(Dataset, levels=unique(Dataset)),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
89 data = df, origin = 0,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
90 horizontal=FALSE,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
91 group=Polarity,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
92 stack=TRUE,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
93 col=c('red', 'blue'),
21
b585cb347a26 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit bbcc21562b752860dc28945ccc69ff1ef29dec5b
artbio
parents: 14
diff changeset
94 scales=list(y=list(tick.number=4, rot=90, relation="same", cex=0.5, alternating=T), x=list(rot=0, cex=0.6, tck=0.5, alternating=c(3,3))),
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
95 xlab=list(label=bottom_first_method[[args$first_plot_method]], cex=.85),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
96 ylab=list(label=legend_first_method[[args$first_plot_method]], cex=.85),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
97 main=title_first_method[[args$first_plot_method]],
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
98 layout = c(2, 6), newpage=T,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
99 as.table=TRUE,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
100 aspect=0.5,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
101 strip = strip.custom(par.strip.text = list(cex = 1), which.given=1, bg="lightblue"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
102 ...
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
103 )
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
104 }
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
105 return(bc)
7
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
106 }
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
107 plot_unit = function(df, method=args$first_plot_method, ...) {
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
108 if (exists('ymin', where=args)){
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
109 min=args$ymin
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
110 }else{
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
111 min=''
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
112 }
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
113 if ((exists('ymax', where=args))){
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
114 max=args$ymax
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
115 }else{
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
116 max=''
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
117 }
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
118 ylimits=c(min,max)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
119 if (method == 'Counts') {
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
120 p = xyplot(Counts~Coordinate|factor(Dataset, levels=unique(Dataset))+factor(Chromosome, levels=unique(Chromosome)),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
121 data=df,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
122 type='h',
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
123 lwd=1.5,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
124 scales= list(relation="free", x=list(rot=0, cex=0.7, axs="i", tck=0.5), y=list(tick.number=4, rot=90, cex=0.7)),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
125 xlab=NULL, main=NULL, ylab=NULL, ylim=ylimits,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
126 as.table=T,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
127 origin = 0,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
128 horizontal=FALSE,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
129 group=Polarity,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
130 col=c("red","blue"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
131 par.strip.text = list(cex=0.7),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
132 ...)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
133 p=combineLimits(p)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
134 } else if (method != "Size") {
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
135 p = xyplot(eval(as.name(method))~Coordinate|factor(Dataset, levels=unique(Dataset))+factor(Chromosome, levels=unique(Chromosome)),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
136 data=df,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
137 type='p',
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
138 pch=19,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
139 cex=0.35,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
140 scales= list(relation="free", x=list(rot=0, cex=0.7, tck=0.5), y=list(tick.number=4, rot=90, cex=0.7)),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
141 xlab=NULL, main=NULL, ylab=NULL, ylim=ylimits,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
142 as.table=T,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
143 origin = 0,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
144 horizontal=FALSE,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
145 group=Polarity,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
146 col=c("red","blue"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
147 par.strip.text = list(cex=0.7),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
148 ...)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
149 } else {
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
150 p = barchart(Counts~as.factor(Size)|factor(Dataset, levels=unique(Dataset))+Chromosome, data = df, origin = 0,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
151 horizontal=FALSE,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
152 group=Polarity,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
153 stack=TRUE,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
154 col=c('red', 'blue'),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
155 scales=list(y=list(rot=90, relation="free", cex=0.7), x=list(rot=0, cex=0.7, axs="i", tck=c(1,0))),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
156 xlab = NULL,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
157 ylab = NULL,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
158 main = NULL,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
159 as.table=TRUE,
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
160 par.strip.text = list(cex=0.6),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
161 ...)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
162 p=combineLimits(p)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
163 }
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
164 return(p)
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
165 }
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
166
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
167
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
168 ## function parameters
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
169
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
170 #par.settings.firstplot = list(layout.heights=list(top.padding=11, bottom.padding = -14))
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
171 #par.settings.secondplot=list(layout.heights=list(top.padding=11, bottom.padding = -15), strip.background=list(col=c("lavender","deepskyblue")))
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
172 par.settings.firstplot = list(layout.heights=list(top.padding=-2, bottom.padding=-2),strip.background=list(col=c("lightblue","lightgreen")))
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
173 par.settings.secondplot=list(layout.heights=list(top.padding=-1, bottom.padding=-1),strip.background=list(col=c("lightblue","lightgreen")))
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
174 title_first_method = list(Counts="Read Counts", Coverage="Coverage depths", Median="Median sizes", Mean="Mean sizes", Size="Size Distributions")
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
175 title_extra_method = list(Counts="Read Counts", Coverage="Coverage depths", Median="Median sizes", Mean="Mean sizes", Size="Size Distributions")
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
176 legend_first_method =list(Counts="Read count", Coverage="Coverage depth", Median="Median size", Mean="Mean size", Size="Read count")
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
177 legend_extra_method =list(Counts="Read count", Coverage="Coverage depth", Median="Median size", Mean="Mean size", Size="Read count")
14
cd75c72e1d75 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 5c55f75e094983228200111277fef7f349507174
artbio
parents: 12
diff changeset
178 bottom_first_method =list(Counts="Coordinates (nucleotides)",Coverage="Coordinates (nucleotides)", Median="Coordinates (nucleotides)", Mean="Coordinates (nucleotides)", Size="Sizes of reads")
cd75c72e1d75 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 5c55f75e094983228200111277fef7f349507174
artbio
parents: 12
diff changeset
179 bottom_extra_method =list(Counts="Coordinates (nucleotides)",Coverage="Coordinates (nucleotides)", Median="Coordinates (nucleotides)", Mean="Coordinates (nucleotides)", Size="Sizes of reads")
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
180
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
181 ## Plotting Functions
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
182
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
183 double_plot <- function(...) {
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
184 page_height = 15
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
185 rows_per_page = 10
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
186 graph_heights=c(40,30,40,30,40,30,40,30,40,30,10)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
187 page_width=8.2677 * n_samples / 2
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
188 pdf(file=args$output_pdf, paper="special", height=page_height, width=page_width)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
189 for (i in seq(1,n_genes,rows_per_page/2)) {
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
190 start=i
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
191 end=i+rows_per_page/2-1
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
192 if (end>n_genes) {end=n_genes}
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
193 if (end-start+1 < 5) {graph_heights=c(rep(c(40,30),end-start+1),10,rep(c(40,30),5-(end-start+1)))}
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
194 first_plot.list = lapply(per_gene_readmap[start:end], function(x) update(useOuterStrips(plot_unit(x, par.settings=par.settings.secondplot), strip.left=strip.custom(par.strip.text = list(cex=0.5)))))
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
195 second_plot.list = lapply(per_gene_size[start:end], function(x) update(useOuterStrips(plot_unit(x, method=args$extra_plot_method, par.settings=par.settings.firstplot), strip.left=strip.custom(par.strip.text = list(cex=0.5)), strip=FALSE)))
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
196 plot.list=rbind(first_plot.list, second_plot.list)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
197 args_list=c(plot.list, list( nrow=rows_per_page+1, ncol=1, heights=unit(graph_heights, rep("mm", 11)),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
198 top=textGrob(paste(title_first_method[[args$first_plot_method]], "and", title_extra_method[[args$extra_plot_method]]), gp=gpar(cex=1), vjust=0, just="top"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
199 left=textGrob(paste(legend_first_method[[args$first_plot_method]], "/", legend_extra_method[[args$extra_plot_method]]), gp=gpar(cex=1), vjust=0, hjust=0, x=1, y=(-0.38/4)*(end-start-(3.28/0.38)), rot=90),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
200 sub=textGrob(paste(bottom_first_method[[args$first_plot_method]], "/", bottom_extra_method[[args$extra_plot_method]]), gp=gpar(cex=1), just="bottom", vjust=2)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
201 )
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
202 )
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
203 do.call(grid.arrange, args_list)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
204 }
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
205 devname=dev.off()
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
206 }
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
207
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
208
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
209 single_plot <- function(...) {
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
210 width = 8.2677 * n_samples / 2
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
211 rows_per_page=8
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
212 graph_heights=c(rep(40,8),10)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
213 pdf(file=args$output_pdf, paper="special", height=15, width=width)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
214 for (i in seq(1,n_genes,rows_per_page)) {
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
215 start=i
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
216 end=i+rows_per_page-1
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
217 if (end>n_genes) {end=n_genes}
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
218 if (end-start+1 < 8) {graph_heights=c(rep(c(40),end-start+1),10,rep(c(40),8-(end-start+1)))}
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
219 first_plot.list = lapply(per_gene_readmap[start:end], function(x) update(useOuterStrips(plot_unit(x, par.settings=par.settings.firstplot),strip.left=strip.custom(par.strip.text = list(cex=0.5)))))
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
220 plot.list=rbind(first_plot.list)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
221 args_list=c(plot.list, list( nrow=rows_per_page+1, ncol=1, heights=unit(graph_heights, rep("mm", 9)),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
222 top=textGrob(title_first_method[[args$first_plot_method]], gp=gpar(cex=1), vjust=0, just="top"),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
223 left=textGrob(legend_first_method[[args$first_plot_method]], gp=gpar(cex=1), vjust=0, hjust=0, x=1, y=(-0.41/7)*(end-start-(6.23/0.41)), rot=90),
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
224 sub=textGrob(bottom_first_method[[args$first_plot_method]], gp=gpar(cex=1), just="bottom", vjust=2)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
225 )
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
226 )
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
227 do.call(grid.arrange, args_list)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
228 }
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
229 devname=dev.off()
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
230 }
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
231
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
232 # main
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
233
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
234 if (args$extra_plot_method != '') { double_plot() }
7
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
235 if (args$extra_plot_method == '' & !exists('global', where=args)) {
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
236 single_plot()
5
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
237 }
7
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
238 if (exists('global', where=args)) {
12
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
239 pdf(file=args$output, paper="special", height=11.69)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
240 Table <- within(Table, Counts[Polarity=="R"] <- abs(Counts[Polarity=="R"])) # retropedalage
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
241 library(reshape2)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
242 ml = melt(Table, id.vars = c("Dataset", "Chromosome", "Polarity", "Size"))
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
243 if (args$global == "nomerge") {
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
244 castml = dcast(ml, Dataset+Polarity+Size ~ variable, function(x) sum(x))
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
245 castml <- within(castml, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-1))
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
246 bc = globalbc(castml, global="no")
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
247 } else {
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
248 castml = dcast(ml, Dataset+Size ~ variable, function(x) sum(x))
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
249 bc = globalbc(castml, global="yes")
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
250 }
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
251 plot(bc)
d33263e6e812 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit b0676fd329c2ca50002f9f2fede531d8e550569f
artbio
parents: 11
diff changeset
252 devname=dev.off()
7
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
253 }
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
254