annotate small_rna_maps.r @ 11:a561a71bd7d7 draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
author artbio
date Tue, 06 Mar 2018 06:11:55 -0500
parents a96e6a7df2b7
children d33263e6e812
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,
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
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(
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
14 make_option(c("-f", "--first_dataframe"), type="character", help="path to first dataframe"),
507383cce5a8 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit edbb53cb13b52bf8e71c562fa8acc2c3be2fb270
artbio
parents: 0
diff changeset
15 make_option(c("-e", "--extra_dataframe"), type="character", help="path to additional dataframe"),
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
16 make_option(c("-n", "--normalization"), type="character", help="space-separated normalization/size factors"),
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
17 make_option("--first_plot_method", type = "character", help="How additional data should be plotted"),
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
18 make_option("--extra_plot_method", type = "character", help="How additional data should be plotted"),
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
19 make_option("--global", type = "character", help="data should be plotted as global size distribution"),
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
20 make_option("--output_pdf", type = "character", help="path to the pdf file with plots")
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
21 )
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
22
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
23 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
24 args = parse_args(parser)
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
25
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
26 # 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
27 ## 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
28 Table = read.delim(args$first_dataframe, header=T, row.names=NULL)
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 if (args$first_plot_method == "Counts" | args$first_plot_method == "Size") {
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
30 Table <- within(Table, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-1))
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
31 }
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
32 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
33 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
34 if (args$normalization != "") {
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
35 norm_factors = as.numeric(unlist(strsplit(args$normalization, " ")))
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 } else {
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 norm_factors = rep(1, n_samples)
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
38 }
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 if (args$first_plot_method == "Counts" | args$first_plot_method == "Size" | args$first_plot_method == "Coverage") {
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
40 i = 1
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 for (sample in samples) {
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 Table[, length(Table)][Table$Dataset==sample] <- Table[, length(Table)][Table$Dataset==sample]*norm_factors[i]
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
43 i = i + 1
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
44 }
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
45 }
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
46 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
47 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
48 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
49 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
50 # 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
51 if (args$extra_plot_method != '') {
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
52 ExtraTable=read.delim(args$extra_dataframe, header=T, row.names=NULL)
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 if (args$extra_plot_method == "Counts" | args$extra_plot_method=='Size') {
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 ExtraTable <- within(ExtraTable, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-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
55 }
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
56 if (args$extra_plot_method == "Counts" | args$extra_plot_method == "Size" | args$extra_plot_method == "Coverage") {
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
57 i = 1
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
58 for (sample in samples) {
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
59 ExtraTable[, length(ExtraTable)][ExtraTable$Dataset==sample] <- ExtraTable[, length(ExtraTable)][ExtraTable$Dataset==sample]*norm_factors[i]
a3be3601bcb3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
artbio
parents: 5
diff changeset
60 i = i + 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
61 }
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
62 }
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
63 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
64 }
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
65
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
66 ## 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
67 globalbc = function(df, global="", ...) {
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
68 if (global == "yes") {
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
69 bc <- barchart(Counts~as.factor(Size)|factor(Dataset, levels=unique(Dataset)),
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
70 data = df, origin = 0,
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 horizontal=FALSE,
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
72 col=c("darkblue"),
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
73 scales=list(y=list(tick.number=4, rot=90, relation="free", cex=0.5, alternating=T), x=list(rot=0, cex=0.6, tck=0.5, alternating=c(3,3))),
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
74 xlab=list(label=bottom_first_method[[args$first_plot_method]], cex=.85),
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
75 ylab=list(label=legend_first_method[[args$first_plot_method]], cex=.85),
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
76 main=title_first_method[[args$first_plot_method]],
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
77 layout = c(2, 6), newpage=T,
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
78 as.table=TRUE,
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
79 aspect=0.5,
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
80 strip = strip.custom(par.strip.text = list(cex = 1), which.given=1, bg="lightblue"),
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
81 ...
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
82 )
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
83 } else {
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
84 bc <- barchart(Counts~as.factor(Size)|factor(Dataset, levels=unique(Dataset)),
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
85 data = df, origin = 0,
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
86 horizontal=FALSE,
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
87 group=Polarity,
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
88 stack=TRUE,
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
89 col=c('red', 'blue'),
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
90 scales=list(y=list(tick.number=4, rot=90, relation="free", cex=0.5, alternating=T), x=list(rot=0, cex=0.6, tck=0.5, alternating=c(3,3))),
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
91 xlab=list(label=bottom_first_method[[args$first_plot_method]], cex=.85),
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
92 ylab=list(label=legend_first_method[[args$first_plot_method]], cex=.85),
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
93 main=title_first_method[[args$first_plot_method]],
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
94 layout = c(2, 6), newpage=T,
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
95 as.table=TRUE,
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
96 aspect=0.5,
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
97 strip = strip.custom(par.strip.text = list(cex = 1), which.given=1, bg="lightblue"),
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
98 ...
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
99 )
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
100 }
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
101 return(bc)
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
102 }
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
103 plot_unit = function(df, method=args$first_plot_method, ...) {
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
104 if (method == 'Counts') {
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
105 p = xyplot(Counts~Coordinate|factor(Dataset, levels=unique(Dataset))+factor(Chromosome, levels=unique(Chromosome)),
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
106 data=df,
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 type='h',
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
108 lwd=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
109 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)),
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
110 xlab=NULL, main=NULL, ylab=NULL,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
111 as.table=T,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
112 origin = 0,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
113 horizontal=FALSE,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
114 group=Polarity,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
115 col=c("red","blue"),
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
116 par.strip.text = list(cex=0.7),
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
117 ...)
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
118 } else if (method != "Size") {
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
119 p = xyplot(eval(as.name(method))~Coordinate|factor(Dataset, levels=unique(Dataset))+factor(Chromosome, levels=unique(Chromosome)),
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
120 data=df,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
121 type='p',
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
122 pch=19,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
123 cex=0.35,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
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)),
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
125 xlab=NULL, main=NULL, ylab=NULL,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
126 as.table=T,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
127 origin = 0,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
128 horizontal=FALSE,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
129 group=Polarity,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
130 col=c("red","blue"),
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
131 par.strip.text = list(cex=0.7),
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
132 ...)
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
133 } else {
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
134 p = barchart(Counts~as.factor(Size)|factor(Dataset, levels=unique(Dataset))+Chromosome, data = df, origin = 0,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
135 horizontal=FALSE,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
136 group=Polarity,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
137 stack=TRUE,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
138 col=c('red', 'blue'),
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
139 scales=list(y=list(tick.number=4, rot=90, relation="free", cex=0.7), x=list(rot=0, cex=0.7, axs="i", tck=0.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
140 xlab = NULL,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
141 ylab = NULL,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
142 main = NULL,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
143 as.table=TRUE,
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
144 par.strip.text = list(cex=0.6),
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
145 ...)
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
146 }
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
147 combineLimits(p)
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
148 }
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
149
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
150 ## 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
151
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
152 #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
153 #par.settings.secondplot=list(layout.heights=list(top.padding=11, bottom.padding = -15), strip.background=list(col=c("lavender","deepskyblue")))
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
154 par.settings.firstplot = list(layout.heights=list(top.padding=-2, bottom.padding=-2))
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
155 par.settings.secondplot=list(layout.heights=list(top.padding=-1, bottom.padding=-1), strip.background=list(col=c("lavender","deepskyblue")))
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
156 par.settings.single_plot=list(strip.background = list(col = c("lightblue", "lightgreen")))
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
157 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
158 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
159 legend_first_method =list(Counts="Read count", Coverage="Coverage depth", Median="Median size", Mean="Mean size", Size="Read count")
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
160 legend_extra_method =list(Counts="Read count", Coverage="Coveragedepth", Median="Median size", Mean="Mean size", Size="Read count")
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
161 bottom_first_method =list(Counts="Coordinates (nbre of bases)",Coverage="Coordinates (nbre of bases)", Median="Coordinates (nbre of bases)", Mean="Coordinates (nbre of bases)", Size="Sizes of reads")
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
162 bottom_extra_method =list(Counts="Coordinates (nbre of bases)",Coverage="Coordinates (nbre of bases)", Median="Coordinates (nbre of bases)", Mean="Coordinates (nbre of bases)", Size="Sizes of reads")
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
163
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
164 ## 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
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 double_plot <- function(...) {
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
167 page_height = 15
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
168 rows_per_page = 10
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
169 graph_heights=c(40,30,40,30,40,30,40,30,40,30,10)
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
170 if (n_samples > 4) {page_width = 8.2677*n_samples/4} else {page_width = 2.3*n_samples +2.5}
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
171 pdf(file=args$output_pdf, paper="special", height=page_height, width=page_width)
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
172 for (i in seq(1,n_genes,rows_per_page/2)) {
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
173 start=i
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 end=i+rows_per_page/2-1
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 if (end>n_genes) {end=n_genes}
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
176 if (end-start+1 < 5) {graph_heights=c(rep(c(40,30),end-start+1),10,rep(c(40,30),5-(end-start+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
177 first_plot.list = lapply(per_gene_readmap[start:end], function(x) plot_unit(x, strip=FALSE, par.settings=par.settings.firstplot))
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
178 second_plot.list = lapply(per_gene_size[start:end], function(x) plot_unit(x, method=args$extra_plot_method, par.settings=par.settings.secondplot))
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
179 plot.list=rbind(second_plot.list, first_plot.list)
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
180 args_list=c(plot.list, list( nrow=rows_per_page+1, ncol=1, heights=unit(graph_heights, rep("mm", 11)),
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
181 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"),
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
182 left=textGrob(paste(legend_first_method[[args$first_plot_method]], "/", legend_extra_method[[args$extra_plot_method]]), gp=gpar(cex=1), just=0.675*(end-start-(2.2*(4/2.7))),vjust=2, rot=90),
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
183 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)
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
184 )
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
185 )
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
186 do.call(grid.arrange, args_list)
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
187 }
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
188 devname=dev.off()
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
189 }
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
190
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
191
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
192 single_plot <- function(...) {
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
193 width = 8.2677 * n_samples / 2
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
194 rows_per_page=8
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
195 graph_heights=c(rep(40,8),10)
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
196 pdf(file=args$output_pdf, paper="special", height=15, width=width)
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
197 for (i in seq(1,n_genes,rows_per_page)) {
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
198 start=i
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
199 end=i+rows_per_page-1
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
200 if (end>n_genes) {end=n_genes}
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
201 if (end-start+1 < 8) {graph_heights=c(rep(c(40),end-start+1),10,rep(c(40),8-(end-start+1)))}
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
202 first_plot.list = lapply(per_gene_readmap[start:end], function(x) plot_unit(x, par.settings=par.settings.firstplot))
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
203 plot.list=rbind(first_plot.list)
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
204 args_list=c(plot.list, list( nrow=rows_per_page+1, ncol=1, heights=unit(graph_heights, rep("mm", 9)),
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
205 top=textGrob(title_first_method[[args$first_plot_method]], gp=gpar(cex=1), vjust=0, just="top"),
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
206 left=textGrob(legend_first_method[[args$first_plot_method]], gp=gpar(cex=1), just=(6.4/7)*(end-start-(6.2*(7/6.4))),vjust=2, rot=90),
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
207 sub=textGrob(bottom_first_method[[args$first_plot_method]], gp=gpar(cex=1), just="bottom", vjust=2)
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
208 )
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
209 )
a561a71bd7d7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit c24bbb6d53574eb1c1eb8d219cf2a39a9ed5b3ff
artbio
parents: 7
diff changeset
210 do.call(grid.arrange, args_list)
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
211 }
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
212 devname=dev.off()
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
213 }
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
214
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
215 # 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
216
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
217 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
218 if (args$extra_plot_method == '' & !exists('global', where=args)) {
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
219 single_plot()
12c14642e6ac planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 24a21619d79d83b38cef7f1a7b858c621e4c8449
artbio
parents: 2
diff changeset
220 }
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
221 if (exists('global', where=args)) {
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
222 pdf(file=args$output, paper="special", height=11.69)
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
223 Table <- within(Table, Counts[Polarity=="R"] <- abs(Counts[Polarity=="R"])) # retropedalage
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
224 library(reshape2)
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
225 ml = melt(Table, id.vars = c("Dataset", "Chromosome", "Polarity", "Size"))
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
226 if (args$global == "nomerge") {
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
227 castml = dcast(ml, Dataset+Polarity+Size ~ variable, function(x) sum(x))
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
228 castml <- within(castml, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-1))
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
229 bc = globalbc(castml, global="no")
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
230 } else {
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
231 castml = dcast(ml, Dataset+Size ~ variable, function(x) sum(x))
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
232 bc = globalbc(castml, global="yes")
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
233 }
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
234 plot(bc)
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 devname=dev.off()
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
236 }
a96e6a7df2b7 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 06472d1bd1365e4f7b385d578a69f4646481e22f
artbio
parents: 6
diff changeset
237
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
238
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
239
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
240
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
241
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
242
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
243
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
244
0
6d48150495e3 planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d4d8106d66b65679a1a685ab94bfcf99cdb7b959
artbio
parents:
diff changeset
245
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
246