Mercurial > repos > artbio > small_rna_maps
comparison small_rna_maps.r @ 6:a3be3601bcb3 draft
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/small_rna_maps commit 9f9c64aff0d225881bedb97bd5035ccbca945d9d
author | artbio |
---|---|
date | Mon, 09 Oct 2017 11:07:09 -0400 |
parents | 12c14642e6ac |
children | a96e6a7df2b7 |
comparison
equal
deleted
inserted
replaced
5:12c14642e6ac | 6:a3be3601bcb3 |
---|---|
10 library(optparse) | 10 library(optparse) |
11 | 11 |
12 option_list <- list( | 12 option_list <- list( |
13 make_option(c("-f", "--first_dataframe"), type="character", help="path to first dataframe"), | 13 make_option(c("-f", "--first_dataframe"), type="character", help="path to first dataframe"), |
14 make_option(c("-e", "--extra_dataframe"), type="character", help="path to additional dataframe"), | 14 make_option(c("-e", "--extra_dataframe"), type="character", help="path to additional dataframe"), |
15 make_option(c("-n", "--normalization"), type="character", help="space-separated normalization/size factors"), | |
15 make_option("--first_plot_method", type = "character", help="How additional data should be plotted"), | 16 make_option("--first_plot_method", type = "character", help="How additional data should be plotted"), |
16 make_option("--extra_plot_method", type = "character", help="How additional data should be plotted"), | 17 make_option("--extra_plot_method", type = "character", help="How additional data should be plotted"), |
17 make_option("--output_pdf", type = "character", help="path to the pdf file with plots") | 18 make_option("--output_pdf", type = "character", help="path to the pdf file with plots") |
18 ) | 19 ) |
19 | 20 |
25 Table = read.delim(args$first_dataframe, header=T, row.names=NULL) | 26 Table = read.delim(args$first_dataframe, header=T, row.names=NULL) |
26 if (args$first_plot_method == "Counts" | args$first_plot_method == "Size") { | 27 if (args$first_plot_method == "Counts" | args$first_plot_method == "Size") { |
27 Table <- within(Table, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-1)) | 28 Table <- within(Table, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-1)) |
28 } | 29 } |
29 n_samples=length(unique(Table$Dataset)) | 30 n_samples=length(unique(Table$Dataset)) |
31 samples = unique(Table$Dataset) | |
32 if (args$normalization != "") { | |
33 norm_factors = as.numeric(unlist(strsplit(args$normalization, " "))) | |
34 } else { | |
35 norm_factors = rep(1, n_samples) | |
36 } | |
37 if (args$first_plot_method == "Counts" | args$first_plot_method == "Size" | args$first_plot_method == "Coverage") { | |
38 i = 1 | |
39 for (sample in samples) { | |
40 print(norm_factors[i]) | |
41 Table[, length(Table)][Table$Dataset==sample] <- Table[, length(Table)][Table$Dataset==sample]*norm_factors[i] | |
42 i = i + 1 | |
43 } | |
44 print(tail(Table)) | |
45 } | |
30 genes=unique(levels(Table$Chromosome)) | 46 genes=unique(levels(Table$Chromosome)) |
31 per_gene_readmap=lapply(genes, function(x) subset(Table, Chromosome==x)) | 47 per_gene_readmap=lapply(genes, function(x) subset(Table, Chromosome==x)) |
32 per_gene_limit=lapply(genes, function(x) c(1, unique(subset(Table, Chromosome==x)$Chrom_length)) ) | 48 per_gene_limit=lapply(genes, function(x) c(1, unique(subset(Table, Chromosome==x)$Chrom_length)) ) |
33 n_genes=length(per_gene_readmap) | 49 n_genes=length(per_gene_readmap) |
34 # second table | 50 # second table |
35 if (args$extra_plot_method != '') { | 51 if (args$extra_plot_method != '') { |
36 ExtraTable=read.delim(args$extra_dataframe, header=T, row.names=NULL) | 52 ExtraTable=read.delim(args$extra_dataframe, header=T, row.names=NULL) |
37 if (args$extra_plot_method == "Counts" | args$extra_plot_method=='Size') { | 53 if (args$extra_plot_method == "Counts" | args$extra_plot_method=='Size') { |
38 ExtraTable <- within(ExtraTable, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-1)) | 54 ExtraTable <- within(ExtraTable, Counts[Polarity=="R"] <- (Counts[Polarity=="R"]*-1)) |
39 } | 55 } |
56 if (args$extra_plot_method == "Counts" | args$extra_plot_method == "Size" | args$extra_plot_method == "Coverage") { | |
57 i = 1 | |
58 for (sample in samples) { | |
59 ExtraTable[, length(ExtraTable)][ExtraTable$Dataset==sample] <- ExtraTable[, length(ExtraTable)][ExtraTable$Dataset==sample]*norm_factors[i] | |
60 i = i + 1 | |
61 } | |
62 } | |
40 per_gene_size=lapply(genes, function(x) subset(ExtraTable, Chromosome==x)) | 63 per_gene_size=lapply(genes, function(x) subset(ExtraTable, Chromosome==x)) |
41 } | 64 } |
42 | 65 |
43 ## functions | 66 ## functions |
44 | 67 |
45 plot_unit = function(df, method=args$first_plot_method, ...) { | 68 plot_unit = function(df, method=args$first_plot_method, ...) { |
46 if (method == 'Counts') { | 69 if (method == 'Counts') { |