Mercurial > repos > brasset_jensen > srnapipe
annotate bin/Rcall.pm @ 62:e6c4f3e96e47 draft
planemo upload for repository https://github.com/GReD-Clermont/sRNAPipe/ commit 87e0c95b4d0d1954e81247c31a8f74c5d87c7f9e
author | pierre.pouchin |
---|---|
date | Thu, 17 Jan 2019 09:56:52 -0500 |
parents | 9185ca0a7b43 |
children |
rev | line source |
---|---|
61
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
1 package Rcall; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
2 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
3 use strict; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
4 use warnings; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
5 use Statistics::R; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
6 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
7 use Exporter; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
8 our @ISA = qw(Exporter); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
9 our @EXPORT_OK = qw( &histogram &pie_chart &bg_to_png ); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
10 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
11 sub histogram |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
12 { |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
13 my ($size_hashR, $out_png, $size) = @_; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
14 my (@abs, @ord); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
15 my $i = 0; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
16 foreach my $k (sort {$a <=> $b} keys %{$size_hashR}) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
17 { |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
18 my $percentage = 0; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
19 $percentage = $size_hashR->{$k} * 100 / $size if $size != 0; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
20 $abs[$i] = $k ; $ord[$i] = $percentage; $i++; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
21 } |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
22 my $abs = join (",", @abs ); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
23 my $ord = join (",", @ord ); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
24 if (scalar(@abs) != 0) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
25 { |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
26 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
27 my $R = Statistics::R->new(); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
28 $R->startR; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
29 $R->send( |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
30 qq`library(ggplot2) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
31 percentage = c($ord) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
32 size =c($abs) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
33 min = min(size) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
34 max = max(size) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
35 dat = data.frame(size,percentage) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
36 png(filename=\"$out_png\", width = 640, height = 640) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
37 c = ggplot(dat,aes(size,percentage)) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
38 c + geom_bar(stat="identity") + scale_x_continuous(breaks=min:max)+theme( axis.text.x = element_text(angle=90, hjust=0.5, size=20), axis.text.y = element_text( size=20 ), axis.title.x = element_text( size=25, face="bold"), axis.title.y = element_text( size=25, face="bold") ) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
39 dev.off()`); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
40 $R->stopR(); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
41 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
42 } |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
43 } |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
44 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
45 sub bg_to_png |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
46 { |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
47 my ( $fai, $bgP, $bgM, $dir, $sb ) = @_; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
48 my $R = Statistics::R->new(); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
49 $R->startR; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
50 $R->send( |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
51 qq`library('Sushi') |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
52 fai =read.table("$fai") |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
53 if ( file.info("$bgP")\$size !=0 ) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
54 { |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
55 bgP = read.table("$bgP") |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
56 } else { bgP = data.frame(factor(),integer()) } |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
57 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
58 if ( file.info("$bgM")\$size !=0 ) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
59 { |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
60 bgM = read.table("$bgM") |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
61 } else { bgM = data.frame(factor(),integer()) } |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
62 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
63 f_both = function(chr,end) { |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
64 jpeg( paste0("$dir",as.character(chr),".png"), quality=100) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
65 par(mfrow=c(2,1),mar=c(1,10,1,3)) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
66 plotBedgraph(bgP, chrom=chr,chromstart=0,chromend=end,transparency=.50, color=SushiColors(2)(2)[1]) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
67 axis(side=2,las=2,tcl=.2) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
68 mtext("Scaled Read Depth",side=2,line=4,cex=1,font=2) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
69 plotBedgraph(bgM, chrom=chr,chromstart=0,chromend=end,transparency=.50, flip=TRUE, color=SushiColors(2)(2)[2]) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
70 labelgenome(chrom=chr,chromstart=0,chromend=end,side=3,n=3,scale="$sb", line=0, chromline = 0.5, scaleline = 0.5, scaleadjust =1.05, chromadjust = -0.4) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
71 axis(side=2,las=2,tcl=.2,at=pretty(par("yaxp")[c(1,2)]),labels=-1*pretty(par("yaxp")[c(1,2)])) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
72 mtext("Scaled Read Depth",side=2,line=4.5,cex=1,font=2) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
73 dev.off() |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
74 } |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
75 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
76 f_plus = function(chr,end) { |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
77 jpeg( paste0("$dir",as.character(chr),".png"), quality=100) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
78 plotBedgraph(bgP, chrom=chr,chromstart=0,chromend=end,transparency=.50, color=SushiColors(2)(2)[1]) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
79 labelgenome(chrom=chr,chromstart=0,chromend=end,n=3,scale="$sb", line=0, chromline = 0.5, scaleline = 0.5, scaleadjust =1.05, chromadjust = -0.4) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
80 axis(side=2,las=2,tcl=.2) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
81 mtext("Scaled Read Depth",side=2,line=4,cex=1,font=2) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
82 dev.off() |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
83 } |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
84 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
85 f_minus = function(chr,end) { |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
86 jpeg( paste0("$dir",as.character(chr),".png"), quality=100) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
87 plotBedgraph(bgM, chrom=chr,chromstart=0,chromend=end,transparency=.50, flip=TRUE, color=SushiColors(2)(2)[2]) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
88 labelgenome(chrom=chr,chromstart=0,chromend=end,n=3,scale="$sb", line=0, chromline = 0.5, scaleline = 0.5, scaleadjust =1.05, chromadjust = -0.4) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
89 axis(side=2,las=2,tcl=.2,at=pretty(par("yaxp")[c(1,2)]),labels=-1*pretty(par("yaxp")[c(1,2)])) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
90 mtext("Scaled Read Depth",side=2,line=4.5,cex=1,font=2) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
91 dev.off() |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
92 } |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
93 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
94 fai_b = fai[fai\$V1 %in% intersect(bgM\$V1,bgP\$V1), ] |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
95 mapply( f_both, fai_b\$V1, fai_b\$V2) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
96 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
97 fai_p = fai[fai\$V1 %in% setdiff(bgP\$V1,bgM\$V1), ] |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
98 mapply( f_plus, fai_p\$V1, fai_p\$V2) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
99 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
100 fai_m = fai[fai\$V1 %in% setdiff(bgM\$V1,bgP\$V1), ] |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
101 mapply( f_minus, fai_m\$V1, fai_m\$V2) `); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
102 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
103 $R->stopR(); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
104 } |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
105 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
106 sub pie_chart |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
107 { |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
108 my $dir = shift; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
109 my $in = $dir.'repartition.txt'; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
110 my $out = $dir.'pie_chart.png'; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
111 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
112 my $R = Statistics::R->new(); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
113 $R->startR; |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
114 $R->send( |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
115 qq` |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
116 library(plotrix) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
117 library(RColorBrewer) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
118 R =read.table("$in",header=T) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
119 values = round(R\$percentage) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
120 keys = R\$type |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
121 lab = paste(values, "%", sep="") |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
122 png("$out") |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
123 colors <- brewer.pal(7,"Paired") |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
124 pie(values, col=colors, labels=lab, clockwise=TRUE) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
125 legend("bottom", legend = keys, fill=colors, bty="n", ncol = 3) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
126 par(mai = c(0,0,0,0)) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
127 layout(c(1,2),heights=c(0.3,1)) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
128 plot.new() |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
129 legend("bottom", legend = keys, fill=colors, bty="n",ncol = 3) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
130 pie(values, col=colors, labels=lab, clockwise=TRUE) |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
131 dev.off()` |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
132 ); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
133 $R->stopR(); |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
134 } |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
135 |
9185ca0a7b43
Updated package according to recommendations.
pierre.pouchin
parents:
40
diff
changeset
|
136 1; |