Mercurial > repos > artbio > small_rna_maps
comparison small_rna_maps.r @ 30:183bf49fe77c draft
"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit d280e9be7cf96f4938a73ccf5985533109f3328f"
author | artbio |
---|---|
date | Sat, 05 Oct 2019 18:25:19 -0400 |
parents | fe1a9cfaf5c3 |
children | f2e7ad3058e8 |
comparison
equal
deleted
inserted
replaced
29:8b5695592784 | 30:183bf49fe77c |
---|---|
24 | 24 |
25 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list) | 25 parser <- OptionParser(usage = "%prog [options] file", option_list = option_list) |
26 args = parse_args(parser) | 26 args = parse_args(parser) |
27 | 27 |
28 # data frames implementation | 28 # data frames implementation |
29 | |
29 ## first table | 30 ## first table |
30 Table = read.delim(args$first_dataframe, header=T, row.names=NULL) | 31 Table = read.delim(args$first_dataframe, header=T, row.names=NULL) |
31 colnames(Table)[1] <- "Dataset" | 32 colnames(Table)[1] <- "Dataset" |
33 dropcol <- c("Strandness", "z.score") # not used by this Rscript and is dropped for backward compatibility | |
34 Table <- Table[,!(names(Table) %in% dropcol)] | |
32 if (args$first_plot_method == "Counts" | args$first_plot_method == "Size") { | 35 if (args$first_plot_method == "Counts" | args$first_plot_method == "Size") { |
33 Table <- within(Table, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-1)) | 36 Table <- within(Table, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-1)) |
34 } | 37 } |
35 n_samples=length(unique(Table$Dataset)) | 38 n_samples=length(unique(Table$Dataset)) |
36 samples = unique(Table$Dataset) | 39 samples = unique(Table$Dataset) |
40 norm_factors = rep(1, n_samples) | 43 norm_factors = rep(1, n_samples) |
41 } | 44 } |
42 if (args$first_plot_method == "Counts" | args$first_plot_method == "Size" | args$first_plot_method == "Coverage") { | 45 if (args$first_plot_method == "Counts" | args$first_plot_method == "Size" | args$first_plot_method == "Coverage") { |
43 i = 1 | 46 i = 1 |
44 for (sample in samples) { | 47 for (sample in samples) { |
48 # Warning | |
49 # Here the column is hard coded as the last column (dangerous) | |
50 # because its name changes with the method | |
45 Table[, length(Table)][Table$Dataset==sample] <- Table[, length(Table)][Table$Dataset==sample]*norm_factors[i] | 51 Table[, length(Table)][Table$Dataset==sample] <- Table[, length(Table)][Table$Dataset==sample]*norm_factors[i] |
46 i = i + 1 | 52 i = i + 1 |
47 } | 53 } |
48 } | 54 } |
49 genes=unique(Table$Chromosome) | 55 genes=unique(Table$Chromosome) |
50 per_gene_readmap=lapply(genes, function(x) subset(Table, Chromosome==x)) | 56 per_gene_readmap=lapply(genes, function(x) subset(Table, Chromosome==x)) |
51 per_gene_limit=lapply(genes, function(x) c(1, unique(subset(Table, Chromosome==x)$Chrom_length)) ) | 57 per_gene_limit=lapply(genes, function(x) c(1, unique(subset(Table, Chromosome==x)$Chrom_length)) ) |
52 n_genes=length(per_gene_readmap) | 58 n_genes=length(per_gene_readmap) |
59 | |
53 # second table | 60 # second table |
54 if (args$extra_plot_method != '') { | 61 if (args$extra_plot_method != '') { |
55 ExtraTable=read.delim(args$extra_dataframe, header=T, row.names=NULL) | 62 ExtraTable=read.delim(args$extra_dataframe, header=T, row.names=NULL) |
56 colnames(ExtraTable)[1] <- "Dataset" | 63 colnames(ExtraTable)[1] <- "Dataset" |
64 dropcol <- c("Strandness", "z.score") # not used by this Rscript and is dropped for backward compatibility | |
65 Table <- Table[,!(names(Table) %in% dropcol)] | |
57 if (args$extra_plot_method == "Counts" | args$extra_plot_method=='Size') { | 66 if (args$extra_plot_method == "Counts" | args$extra_plot_method=='Size') { |
58 ExtraTable <- within(ExtraTable, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-1)) | 67 ExtraTable <- within(ExtraTable, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-1)) |
59 } | 68 } |
60 if (args$extra_plot_method == "Counts" | args$extra_plot_method == "Size" | args$extra_plot_method == "Coverage") { | 69 if (args$extra_plot_method == "Counts" | args$extra_plot_method == "Size" | args$extra_plot_method == "Coverage") { |
61 i = 1 | 70 i = 1 |
132 ...) | 141 ...) |
133 p=combineLimits(p) | 142 p=combineLimits(p) |
134 } else if (method != "Size") { | 143 } else if (method != "Size") { |
135 p = xyplot(eval(as.name(method))~Coordinate|factor(Dataset, levels=unique(Dataset))+factor(Chromosome, levels=unique(Chromosome)), | 144 p = xyplot(eval(as.name(method))~Coordinate|factor(Dataset, levels=unique(Dataset))+factor(Chromosome, levels=unique(Chromosome)), |
136 data=df, | 145 data=df, |
137 type='p', | 146 type= ifelse(method=='Coverage', 'l', 'p'), |
138 pch=19, | 147 pch=19, |
139 cex=0.35, | 148 cex=0.35, |
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)), | 149 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)), |
141 xlab=NULL, main=NULL, ylab=NULL, ylim=ylimits, | 150 xlab=NULL, main=NULL, ylab=NULL, ylim=ylimits, |
142 as.table=T, | 151 as.table=T, |
143 origin = 0, | 152 origin = 0, |
144 horizontal=FALSE, | 153 horizontal=FALSE, |
145 group=Polarity, | 154 group=Polarity, |
146 col=c("red","blue"), | 155 col=c("red","blue"), |
147 par.strip.text = list(cex=0.7), | 156 par.strip.text = list(cex=0.7), |
148 ...) | 157 ...) |
158 p=combineLimits(p) | |
149 } else { | 159 } else { |
150 p = barchart(Counts~as.factor(Size)|factor(Dataset, levels=unique(Dataset))+Chromosome, data = df, origin = 0, | 160 p = barchart(Counts~as.factor(Size)|factor(Dataset, levels=unique(Dataset))+Chromosome, data = df, origin = 0, |
151 horizontal=FALSE, | 161 horizontal=FALSE, |
152 group=Polarity, | 162 group=Polarity, |
153 stack=TRUE, | 163 stack=TRUE, |