-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathploidyNGS_generateHistogram.R
executable file
·52 lines (47 loc) · 2.19 KB
/
ploidyNGS_generateHistogram.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env -S Rscript --vanilla
#ploidyNGS_generateHistogram.R
# __author__ = "Diego Mauricio Riano-Pachon & Renato Augusto Correa dos Santos"
# __copyright__ = "Copyright 2016,2017"
# __license__ = "GPL v3.0"
# __maintainer__ = "Diego Mauricio Riano-Pachon"
# __email__ = "[email protected]"
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#First argument must be the TAB file with allele frequencies generated by ploidyNGS
#Second argument must be the name of a PDF that will be used as output
#Third argument is xmin in a scale of 0 to 1. It is 1-AllowedMaxAlleleFreq from ploidyNGS
#Fourth argument is xmax in a scale of 0 to 1. It is AllowedMaxAlleleFreq in ploidyNGS
#Usage: Rscript --vanilla ploidyNGS_generateHistogram.R test_depth100.tab test.pdf
args = commandArgs(trailingOnly=TRUE)
xmin=as.numeric(args[3])*100
xmax=as.numeric(args[4])*100
suppressMessages(library(ggplot2))
datain<-read.table(args[1],header=F)
colnames(datain)<-c('Chrom','Pos','Type','Freq')
datain$Typt = factor(datain$Type)
hist_plot<-ggplot(datain,aes(x=Freq, fill=Type)) +
theme_bw()+
geom_histogram(binwidth = 0.5, alpha=0.4) +
ggtitle(args[1]) +
ylab("Number of heteromorphic positions") +
xlab("Allele Frequency") +
scale_x_continuous(limits=c(xmin,xmax))+
scale_fill_manual(values=c("#920000",
"#24FF24",
"#6DB6FF",
"#FFFF6D"))
#Friendly to colour-blind users:
#http://www.somersault1824.com/tips-for-designing-scientific-figures-for-color-blind-readers/
pdf(file=args[2])
suppressWarnings(print(hist_plot))
invisible(dev.off())